def appositive(pair,parsed_sentences): if pair.first.sentenceID == pair.second.sentenceID: index1 = eval(pair.first.offsets[0]) index2 = eval(pair.second.offsets[0]) #print index1,index2 #print pair.first.str,pair.second.str tree = parsed_sentences[eval(pair.first.sentenceID)] #print tree1,tree2 path1 = list(tree.leaf_treeposition(index1)) path2 = list(tree.leaf_treeposition(index2)) if index1 < index2: dominate_path = tree.treeposition_spanning_leaves(index1,index2+1) else: dominate_path = tree.treeposition_spanning_leaves(index2,index1+1) dept = len(dominate_path) subtree = copy.deepcopy(tree) #print index1,index2 #print dominate_path for i in list(dominate_path): temp = subtree[i] subtree = temp #print subtree if subtree.node == 'NP': if subtree[path1[dept]].node == 'NP' and subtree[path2[dept]].node == 'NP': if path1[dept] == (path2[dept] - 2) and subtree[path1[dept]+1].node == ',': return True if path1[dept] == (path2[dept] + 2) and subtree[path1[dept]-1].node == ',': return True return False
def span_np(pair,parsed_sentences): if pair.first.sentenceID == pair.second.sentenceID and pair.first.type in nouns and pair.second.type in nouns: index1 = eval(pair.first.offsets[0]) index2 = eval(pair.second.offsets[0]) #print index1,index2 #print pair.first.str,pair.second.str tree = parsed_sentences[eval(pair.first.sentenceID)] #print tree1,tree2 if index1 < index2: dominate_path = tree.treeposition_spanning_leaves(index1,index2+1) else: dominate_path = tree.treeposition_spanning_leaves(index2,index1+1) subtree = copy.deepcopy(tree) for i in list(dominate_path): temp = subtree[i] subtree = temp return subtree.node return "unknown"