Last active
February 17, 2016 06:55
-
-
Save rajeshmr/ec853f1cc73e88c100f2 to your computer and use it in GitHub Desktop.
Structuring text using Conditional Random Field (CRF). Tagging recipe ingredient phrases.
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 sys | |
import nltk | |
import json | |
for line in sys.stdin: | |
data = json.loads(line) | |
for ingredient in data['ingredients']: | |
tokens = nltk.word_tokenize(ingredient.strip()) | |
tagged_tokens = nltk.pos_tag(tokens) | |
for token, pos in tagged_tokens: | |
try: | |
print "%s\t%s\tXXX" % (token.encode('utf8'), pos) | |
except Exception as e: | |
print e | |
print "Error writing token:", token | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment