Vasyl Lyashkevych Vasyl Lyashkevych - 1 year ago 122
Python Question

NameError: name 'parser' is not defined in SpaCy

I have an example for working with NLP in spacy code:

from subject_object_extraction import findSVOs

# can still work even without punctuation
parse = parser("he and his brother shot me and my sister")
print(findSVOs(parse))

# very complex sample. Only some are correct. Some are missed.
parse = parser("Far out in the uncharted backwaters of the unfashionable end of the Western Spiral arm of the Galaxy lies a small unregarded yellow sun. ")
print(findSVOs(parse))


Before I installed all dictionaries for spacy:

$ sudo python -m spacy.en.download all
$ python -m spacy.en.download parser
$ python -m spacy.en.download glove


but, as results, I have a mistake:

Traceback (most recent call last):
File "/home/vv/PythProj/sp_ex_1.py", line 5, in <module>
nasa = parser.vocab['NASA']
NameError: name 'parser' is not defined


Please, Where is my mistake? Thank you

Answer Source

I think you are missing this:

# Set up spaCy
from spacy.en import English
parser = English()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download