Reputation: 479
I want to print Parse Tree
using Spacy
. But the code below is giving the error
en_nlp = spacy.language('English') TypeError: 'module' object is not callable
The error is on this en_nlp = spacy.loads('en')
line. I tried to shake off as en_nlp = spacy.language(English)
by importing from spacy.en import English
But still it is not working. Can someone help?
Code:
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]
Upvotes: 0
Views: 3161
Reputation: 963
Is it spacy.load('en') or spacy.loads('en') ?
The official doc https://spacy.io/docs/ says : spacy.load('en'). It may be the problem.
Upvotes: 1