Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
109 lines (83 loc) · 2.62 KB
/
Copy pathapp.py
File metadata and controls
109 lines (83 loc) · 2.62 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
from flask import Flask, render_template, send_from_directory, request
from syntax.syntax import generate_syntaxtree
# =============================================================================
# Flask App
# =============================================================================
app = Flask(__name__)
# =============================================================================
# Routes
# =============================================================================
@app.route("/health")
def health():
return {"status": "ok"}, 200
@app.route("/favicon.ico")
def favicon():
return send_from_directory(
os.path.join(app.root_path, "static"),
"favicon.ico",
mimetype="image/vnd.microsoft.icon"
)
@app.route("/")
def landing():
return render_template("index.html")
@app.route("/syntax")
def syntax():
return render_template("syntax.html")
@app.route("/parse-sentence")
def parse_sentence():
"""
Generate a syntax tree from the submitted sentence and grammar options.
Expected query parameters:
- sentence
- Grammar
- GrammarOption
- LangOption
"""
sentence = request.args.get("sentence", "").strip()
grammar_rules = request.args.get("Grammar", "").strip()
option_grammar = request.args.get("GrammarOption", "").strip()
option_lang = request.args.get("LangOption", "").strip()
if not sentence:
return render_template(
"syntax.html",
error="Bitte gib einen Satz ein."
), 400
try:
tree, notation, grammar = generate_syntaxtree(
sentence,
grammar_rules,
option_grammar,
option_lang
)
return render_template(
"syntax.html",
tree=tree,
notation=notation,
grammar=grammar
)
except Exception:
app.logger.exception("Syntax tree generation failed")
return render_template(
"syntax.html",
error="Beim Erstellen des Syntaxbaums ist ein Fehler aufgetreten."
), 500
# =============================================================================
# Local Deployment
# =============================================================================
# Use this block ONLY when you want to run the app locally with:
#
# python app.py
#
# For production with Docker + Gunicorn, this block is NOT used.
# Gunicorn starts the app with:
#
# gunicorn app:app
#
# To use local deployment, uncomment the block below.
# if __name__ == "__main__":
# app.run(
# host="0.0.0.0",
# port=5000,
# debug=False
# )