-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqac_api.py
44 lines (34 loc) · 1.1 KB
/
qac_api.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
38
39
40
41
42
43
44
# Copyright 2020, University of Freiburg
# Author: Natalie Prange <[email protected]>
import flask
import sys
from flask import request, jsonify
from urllib import parse
from qac import QAC
app = flask.Flask(__name__)
# Initialize the QAC system
qac = QAC()
@app.route('/', methods=['GET'])
def qac_api():
question_prefix = request.args.get('q', '')
# Normalize question.
question_prefix = parse.unquote(question_prefix)
# Send results with proper HTTP headers.
results = qac.complete_question(question_prefix)
json_obj = [{"completion": compl,
"qids": qids,
"types": types,
"matched_alias": alias,
"score": score}
for compl, qids, types, alias, score in results]
json_obj = {"results": json_obj}
return jsonify(json_obj)
if __name__ == "__main__":
if len(sys.argv) == 1:
port = 8183
elif len(sys.argv) == 2:
port = int(sys.argv[1])
else:
print("Usage: python3 %s <port>" % sys.argv[0])
exit(1)
app.run(debug=False, host="::", port=port)