Is there a more efficient way of doing this? My code reads a text file and extracts all Nouns.
import nltk
File = open(fileName) #open file
lines = File.rea
If you are open to options other than NLTK
, check out TextBlob. It extracts all nouns and noun phrases easily:
>>> from textblob import TextBlob
>>> txt = """Natural language processing (NLP) is a field of computer science, artificial intelligence, and computational linguistics concerned with the inter
actions between computers and human (natural) languages."""
>>> blob = TextBlob(txt)
>>> print(blob.noun_phrases)
[u'natural language processing', 'nlp', u'computer science', u'artificial intelligence', u'computational linguistics']