Skip to content

Instantly share code, notes, and snippets.

@amnrzv
Last active November 1, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amnrzv/aa9b25a1ebab4248aa41272039cc9251 to your computer and use it in GitHub Desktop.
Save amnrzv/aa9b25a1ebab4248aa41272039cc9251 to your computer and use it in GitHub Desktop.
An example of NLTK's POS tagging. Output here: https://gist.github.com/amnrzv/2d726c1f107d444b0cdaed21299b7da1
import nltk
from nltk.tokenize import word_tokenize, sent_tokenize
text1 = "I'm going to watch a play tonight."
text2 = "I like to play guitar."
words1 = word_tokenize(text1)
pos_tags1 = nltk.pos_tag(words1)
words2 = word_tokenize(text2)
pos_tags2 = nltk.pos_tag(words2)
print (pos_tags1)
print (pos_tags2)
[('I', 'PRP'), ("'m", 'VBP'), ('going', 'VBG'), ('to', 'TO'), ('watch', 'VB'), ('a', 'DT'), ('play', 'NN'), ('tonight', 'NN'), ('.', '.')]
[('I', 'PRP'), ('like', 'VBP'), ('to', 'TO'), ('play', 'VB'), ('guitar', 'NN'), ('.', '.')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment