Skip to content

Instantly share code, notes, and snippets.

@amrakm
Last active May 26, 2022 11:19
Show Gist options
  • Save amrakm/044668246fb17d4b13b2d896f1acc398 to your computer and use it in GitHub Desktop.
Save amrakm/044668246fb17d4b13b2d896f1acc398 to your computer and use it in GitHub Desktop.
filter nouns only
import nltk
import nltk
nltk.download('averaged_perceptron_tagger')
lines = 'lines is some string of words'
def filter_nouns_only(text):
tokenized = nltk.word_tokenize(text)
nouns = [word for (word, pos) in nltk.pos_tag(tokenized) if(pos[:2] == 'NN')]
return " ".join(nouns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment