0
#!/usr/bin/env python3
print("Content-type: text/html\n\n")
print("Test by SG")
import nltk
nltk.download('punkt')
nltk.download('averaged_perceptron_tagger')
lines = 'I was running around in the road then saw a bus'
is_noun = lambda pos:pos[:2] == 'NN'
tokenized = nltk.word_tokenize(lines)
nouns = [word for (word, pos) in nltk.pos_tag(tokenized) if is_noun(pos)] 
print (nouns)

I am only getting output:

Test by SG Content-Type: text/html

but the output should be:

['road', 'bus']

I am not getting the correct output.

sophros
  • 14,672
  • 11
  • 46
  • 75

1 Answers1

0

Working fine in both Notebook and python console. The problem may be in you NLTK package installation. Please use virtual environment if not and install nltk package, download the nltk-data . Must check the nltk-data download location for confirmation. The download location will be looked like:

[nltk_data] Downloading package punkt to
[nltk_data]     C:\Users\username\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping tokenizers\punkt.zip.
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data]     C:\Users\username\AppData\Roaming\nltk_data...
[nltk_data]   Unzipping taggers\averaged_perceptron_tagger.zip.

If you are a windows user.

raihan_s
  • 1
  • 1