-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.py
43 lines (38 loc) · 1.38 KB
/
backend.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
from flask import Flask,request, g, url_for, redirect
import json
from hyperviterbi import Hyperviterbi
from freq_analizer import PriorGenerator
from adiacenti import ModelloErrore
app = Flask(__name__)
priorGenerator = None
def get_prior_generator():
global priorGenerator
if priorGenerator is None:
priorGenerator = PriorGenerator(1e-20)
priorGenerator.deserialize("freq_analized.json")
priorGenerator.load_stop_symbols_from_file("stop_symbols.txt")
return priorGenerator
@app.route('/stop_symbols')
def get_stop_symbols():
return json.dumps(get_prior_generator().stopSymbols)
@app.route('/viterbi/<input_type>', methods=['POST'])
def viterbi(input_type):
js = request.get_json(force=True)
pre_analized = js['mat']
phrase = js['phrase']
priorGenerator = get_prior_generator()
v = Hyperviterbi(priorGenerator, 10)
if input_type == "tastiera":
v.m_err.calcola_adiacenze()
elif input_type == "braille":
v.m_err.calcola_adiacenze("adiacentiBraille.txt")
corrected_phrase = v.viterbi(phrase, pre_analized)
ret_dic = {"mat":pre_analized,"viterbi":corrected_phrase}
return json.dumps(ret_dic)
@app.route('/')
def home():
return redirect(url_for('static', filename='index.html'))
@app.route('/braille')
def braille():
return redirect(url_for('static', filename='braille.html'))
app.run(host="0.0.0.0")