Skip to content

Instantly share code, notes, and snippets.

@rajeshmr
Created May 31, 2016 09:13
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 rajeshmr/8525271f7c8aaace3d45b340d1686b46 to your computer and use it in GitHub Desktop.
Save rajeshmr/8525271f7c8aaace3d45b340d1686b46 to your computer and use it in GitHub Desktop.
@app.route("/tag", methods=['GET', 'POST'])
def tag():
content = request.get_json(silent=True)
if len(content) > 50:
return abort(400)
tokens = map(nltk.word_tokenize, content)
tagged_tokens = map(nltk.pos_tag, tokens)
for_feature = pre_feature(tagged_tokens)
with_feature = map(feature_extractor, for_feature)
flattened_with_feature = [item for sublist in with_feature for item in sublist]
xseq = to_crfsuite(flattened_with_feature)
yseq = tagger.tag(xseq)
tags = []
for y in yseq:
tags.append(y)
tags = list(reversed(tags))
result = []
for feature in with_feature:
tagged_token = []
for token in feature:
tagged_token.append({"token": token['w'], "tag": tags.pop()})
result.append(tagged_token)
return jsonify(tagged_tokens=result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment