Ejemplo n.º 1
0
 def var(self, node):
     if self.do_indent: self.data += self.indent
     if node.value == Element():
         self.data += 'Var({0})'.format(repr(node.id))
     else:
         self.data += 'Var({0}, {1})'.format(repr(node.id),
                                             repr(node.value))
Ejemplo n.º 2
0
 def noun_phrase(self, node):
     if node.specifier != Element():
         node.specifier.accept(self)
     for mod in node.premodifiers:
         mod.accept(self)
     node.head.accept(self)
     for mod in node.complements:
         mod.accept(self)
     for mod in node.postmodifiers:
         mod.accept(self)
Ejemplo n.º 3
0
 def noun_phrase(self, node):
     if self.do_indent: self.data += self.indent
     self.data += 'NounPhrase('
     self.indent += ' ' * len('NounPhrase(')
     self.do_indent = False
     node.head.accept(self)
     if node.specifier != Element():
         self.data += ', '
         node.specifier.accept(self)
     self.data += ')'
     self.do_indent = True
     self.indent = self.indent[:-len('NounPhrase(')]
Ejemplo n.º 4
0
 def noun_phrase(self, node):
     if self.do_indent: self.data += self.indent
     self.data += 'NounPhrase('
     self.indent += ' ' * len('NounPhrase(')
     self.do_indent = False
     node.head.accept(self)
     if node.specifier != Element():
         self.data += ', '
         node.specifier.accept(self)
     self.add_features(node)
     self.do_indent = True
     self._process_elements(node, 'premodifiers')
     self._process_elements(node, 'complements')
     self._process_elements(node, 'postmodifiers')
     self.data += ')'
     self.indent = self.indent[:-len('NounPhrase(')]
Ejemplo n.º 5
0
def replace_element_with_id(sent, elt_id, replacement=None):
    import warnings
    warnings.warn('replace_element is deprecated')

    if id(sent) == elt_id:
        return True

    if isinstance(sent, Coordination):
        for i, o in list(enumerate(sent.coords)):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.coords[i]
                else:
                    sent.coords[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True

    if isinstance(sent, Clause):
        for i, o in reversed(list(enumerate(sent.premodifiers))):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.premodifiers[i]
                else:
                    sent.premodifiers[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True

        if id(sent.subject) == elt_id:
            sent.subject = replacement or Element()
            return True
        else:
            if replace_element_with_id(sent.subject, elt_id, replacement):
                return True

        if id(sent.predicate) == elt_id:
            sent.predicate = replacement
            return True

        else:
            if replace_element_with_id(sent.predicate, elt_id, replacement):
                return True

        for i, o in reversed(list(enumerate(sent.complements))):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.complements[i]
                else:
                    sent.complements[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True

        for i, o in reversed(list(enumerate(sent.postmodifiers))):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.postmodifiers[i]
                else:
                    sent.postmodifiers[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True

    if isinstance(sent, Phrase):
        for i, o in reversed(list(enumerate(sent.postmodifiers))):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.postmodifiers[i]
                else:
                    sent.postmodifiers[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True
        for i, o in reversed(list(enumerate(sent.complements))):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.complements[i]
                else:
                    sent.complements[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True
        if id(sent.head) == elt_id:
            sent.head = replacement
            return True
        for i, o in reversed(list(enumerate(sent.premodifiers))):
            if id(o) == elt_id:
                if replacement is None:
                    del sent.premodifiers[i]
                else:
                    sent.premodifiers[i] = replacement
                return True
            else:
                if replace_element_with_id(o, elt_id, replacement):
                    return True

        if isinstance(sent, NounPhrase):
            if sent.specifier == elt_id:
                sent.specifier = replacement
                return True
    return False
Ejemplo n.º 6
0
 def var(self, node):
     if self.do_indent: self.data += self.indent
     if node.value == Element():
         self.data = ' '.join((self.data, str(node.id)))
     else:
         self.data = ' '.join((self.data, str(node.value)))