def subgraph_to_string(graph,node,exclude=[]): nodes = [node] change = True while change: change=False for curNode in nodes: for curNeigbour in graph.neighbors(curNode): if (curNeigbour in nodes) or (curNeigbour in exclude): continue nodes.append(curNeigbour) change = True # minInd = min([n.minIndex() for n in nodes])-1 # maxInd = max([n.maxIndex() for n in nodes])-1 # ret = " ".join(graph.originalSentence.split(" ")[minInd:maxInd+1]) # nodes = [n for n in minimal_spanning_tree(graph, node) if not n in exclude] # ret = " ".join(node.get_original_text() for node in sorted(nodes,key = lambda n: n.minIndex())) try: ret = "" words = [] for n in nodes: words += n.surface_form words = list(set(words)) ret = " ".join([w.word for w in strip_punctuations(sorted(words,key=lambda w:w.index))])+" " except: raise Exception() # return ret
def subgraph_to_string(graph, node, exclude=[]): nodes = [node] change = True while change: change = False for curNode in nodes: for curNeigbour in graph.neighbors(curNode): if (curNeigbour in nodes) or (curNeigbour in exclude): continue nodes.append(curNeigbour) change = True # minInd = min([n.minIndex() for n in nodes])-1 # maxInd = max([n.maxIndex() for n in nodes])-1 # ret = " ".join(graph.originalSentence.split(" ")[minInd:maxInd+1]) # nodes = [n for n in minimal_spanning_tree(graph, node) if not n in exclude] # ret = " ".join(node.get_original_text() for node in sorted(nodes,key = lambda n: n.minIndex())) try: ret = "" words = [] for n in nodes: words += n.surface_form words = list(set(words)) ret = " ".join([ w.word for w in strip_punctuations(sorted(words, key=lambda w: w.index)) ]) + " " except: raise Exception() # return ret
def __str__(self): ret = '<TABLE BORDER="0" CELLSPACING="0"><TR><TD>' filtered_spans = [] for feat,_ in PRINT_FEATURES: if (feat in self.features) and (isinstance(self.features[feat], dict)) and ("Span" in self.features[feat]): filtered_spans.extend(self.features[feat]["Span"]) if 'Lemma' in self.features and len(self.text)==1: self.str = [Word(index = self.text[0].index,word=self.features['Lemma'])] else: ls = self.text if self.orderText: ls = sorted(self.text,key=lambda word:word.index) # self.str stores the words as displayed in the node self.str = [w for w in ls if w.index not in filtered_spans] self.str = strip_punctuations(self.str) ret+= " ".join([str(x) for x in self.str]) ret+="</TD></TR>" for feat, printFunc in PRINT_FEATURES: if feat in self.features: if self.isPredicate and feat =="Definite": continue ret += "<TR><TD>" ret+= '<FONT POINT-SIZE="10">{0}</FONT>'.format(cgi.escape(str(printFunc(self.features[feat])))) ret+="</TD></TR>" ret +="</TABLE>" return ret
def __str__(self): ret = '<TABLE BORDER="0" CELLSPACING="0"><TR><TD>' filtered_spans = [] for feat,_ in PRINT_FEATURES: if (feat in self.features) and (isinstance(self.features[feat], dict)) and ("Span" in self.features[feat]): filtered_spans.extend(self.features[feat]["Span"]) if 'Lemma' in self.features and len(self.text)==1: self.str = [Word(index = self.text[0].index,word=self.features['Lemma'])] else: ls = self.text if self.orderText: ls = sorted(self.text,key=lambda word:word.index) # self.str stores the words as displayed in the node self.str = [w for w in ls if w.index not in filtered_spans] self.str = strip_punctuations(self.str) ret+= " ".join([str(x) for x in self.str]) ret+="</TD></TR>" for feat, printFunc in PRINT_FEATURES: if feat in self.features: if self.isPredicate and feat =="Definite": continue if self.features.get("Determiner",{"Value":""})["Value"] == "no": del(self.features["Determiner"]) continue ret += "<TR><TD>" ret+= '<FONT POINT-SIZE="10">{0}</FONT>'.format(cgi.escape(str(printFunc(self.features[feat])))) ret+="</TD></TR>" ret +="</TABLE>" return ret