Grammalecte  Check-in [966babe645]

Overview
Comment:[cli] suggest() in spellchecker is a generator
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | cli | multid
Files: files | file ages | folders
SHA3-256: 966babe645b15984223f073367f3c420f403e769090f5ffd6c0c3086576ec258
User & Date: olr on 2018-02-13 15:57:14
Other Links: branch diff | manifest | tags
Context
2018-02-13
16:05
[graphspell][py] drawPath() for spellchecker check-in: ad736fa52b user: olr tags: graphspell, multid
15:57
[cli] suggest() in spellchecker is a generator check-in: 966babe645 user: olr tags: cli, multid
15:44
[core][cli][server][graphspell][fx] use spellchecker instead of ibdawg check-in: 18db5d65f0 user: olr tags: cli, core, fx, graphspell, multid, server
Changes

Modified grammalecte-cli.py from [93945e25e2] to [d66b04b565].

    47     47   def _getErrors (sText, oTokenizer, oSpellChecker, bContext=False, bSpellSugg=False, bDebug=False):
    48     48       "returns a tuple: (grammar errors, spelling errors)"
    49     49       aGrammErrs = gce.parse(sText, "FR", bDebug=bDebug, bContext=bContext)
    50     50       aSpellErrs = []
    51     51       for dToken in oTokenizer.genTokens(sText):
    52     52           if dToken['sType'] == "WORD" and not oSpellChecker.isValidToken(dToken['sValue']):
    53     53               if bSpellSugg:
    54         -                dToken['aSuggestions'] = oSpellChecker.suggest(dToken['sValue'])
           54  +                dToken['aSuggestions'] = []
           55  +                for lSugg in oSpellChecker.suggest(dToken['sValue']):
           56  +                    dToken['aSuggestions'].extend(lSugg)
    55     57               aSpellErrs.append(dToken)
    56     58       return aGrammErrs, aSpellErrs
    57     59   
    58     60   
    59     61   def generateText (sText, oTokenizer, oSpellChecker, bDebug=False, bEmptyIfNoErrors=False, bSpellSugg=False, nWidth=100):
    60     62       aGrammErrs, aSpellErrs = _getErrors(sText, oTokenizer, oSpellChecker, False, bSpellSugg, bDebug)
    61     63       if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
................................................................................
   140    142           if xArgs.list_options:
   141    143               gce.displayOptions("fr")
   142    144           if xArgs.list_rules:
   143    145               gce.displayRules(None  if xArgs.list_rules == "*"  else xArgs.list_rules)
   144    146           exit()
   145    147   
   146    148       if xArgs.suggest:
   147         -        lSugg = oSpellChecker.suggest(xArgs.suggest)
   148         -        if xArgs.json:
   149         -            sText = json.dumps({ "aSuggestions": lSugg }, ensure_ascii=False)
   150         -        else:
   151         -            sText = "Suggestions : " + " | ".join(lSugg)
   152         -        echo(sText)
          149  +        for lSugg in oSpellChecker.suggest(xArgs.suggest):
          150  +            if xArgs.json:
          151  +                sText = json.dumps({ "aSuggestions": lSugg }, ensure_ascii=False)
          152  +            else:
          153  +                sText = "Suggestions : " + " | ".join(lSugg)
          154  +            echo(sText)
   153    155           exit()
   154    156   
   155    157       if not xArgs.json:
   156    158           xArgs.context = False
   157    159   
   158    160       gce.setOptions({"html": True, "latex": True})
   159    161       if xArgs.opt_on:
................................................................................
   218    220                       if sWord:
   219    221                           echo("* " + sWord)
   220    222                           for sMorph in oSpellChecker.getMorph(sWord):
   221    223                               echo("  {:<32} {}".format(sMorph, oLexGraphe.formatTags(sMorph)))
   222    224               elif sText.startswith("!"):
   223    225                   for sWord in sText[1:].strip().split():
   224    226                       if sWord:
   225         -                        echo(" | ".join(oSpellChecker.suggest(sWord)))
   226         -                        #echo(" | ".join(oSpellChecker.suggest2(sWord)))
          227  +                        for lSugg in oSpellChecker.suggest(sWord):
          228  +                            echo(" | ".join(lSugg))
   227    229               elif sText.startswith(">"):
   228    230                   oSpellChecker.drawPath(sText[1:].strip())
   229    231               elif sText.startswith("="):
   230    232                   for sRes in oSpellChecker.select(sText[1:].strip()):
   231    233                       echo(sRes)
   232    234               elif sText.startswith("/+ "):
   233    235                   gce.setOptions({ opt:True  for opt in sText[3:].strip().split()  if opt in gce.getOptions() })