sentence = "MH Diagnosis: General anxiety disorder Current MH Medications: Client takes Zoloft 25mg that he just started taking. The criteria do not include level of care recommendations for a primary diagnosis of gambling, caffeine, or nicotine disorders."
diagnosis_keywords: ["Diagnosis:", "primary diagnosis of"]
extraction keywords: ["General anxiety disorder", "gambling, caffeine, or nicotine disorders.", "accident after 12 hours"]
for i in diagnosis_keywords:
if i in sentence:
# How to check whether the "General anxiety disorder" present after "Diagnosis:" keyword in sentence if True then print Diagnosis: General anxiety disorder
Required solution: Diagnosis: General anxiety disorder, Diagnosis: Gambling, caffeine, or nicotine disorders.
Is there any solution to find whether the extraction keyword present after diagnosis keywords . If true I need to extract solution in format of Eg : "Diagnosis: General anxiety disorder"
I need to check General anxiety disorder present after any of the diagnosis_keywords: ["Diagnosis:", "primary diagnosis"]. If true print Diagnosis: General anxiety disorder.
CodePudding user response:
- If you don't need high performance, here is a simple solution:
example code:
sentence = "MH Diagnosis: General anxiety disorder Current MH Medications: Client takes Zoloft 25mg that he just started taking. The criteria do not include level of care recommendations for a primary diagnosis of gambling, caffeine, or nicotine disorders."
diagnosis_keywords = ["Diagnosis:", "primary diagnosis"]
extraction_keywords = ["General anxiety disorder", "of gambling, caffeine, or nicotine disorders.", "accident after 12 hours"]
for dia_word in diagnosis_keywords:
for extra_word in extraction_keywords:
if (dia_word " " extra_word) in sentence:
print(dia_word " " extra_word)
result:
Diagnosis: General anxiety disorder
primary diagnosis of gambling, caffeine, or nicotine disorders.