def get_node_representation(tetre_format, token):
"""Given a format and a SpaCy node (spacy.token), returns this node representation using the NLTK tree (nltk.tree).
It recursivelly builds a NLTK tree and returns it, not only the node itself.
Args:
tetre_format: The attributes of this node that will be part of its string representation.
token: The SpaCy node itself (spacy.token).
Returns:
A NLTK Tree (nltk.tree)
"""
params = tetre_format.split(",")
node_representation = token.pos_
if token.n_lefts + token.n_rights > 0:
tree = Tree(node_representation,
[to_nltk_tree_general(child, attr_list=params, level=0) for child in token.children])
else:
tree = Tree(node_representation, [])
return tree
评论列表
文章目录