Last active
November 1, 2017 13:10
-
-
Save amnrzv/4aee7cf8ce827314d0e9562a35633cf5 to your computer and use it in GitHub Desktop.
Python NLTK POS tagger workaround example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
import re | |
from nltk.tokenize import word_tokenize, sent_tokenize | |
text = "I'm not going to the party." | |
words = word_tokenize(text) | |
pos_tags = nltk.pos_tag(words) | |
print (pos_tags) | |
for index, tag in enumerate(pos_tags): | |
match = re.search('\w.*', tag[1]) | |
if match: | |
if tag[0] == "n't" or tag[0] == "not": | |
pos_tags[index] = (pos_tags[index][0], "NEG") | |
print (pos_tags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[('I', 'PRP'), ("'m", 'VBP'), ('not', 'RB'), ('going', 'VBG'), ('to', 'TO'), ('the', 'DT'), ('party', 'NN'), ('.', '.')] | |
[('I', 'PRP'), ("'m", 'VBP'), ('not', 'NEG'), ('going', 'VBG'), ('to', 'TO'), ('the', 'DT'), ('party', 'NN'), ('.', '.')] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment