0

我想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]
4

1 回答 1

1

是 spacy.load('en') 还是 spacy.loads('en') ?

官方文档https://spacy.io/docs/说:spacy.load('en')。这可能是问题所在。

于 2016-09-04T15:28:15.767 回答