-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfuzzy.py
55 lines (44 loc) · 1.29 KB
/
fuzzy.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
46
47
48
49
50
51
52
53
54
55
""" Flask app """
from flask import (
Flask,
request,
session,
g,
redirect,
url_for,
abort,
render_template,
flash,
jsonify,
)
from aramorph.aramorpher import Aramorpher
# create the application
app = Flask(__name__)
app.config.from_object(__name__)
# not using a database
# not sure if I need this line:
app.config.from_envvar("FLASKR_SETTINGS", silent=True)
analyser = Aramorpher()
# views
@app.route("/")
def main():
return render_template("yamli.html")
@app.route("/query_ajax", methods=["POST"])
def query():
if request.json and "words" in request.json:
results = request.json["words"]
if results is not None:
results = list()
words = request.json["words"].split(",")
for word in words:
for analysis in analyser.analyse_arabic(word):
if analysis and analysis not in results:
results.append(analysis)
if len(results) == 0:
# Yamli gave us some words but we didn't
# find them in Buckwalter AMA,
# give some abbreviated information anyway
results = analyser.information(words)
return jsonify(analyses=results), 201
if __name__ == "__main__":
app.run(debug=False)