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)
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
def sent_to_tree(sentence): head_indexed = defaultdict(list) for token in sentence: head_indexed[token["head"]].append(token) return create_tree(head_indexed)