Ejemplo n.º 1
0
 def copy_subtree(self, troot, aroot):
     """\
     Deep-copy a subtree, creating nodes with the same attributes,
     but different IDs.
     """
     # assume the roots have been copied, just go through children
     for tnode in troot.get_children(ordered=1):
         # copy lemma, delete reflexive particles in verbs
         lemma = tnode.t_lemma or ''
         lemma = re.sub(r'_s[ei]$', '', lemma)
         # skip #Cor nodes
         if lemma != '#Cor':
             # create the new node
             anode = aroot.create_child()
             tnode.lex_anode = anode
             # set lemma and ord
             re.sub(r'_s[ie]$', '', lemma)
             anode.lemma = lemma
             anode.ord = tnode.ord
             # set coap afun, if needed
             if tnode.is_coap_root():
                 anode.afun = tnode.functor == 'APPS' and 'Apos' or 'Coord'
             anode.is_member = tnode.is_member
             anode.set_attr('wild/is_parenthesis', tnode.is_parenthesis)
             self.copy_subtree(tnode, anode)
         else:
             if tnode.get_children():
                 log_warn('#Cor node is not a leaf:' + tnode.id)
             self.copy_subtree(tnode, aroot)
Ejemplo n.º 2
0
 def copy_subtree(self, troot, aroot):
     """\
     Deep-copy a subtree, creating nodes with the same attributes,
     but different IDs.
     """
     # assume the roots have been copied, just go through children
     for tnode in troot.get_children(ordered=1):
         # copy lemma, delete reflexive particles in verbs
         lemma = tnode.t_lemma or ''
         lemma = re.sub(r'_s[ei]$', '', lemma)
         # skip #Cor nodes
         if lemma != '#Cor':
             # create the new node
             anode = aroot.create_child()
             tnode.lex_anode = anode
             # set lemma and ord
             re.sub(r'_s[ie]$', '', lemma)
             anode.lemma = lemma
             anode.ord = tnode.ord
             # set coap afun, if needed
             if tnode.is_coap_root():
                 anode.afun = tnode.functor == 'APPS' and 'Apos' or 'Coord'
             anode.is_member = tnode.is_member
             anode.set_attr('wild/is_parenthesis', tnode.is_parenthesis)
             self.copy_subtree(tnode, anode)
         else:
             if tnode.get_children():
                 log_warn('#Cor node is not a leaf:' + tnode.id)
             self.copy_subtree(tnode, aroot)
Ejemplo n.º 3
0
 def drop_anode(self, tnode):
     "Remove the lexical a-node corresponding to the given t-node"
     anode = tnode.lex_anode
     if not anode:
         log_warn("Can't find a-node to be dropped:" + tnode.id)
         return
     # this should not happen, but just to be sure - rehang children
     for achild in anode.get_children():
         achild.parent = anode.parent
     # remove the node itself
     anode.remove()