Grammalecte  Diff

Differences From Artifact [6dbdf10c60]:

To Artifact [3253a2b2ff]:


   125    125   def genUserId ():
   126    126       i = 0
   127    127       while True:
   128    128           yield str(i)
   129    129           i += 1
   130    130   
   131    131   
   132         -def parseParagraph (iParagraph, sText, oTokenizer, oDict, dOptions, bDebug=False, bEmptyIfNoErrors=False):
          132  +def parseParagraph (iParagraph, sText, oTokenizer, oSpellChecker, dOptions, bDebug=False, bEmptyIfNoErrors=False):
   133    133       aGrammErrs = gce.parse(sText, "FR", bDebug, dOptions)
   134    134       aGrammErrs = list(aGrammErrs)
   135    135       aSpellErrs = []
   136    136       for dToken in oTokenizer.genTokens(sText):
   137         -        if dToken['sType'] == "WORD" and not oDict.isValidToken(dToken['sValue']):
          137  +        if dToken['sType'] == "WORD" and not oSpellChecker.isValidToken(dToken['sValue']):
   138    138               aSpellErrs.append(dToken)
   139    139       if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
   140    140           return ""
   141    141       return "  " + json.dumps({ "iParagraph": iParagraph, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
   142    142       
   143    143   
   144    144   if __name__ == '__main__':
................................................................................
   147    147       echo("Grammalecte v{}".format(gce.version))
   148    148       dServerOptions = getServerOptions()
   149    149       dGCOptions = getConfigOptions("fr")
   150    150       if dGCOptions:
   151    151           gce.setOptions(dGCOptions)
   152    152       dServerGCOptions = gce.getOptions()
   153    153       echo("Grammar options:\n" + " | ".join([ k + ": " + str(v)  for k, v in sorted(dServerGCOptions.items()) ]))
   154         -    oDict = gce.getDictionary()
          154  +    oSpellChecker = gce.getSpellChecker()
   155    155       oTokenizer = tkz.Tokenizer("fr")
   156    156       oTF = tf.TextFormatter()
   157    157       dUser = {}
   158    158       userGenerator = genUserId()
   159    159   
   160    160       app = Bottle()
   161    161   
................................................................................
   195    195                   dOptions.update(json.loads(request.forms.options))
   196    196               except:
   197    197                   sError = "request options not used"
   198    198           sJSON = '{ "program": "grammalecte-fr", "version": "'+gce.version+'", "lang": "'+gce.lang+'", "error": "'+sError+'", "data" : [\n'
   199    199           for i, sText in enumerate(txt.getParagraph(request.forms.text), 1):
   200    200               if bTF:
   201    201                   sText = oTF.formatText(sText)
   202         -            sText = parseParagraph(i, sText, oTokenizer, oDict, dOptions, bEmptyIfNoErrors=True)
          202  +            sText = parseParagraph(i, sText, oTokenizer, oSpellChecker, dOptions, bEmptyIfNoErrors=True)
   203    203               if sText:
   204    204                   if bComma:
   205    205                       sJSON += ",\n"
   206    206                   sJSON += sText
   207    207                   bComma = True
   208    208           sJSON += "\n]}\n"
   209    209           return sJSON