0

I have created the following function to do a boolean search:

def searchString(string):
    if (('ehr' or 'electronic health record' or 'emr' or 'electronic medical record' or 'text narratives' or 'hospital records' or 'electronic patient records' or 'mental health record') and ('natural language processing' or 'nlp' or 'text mining' or 'information extraction' or 'natural language generation' or 'information retrieval' or 'narrative extraction' or 'narrative processing') and ('psych' or 'mental')) in string:
        return True
    return False

When I ran this function on my Pandas dataframe it returned False on this text:

natural language processing for structuring clinical text data on depression using uk-cris. background: utilisation of routinely collected electronic health records from secondary care offers unprecedented possibilities for medical science research but can also present difficulties. one key issue is that medical information is presented as free-form text and, therefore, requires time commitment from clinicians to manually extract salient information. natural language processing (nlp) methods can be used to automatically extract clinically relevant information. objective: our aim is to use natural language processing (nlp) to capture real-world data on individuals with depression from the clinical record interactive search (cris) clinical text to foster the use of electronic healthcare data in mental health research. methods: we used a combination of methods to extract salient information from electronic health records. first, clinical experts define the information of interest and subsequently build the training and testing corpora for statistical models. second, we built and fine-tuned the statistical models using active learning procedures. findings: results show a high degree of accuracy in the extraction of drug-related information. contrastingly, a much lower degree of accuracy is demonstrated in relation to auxiliary variables. in combination with state-of-the-art active learning paradigms, the performance of the model increases considerably. conclusions: this study illustrates the feasibility of using the natural language processing models and proposes a research pipeline to be used for accurately extracting information from electronic health records. clinical implications: real-world, individual patient data are an invaluable source of information, which can be used to better personalise treatment. ci - (c) author(s) (or their employer(s)) 2020. no commercial re-use. see rights and permissions. published by bmj.

And it returned True on this text:

artificial intelligence approaches to predicting and detecting cognitive decline in older adults: a conceptual review. preserving cognition and mental capacity is critical to aging with autonomy. early detection of pathological cognitive decline facilitates the greatest impact of restorative or preventative treatments. artificial intelligence (ai) in healthcare is the use of computational algorithms that mimic human cognitive functions to analyze complex medical data. ai technologies like machine learning (ml) support the integration of biological, psychological, and social factors when approaching diagnosis, prognosis, and treatment of disease. this paper serves to acquaint clinicians and other stakeholders with the use, benefits, and limitations of ai for predicting, diagnosing, and classifying mild and major neurocognitive impairments, by providing a conceptual overview of this topic with emphasis on the features explored and ai techniques employed. we present studies that fell into six categories of features used for these purposes: (1) sociodemographics; (2) clinical and psychometric assessments; (3) neuroimaging and neurophysiology; (4) electronic health records and claims; (5) novel assessments (e.g., sensors for digital data); and (6) genomics/other omics. for each category we provide examples of ai approaches, including supervised and unsupervised ml, deep learning, and natural language processing. ai technology, still nascent in healthcare, has great potential to transform the way we diagnose and treat patients with neurocognitive disorders. ci - copyright (c) 2019 elsevier b.v. all rights reserved.

Because the first text contains the elements 'natural language processing', 'electronic health record' and 'mental', I expect it to be True, but it returns False. Who can tell me what I am doing wrong here?

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Emil
  • 1,531
  • 3
  • 22
  • 47
  • 1
    Look into the precedence of the `in` operator. A hint: You should be writing `('ehr' in string) or ('emr' in string)`. – rassar Feb 21 '20 at 15:49
  • 1
    To add onto rassar's statement, currently python sees your if statement as `if True in string:`. – Error - Syntactical Remorse Feb 21 '20 at 15:50
  • Use a list with all the values to check. Filter or loop through the list to check. – m0dknight Feb 21 '20 at 15:53
  • 1
    @Error-SyntacticalRemorse: Actually, it's equivalent to `if 'psych' in string:`, which is why the OP sees `True` for the second input (it has "psychological" in it); Python's `and` and `or` evaluate to the last operand evaluated (so for `and`, the first falsy operand or the last operand if none are falsy, for `or`, the first truthy operand, or the last operand if none are truthy). Since all the values are truthy (being non-empty) the `and` chain selects the last block of `or`s, and the last block of `or`s returns the first element, `'psych'`. – ShadowRanger Feb 21 '20 at 15:54

0 Answers0