-
Notifications
You must be signed in to change notification settings - Fork 0
/
petitext.py
156 lines (112 loc) · 4.61 KB
/
petitext.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import time, codecs
from MonCoreNLP import lecture_fichier
from MonCoreNLP import get_enhancedPlusPlusDependencies
from gestion import Gestionnaire_Relation
from flask import Flask, redirect, url_for, request
from include_html import getHtml
# declaration de l'application
app = Flask(__name__)
# tableau pour stocker les nouvelles conclusions
tmp = []
@app.route('/success/<name>')
def success(name):
return 'welcome %s' % name
@app.route('/login',methods = ['POST','GET'])
def login():
if request.method == 'POST':
file_name = request.form['file_name']
new_line = request.form['new_line']
return redirect(url_for('generer_tous_arbres',filePath = file_name, newLine=new_line))
else:
file_name = request.args.get('file_name')
new_line = request.args.get('new_line')
return redirect(url_for('generer_tous_arbres',filePath = file_name, newLine=new_line))
@app.route('/result')
def generer_tous_arbres ():
path = request.args['filePath']
data = request.args['newLine']
entete = {
u"./definition de famille (simple).txt" : u"la définition simple de la famille",
u"./univers des objets.txt" : u"l'univers des objets abstraits",
u"./Connaissance des organismes.txt" : u"l'univers de la connaissance des organismes"
}
enhanced = {}
arbre = {}
ner = []
roles = []
words = []
datum = ""
message = ""
message += getHtml("./until_body.html")
donnees = lecture_fichier(path)
if (data == ""):
del tmp[:]
message += "<body onload= 'showNextRow(); window.scrollTo(0,document.body.scrollHeight);' >"
else:
tmp.append(data)
donnees.extend(tmp)
message += "<body onload= 'window.scrollTo(0,document.body.scrollHeight);' >"
message += getHtml("./head_of_body.html")
gestion = Gestionnaire_Relation()
message += "<div style='margin-left: 199px;'><h2>Raisonnement sur "
message += entete[path]
message += "</h2>"
#message += "<div id='myProgress'><div id='myBar'>10%</div></div></td>"
message += "<br></br><table>"
for datum in donnees:
message += "<tr>"
message += u"<td><button class='btn btn-info' > Fait </button> "
message += datum
message += "</td>"
print("# Fait ##############" + datum + "###############")
enhanced, ner, roles, words = get_enhancedPlusPlusDependencies(datum)
label = gestion.pre_traitement(datum, words,roles)
r = gestion.ajouter_relation(label, words, roles, ner)
messageConcHyp = ""
conc = []
hyp = []
messageConcHyp = getConclusionsHypothese (conc, hyp, gestion, r)
message += messageConcHyp
datum = ""
print("###############################################################")
message += "</table><br></br>"
message += "<input type=button class='btn btn-inverse' value='Avancer sur le raisonnement' id='onemore' style='width:260px;height:70px'/>"
message += "<br></br>"
message += "<form action = 'http://127.0.0.1:5000/login' method = 'POST'>"
message += " <input type='HIDDEN' name = 'file_name' value = '" + path + "' />"
message += " <input type='text' name = 'new_line' value='' placeholder='Ajouter ici un nouveau fait' style='width:250px;margin-bottom: 0px;'/>"
message += " <input class='btn btn-info' type='submit' value='Ajouter et raisonner' />"
message += "</form><br></br>"
message += "</div></body></html>"
return message
def getConclusionsHypothese (conc, hyp, gestion, r):
message = ""
concHtml = getConclusions(conc, gestion, r)
message = concHtml
hypHtml = getHypotheses(hyp, gestion, r)
message += hypHtml
return message
def getConclusions (conc, gestion, r):
conc = gestion.getConclusions(r)
message = "<table>"
for c in conc:
message += "<tr>"
message += "<td>"
message += u"<button class='btn btn-primary' >➔ Conclusion(s) générée(s) à ce moment </button> "
message += c.relationToligne()
message += "</td>"
message += "</table>"
return message
def getHypotheses (hyp, gestion, r):
hyp = gestion.getHypotheses(r)
message = "<table>"
for h in hyp:
message += "<tr>"
message += "<td>"
message += u"<button class='btn btn-warning' >➔ Hypothèse(s) générée(s) à ce moment </button> "
message += h.relationToligne()
message += "</td>"
message += "</table>"
return message
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)