コード例 #1
0
def test():
    print "hello"
    syntactic_tree1 = SyntacticTree.read_tree("(VP (VBZ kill) (NP (N man)))")
    syntactic_tree2 = SyntacticTree.read_tree("(VP (VBZ murder) (NP (N man)))")
    kernel = SyntacticTreeKernel(0.4)
    print syntactic_tree1
    print syntactic_tree2
    print [node._label for node in syntactic_tree1.get_nodes()]
コード例 #2
0
def test():
    print "hello"
    syntactic_tree1 = SyntacticTree.read_tree("VP (VBZ play-v) (NP (N guitar-n))")
    syntactic_tree2 = SyntacticTree.read_tree("VP (VBZ play-v) (NP (N instrument-n))")
    lexical_space = io_utils.load("/home/thenghiapham/work/project/tree_kernel/spaces/lexical_ppmi_svd300.pkl")
    kernel = SemanticSyntacticTreeKernel(1.0, lexical_space)
    print syntactic_tree1
    print syntactic_tree2
    print [node._label for node in syntactic_tree1.get_nodes()] 
コード例 #3
0
 def test_read_tree(self):
     test_cases = [self.tree_string1,
                   self.tree_string2]
     for tree_string in test_cases:
         syntactic_tree = SyntacticTree.read_tree(tree_string)
         output_tree_string = str(syntactic_tree)
         self.assertEqual(tree_string,output_tree_string, 
                          "tree strings must be the same")
コード例 #4
0
   </rule>
 </ccg>'''
 
 # parse the tree from the xml string
 syntactic_tree = SyntacticTree.parse_tree_from_xml_string(xml_string)
 
 # print the tree
 print "the syntactic tree:"
 print syntactic_tree, "\n"
 
 # print the height of the tree (for fun)
 print "height of the tree:"
 print syntactic_tree.root.get_height(), "\n"
 
 # get the nodes of the tree
 nodes = syntactic_tree.get_nodes()
 
 # print the label/cat of the nodes
 print "the labels of the nodes:"
 for node in nodes:
     print node.label
 
 # get the string from the tree
 tree_string = str(syntactic_tree)
 
 # read the tree from the string again
 syntactic_tree =  SyntacticTree.read_tree(tree_string)
 
 # check if the tree string is still the same
 assert(tree_string == str(syntactic_tree))