Exemplo n.º 1
0
def sent_to_tree(sentence):
    head_indexed = defaultdict(list)
    for token in sentence:
        # If HEAD is negative, treat it as child of the root node
        head = max(token["head"] or 0, 0)
        head_indexed[head].append(token)

    return create_tree(head_indexed)
Exemplo n.º 2
0
def parse_tree(text):
    result = parse(text)

    trees = []
    for sentence in result:

        head_indexed = defaultdict(list)
        for token in sentence:
            head_indexed[token["head"]].append(token)

        trees += create_tree(head_indexed)

    return trees
Exemplo n.º 3
0
def sent_to_tree(sentence):
    head_indexed = defaultdict(list)
    for token in sentence:
        head_indexed[token["head"]].append(token)

    return create_tree(head_indexed)