Can anyone please tell me how to retrieve noun from the code? Please correct the code if possible. Thanks for the help :)
import nltk
from nltk.corpus import state_union
from textblob import TextBlob
from nltk.tokenize import TweetTokenizer
from nltk.tokenize import RegexpTokenizer
from nltk.tokenize import PunktSentenceTokenizer
sample_text=state_union.raw("2006-GWBush.txt")
train_text= state_union.raw("2005-GWBush.txt")
custom_sent_tokenizer = PunktSentenceTokenizer(train_text)
tokenized = custom_sent_tokenizer.tokenize(sample_text)
def process_content():
try:
for i in tokenized:
words=nltk.word_tokenize(i)
tagged = nltk.pos_tag(words)
if(pos =='NN' or pos == 'NNP' or pos =='NNS' or pos=='NNPS'):
print(tagged)
except Exception as e:
print(str(e))
process_content()
Note: original source of code https://pythonprogramming.net/part-of-speech-tagging-nltk-tutorial/