Reputation: 1625
I am using the below code to check if a word is a stop word or not. As you can see below, if the try block fails, the IS_STOP function is throwing an error.
import spacy
nlp = spacy.load('en')
try:
print 0/0 #Raise and Exception
except:
print nlp.is_stop('is')`
I get the below error:
5 print 0/0
6 except:
----> 7 print spacy.load('en').is_stop('is')
AttributeError: 'English' object has no attribute 'is_stop' `
Upvotes: 2
Views: 2471
Reputation: 21
You need to process some text by 'calling' the nlp
object as a function as explained here. You can then test for stop words on each token of the parsed sentence.
For example:
>>> import spacy
>>> nlp = spacy.load('en')
>>> sentence = nlp(u'this is a sample sentence')
>>> sentence[1].is_stop
True
In case you want to test for stop words directly from the English vocabulary, use the following:
>>> nlp.vocab[u'is'].is_stop
True
Upvotes: 1