-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
45 lines (34 loc) · 1.08 KB
/
server.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
45
from flask import Flask, request
from flask import jsonify
from flask_cors import CORS
from clustering import find_cluster
from hw3 import models
from query_expansion import QueryExpander
app = Flask(__name__)
CORS(app)
qe = QueryExpander()
@app.route("/hw3/models")
def list_models():
return jsonify([model.__class__.__name__ for model in models])
@app.route("/hw3/query", methods=['GET'])
def query_model():
query = request.args.get("query")
mode = request.args.get("mode")
print(f"query_model> '{query}'")
print(f"mode> '{mode}'")
if mode and mode.isdigit():
model = models[int(mode)]
else:
model = models[0]
results = model.search(10, query)
return results.to_json(orient="records")
@app.route("/clustering", methods=['GET'])
def clustering_api():
query = request.args.get("query")
print(f"query> '{query}'")
return find_cluster(query)
@app.route("/qe", methods=['GET'])
def query_expander():
query = request.args.get("query")
print(f"query> '{query}'")
return {"suggestions": qe.get_query_suggestions(query)}