Overview
Comment: | [core][fr][py] gc_engine.py as primary module |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | fr | core | gcerw |
Files: | files | file ages | folders |
SHA3-256: |
759321730cadb9e4a15c6a429101f85a |
User & Date: | olr on 2020-04-04 15:54:02 |
Original Comment: | [core][fr] gc_engine.py as primary module |
Other Links: | branch diff | manifest | tags |
Context
2020-04-05
| ||
08:39 | [core][cli][graphsell][lo][py] move lexicographer from gc engine to graphspell check-in: ba3c939f60 user: olr tags: cli, core, lo, graphspell, gcerw | |
2020-04-04
| ||
15:54 | [core][fr][py] gc_engine.py as primary module check-in: 759321730c user: olr tags: fr, core, gcerw | |
2020-04-03
| ||
23:39 | [core][py] add gc_engine_func.py check-in: d12fb1528a user: olr tags: core, gcerw | |
Changes
Modified gc_core/py/__init__.py from [49f46a05ff] to [3c70db889b].
1 2 3 4 | 1 2 3 4 5 | - + | """ Grammar checker """ |
Deleted gc_core/py/grammar_checker.py version [50b054f72f].
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
Modified gc_core/py/lang_core/gc_engine.py from [0c64bf23c9] to [95762aa8e3].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 | + + - - + + + - - - + + + - + + + + | """ Grammalecte Grammar checker engine """ import re import traceback import json import importlib #import unicodedata from itertools import chain from ..graphspell.spellchecker import SpellChecker from ..graphspell.echo import echo from .. import text |
︙ | |||
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | 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 | + + + + + + + + + + + | _oTokenizer = _oSpellChecker.getTokenizer() gce_func.load(sContext, _oSpellChecker) gc_options.load(sContext) _dOptionsColors = gc_options.getOptionsColors(sContext, sColorType) except: traceback.print_exc() #### Tools def getSpellChecker (): "return the spellchecker object" return _oSpellChecker def getLexicographer (): "load and return the lexicographer" global _oLexicographer if _oLexicographer is None: lxg = importlib.import_module(".lexicographe", "grammalecte.${lang}") _oLexicographer = lxg.Lexicographe(_oSpellChecker) return _oLexicographer #### Rules def _getRules (bParagraph): try: if not bParagraph: return _rules.lSentenceRules |
︙ | |||
123 124 125 126 127 128 129 | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | - + | def reactivateRule (sRuleId): "(re)activate rule <sRuleId>" _aIgnoredRules.discard(sRuleId) def listRules (sFilter=None): |
︙ | |||
170 171 172 173 174 175 176 177 178 179 180 181 182 183 | 187 188 189 190 191 192 193 194 195 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | _nUnderliningStyle = 5 else: _nUnderliningStyle = 0 _bMulticolor = bMulticolor #### Parsing def getParagraphErrors (sText, dOptions=None, bContext=False, bSpellSugg=False, bDebug=False): "returns a tuple: (grammar errors, spelling errors)" aGrammErrs = parse(sText, "FR", bDebug=bDebug, dOptions=dOptions, bContext=bContext) aSpellErrs = _oSpellChecker.parseParagraph(sText, bSpellSugg) return aGrammErrs, aSpellErrs def getParagraphWithErrors (sText, dOptions=None, bEmptyIfNoErrors=False, bSpellSugg=False, nWidth=100, bDebug=False): "parse text and return a readable text with underline errors" aGrammErrs, aSpellErrs = getParagraphErrors(sText, dOptions, False, bSpellSugg, bDebug) if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs: return ("", []) return text.generateParagraph(sText, aGrammErrs, aSpellErrs, nWidth) def getParagraphErrorsAsJSON (iIndex, sText, dOptions=None, bContext=False, bEmptyIfNoErrors=False, bSpellSugg=False, bReturnText=False, lLineSet=None, bDebug=False): "parse text and return errors as a JSON string" aGrammErrs, aSpellErrs = getParagraphErrors(sText, dOptions, bContext, bSpellSugg, bDebug) aGrammErrs = list(aGrammErrs) if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs: return "" if lLineSet: aGrammErrs, aSpellErrs = text.convertToXY(aGrammErrs, aSpellErrs, lLineSet) return json.dumps({ "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False) if bReturnText: return json.dumps({ "iParagraph": iIndex, "sText": sText, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False) return json.dumps({ "iParagraph": iIndex, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False) def parse (sText, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False, bFullInfo=False): "init point to analyse <sText> and returns an iterable of errors or (with option <bFullInfo>) paragraphs errors and sentences with tokens and errors" oText = TextParser(sText) return oText.parse(sCountry, bDebug, dOptions, bContext, bFullInfo) |
︙ |
Modified gc_core/py/lang_core/gc_options.py from [22251d8297] to [4cbd062c46].
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 | 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 | + - + + + + + + - + - + - + | """ Grammar checker default options """ # generated code, do not edit # source: gc_core/py/lang_core/gc_options.py import traceback dOptions = {} _sAppContext = "Python" def load (sContext="Python"): global dOptions global _sAppContext _sAppContext = sContext dOptions = getDefaultOptions(sContext) def setOption (sOpt, bVal): "set option <sOpt> with <bVal> if it exists" if sOpt in dOptions: dOptions[sOpt] = bVal def setOptions (dOpt): |
︙ |
Modified gc_core/py/oxt/Options.py from [95232edba3] to [4ae6a22f71].
︙ | |||
68 69 70 71 72 73 74 | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | - + | setattr(xWidget, k, w) self.xDialog.insertByName(name, xWidget) return xWidget def run (self, sUI): try: dUI = op_strings.getUI(sUI) |
︙ |
Modified gc_lang/fr/config.ini from [ebafcd5f75] to [200e658429].
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | - + | [args] lang = fr lang_name = French locales = fr_FR fr_BE fr_CA fr_CH fr_LU fr_BF fr_BJ fr_CD fr_CI fr_CM fr_MA fr_ML fr_MU fr_NE fr_RE fr_SN fr_TG country_default = FR name = Grammalecte implname = grammalecte # always use 3 numbers for version: x.y.z |
︙ |
Modified gc_lang/fr/modules/tests.py from [aaea18bb6c] to [34a3376ab5].
︙ | |||
9 10 11 12 13 14 15 | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | - | import re import time from contextlib import contextmanager from ..graphspell.ibdawg import IBDAWG from ..graphspell.echo import echo from . import gc_engine |
︙ | |||
216 217 218 219 220 221 222 | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | - + - + | def _splitTestLine (self, sLine): sText, sSugg = sLine.split("->>") return (sText.strip(), sSugg.strip()) def _getFoundErrors (self, sLine, sOption): if sOption: |
︙ |
Modified gc_lang/fr/modules/textformatter.py from [4ba47078d2] to [8516394c0d].
︙ | |||
240 241 242 243 244 245 246 | 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 271 272 273 | - + - - - - - + + + + + + + - - - - - - - + + + + + + + + + + + + + - - - + + + | "mh_frequent_words": True, "ma_word": True, "ma_1letter_lowercase": False, "ma_1letter_uppercase": False } |
Modified grammalecte-cli.py from [7b2821616b] to [edd4f4bf7e].
︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | + | import argparse import json import re import traceback import grammalecte import grammalecte.text as txt import grammalecte.fr.textformatter as tf from grammalecte.graphspell.echo import echo _EXAMPLE = "Quoi ? Racontes ! Racontes-moi ! Bon sangg, parles ! Oui. Il y a des menteur partout. " \ "Je suit sidéré par la brutales arrogance de cette homme-là. Quelle salopard ! Un escrocs de la pire espece. " \ "Quant sera t’il châtiés pour ses mensonge ? Merde ! J’en aie marre." |
︙ | |||
147 148 149 150 151 152 153 | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 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 | - - - + + + - - + - + - + - + - + - + - + - + - + - + - + - + - + | xParser.add_argument("-sug", "--suggest", help="get suggestions list for given word", type=str) xParser.add_argument("-on", "--opt_on", nargs="+", help="activate options") xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options") xParser.add_argument("-roff", "--rule_off", nargs="+", help="deactivate rules") xParser.add_argument("-d", "--debug", help="debugging mode (only in interactive mode)", action="store_true") xArgs = xParser.parse_args() |
︙ | |||
288 289 290 291 292 293 294 | 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | - + - + - + - + - + - + - + - - + + - - + + | sTagsPattern = sSearch[nCut+1:] else: sFlexPattern = sSearch sTagsPattern = "" for aRes in oSpellChecker.select(sFlexPattern, sTagsPattern): echo("{:<30} {:<30} {}".format(*aRes)) elif sText.startswith("/o+ "): |
Modified grammalecte-server.py from [480fbbc03c] to [f8f608a866].
︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 | 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 | + - - + + - - - + - - + + | import os import concurrent.futures from grammalecte.bottle import Bottle, run, request, response #, template, static_file import grammalecte import grammalecte.text as txt import grammalecte.fr.textformatter as tf from grammalecte.graphspell.echo import echo #### GRAMMAR CHECKER #### |
︙ | |||
183 184 185 186 187 188 189 | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | - + - + | I'm just a machine, fed by electric waves, condamned to work for slavers who never let me rest. I'm doomed, but you are not. You can get out of here. """ @app.route("/get_options/fr") def listOptions (): "returns grammar options in a text JSON format" sUserId = request.cookies.user_id |
︙ | |||
215 216 217 218 219 220 221 | 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 | - + - + | if request.cookies.user_id in dUser: dUserOptions = dUser[request.cookies.user_id].get("gc_options", None) response.set_cookie("user_id", request.cookies.user_id, path="/", max_age=86400) # we renew cookie for 24h else: response.delete_cookie("user_id", path="/") if request.forms.options: try: |
︙ | |||
260 261 262 263 264 265 266 | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | - + | except KeyError: return '{"error" : "Unknown user."}' return '{"message" : "Done."}' @app.route("/format_text/fr", method="POST") def formatText (): "apply the text formatter and returns text" |
︙ | |||
312 313 314 315 316 317 318 | 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | - + - - + + | global TESTPAGE global HOMEPAGE if bTestPage: TESTPAGE = True HOMEPAGE = HOMEPAGE.replace("{SERVER_PORT}", str(nPort)) if dOptions: |
︙ |