Пример #1
0
 def _RELCLAUSE_PREDICATE_FEATURE_Prop(self):
     subj,obj = [""]*2
     pred = self.rcChild.word
     
     if self.rcmodRel in subject_dependencies:
         subj = self.word
         dobjs = any_in([x.parent_relation for x in self.rcChild.children],[DIRECT_OBJECT_LABEL])
         if dobjs:
             obj = self.rcChild.children[dobjs[0]].get_original_sentence(False)
         else:
             objs = any_in([x.parent_relation for x in self.rcChild.children],[OBJECT_LABEL])
             if objs:
                 obj = self.rcChild.children[objs[0]].get_original_sentence(False)
             else:
                 objs = any_in([x.parent_relation for x in self.rcChild.children],object_dependencies)
                 if objs:
                     obj = self.rcChild.children[objs[0]].get_original_sentence(False)
             
     elif self.rcmodRel in object_dependencies:
         obj = self.word
         subjs = any_in([x.parent_relation for x in self.rcChild.children],subject_dependencies)
         if subjs:
             subj = self.rcChild.children[subjs[0]].get_original_sentence(False)
     
     return {"Value":"{0}:({1},{2})".format(pred,subj,obj),
             "Span":[self.id]}
Пример #2
0
 def _PREPOSITIONAL_PREDICATE_FEATURE_pobj(self):
     prepChild = self.children[self.prepChildInd]
     if not prepChild.children:
         return {"Value":False,
                 "Span":{}}
     pobjChildren = any_in([c.parent_relation for c in prepChild.children], ["pobj"])
     pcompChildren = any_in([c.parent_relation for c in prepChild.children], ["pcomp"])
     if (len(pobjChildren)>1) or (len(pcompChildren)>1):
         print pobjChildren
         print self.word
         print GraphParsingException("misproper handling for more than one pobj child " +self.report())
     
     if pobjChildren:
         pobjChild = prepChild.children[pobjChildren[0]]
     else:
         pobjChild = False
     if pcompChildren:
         pcompChild = prepChild.children[pcompChildren[0]]
     else:
         pcompChild = False
     
     
     retChild = pcompChild
     #stick obj child under compchild
     if pcompChild and pobjChild:
         pcompChild.children.append(pobjChild)
         pobjChild.parent = pcompChild
         pobjChild.parent_id = pcompChild.id
     elif pobjChild:
         retChild = pobjChild
         
     if not retChild:
         #TODO: no pcomp and no pobj - return the prep child itself
         retChild = prepChild
     
     else:
     
         notPobjChildren = [x for i,x in enumerate(prepChild.children) if i not in pobjChildren+pcompChildren]
         # workaround to deal with cases where there're more than just pobj children - put them all under pobj
         for curChild in notPobjChildren:
             retChild.children.append(curChild)
             curChild.parent = retChild
             curChild.parent_id = retChild.id
     
     if (retChild.word.lower() == "to") and len(retChild.children)==1:
         retChild = retChild.children[0]
         self.prepType += " to"
         
     
     #self.children.remove(self.children[self.possChild[0]])
     #d = self._get_subtree_nodes(includeHead = True)
     ret = {"Value":retChild,
            "Span":{}}
     return ret
Пример #3
0
    def is_copular_predicate(self):
        if (self.word.lower() in copular_verbs) and (self.is_verbal_predicate()):
            self.copSubj = any_in([c.parent_relation for c in self.children],subject_dependencies)
    
            if self.copSubj:
                if len(self.copSubj) !=1:
#TODO                    print "subj - " + self.get_original_sentence(False)
                    return []
                self.copObj = any_in([c.parent_relation for c in self.children],clausal_complements)
                if len(self.copObj) !=1:
#TODO                    print "obj - " + self.get_original_sentence(False)
                    return []
            #print " , ".join([c.parent_relation for c in self.children])
                return [self]
        return []
Пример #4
0
 def is_conjunction_predicate(self):
     self.conjResult = []
     conjChildIndList = any_in([c.parent_relation for c in self.children], conjunction_dependencies)
     if not conjChildIndList:
         return False
     childrenCopy = [x for x in self.children]
     self.children = [x for i,x in enumerate(self.children) if i not in conjChildIndList and 
                      x.parent_relation !='conj']
     self.baseElm = copy.copy(self)
     self.children = childrenCopy
     
     cc = []
     conjElements = []
     for child in self.children:
         if child.parent_relation == 'cc':
             if cc and (cc[-1][0] != child.id-1):
                 self.conjResult.append((copy.copy(cc),copy.copy(conjElements)))
                 cc = []
                 conjElements = []
             cc.append((child.id,child.word))
             
                 
         elif child.parent_relation == 'conj':
             conjElements.append(child)              
     
     if cc:
         self.conjResult.append((copy.copy(cc),copy.copy(conjElements)))
     
     return True
Пример #5
0
 def is_verbal_predicate(self):
     child_dic = self._get_child_dic()
     if self.parent_relation in aux_cop_dependencies:
         return []
     if self.pos in VERB_POS:
         return [self]
     if (self.pos == VBG) and any_in(child_dic.keys(),arguments_dependencies):
         return [self]
     return []
Пример #6
0
 def is_possesive_predicate(self):
     possChildList = any_in([c.parent_relation for c in self.children], [POSS_LABEL])
     ret = []
     # for each possessive create a different predicate
     for poss in possChildList:
         #poss child holds the index of the possesor
         if self.children[poss].is_determined():
             self.possChild = [poss]
             ret.append(copy.copy(self))
             self.adjectivalChild=[]
         
     return ret
Пример #7
0
 def is_conditional_predicate(self):
     self.condPred = []
     self.markChildren = [] 
     for childInd,child in enumerate(self.children):
         if child.parent_relation in clausal_modifiers_labels:
             self.condRel = []
             markChildList = [x for x in any_in([c.parent_relation for c in child.children], ["mark"])
                              if len(child.children[x].children)==0]
             if not markChildList:
                 markChildList = [x for x in any_in([c.parent_relation for c in child.children], ["advmod"])
                                  if len(child.children[x].children)==0]
             if len(markChildList)>0:
                 # return the parent of this node, and mark the way to the mark child
                 self.markChildNode = child
                 self.markChildren.append(childInd)
                 for markChildInd in sorted(markChildList,reverse=True): # append all marks - Assuming this is a dep limitation, see sentence 129 ("so that")
                     curChild = child.children[markChildInd]
                     self.condRel = [curChild] + self.condRel
                     child.children.remove(curChild)
                                             
                 self.condPred.append(copy.copy(self)) 
 #             elif len(markChildList)>1:
 #                 raise GraphParsingException("No handling for more that one mark ")
     return self.condPred
Пример #8
0
 def is_relative_clause(self):
     self.rcChildIndList = any_in([c.parent_relation for c in self.children], relclause_dependencies)
     ret = []
     
     for c in self.rcChildIndList:    
         self.rcChildIndex = c
         self.rcChild = self.children[c]
         
         # find markers
         inds = any_in([x.word.strip() for x in self.rcChild.children],
                       relclause_markers)
         
         # if there is a marker, check if it has a suitable relation
         self.possRels = [(x,self.rcChild.children[x].parent_relation) for x in inds 
                     if self.rcChild.children[x].parent_relation in object_dependencies + subject_dependencies]
         
         if self.possRels:
             assert len(self.possRels)==1
             self.rcmodRel = self.possRels[0][1]
             #remove the marker from tree
             del(self.rcChild.children[self.possRels[0][0]])
             
         # else - find what of (subj, dobj, iobj) doesn't exist
         else:
             rels = [x.parent_relation for x in self.rcChild.children]
             if not any_in(rels,subject_dependencies):
                 self.rcmodRel = SUBJ_LABEL
             elif not ((DIRECT_OBJECT_LABEL in rels) or (OBJECT_LABEL in rels)):
                 self.rcmodRel = DIRECT_OBJECT_LABEL
             else:
                 self.rcmodRel = INDIRECT_OBJECT_LABEL
         
         self.rcType = self.rcChild.parent_relation
         ret.append(copy.copy(self))
     self.rcmodPred = ret
     return ret
Пример #9
0
 def is_clausal_complement(self):
     compChildIndList = any_in([c.parent_relation for c in self.children], clausal_complements)
     d1 = self._get_child_dic()
     if self.parent_relation == 'ccomp':
         for c1 in d1.get('advcl',[]):
             d2 = c1._get_child_dic()
             if MARK_LABEL not in d2:
                 compChildIndList.append(self.children.index(c1))
         
         
     if not compChildIndList:
         return False
     self.compChildList = [self.children[ind] for ind in compChildIndList]
     children_copy = [c for c in self.children]
     self.children = [children_copy[i] for i in range(len(self.children)) 
                      if i not in compChildIndList]
     self.compSubj = copy.copy(self)
     self.children = children_copy
     return True
Пример #10
0
 def is_prepositional_predicate(self):
     self.prepChildIndList = any_in([c.parent_relation for c in self.children], prepositions_dependencies)
     self.prepChildIndList.extend([i for i in range(len(self.children))
                                   if (self.children[i].pos == 'TO') and  (self.children[i].parent_relation == 'dep')])
     ret = []
     
     for prep in self.prepChildIndList:     
         self.prepChildInd = prep
         prepChild = self.children[self.prepChildInd]
         childDic = prepChild._get_child_dic()
         extraChildren = childDic.get('advmod',[]) + childDic.get('mwe',[]) 
         self.prepType = " ".join([c.word for c in sorted([prepChild] + extraChildren,key=lambda c:c.id)])
         self.prepInd = prepChild.id
         #children_copy = [c for c in prepChild.children]
         prepChild.children = [c for c in prepChild.children if c not in extraChildren]
         ret.append(copy.copy(self))
         #prepChild.children = children_copy
         self.prepChildInd=[]
         
     self.prepChildList = ret
     return ret