Esempio n. 1
0
 def grammar(cls):
     return Grammar.load()
Esempio n. 2
0
        else:
            print(tree_name, anchor)
            raise NotImplementedError

        node_dict = sem_map[key]
        for node_label, (sem_str, var_str) in node_dict.items():
            sem_str = sem_str(anchor)
            node = tree.find(node_label)
            node.semantics = SemanticParser.parse(sem_str)
            var, rest = VariableParser.parse(var_str)
            node.sem_var = var

        return tree

if __name__ == '__main__':
    g = Grammar.load()
    vnet = VerbNet.load()
    mapper = XTAGMapper.load()
    propbank = Propbank.load()
    s = SemTreeGrammar(g, vnet, mapper, propbank)

    jump = s.get_semtree('alphanx0Vnx1', 'jumped', lemma='run')
    tree_families = set(mapper.xtag_mapping.values())
    all_trees = set()
    for tf in tree_families:
        all_trees.update([t.tree_name for t in g.get_trees_from_tree_family(tf)])
        print(tf)
    #for tree_name in sorted(all_trees):
    #    print(tree_name)

    '''
import re, nltk, sys, heapq
import graphviz as gv
import itertools
import operator
import copy
import collections

from collections import deque
from functools import reduce

from xtag_verbnet.grammar import Grammar

XTAG_GRAMMAR = Grammar.load()

def flatten(lst_of_lsts):
    return [a for lst in lst_of_lsts for a in lst]

def prod(iterable):
    return reduce(operator.mul, iterable, 1)

class KHeapFactory(object):
    def __init__(self, k, key=lambda x: x):
        self.k = k 
        self.key = key

    def new_heap(self, initial=None):
        if len(initial) < k:
            return initial
        return KHeap(self.k, initial, self.key)

    def new_higher_order_heap(self, initial=None, f=sum):