예제 #1
0
 def load_trees(self):
     sfs = get_start_feature(self.catalog.cata)
     sfs = remove_or_tag(sfs)
     t = parse_from_files(self.catalog.cata, 'tree-files', self.language)
     t += parse_from_files(self.catalog.cata, 'family-files', self.language)
     t.set_start_fs(sfs)
     return t
예제 #2
0
    def get_lexicalized_trees(self, word, pos=None):
        """
        Takes a word and an optional pos and returns all trees lexicalized with 
        the given word.
        """

        morph_entries = self.word_to_morphologies(word, pos)
        feature_list = self.morphologies_to_features(morph_entries, word, pos)

        lex_trees = []
        for entry_pos_list, tree_list, family_list, syn_feature, morph_feature in feature_list:
            tree_names = set(tree_list)
            for family in family_list:
                tree_names.update(set(self.trees.family_to_tree_names(family)))

            for tree_name in tree_names:
                tree = self.trees.find_tree(tree_name).copy(deep=True)
                tree.init_lex(entry_pos_list, remove_or_tag(syn_feature), remove_or_tag(morph_feature))
                tree.lexicalize()
                lex_trees.append(tree)

        return lex_trees
예제 #3
0
def test_relative_clauses():
    from xtag.xtag_nltk.xparse import perform_substitution, perform_adjunction, perform_all_substitutions, perform_all_adjunctions
    from xtag.xtag_nltk.feature import remove_or_tag
    g = Grammar('english')

    dog_tree = g.get_lexicalized_tree('dog', '\x02NXN')
    chase_tree = g.get_lexicalized_tree('chase', '\x03Nc0nx0Vnx1')
    t = perform_all_adjunctions(dog_tree, chase_tree, feature_enabled=True)[0]

    that_tree = g.get_lexicalized_tree('that', '\x03COMPs')
    adj_node_success = t.search('S_2')
    adj_node_fail = t.search('S_p')

    t2 = perform_adjunction(t, that_tree, adj_node_success, feature_enabled=True)
    t3 = perform_adjunction(t, that_tree, adj_node_fail, feature_enabled=True)

    print(remove_or_tag(t2.get_all_fs()))
    t2.draw()