Exemplo n.º 1
0
 def traverseTree(self, tree):
     
     if type(tree) is Tree:
         print "LABEL: " + tree.label()
         if tree.label() == "ROOT":
             return self.traverseTree(tree[0])
         #elif tree.label() == "S":
         #    return self.traverseTree(tree[0])
         else:
             p = Phrase()
             p.type = tree.label()
             word_idx = 0
             for subtree in tree:
                 if type(subtree) == Tree:
                     if is_pos_type( subtree.label() ):
                         w = Word()
                         w.type = subtree.label()
                         w.order = word_idx
                         w.text = str( subtree[0] )
                         word_idx += 1
                         p.words.append(w)   
                     elif is_phrase_type( subtree.label() ):
                         child_phrase = self.traverseTree( subtree )
                         p.children.append(child_phrase)
             return p
     return None
     
     
Exemplo n.º 2
0
'''
Created on Dec 1, 2015

@author: walter
'''

from parser.CYKParser import *
from language.Phrase import *

if __name__ == '__main__':
    
    SENTENCE1 = "The real voyage of discovery consists not in seeking new landscapes, but in having new eyes."
    SENTENCE2 = "go to the door"
    parser = CYKParser()
    s1 = parser.parse(SENTENCE2)
    
    FILENAME1 = "1.xml"
    FILENAME2 = "2.xml"
    s1.write_xml(FILENAME1)
    
    s2 = Phrase() 
    s2.read_xml(FILENAME1)
    print s2
    s2.write_xml(FILENAME2)