我想Parse Tree
使用打印Spacy
。但是下面的代码给出了错误
en_nlp = spacy.language('English') TypeError: 'module' object is not callable
错误在这一en_nlp = spacy.loads('en')
行。en_nlp = spacy.language(English)
我试图通过导入来摆脱,from spacy.en import English
但它仍然无法正常工作。有人可以帮忙吗?
代码:
import spacy
from nltk import Tree
en_nlp = spacy.loads('en')
doc = en_nlp("The quick brown fox jumps over the lazy dog.")
def to_nltk_tree(node):
if node.n_lefts + node.n_rights > 0:
return Tree(node.orth_, [to_nltk_tree(child) for child in node.children])
else:
return node.orth_
[to_nltk_tree(sent.root).pretty_print() for sent in doc.sents]