-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
37 lines (30 loc) · 1.04 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
from classifier import classify
from tagger import tagger
from crossdomain import crossdomain
from flask import Flask, request, render_template, json
app = Flask(__name__)
def parse(input):
tagged_words = tagger.tag(input.strip().lower().split(' '))
commodities = classify(tagged_words)
return [commodity.serialize() for commodity in commodities]
@app.route("/nlparse.json", methods=['POST', 'OPTIONS'])
@crossdomain(origin='*', headers='Content-Type')
def parse_json():
input = request.json['input']
return json.dumps(parse(input))
@app.route("/nlparse.test", methods=['GET', 'POST'])
def parse_test():
if request.method == 'POST':
input = request.form['input']
result = json.dumps(parse(input))
else:
input = result = ''
return render_template('./parse_test.html', input=input, result=result)
if __name__ == "__main__":
try:
debug = sys.argv[1] == 'dev'
except IndexError:
debug = False
app.config["JSON_SORT_KEYS"] = False
app.run(host='0.0.0.0', debug=debug)