Reputation: 83
Currently doing a project in NLP. I need to find out whether a sentence have a noun in it. How can I achieve this using spacy?
Upvotes: 4
Views: 905
Reputation: 5283
Solution 1:
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp(u'hello india how are you?')
print(len([np.text for np in doc.noun_chunks])>0)
Solution 2:
import spacy
nlp = spacy.load('en_core_web_sm')
doc = nlp(u'hello india how are you?')
print(len([token.pos_ for token in doc if token.pos_=="NOUN"])>0)
Upvotes: 4