Overview
Comment: | [cli][server][graphspell][core] interactive correction with CLI |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | cli | core | server | graphspell |
Files: | files | file ages | folders |
SHA3-256: |
c8ad079d5789150767bc85ab1558db78 |
User & Date: | olr on 2020-03-05 19:07:35 |
Other Links: | manifest | tags |
Context
2020-03-05
| ||
20:37 | [cli] add comment check-in: 36a06e8ba5 user: olr tags: trunk, cli | |
19:07 | [cli][server][graphspell][core] interactive correction with CLI check-in: c8ad079d57 user: olr tags: trunk, cli, core, server, graphspell | |
2020-03-04
| ||
14:15 | [fx] create custom event on text area when Grammalecte change the text content check-in: 65c3b076ec user: olr tags: trunk, fx | |
Changes
Modified gc_core/py/grammar_checker.py from [f8aade78d9] to [5ca2376e71].
︙ | |||
51 52 53 54 55 56 57 | 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 | - - - - - - - + + + + - + + + + | def getParagraphErrors (self, sText, dOptions=None, bContext=False, bSpellSugg=False, bDebug=False): "returns a tuple: (grammar errors, spelling errors)" aGrammErrs = self.gce.parse(sText, "FR", bDebug=bDebug, dOptions=dOptions, bContext=bContext) aSpellErrs = self.oSpellChecker.parseParagraph(sText, bSpellSugg) return aGrammErrs, aSpellErrs |
Modified gc_core/py/text.py from [0d4a1aba9d] to [df68ef0738].
︙ | |||
57 58 59 60 61 62 63 64 65 66 67 68 69 70 | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | + + + | def generateParagraph (sParagraph, aGrammErrs, aSpellErrs, nWidth=100): "Returns a text with readable errors" if not sParagraph: return "" lGrammErrs = sorted(aGrammErrs, key=lambda d: d["nStart"]) lSpellErrs = sorted(aSpellErrs, key=lambda d: d['nStart']) lErrors = sorted(lGrammErrs + lSpellErrs, key=lambda d: d["nStart"]) for n, dErr in enumerate(lErrors, 1): dErr["iError"] = n sText = "" nOffset = 0 for sLine in wrap(sParagraph, nWidth): # textwrap.wrap(sParagraph, nWidth, drop_whitespace=False) sText += sLine + "\n" nLineLen = len(sLine) sErrLine = "" nLenErrLine = 0 |
︙ | |||
94 95 96 97 98 99 100 | 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 | - + - + - + - + | if nGrammErr: sText += getReadableErrors(lGrammErrs[:nGrammErr], nWidth) del lGrammErrs[0:nGrammErr] if nSpellErr: sText += getReadableErrors(lSpellErrs[:nSpellErr], nWidth, True) del lSpellErrs[0:nSpellErr] nOffset += nLineLen |
︙ |
Modified grammalecte-cli.py from [6a3b09f861] to [660294b341].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | + + | #!/usr/bin/env python3 """ Grammalecte CLI (command line interface) """ import sys import os.path import argparse import json import re import traceback import grammalecte import grammalecte.text as txt from grammalecte.graphspell.echo import echo _EXAMPLE = "Quoi ? Racontes ! Racontes-moi ! Bon sangg, parles ! Oui. Il y a des menteur partout. " \ |
︙ | |||
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 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 | + + + + + + + + + + + + + + + + + + + + + | except json.JSONDecodeError: print("# Error. File <" + spf + " is not a valid JSON file.") return None return oJSON print("# Error: file <" + spf + "> not found.") return None def getCommand (): while True: print("COMMANDS: [N]ext paragraph [Q]uit.") print(" [Error number]>[suggestion number]") print(" [Error number] (apply first suggestion)") print(" [Error number]=[replacement]") sCommand = input(" ? ") if sCommand == "q" or sCommand == "Q" or sCommand == "n" or sCommand == "N": return sCommand elif re.match("^([0-9]+)(>[0-9]*|=.*|)$", sCommand): m = re.match("^([0-9]+)(>[0-9]*|=.*|)$", sCommand) nError = int(m.group(1)) - 1 cAction = m.group(2)[0:1] or ">" if cAction == ">": vSugg = int(m.group(2)[1:]) - 1 if m.group(2) else 0 else: vSugg = m.group(2)[1:] return (nError, cAction, vSugg) def main (): "launch the CLI (command line interface)" xParser = argparse.ArgumentParser() xParser.add_argument("-f", "--file", help="parse file (UTF-8 required!) [on Windows, -f is similar to -ff]", type=str) xParser.add_argument("-ff", "--file_to_file", help="parse file (UTF-8 required!) and create a result file (*.res.txt)", type=str) xParser.add_argument("-iff", "--interactive_file_to_file", help="parse file (UTF-8 required!) and create a result file (*.res.txt)", type=str) xParser.add_argument("-owe", "--only_when_errors", help="display results only when there are errors", action="store_true") xParser.add_argument("-j", "--json", help="generate list of errors in JSON (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-cl", "--concat_lines", help="concatenate lines not separated by an empty paragraph (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-tf", "--textformatter", help="auto-format text according to typographical rules (not with option --concat_lines)", action="store_true") xParser.add_argument("-tfo", "--textformatteronly", help="auto-format text and disable grammar checking (only with option --file or --file_to_file)", action="store_true") xParser.add_argument("-ctx", "--context", help="return errors with context (only with option --json)", action="store_true") xParser.add_argument("-wss", "--with_spell_sugg", help="add suggestions for spelling errors (only with option --file or --file_to_file)", action="store_true") |
︙ | |||
173 174 175 176 177 178 179 | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | oGrammarChecker.gce.setOptions({ opt:False for opt in xArgs.opt_off }) # disable grammar rules if xArgs.rule_off: for sRule in xArgs.rule_off: oGrammarChecker.gce.ignoreRule(sRule) |
︙ | |||
283 284 285 286 287 288 289 | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | - + | " ".join(dToken.get("lMorph", "")), \ "·".join(dToken.get("aTags", "")) ) ) echo(txt.getReadableErrors(dSentence["lGrammarErrors"], xArgs.width)) else: for sParagraph in txt.getParagraph(sText): if xArgs.textformatter: sText = oTextFormatter.formatText(sParagraph) |
Modified grammalecte-server.py from [38ce8a200e] to [2560b5c98b].
︙ | |||
30 31 32 33 34 35 36 | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | - + | def parseText (sText, dOptions=None, bFormatText=False, sError=""): "parse <sText> and return errors in a JSON format" sJSON = '{ "program": "grammalecte-fr", "version": "'+oGCE.version+'", "lang": "'+oGCE.lang+'", "error": "'+sError+'", "data" : [\n' sDataJSON = "" for i, sParagraph in enumerate(txt.getParagraph(sText), 1): if bFormatText: sParagraph = oTextFormatter.formatText(sParagraph) |
︙ |