def pycontextnlp_markup_sentence(s, modifiers, targets, prune_inactive=True): markup = pyConText.ConTextMarkup() markup.setRawText(s) markup.cleanText() markup.markItems(modifiers, mode="modifier") markup.markItems(targets, mode="target") markup.pruneMarks() markup.dropMarks('Exclusion') markup.applyModifiers() markup.pruneSelfModifyingRelationships() if prune_inactive: markup.dropInactiveModifiers() list_negated_edges = [] for edge in markup.edges(): # modifier_category = edge[0].getCategory() # if('neg' in modifier_category[0]): # # print(edge) # list_negated_edges.append(edge) list_negated_edges.append(edge) return list_negated_edges
def markup_sentence(s, modifiers, targets, prune_inactive=True): """ """ markup = pyConText.ConTextMarkup() markup.setRawText(s) markup.cleanText() markup.markItems(my_modifiers, mode="modifier") markup.markItems(my_targets, mode="target") markup.pruneMarks() markup.dropMarks('Exclusion') # apply modifiers to any targets within the modifiers scope markup.applyModifiers() markup.pruneSelfModifyingRelationships() if prune_inactive: markup.dropInactiveModifiers() return markup
def test_1(self): sent1 = 'IMPRESSION: 1. R/O STUDY DEMONSTRATING NO GROSS EVIDENCE OF SIGNIFICANT PULMONARY EMBOLISM.' print(os.getcwd()) modifiers = itemData.get_items( os.path.join(os.getcwd(), "../../KB/pneumonia_modifiers.yml")) targets = itemData.get_items( os.path.join(os.getcwd(), "../../KB/pneumonia_targets.yml")) markup = pyConText.ConTextMarkup() markup.setRawText(sent1.lower()) markup.markItems(modifiers, mode="modifier") markup.markItems(targets, mode="target") found = False for node in markup.nodes(data=True): if 'r/o' in str(node): found = True assert found
def analyze_sentence(sentence, modifiers, targets, tagExperiencer=False): context = pyConText.ConTextDocument() markup = pyConText.ConTextMarkup() markup.setRawText(sentence) markup.markItems(modifiers, mode="modifier") markup.markItems(targets, mode="target") markup.pruneMarks() markup.dropMarks('Exclusion') markup.applyModifiers() markup.dropInactiveModifiers() markup.updateScopes() context.addMarkup(markup) g = context.getDocumentGraph() ma = g.getMarkedTargets() tst = [] details = [] found = {} for te in ma: #print ma tmp1, tmp2 = getNegationValue(g, te) if tagExperiencer: e1, e2 = getExperiencerValue(g, te) if e1 != 'Other': tst.append(tmp1) details.append(tmp2) found[tmp2] = Counter(tmp1) else: tst.append(tmp1) details.append(tmp2) found[tmp2] = Counter(tmp1) return tst, details
"https://raw.githubusercontent.com/chapmanbe/pyConTextNLP/20c752d6bd5191833f21ab81fc7f41877dca1db6/KB/pneumonia_modifiers.yml" ) for i in range(len(sentences)): # omg targets = [] with open('./hpo_labels.txt') as labelfile: reader = csv.reader(labelfile, delimiter='\t') for row in reader: if (row[1] == iris[i]): targets.append(contextItem((row[0], row[1], '', ''))) s = sentences[i] markup = pyConText.ConTextMarkup() markup.setRawText(s.lower()) markup.cleanText() markup.markItems(modifiers, mode="modifier") markup.markItems(targets, mode="target") markup.applyModifiers() markup.pruneMarks() markup.pruneSelfModifyingRelationships() markup.dropInactiveModifiers() foundTargets = [ n[0] for n in markup.nodes(data=True) if n[1].get("category", "") == 'target' ]