def to_nltk_tree(node):
"""Creates a fixed representation of a Spacy dependency tree as a NLTK tree. This fixed representation
will be formed by the Spacy's node attributes: dep_, orth_ and pos_.
Args:
node: The starting node from the tree in which the transformation will occur.
Returns:
A NLTK Tree (nltk.tree)
"""
if node.n_lefts + node.n_rights > 0:
return Tree(node.dep_+"/"+node.orth_+"/"+node.pos_, [to_nltk_tree(child) for child in node.children])
else:
return node.dep_+"/"+node.orth_+"/"+node.pos_
评论列表
文章目录