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
157
158
159
160
161
|
def genUserId ():
i = 0
while True:
yield str(i)
i += 1
def parseParagraph (iParagraph, sText, oTokenizer, oDict, dOptions, bDebug=False, bEmptyIfNoErrors=False):
aGrammErrs = gce.parse(sText, "FR", bDebug, dOptions)
aGrammErrs = list(aGrammErrs)
aSpellErrs = []
for dToken in oTokenizer.genTokens(sText):
if dToken['sType'] == "WORD" and not oDict.isValidToken(dToken['sValue']):
aSpellErrs.append(dToken)
if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
return ""
return " " + json.dumps({ "iParagraph": iParagraph, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
if __name__ == '__main__':
gce.load("Server")
echo("Grammalecte v{}".format(gce.version))
dServerOptions = getServerOptions()
dGCOptions = getConfigOptions("fr")
if dGCOptions:
gce.setOptions(dGCOptions)
dServerGCOptions = gce.getOptions()
echo("Grammar options:\n" + " | ".join([ k + ": " + str(v) for k, v in sorted(dServerGCOptions.items()) ]))
oDict = gce.getDictionary()
oTokenizer = tkz.Tokenizer("fr")
oTF = tf.TextFormatter()
dUser = {}
userGenerator = genUserId()
app = Bottle()
|
|
|
|
|
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
157
158
159
160
161
|
def genUserId ():
i = 0
while True:
yield str(i)
i += 1
def parseParagraph (iParagraph, sText, oTokenizer, oSpellChecker, dOptions, bDebug=False, bEmptyIfNoErrors=False):
aGrammErrs = gce.parse(sText, "FR", bDebug, dOptions)
aGrammErrs = list(aGrammErrs)
aSpellErrs = []
for dToken in oTokenizer.genTokens(sText):
if dToken['sType'] == "WORD" and not oSpellChecker.isValidToken(dToken['sValue']):
aSpellErrs.append(dToken)
if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
return ""
return " " + json.dumps({ "iParagraph": iParagraph, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
if __name__ == '__main__':
gce.load("Server")
echo("Grammalecte v{}".format(gce.version))
dServerOptions = getServerOptions()
dGCOptions = getConfigOptions("fr")
if dGCOptions:
gce.setOptions(dGCOptions)
dServerGCOptions = gce.getOptions()
echo("Grammar options:\n" + " | ".join([ k + ": " + str(v) for k, v in sorted(dServerGCOptions.items()) ]))
oSpellChecker = gce.getSpellChecker()
oTokenizer = tkz.Tokenizer("fr")
oTF = tf.TextFormatter()
dUser = {}
userGenerator = genUserId()
app = Bottle()
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
dOptions.update(json.loads(request.forms.options))
except:
sError = "request options not used"
sJSON = '{ "program": "grammalecte-fr", "version": "'+gce.version+'", "lang": "'+gce.lang+'", "error": "'+sError+'", "data" : [\n'
for i, sText in enumerate(txt.getParagraph(request.forms.text), 1):
if bTF:
sText = oTF.formatText(sText)
sText = parseParagraph(i, sText, oTokenizer, oDict, dOptions, bEmptyIfNoErrors=True)
if sText:
if bComma:
sJSON += ",\n"
sJSON += sText
bComma = True
sJSON += "\n]}\n"
return sJSON
|
|
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
dOptions.update(json.loads(request.forms.options))
except:
sError = "request options not used"
sJSON = '{ "program": "grammalecte-fr", "version": "'+gce.version+'", "lang": "'+gce.lang+'", "error": "'+sError+'", "data" : [\n'
for i, sText in enumerate(txt.getParagraph(request.forms.text), 1):
if bTF:
sText = oTF.formatText(sText)
sText = parseParagraph(i, sText, oTokenizer, oSpellChecker, dOptions, bEmptyIfNoErrors=True)
if sText:
if bComma:
sJSON += ",\n"
sJSON += sText
bComma = True
sJSON += "\n]}\n"
return sJSON
|