Extracting all Nouns from a text file using nltk

前端 未结 7 1841
清歌不尽
清歌不尽 2020-12-08 08:35

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         


        
7条回答
  •  感情败类
    2020-12-08 09:06

    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']
    

提交回复
热议问题