def checkForInverterWordInPreceedingSentence(self, sentence, argExtractor): #TODO: Work on an NLTK contractions aclass to filer out words like not etc symtomStatements = [ 'side-effects', 'side effects', 'symptoms', 'symptom' ] # Extract the words preceeding the symptomStatement keyword preceedingSentence = '' sideEffectStatus = '' listOfContractions = argExtractor.getListOfContractions() expandedSentence = messageCleaner.replaceWordContractions( sentence, listOfContractions) for symptomStatement in symtomStatements: indexOfSymptomKeyWord = expandedSentence.find(symptomStatement) if indexOfSymptomKeyWord == -1: continue # We pull out the preceeeding sentence. We have a -1 here in the final index range so that we can remove the space before the key symptom word preceedingSentence = expandedSentence[0:(indexOfSymptomKeyWord - 1)] break # This means we could not find the key word from the side effects list if preceedingSentence == '': return (False, sideEffectStatus) try: taggedSentence = naturalLanguageWhiz.tag(preceedingSentence) if len(taggedSentence) <= 0: return (False, sideEffectStatus) except: logger.exception('Error when running checkForMentionOfNoSymptoms') return (False, sideEffectStatus) result = argExtractor.checkIfInverterWordInSentence(taggedSentence) if result == True: sideEffectStatus = 'Possibly no side effects' return (True, sideEffectStatus) else: sideEffectStatus = 'Side effects Present - because no preceeding inverterword' return (False, sideEffectStatus)
def checkForInverterWordInPreceedingSentence(self, sentence, argExtractor): #TODO: Work on an NLTK contractions aclass to filer out words like not etc symtomStatements = ['side-effects', 'side effects', 'symptoms', 'symptom'] # Extract the words preceeding the symptomStatement keyword preceedingSentence = '' sideEffectStatus = '' listOfContractions = argExtractor.getListOfContractions() expandedSentence = messageCleaner.replaceWordContractions(sentence, listOfContractions) for symptomStatement in symtomStatements: indexOfSymptomKeyWord = expandedSentence.find(symptomStatement) if indexOfSymptomKeyWord == -1: continue # We pull out the preceeeding sentence. We have a -1 here in the final index range so that we can remove the space before the key symptom word preceedingSentence = expandedSentence[0:(indexOfSymptomKeyWord - 1)] break # This means we could not find the key word from the side effects list if preceedingSentence == '': return (False, sideEffectStatus) try: taggedSentence = naturalLanguageWhiz.tag(preceedingSentence) if len(taggedSentence) <= 0: return (False, sideEffectStatus) except: logger.exception('Error when running checkForMentionOfNoSymptoms') return (False, sideEffectStatus) result = argExtractor.checkIfInverterWordInSentence(taggedSentence) if result == True: sideEffectStatus = 'Possibly no side effects' return (True, sideEffectStatus) else: sideEffectStatus = 'Side effects Present - because no preceeding inverterword' return (False, sideEffectStatus)
def checkForMentionOfNoSymptoms(self, sentence, argExtractor): symtomStatements = [ 'side-effects', 'side effects', 'symptoms', 'symptom' ] # Extract the words preceeding the symptomStatement keyword preceedingSentence = '' symptomMentioned = '' for symptomStatement in symtomStatements: indexOfSymptomKeyWord = sentence.find(symptomStatement) if indexOfSymptomKeyWord == -1: continue # We pull out the preceeeding sentence. We have a -1 here in the final index range so that we can remove the space before the key symptom word preceedingSentence = sentence[0:(indexOfSymptomKeyWord - 1)] break # This means we could not find the key word from the side effects list if preceedingSentence == '': return (False, symptomMentioned) try: taggedSentence = naturalLanguageWhiz.tag(preceedingSentence) if len(taggedSentence) <= 0: return (False, symptomMentioned) except: logger.exception('Error when running checkForMentionOfNoSymptoms') return (False, symptomMentioned) result = argExtractor.checkIfInverterWordEndOfSentence(taggedSentence) if result == True: symptomMentioned = 'No Side Effects' return (True, symptomMentioned) else: symptomMentioned = 'Side effects Present - because of no direct inverter word before ' return (False, symptomMentioned)
def checkForMentionOfNoSymptoms(self, sentence, argExtractor): symtomStatements = ['side-effects', 'side effects', 'symptoms', 'symptom'] # Extract the words preceeding the symptomStatement keyword preceedingSentence = '' symptomMentioned = '' for symptomStatement in symtomStatements: indexOfSymptomKeyWord = sentence.find(symptomStatement) if indexOfSymptomKeyWord == -1: continue # We pull out the preceeeding sentence. We have a -1 here in the final index range so that we can remove the space before the key symptom word preceedingSentence = sentence[0:(indexOfSymptomKeyWord - 1)] break # This means we could not find the key word from the side effects list if preceedingSentence == '': return (False, symptomMentioned) try: taggedSentence = naturalLanguageWhiz.tag(preceedingSentence) if len(taggedSentence) <= 0: return (False, symptomMentioned) except: logger.exception('Error when running checkForMentionOfNoSymptoms') return (False, symptomMentioned) result = argExtractor.checkIfInverterWordEndOfSentence(taggedSentence) if result == True: symptomMentioned = 'No Side Effects' return (True, symptomMentioned) else: symptomMentioned = 'Side effects Present - because of no direct inverter word before ' return (False, symptomMentioned)