Changes In Branch rg Through [9d39408049] Excluding Merge-Ins
This is equivalent to a diff from cb3f319c08 to 9d39408049
2018-07-16
| ||
13:37 | [build] changeReferenceToken before prepareFunction check-in: 7d80af29a6 user: olr tags: build, rg | |
2018-07-15
| ||
11:33 | [build] fix rules generation when first token was multiple and a selected group check-in: 9d39408049 user: olr tags: build, rg | |
09:43 | [build] prepareFunctions: use token value by default check-in: 450e1ec422 user: olr tags: build, rg | |
2018-06-25
| ||
07:58 | [fr] faux positif: en tant que président du conseil (trailing spaces automatically removed) check-in: 37fb199673 user: olr tags: trunk, fr | |
2018-06-24
| ||
19:03 | merge trunk check-in: 099647c959 user: olr tags: rg | |
2018-06-22
| ||
07:46 | [cli] option to load personal dictionary check-in: cb3f319c08 user: olr tags: trunk, cli | |
2018-06-15
| ||
20:44 | [fr] faux positif: accord de laisser avec les pronoms sans impératif check-in: 24d41be12e user: olr tags: trunk, fr | |
Modified compile_rules.py from [1ea2b6d97a] to [4d074615bf].
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 | 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 66 67 68 | + + + + + - - + + - + - - - + + + - - - - - - + + + + + + | """ Grammalecte: compile rules """ import re import traceback import json import compile_rules_js_convert as jsconv import compile_rules_graph as crg dDEF = {} lFUNCTIONS = [] aRULESET = set() # set of rule-ids to check if there is several rules with the same id nRULEWITHOUTNAME = 0 dJSREGEXES = {} sWORDLIMITLEFT = r"(?<![\w.,–-])" # r"(?<![-.,—])\b" seems slower sWORDLIMITRIGHT = r"(?![\w–-])" # r"\b(?!-—)" seems slower def prepareFunction (s): "convert simple rule syntax to a string of Python code" s = s.replace("__also__", "bCondMemo") s = s.replace("__else__", "not bCondMemo") s = re.sub(r"isStart *\(\)", 'before("^ *$|, *$")', s) s = re.sub(r"isRealStart *\(\)", 'before("^ *$")', s) s = re.sub(r"isStart0 *\(\)", 'before0("^ *$|, *$")', s) s = re.sub(r"isRealStart0 *\(\)", 'before0("^ *$")', s) s = re.sub(r"isEnd *\(\)", 'after("^ *$|^,")', s) s = re.sub(r"isRealEnd *\(\)", 'after("^ *$")', s) s = re.sub(r"isEnd0 *\(\)", 'after0("^ *$|^,")', s) s = re.sub(r"isRealEnd0 *\(\)", 'after0("^ *$")', s) |
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | 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 138 | + - + + + + + + + + + | nState = 4 elif nState == 4: nState = 0 return sUp def countGroupInRegex (sRegex): "returns the number of groups in <sRegex>" try: return re.compile(sRegex).groups except: traceback.print_exc() print(sRegex) return 0 def createRule (s, nIdLine, sLang, bParagraph, dOptPriority): "returns rule as list [option name, regex, bCaseInsensitive, identifier, list of actions]" global dJSREGEXES global nRULEWITHOUTNAME |
145 146 147 148 149 150 151 | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | - + | #### REGEX TRIGGER i = s.find(" <<-") if i == -1: print("# Error: no condition at line " + sLineId) return None sRegex = s[:i].strip() s = s[i+4:] |
200 201 202 203 204 205 206 | 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | - + - + + + + + + + + + + + + + + + + - - - - + + - - - + - + + - + - - - - + - - - + - - - + + - - - - - - - - - - + + + + + + + + + - - - - + + - - - - + + - - - - + + + + + - - - + + - - + + + | sRegex = sRegex.replace("(?i)", "") sRegex = uppercase(sRegex, sLang) else: print("# Unknown case mode [" + cCaseMode + "] at line " + sLineId) ## check regex try: |
389 390 391 392 393 394 395 | 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | - + | m = re.match("OPTGROUP/([a-z0-9]+):(.+)$", sLine) lStructOpt.append( (m.group(1), list(map(str.split, m.group(2).split(",")))) ) elif sLine.startswith("OPTSOFTWARE:"): lOpt = [ [s, {}] for s in sLine[12:].strip().split() ] # don’t use tuples (s, {}), because unknown to JS elif sLine.startswith("OPT/"): m = re.match("OPT/([a-z0-9]+):(.+)$", sLine) for i, sOpt in enumerate(m.group(2).split()): |
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | + - - - - + + + + - + - - + - - - + + + - - - + + - + + + + + + + + + + + + + + + + + + + + + + + - + + | print(" options defined for: " + ", ".join([ t[0] for t in lOpt ])) dOptions = { "lStructOpt": lStructOpt, "dOptLabel": dOptLabel, "sDefaultUILang": sDefaultUILang } dOptions.update({ "dOpt"+k: v for k, v in lOpt }) return dOptions, dOptPriority def printBookmark (nLevel, sComment, nLine): "print bookmark within the rules file" print(" {:>6}: {}".format(nLine, " " * nLevel + sComment)) def make (spLang, sLang, bJavaScript): "compile rules, returns a dictionary of values" # for clarity purpose, don’t create any file here print("> read rules file...") try: lRules = open(spLang + "/rules.grx", 'r', encoding="utf-8").readlines() except: print("Error. Rules file in project [" + sLang + "] not found.") exit() # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines print(" parsing rules...") |
513 514 515 516 517 518 519 | 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | - - - - + + + - + - + - - + + - - - - - - - - - + + + + + + + + + + + + + - + | lSentenceRulesJS.append(jsconv.pyRuleToJS(aRule, dJSREGEXES, sWORDLIMITLEFT)) # creating file with all functions callable by rules print(" creating callables...") sPyCallables = "# generated code, do not edit\n" sJSCallables = "// generated code, do not edit\nconst oEvalFunc = {\n" for sFuncName, sReturn in lFUNCTIONS: |
Added compile_rules_graph.py version [60e97fc2e5].
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 66 67 68 69 70 71 72 73 74 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 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 143 144 145 146 147 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 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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | """ Grammalecte: compile rules Create a Direct Acyclic Rule Graphs (DARGs) """ import re import traceback import json import darg dACTIONS = {} dFUNCTIONS = {} def prepareFunction (s): "convert simple rule syntax to a string of Python code" s = s.replace("__also__", "bCondMemo") s = s.replace("__else__", "not bCondMemo") s = re.sub(r"(morph|analyse|value|displayInfo)[(]\\(\d+)", 'g_\\1(lToken[\\2+nTokenOffset]', s) s = re.sub(r"(select|exclude|define|define_from)[(][\\](\d+)", 'g_\\1(lToken[\\2+nTokenOffset]', s) s = re.sub(r"(tag_before|tag_after)[(][\\](\d+)", 'g_\\1(lToken[\\2+nTokenOffset], dTags', s) s = re.sub(r"space_after[(][\\](\d+)", 'g_space_between_tokens(lToken[\\1+nTokenOffset], lToken[\\1+nTokenOffset+1]', s) s = re.sub(r"analyse_with_next[(][\\](\d+)", 'g_merged_analyse(lToken[\\1+nTokenOffset], lToken[\\1+nTokenOffset+1]', s) s = re.sub(r"(morph|analyse|value)\(>1", 'g_\\1(lToken[nLastToken+1]', s) # next token s = re.sub(r"(morph|analyse|value)\(<1", 'g_\\1(lToken[nTokenOffset]', s) # previous token s = re.sub(r"\bspell *[(]", '_oSpellChecker.isValid(', s) s = re.sub(r"\bbefore\(\s*", 'look(sSentence[:lToken[1+nTokenOffset]["nStart"]], ', s) # before(s) s = re.sub(r"\bafter\(\s*", 'look(sSentence[lToken[nLastToken]["nEnd"]:], ', s) # after(s) s = re.sub(r"\bbefore0\(\s*", 'look(sSentence0[:lToken[1+nTokenOffset]["nStart"]], ', s) # before0(s) s = re.sub(r"\bafter0\(\s*", 'look(sSentence[lToken[nLastToken]["nEnd"]:], ', s) # after0(s) s = re.sub(r"[\\](\d+)", 'lToken[\\1+nTokenOffset]["sValue"]', s) return s def genTokenLines (sTokenLine, dDef): "tokenize a string and return a list of lines of tokens" lToken = sTokenLine.split() lTokenLines = None for sToken in lToken: # optional token? bNullPossible = sToken.startswith("?") and sToken.endswith("¿") if bNullPossible: sToken = sToken[1:-1] # token with definition? if sToken.startswith("({") and sToken.endswith("})") and sToken[1:-1] in dDef: sToken = "(" + dDef[sToken[1:-1]] + ")" elif sToken.startswith("{") and sToken.endswith("}") and sToken in dDef: sToken = dDef[sToken] if ( (sToken.startswith("[") and sToken.endswith("]")) or (sToken.startswith("([") and sToken.endswith("])")) ): # multiple token bSelectedGroup = sToken.startswith("(") and sToken.endswith(")") if bSelectedGroup: sToken = sToken[1:-1] lNewToken = sToken[1:-1].split("|") if not lTokenLines: lTokenLines = [ ["("+s+")"] for s in lNewToken ] if bSelectedGroup else [ [s] for s in lNewToken ] if bNullPossible: lTokenLines.extend([ [] for i in range(len(lNewToken)+1) ]) else: lNewTemp = [] if bNullPossible: for aRule in lTokenLines: for sElem in lNewToken: aNewRule = list(aRule) aNewRule.append(sElem) lNewTemp.append(aNewRule) else: sElem1 = lNewToken.pop(0) for aRule in lTokenLines: for sElem in lNewToken: aNewRule = list(aRule) aNewRule.append("(" + sElem + ")" if bSelectedGroup else sElem) lNewTemp.append(aNewRule) aRule.append("(" + sElem1 + ")" if bSelectedGroup else sElem1) lTokenLines.extend(lNewTemp) else: # simple token if not lTokenLines: lTokenLines = [[sToken], []] if bNullPossible else [[sToken]] else: if bNullPossible: lNewTemp = [] for aRule in lTokenLines: lNew = list(aRule) lNew.append(sToken) lNewTemp.append(lNew) lTokenLines.extend(lNewTemp) else: for aRule in lTokenLines: aRule.append(sToken) for aRule in lTokenLines: yield aRule def createRule (iLine, sRuleName, sTokenLine, iActionBlock, sActions, nPriority, dOptPriority, dDef): "generator: create rule as list" # print(iLine, "//", sRuleName, "//", sTokenLine, "//", sActions, "//", nPriority) for lToken in genTokenLines(sTokenLine, dDef): # Calculate positions dPos = {} # key: iGroup, value: iToken iGroup = 0 if iLine == 2211: print(lToken) for i, sToken in enumerate(lToken): if sToken.startswith("(") and sToken.endswith(")"): lToken[i] = sToken[1:-1] iGroup += 1 dPos[iGroup] = i + 1 # we add 1, for we count tokens from 1 to n (not from 0) # Parse actions for iAction, sAction in enumerate(sActions.split(" <<- ")): sAction = sAction.strip() if sAction: sActionId = sRuleName + "__b" + str(iActionBlock) + "_a" + str(iAction) + "_" + str(len(lToken)) aAction = createAction(sActionId, sAction, nPriority, dOptPriority, len(lToken), dPos) if aAction: dACTIONS[sActionId] = aAction lResult = list(lToken) lResult.extend(["##"+str(iLine), sActionId]) yield lResult else: print(" # Error on action at line:", iLine) def changeReferenceToken (sText, dPos): "change group reference in <sText> with values in <dPos>" for i in range(len(dPos), 0, -1): sText = sText.replace("\\"+str(i), "\\"+str(dPos[i])) return sText def checkTokenNumbers (sText, sActionId, nToken): "check if token references in <sText> greater than <nToken> (debugging)" for x in re.finditer(r"\\(\d+)", sText): if int(x.group(1)) > nToken: print("# Error in token index at line " + sActionId + " ("+str(nToken)+" tokens only)") print(sText) def checkIfThereIsCode (sText, sActionId): "check if there is code in <sText> (debugging)" if re.search("[.]\\w+[(]|sugg\\w+[(]|\\([0-9]|\\[[0-9]", sText): print("# Warning at line " + sActionId + ": This message looks like code. Line should probably begin with =") print(sText) def createAction (sActionId, sAction, nPriority, dOptPriority, nToken, dPos): "create action rule as a list" # Option sOption = False m = re.match("/(\\w+)/", sAction) if m: sOption = m.group(1) sAction = sAction[m.end():].strip() if nPriority == -1: nPriority = dOptPriority.get(sOption, 4) # valid action? m = re.search(r"(?P<action>[-~=/>])(?P<start>\d+\.?|)(?P<end>:\.?\d+|)>>", sAction) if not m: print(" # Error. No action found at: ", sActionId) return None # Condition sCondition = sAction[:m.start()].strip() if sCondition: sCondition = prepareFunction(sCondition) sCondition = changeReferenceToken(sCondition, dPos) dFUNCTIONS["_g_c_"+sActionId] = sCondition sCondition = "_g_c_"+sActionId else: sCondition = "" # Action cAction = m.group("action") sAction = sAction[m.end():].strip() sAction = changeReferenceToken(sAction, dPos) if not m.group("start"): iStartAction = 1 iEndAction = 0 else: if cAction != "-" and (m.group("start").endswith(".") or m.group("end").startswith(":.")): print(" # Error. Wrong selection on tokens.", sActionId) return None iStartAction = int(m.group("start")) if not m.group("start").endswith(".") else int("-"+m.group("start")[:-1]) if not m.group("end"): iEndAction = iStartAction else: iEndAction = int(m.group("end")[1:]) if not m.group("end").startswith(":.") else int("-" + m.group("end")[2:]) if dPos and m.group("start"): try: iStartAction = dPos[iStartAction] if iEndAction: iEndAction = dPos[iEndAction] except: print("# Error. Wrong groups in: " + sActionId) print(" iStartAction:", iStartAction, "iEndAction:", iEndAction) print(" ", dPos) if cAction == "-": ## error iMsg = sAction.find(" # ") if iMsg == -1: sMsg = "# Error. Error message not found." sURL = "" print(sMsg + " Action id: " + sActionId) else: sMsg = sAction[iMsg+3:].strip() sAction = sAction[:iMsg].strip() sURL = "" mURL = re.search("[|] *(https?://.*)", sMsg) if mURL: sURL = mURL.group(1).strip() sMsg = sMsg[:mURL.start(0)].strip() checkTokenNumbers(sMsg, sActionId, nToken) if sMsg[0:1] == "=": sMsg = prepareFunction(sMsg[1:]) dFUNCTIONS["g_m_"+sActionId] = sMsg sMsg = "=g_m_"+sActionId else: checkIfThereIsCode(sMsg, sActionId) # checking consistancy checkTokenNumbers(sAction, sActionId, nToken) if cAction == ">": ## no action, break loop if condition is False return [sOption, sCondition, cAction, ""] if not sAction: print("# Error in action at line " + sActionId + ": This action is empty.") if sAction[0:1] != "=" and cAction != "=": checkIfThereIsCode(sAction, sActionId) if cAction == "-": ## error detected --> suggestion if sAction[0:1] == "=": sAction = prepareFunction(sAction) dFUNCTIONS["_g_s_"+sActionId] = sAction[1:] sAction = "=_g_s_"+sActionId elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] if not sMsg: print("# Error in action at line " + sActionId + ": The message is empty.") return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction, nPriority, sMsg, sURL] elif cAction == "~": ## text processor if sAction[0:1] == "=": sAction = prepareFunction(sAction) dFUNCTIONS["_g_p_"+sActionId] = sAction[1:] sAction = "=_g_p_"+sActionId elif sAction.startswith('"') and sAction.endswith('"'): sAction = sAction[1:-1] return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction] elif cAction == "/": ## tags return [sOption, sCondition, cAction, sAction, iStartAction, iEndAction] elif cAction == "=": ## disambiguator if sAction[0:1] == "=": sAction = sAction[1:] if "define(" in sAction and not re.search(r"define\(\\\d+ *, *\[.*\] *\)", sAction): print("# Error in action at line " + sActionId + ": second argument for <define> must be a list of strings") sAction = prepareFunction(sAction) dFUNCTIONS["_g_d_"+sActionId] = sAction sAction = "_g_d_"+sActionId return [sOption, sCondition, cAction, sAction] else: print(" # Unknown action.", sActionId) return None def make (lRule, dDef, sLang, dOptPriority, bJavaScript): "compile rules, returns a dictionary of values" # for clarity purpose, don’t create any file here # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines print(" parsing rules...") lTokenLine = [] sActions = "" nPriority = -1 dAllGraph = {} sGraphName = "" iActionBlock = 0 for i, sLine in lRule: sLine = sLine.rstrip() if "\t" in sLine: # tabulation not allowed print("Error. Tabulation at line: ", i) exit() elif sLine.startswith("@@@@GRAPH: "): # rules graph call m = re.match(r"@@@@GRAPH: *(\w+)", sLine.strip()) if m: sGraphName = m.group(1) if sGraphName in dAllGraph: print("Error. Group name " + sGraphName + " already exists.") exit() dAllGraph[sGraphName] = [] else: print("Error. Graph name not found at line", i) exit() elif sLine.startswith("__") and sLine.endswith("__"): # new rule group m = re.match("__(\\w+)(!\\d|)__", sLine) if m: sRuleName = m.group(1) iActionBlock = 1 nPriority = int(m.group(2)[1:]) if m.group(2) else -1 else: print("Error at rule group: ", sLine, " -- line:", i) break elif re.search("^ +<<- ", sLine) or sLine.startswith(" ") \ or re.search("^ +#", sLine) or re.search(r"^ [-~=>/](?:\d\.?(?::\.?\d+|)|)>> ", sLine) : # actions sActions += " " + sLine.strip() elif re.match("[ ]*$", sLine): # empty line to end merging if not lTokenLine: continue if not sActions: print("Error. No action found at line:", i) exit() if not sGraphName: print("Error. All rules must belong to a named graph. Line: ", i) exit() for j, sTokenLine in lTokenLine: dAllGraph[sGraphName].append((j, sRuleName, sTokenLine, iActionBlock, sActions, nPriority)) lTokenLine.clear() sActions = "" iActionBlock += 1 elif sLine.startswith((" ")): # tokens lTokenLine.append([i, sLine.strip()]) else: print("Unknown line:") print(sLine) # processing rules print(" preparing rules...") for sGraphName, lRuleLine in dAllGraph.items(): lPreparedRule = [] for i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority in lRuleLine: for lRule in createRule(i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority, dOptPriority, dDef): lPreparedRule.append(lRule) # Graph creation oDARG = darg.DARG(lPreparedRule, sLang) dAllGraph[sGraphName] = oDARG.createGraph() # Debugging if False: print("\nRULES:") for e in lPreparedRule: if e[-2] == "##2211": print(e) if False: print("\nGRAPH:", sGraphName) for k, v in dAllGraph[sGraphName].items(): print(k, "\t", v) # creating file with all functions callable by rules print(" creating callables...") sPyCallables = "# generated code, do not edit\n" #sJSCallables = "// generated code, do not edit\nconst oEvalFunc = {\n" for sFuncName, sReturn in dFUNCTIONS.items(): if sFuncName.startswith("_g_c_"): # condition sParams = "lToken, nTokenOffset, nLastToken, sCountry, bCondMemo, dTags, sSentence, sSentence0" elif sFuncName.startswith("g_m_"): # message sParams = "lToken, nTokenOffset" elif sFuncName.startswith("_g_s_"): # suggestion sParams = "lToken, nTokenOffset" elif sFuncName.startswith("_g_p_"): # preprocessor sParams = "lToken, nTokenOffset" elif sFuncName.startswith("_g_d_"): # disambiguator sParams = "lToken, nTokenOffset" else: print("# Unknown function type in [" + sFuncName + "]") continue sPyCallables += "def {} ({}):\n".format(sFuncName, sParams) sPyCallables += " return " + sReturn + "\n" #sJSCallables += " {}: function ({})".format(sFuncName, sParams) + " {\n" #sJSCallables += " return " + jsconv.py2js(sReturn) + ";\n" #sJSCallables += " },\n" #sJSCallables += "}\n" # Debugging if False: print("\nActions:") for sActionName, aAction in dACTIONS.items(): print(sActionName, aAction) print("\nFunctions:") print(sPyCallables) # Result return { "graph_callables": sPyCallables, "rules_graphs": dAllGraph, "rules_actions": dACTIONS } |
Modified compile_rules_js_convert.py from [5ad87f3f46] to [9aa0239064].
| 1 2 3 4 5 6 7 8 9 10 | + - + + | """ |
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + | sRegex = sRegex + "i" if not lNegLookBeforeRegex: lNegLookBeforeRegex = None return (sRegex, lNegLookBeforeRegex) def pyRuleToJS (lRule, dJSREGEXES, sWORDLIMITLEFT): "modify Python rules -> JS rules" lRuleJS = copy.deepcopy(lRule) # graph rules if lRuleJS[0] == "@@@@": return lRuleJS del lRule[-1] # tGroups positioning codes are useless for Python # error messages for aAction in lRuleJS[6]: if aAction[1] == "-": aAction[2] = aAction[2].replace(" ", " ") # nbsp --> nnbsp aAction[4] = aAction[4].replace("« ", "« ").replace(" »", " »").replace(" :", " :").replace(" :", " :") # js regexes lRuleJS[1], lNegLookBehindRegex = regex2js(dJSREGEXES.get(lRuleJS[3], lRuleJS[1]), sWORDLIMITLEFT) lRuleJS.append(lNegLookBehindRegex) return lRuleJS def writeRulesToJSArray (lRules): "create rules as a string of arrays (to be bundled in a JSON string)" sArray = "[\n" for sOption, aRuleGroup in lRules: if sOption != "@@@@": |
Added darg.py version [ad8b8ac55e].
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 66 67 68 69 70 71 72 73 74 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 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 143 144 145 146 147 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 247 248 249 250 251 252 253 254 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | #!python3 """ RULE GRAPH BUILDER """ # by Olivier R. # License: MPL 2 import re import traceback from graphspell.progressbar import ProgressBar class DARG: """DIRECT ACYCLIC RULE GRAPH""" # This code is inspired from Steve Hanov’s DAWG, 2011. (http://stevehanov.ca/blog/index.php?id=115) def __init__ (self, lRule, sLangCode): print("===== Direct Acyclic Rule Graph - Minimal Acyclic Finite State Automaton =====") # Preparing DARG print(" > Preparing list of tokens") self.sLangCode = sLangCode self.nRule = len(lRule) self.aPreviousRule = [] Node.resetNextId() self.oRoot = Node() self.lUncheckedNodes = [] # list of nodes that have not been checked for duplication. self.lMinimizedNodes = {} # list of unique nodes that have been checked for duplication. self.nNode = 0 self.nArc = 0 # build lRule.sort() oProgBar = ProgressBar(0, len(lRule)) for aRule in lRule: self.insert(aRule) oProgBar.increment(1) oProgBar.done() self.finish() self.countNodes() self.countArcs() self.displayInfo() # BUILD DARG def insert (self, aRule): "insert a new rule (tokens must be inserted in order)" if aRule < self.aPreviousRule: exit("# Error: tokens must be inserted in order.") # find common prefix between word and previous word nCommonPrefix = 0 for i in range(min(len(aRule), len(self.aPreviousRule))): if aRule[i] != self.aPreviousRule[i]: break nCommonPrefix += 1 # Check the lUncheckedNodes for redundant nodes, proceeding from last # one down to the common prefix size. Then truncate the list at that point. self._minimize(nCommonPrefix) # add the suffix, starting from the correct node mid-way through the graph if len(self.lUncheckedNodes) == 0: oNode = self.oRoot else: oNode = self.lUncheckedNodes[-1][2] iToken = nCommonPrefix for sToken in aRule[nCommonPrefix:]: oNextNode = Node() oNode.dArcs[sToken] = oNextNode self.lUncheckedNodes.append((oNode, sToken, oNextNode)) if iToken == (len(aRule) - 2): oNode.bFinal = True iToken += 1 oNode = oNextNode oNode.bFinal = True self.aPreviousRule = aRule def finish (self): "minimize unchecked nodes" self._minimize(0) def _minimize (self, downTo): # proceed from the leaf up to a certain point for i in range( len(self.lUncheckedNodes)-1, downTo-1, -1 ): oNode, sToken, oChildNode = self.lUncheckedNodes[i] if oChildNode in self.lMinimizedNodes: # replace the child with the previously encountered one oNode.dArcs[sToken] = self.lMinimizedNodes[oChildNode] else: # add the state to the minimized nodes. self.lMinimizedNodes[oChildNode] = oChildNode self.lUncheckedNodes.pop() def countNodes (self): "count nodes within the whole graph" self.nNode = len(self.lMinimizedNodes) def countArcs (self): "count arcs within the whole graph" self.nArc = 0 for oNode in self.lMinimizedNodes: self.nArc += len(oNode.dArcs) def displayInfo (self): "display informations about the rule graph" print(" * {:<12} {:>16,}".format("Rules:", self.nRule)) print(" * {:<12} {:>16,}".format("Nodes:", self.nNode)) print(" * {:<12} {:>16,}".format("Arcs:", self.nArc)) def createGraph (self): "create the graph as a dictionary" dGraph = { 0: self.oRoot.getNodeAsDict() } for oNode in self.lMinimizedNodes: sHashId = oNode.__hash__() if sHashId not in dGraph: dGraph[sHashId] = oNode.getNodeAsDict() else: print("Error. Double node… same id: ", sHashId) print(str(oNode.getNodeAsDict())) dGraph = self._rewriteKeysOfDARG(dGraph) self._checkRegexes(dGraph) return dGraph def _rewriteKeysOfDARG (self, dGraph): "keys of DARG are long numbers (hashes): this function replace these hashes with smaller numbers (to reduce storing size)" # create translation dictionary dKeyTrans = {} for i, nKey in enumerate(dGraph): dKeyTrans[nKey] = i # replace keys dNewGraph = {} for nKey, dVal in dGraph.items(): dNewGraph[dKeyTrans[nKey]] = dVal for nKey, dVal in dGraph.items(): for sArc, val in dVal.items(): if type(val) is int: dVal[sArc] = dKeyTrans[val] else: for sArc, nKey in val.items(): val[sArc] = dKeyTrans[nKey] return dNewGraph def _checkRegexes (self, dGraph): "check validity of regexes" aRegex = set() for nKey, dVal in dGraph.items(): if "<re_value>" in dVal: for sRegex in dVal["<re_value>"]: if sRegex not in aRegex: self._checkRegex(sRegex) aRegex.add(sRegex) if "<re_morph>" in dVal: for sRegex in dVal["<re_morph>"]: if sRegex not in aRegex: self._checkRegex(sRegex) aRegex.add(sRegex) aRegex.clear() def _checkRegex (self, sRegex): #print(sRegex) if "¬" in sRegex: sPattern, sNegPattern = sRegex.split("¬") try: if not sNegPattern: print("# Warning! Empty negpattern:", sRegex) re.compile(sPattern) if sNegPattern != "*": re.compile(sNegPattern) except: print("# Error. Wrong regex:", sRegex) exit() else: try: if not sRegex: print("# Warning! Empty pattern:", sRegex) re.compile(sRegex) except: print("# Error. Wrong regex:", sRegex) exit() class Node: """Node of the rule graph""" NextId = 0 def __init__ (self): self.i = Node.NextId Node.NextId += 1 self.bFinal = False self.dArcs = {} # key: arc value; value: a node @classmethod def resetNextId (cls): "reset to 0 the node counter" cls.NextId = 0 def __str__ (self): # Caution! this function is used for hashing and comparison! cFinal = "1" if self.bFinal else "0" l = [cFinal] for (key, oNode) in self.dArcs.items(): l.append(str(key)) l.append(str(oNode.i)) return "_".join(l) def __hash__ (self): # Used as a key in a python dictionary. return self.__str__().__hash__() def __eq__ (self, other): # Used as a key in a python dictionary. # Nodes are equivalent if they have identical arcs, and each identical arc leads to identical states. return self.__str__() == other.__str__() def getNodeAsDict (self): "returns the node as a dictionary structure" dNode = {} dReValue = {} dReMorph = {} dRule = {} dLemma = {} dMeta = {} for sArc, oNode in self.dArcs.items(): if sArc.startswith("@") and len(sArc) > 1: dReMorph[sArc[1:]] = oNode.__hash__() elif sArc.startswith("~") and len(sArc) > 1: dReValue[sArc[1:]] = oNode.__hash__() elif sArc.startswith(">") and len(sArc) > 1: dLemma[sArc[1:]] = oNode.__hash__() elif sArc.startswith("*") and len(sArc) > 1: dMeta[sArc[1:]] = oNode.__hash__() elif sArc.startswith("##"): dRule[sArc[1:]] = oNode.__hash__() else: dNode[sArc] = oNode.__hash__() if dReValue: dNode["<re_value>"] = dReValue if dReMorph: dNode["<re_morph>"] = dReMorph if dLemma: dNode["<lemmas>"] = dLemma if dMeta: dNode["<meta>"] = dMeta if dRule: dNode["<rules>"] = dRule #if self.bFinal: # dNode["<final>"] = 1 return dNode |
Modified gc_core/js/lang_core/gc_engine.js from [7ee1350cd7] to [12095116ac].
35 36 37 38 39 40 41 | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | - | // data let _sAppContext = ""; // what software is running let _dOptions = null; let _aIgnoredRules = new Set(); let _oSpellChecker = null; |
325 326 327 328 329 330 331 332 333 334 335 336 337 338 | 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | + | var spellchecker = require("resource://grammalecte/graphspell/spellchecker.js"); _oSpellChecker = new spellchecker.SpellChecker("${lang}", "", "${dic_main_filename_js}", "${dic_extended_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}"); } else { _oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_main_filename_js}", "${dic_extended_filename_js}", "${dic_community_filename_js}", "${dic_personal_filename_js}"); } _sAppContext = sContext; _dOptions = gc_options.getOptions(sContext).gl_shallowCopy(); // duplication necessary, to be able to reset to default _oSpellChecker.activateStorage(); } catch (e) { helpers.logerror(e); } }, getSpellChecker: function () { |
374 375 376 377 378 379 380 | 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | - - + + + - + - - - - - - - - - - - + - - - - + - + + - + - + - + + - + - + - - - - - - - - - - - | function displayInfo (dDA, aWord) { // for debugging: info of word if (!aWord) { helpers.echo("> nothing to find"); return true; } |
563 564 565 566 567 568 569 | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | - + - - - + - + - + - + - - - + - + - + | function select (dDA, nPos, sWord, sPattern, lDefault=null) { if (!sWord) { return true; } if (dDA.has(nPos)) { return true; } |
Modified gc_core/py/__init__.py from [aeadedff14] to [49f46a05ff].
1 2 | 1 2 3 4 5 | + + + | """ Grammar checker """ from .grammar_checker import * |
Modified gc_core/py/grammar_checker.py from [79ce1061e8] to [634e5c7c61].
| 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | + - + - + + + + + - - - + + + + - - - + + + + + + + + | """ |
Modified gc_core/py/lang_core/gc_engine.py from [72ecd7c680] to [e5bcf3ef2a].
| 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 | + - - + + + + + + + + + + + + + + + + | """ |
29 30 31 32 33 34 35 | 44 45 46 47 48 49 50 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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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 138 139 140 141 142 143 144 145 146 147 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 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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + - + - - + + + + - - - + + + - - - - - - - - + - - - + - + - - + + - + + - + - - - + + - - + + - + - - + - + - - + + - + + - - + + - - + + - - - - - - - - + + + | author = "${author}" _rules = None # module gc_rules # data _sAppContext = "" # what software is running _dOptions = None |
510 511 512 513 514 515 516 | 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 | - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + - - + - - - + + - - + - - - - - + + + + + + + + + + + + + + - - - + - - - - - - - - - - + - - + + - - + - + - - - + + + + + + + + + + + + + + + + | if sNegPattern and re.search(sNegPattern, s): return False if re.search(sPattern, s): return True return False |
Modified gc_core/py/lang_core/gc_options.py from [871c8d4b8f] to [c84731594a].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | + + + + + + | """ Grammar checker default options """ # generated code, do not edit def getUI (sLang): "returns dictionary of UI labels" if sLang in _dOptLabel: return _dOptLabel[sLang] return _dOptLabel["fr"] def getOptions (sContext="Python"): "returns dictionary of options" if sContext in dOpt: return dOpt[sContext] return dOpt["Python"] lStructOpt = ${lStructOpt} |
Modified gc_core/py/lang_core/gc_rules.py from [3cf95f4a21] to [2ef08593b5].
1 2 3 4 5 | 1 2 3 4 5 6 7 8 9 | + + + + | """ Grammar checker regex rules """ # generated code, do not edit lParagraphRules = ${paragraph_rules} lSentenceRules = ${sentence_rules} |
Added gc_core/py/lang_core/gc_rules_graph.py version [373592f3fb].
1 2 3 4 5 6 7 8 9 | + + + + + + + + + | """ Grammar checker graph rules """ # generated code, do not edit dAllGraph = ${rules_graphs} dRule = ${rules_actions} |
Modified gc_core/py/text.py from [133d154e72] to [137c7cc30f].
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 9 10 11 12 | + + + + | #!python3 """ Text tools """ import textwrap from itertools import chain def getParagraph (sText): "generator: returns paragraphs of text" |
39 40 41 42 43 44 45 | 43 44 45 46 47 48 49 50 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 83 84 85 86 87 88 89 | - + - + - + - + | return "" lGrammErrs = sorted(aGrammErrs, key=lambda d: d["nStart"]) lSpellErrs = sorted(aSpellErrs, key=lambda d: d['nStart']) sText = "" nOffset = 0 for sLine in wrap(sParagraph, nWidth): # textwrap.wrap(sParagraph, nWidth, drop_whitespace=False) sText += sLine + "\n" |
93 94 95 96 97 98 99 | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | - + - - + + - + - - + + | return sErrors def getReadableError (dErr, bSpell=False): "Returns an error dErr as a readable error" try: if bSpell: |
Added gc_lang/fr/French_language.txt version [0f13f2288a].
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 66 67 68 69 70 71 72 73 74 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 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 143 144 145 146 147 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 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 274 275 276 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | # NOTES SUR LA LANGUE FRANÇAISE ## CE QUI ENTOURE UN VERBE PRONOMS (avant) COD COI le / l’ la / l’ les en me / m’ me / m’ te / t’ te / t’ se / s’ lui nous nous vous nous se / s’ leur y SOMME [le|la|l’|les|en|me|m’|te|t’|se|s’|nous|vous|lui|leur|y] ADVERBE DE NÉGATION (avant) ne / n’ COMBINAISONS VALIDES ?[ne|n’]¿ [me|te|se] [le|la|l’|les] ?[ne|n’]¿ [m’|t’|s’] [le|la|l’|les|en|y] ?[ne|n’]¿ [le|la] [lui|leur] ?[ne|n’]¿ [l’|les] [lui|leur|en|y] ?[ne|n’]¿ [lui|leur] en ?[ne|n’]¿ [nous|vous] [le|la|l’|les|en|y] ne [le|la|l’|les|me|m’|te|t’|se|s’|nous|vous|lui|leur] n’ [en|y] RÉSUMÉ & SIMPLIFICATION [ne|n’|le|la|l’|les|en|me|m’|te|t’|se|s’|nous|vous|lui|leur|y] ?[ne|n’]¿ [le|la|l’|les|en|me|m’|te|t’|se|s’|nous|vous|lui|leur|y] ?[ne|n’]¿ [me|m’|te|t’|se|s’|nous|vous] [le|la|l’|les|en|y] ?[ne|n’]¿ [le|la|l’|les] [lui|leur|en|y] ?[ne|n’]¿ [lui|leur] en ADVERBE DE NÉGATION (après) guère jamais pas plus point que / qu’ rien PRONOMS À L’IMPÉRATIF APRÈS -moi -toi -lui -leur -nous -vous -le -la -les -en -y AVANT Uniquement les combinaisons avec l’adverbe de négation [ne|n’] ## DÉTERMINANTS SINGULIER PLURIEL le / la / l’ les ledit / ladite lesdits / lesdites un / une des du / de la des dudit / de ladite desdits / desdites de de ce / cet / cette ces icelui / icelle iceux / icelles mon / ma mes ton / ta tes son / sa ses votre nos notre vos leur leurs quel / quelle quels / quelles quelque quelques tout / toute tous / toutes chaque aucun / aucune nul / nulle plusieurs certains / certaines divers / diverses DÉTERMINANT & PRÉPOSITION au / à la aux audit / à ladite auxdits / auxdites ## CONJONCTIONS DE COORDINATION DE SUBORDINATION c’est-à-dire afin que pendant que c.-à-d. après que pour que car attendu que pourvu que donc avant que puisque et / & bien que quand mais comme que ni depuis que quoique or dès que sans que ou dès lors que sauf que partant excepté que selon que puis lorsque si sinon lors que tandis que soit malgré que tant que parce que ## PRÉPOSITIONS VERBALES UNIQUEMENT afin de NOMINALES ET VERBALES à entre excepté outre par pour sans sauf PRÉPOSITIONS ET DÉTERMINANTS au aux audit auxdits auxdites NOMINALES à l’instar de devers par-dessus (adv) à mi-distance de dixit par-devant (adv) après durant par-devers attendu dès parmi au-dedans (adv) en passé au-dehors (adv) endéans pendant au-delà (adv) envers pour au-dessous (adv) ès quant à/au/à la/aux au-dessus (adv) excepté revoici au-devant (adv) face à revoilà auprès de fors sauf autour de grâce à sans av hormis selon avant hors sous avec jusque suivant chez jusques sur concernant lez tandis (adv) contre lors de vers courant (+mois) lès versus dans malgré via depuis moins (adv) vis-à-vis derrière nonobstant (adv) voici dessous (adv) par-delà voilà dessus (adv) par-derrière (adv) vs devant (adv) par-dessous (adv) vu ## PRONOMS PRONOMS PERSONNELS SUJETS je moi-même mézigue tu toi-même tézigue il / elle lui / lui-même / elle-même césigue / sézigue on nous nous-même / nous-mêmes noszigues vous vous-même / vous-mêmes voszigues ils / elles eux / eux-mêmes / elles-mêmes leurszigues PRONOMS PERSONNELS OBJETS moi moi-même mézigue toi toi-même tézigue lui / elle lui-même / elle-même césigue / sézigue soi soi-même nous nous-même / nous-mêmes noszigues vous vous-même / vous-mêmes voszigues eux / elles eux / eux-mêmes / elles-mêmes leurszigues PRONOMS NÉGATIFS (SUJETS & OBJETS) aucun aucune dégun nul personne rien PRONOMS OBJETS PRÉVERBES la COD le COD les COD l’ COD leur COI lui COI me COD/COI te COD/COI se COD/COI nous COD/COI vous COD/COI y COI (proadv) en COD (proadv) PRONOMS DÉMONSTRATIFS (SUJETS ET OBJETS) çuilà propersuj properobj 3pe mas sg ça prodem mas sg ceci prodem mas sg cela prodem mas sg celle qui prodem fem sg celles qui prodem fem pl celle-ci prodem fem sg celle-là prodem fem sg celles-ci prodem fem pl celles-là prodem fem pl celui qui prodem mas sg celui-ci prodem mas sg celui-là prodem mas sg ceux qui prodem mas pl ceux-ci prodem mas pl ceux-là prodem mas pl icelle detdem prodem fem sg icelles detdem prodem fem pl icelui detdem prodem mas sg iceux detdem prodem mas pl PRONOMS DÉMONSTRATIFS (SUJETS) ce PRONOMS DÉMONSTRATIFS (OBJETS) ci (adv) PRONOMS RELATIFS auquel proint prorel mas sg auxquelles proint prorel fem pl auxquels proint prorel mas pl desquelles proint prorel fem pl desquels proint prorel mas pl dont prorel duquel proint prorel mas sg laquelle proint prorel fem sg lequel proint prorel mas sg lesquelles proint prorel fem pl lesquels proint prorel mas pl où advint prorel qué proint prorel qui proint prorel que proint prorel quid proint quoi proint prorel autre proind autrui proind quiconque proind prorel certaine detind proind chacun proind mas sg chacune proind fem sg d'aucuns proind mas pl grand-chose proind n'importe quoi proind n'importe qui proind plupart proind epi pl quelques-unes proind fem pl quelques-uns proind mas pl quelqu'un proind mas sg quelqu'une proind fem sg telle proind |
Modified gc_lang/fr/config.ini from [7c7adf7950] to [b6aa293b9a].
1 2 3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | - + - + | [args] lang = fr lang_name = French |
Modified gc_lang/fr/modules-js/conj.js from [f544af05b0] to [8124143953].
83 84 85 86 87 88 89 | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | - + | return this._lVtyp[this._dVerb[sVerb][0]]; }, getSimil: function (sWord, sMorph, bSubst=false) { if (!sMorph.includes(":V")) { return new Set(); } |
Modified gc_lang/fr/modules-js/gce_analyseur.js from [e2613ddcd2] to [bdc2b54804].
18 19 20 21 22 23 24 | 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 66 67 68 69 70 71 72 73 74 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 105 106 107 108 109 110 111 112 113 114 115 | - - + - - + - + + - + - + - - - + + - - + + - - - + + - - + + - - - + + - - + + | if (s2 == "vous") { return "vous"; } if (s2 == "eux") { return "ils"; } if (s2 == "elle" || s2 == "elles") { |
Modified gc_lang/fr/modules-js/gce_suggestions.js from [0c31bc1a27] to [6803550153].
8 9 10 11 12 13 14 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | - - + - + - + | var phonet = require("resource://grammalecte/fr/phonet.js"); } //// verbs function suggVerb (sFlex, sWho, funcSugg2=null) { |
57 58 59 60 61 62 63 | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | - + | return Array.from(aSugg).join("|"); } return ""; } function suggVerbPpas (sFlex, sWhat=null) { let aSugg = new Set(); |
107 108 109 110 111 112 113 | 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 143 144 145 146 147 148 149 150 151 152 153 154 | - + - + - + | return Array.from(aSugg).join("|"); } return ""; } function suggVerbTense (sFlex, sTense, sWho) { let aSugg = new Set(); |
172 173 174 175 176 177 178 | 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 | - + - + + - + | if (!sWho) { if (sSuj[0].gl_isLowerCase()) { // pas un pronom, ni un nom propre return ""; } sWho = ":3s"; } let aSugg = new Set(); |
254 255 256 257 258 259 260 | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | - - + | return Array.from(aSugg).join("|"); } return ""; } function suggMasSing (sFlex, bSuggSimil=false) { // returns masculine singular forms |
290 291 292 293 294 295 296 | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | - - + | return Array.from(aSugg).join("|"); } return ""; } function suggMasPlur (sFlex, bSuggSimil=false) { // returns masculine plural forms |
331 332 333 334 335 336 337 | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | - - + | } return ""; } function suggFemSing (sFlex, bSuggSimil=false) { // returns feminine singular forms |
365 366 367 368 369 370 371 | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | - - + | return Array.from(aSugg).join("|"); } return ""; } function suggFemPlur (sFlex, bSuggSimil=false) { // returns feminine plural forms |
398 399 400 401 402 403 404 | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | - + - + - - + - + - + - + - + | if (aSugg.size > 0) { return Array.from(aSugg).join("|"); } return ""; } function hasFemForm (sFlex) { |
511 512 513 514 515 516 517 | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | - - + | if (sWord[0] == "h" || sWord[0] == "H") { return "ce|cet"; } return "ce"; } function suggLesLa (sWord) { |
Modified gc_lang/fr/modules-js/lexicographe.js from [823f277d47] to [8830593e2a].
83 84 85 86 87 88 89 | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | - + | [':O2', [" 2ᵉ pers.,", "Pronom : 2ᵉ personne"]], [':O3', [" 3ᵉ pers.,", "Pronom : 3ᵉ personne"]], [':C', [" conjonction,", "Conjonction"]], [':Ĉ', [" conjonction (él.),", "Conjonction (élément)"]], [':Cc', [" conjonction de coordination,", "Conjonction de coordination"]], [':Cs', [" conjonction de subordination,", "Conjonction de subordination"]], [':Ĉs', [" conjonction de subordination (él.),", "Conjonction de subordination (élément)"]], |
187 188 189 190 191 192 193 | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | - + | ['en', " pronom adverbial"], ["m'en", " (me) pronom personnel objet + (en) pronom adverbial"], ["t'en", " (te) pronom personnel objet + (en) pronom adverbial"], ["s'en", " (se) pronom personnel objet + (en) pronom adverbial"] ]); |
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | 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 | + + + + + | ['–', "tiret demi-cadratin"], ['«', "guillemet ouvrant (chevrons)"], ['»', "guillemet fermant (chevrons)"], ['“', "guillemet ouvrant double"], ['”', "guillemet fermant double"], ['‘', "guillemet ouvrant"], ['’', "guillemet fermant"], ['"', "guillemets droits (déconseillé en typographie)"], ['/', "signe de la division"], ['+', "signe de l’addition"], ['*', "signe de la multiplication"], ['=', "signe de l’égalité"], ['<', "inférieur à"], ['>', "supérieur à"], ['⩽', "inférieur ou égal à"], ['⩾', "supérieur ou égal à"], ['%', "signe de pourcentage"], ['‰', "signe pour mille"], ]); class Lexicographe { constructor (oSpellChecker, oTokenizer, oLocGraph) { this.oSpellChecker = oSpellChecker; |
241 242 243 244 245 246 247 248 249 250 | 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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | + - + - + + + + + + + + - + | getInfoForToken (oToken) { // Token: .sType, .sValue, .nStart, .nEnd // return a object {sType, sValue, aLabel} let m = null; try { switch (oToken.sType) { case 'SEPARATOR': case 'SIGN': return { sType: oToken.sType, sValue: oToken.sValue, |
452 453 454 455 456 457 458 | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | - + | let aTokenList = this.getListOfTokens(sText.replace("'", "’").trim(), false); let iKey = 0; let aElem = []; do { let oToken = aTokenList[iKey]; let sMorphLoc = ''; let aTokenTempList = [oToken]; |
Modified gc_lang/fr/modules-js/tests_data.json from [f05e835c66] to [ef6f6c1c40].
| 1 | - + |
|
Modified gc_lang/fr/modules/conj.py from [c668aaf269] to [258383e97f].
| 1 2 3 4 5 6 7 8 9 10 11 | + - + + + | """ |
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | + | _dGroup = { "0": "auxiliaire", "1": "1ᵉʳ groupe", "2": "2ᵉ groupe", "3": "3ᵉ groupe" } _dTenseIdx = { ":PQ": 0, ":Ip": 1, ":Iq": 2, ":Is": 3, ":If": 4, ":K": 5, ":Sp": 6, ":Sq": 7, ":E": 8 } def isVerb (sVerb): "return True if it’s a existing verb" return sVerb in _dVerb def getConj (sVerb, sTense, sWho): "returns conjugation (can be an empty string)" if sVerb not in _dVerb: return None |
52 53 54 55 56 57 58 59 60 | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | + - + | "returns raw informations about sVerb" if sVerb not in _dVerb: return None return _lVtyp[_dVerb[sVerb][0]] def getSimil (sWord, sMorph, bSubst=False): "returns a set of verbal forms similar to <sWord>, according to <sMorph>" if ":V" not in sMorph: return set() |
96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | + | # if there is only one past participle (epi inv), unreliable. if len(aSugg) == 1: aSugg.clear() return aSugg def getConjSimilInfiV1 (sInfi): "returns verbal forms phonetically similar to infinitive form (for verb in group 1)" if sInfi not in _dVerb: return set() aSugg = set() tTags = _getTags(sInfi) if tTags: aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":2s")) aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s")) |
138 139 140 141 142 143 144 | 144 145 146 147 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 | - + - + + + - + | "returns sWord modified by sSfx" if not sSfx: return "" if sSfx == "0": return sWord try: return sWord[:-(ord(sSfx[0])-48)] + sSfx[1:] if sSfx[0] != '0' else sWord + sSfx[1:] # 48 is the ASCII code for "0" |
287 288 289 290 291 292 293 294 295 296 297 298 299 300 | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | + | sInfo = "# erreur - code : " + self._sRawInfo return sGroup + " · " + sInfo except: traceback.print_exc() return "# erreur" def infinitif (self, bPro, bNeg, bTpsCo, bInt, bFem): "returns string (conjugaison à l’infinitif)" try: if bTpsCo: sInfi = self.sVerbAux if not bPro else "être" else: sInfi = self.sVerb if bPro: if self.bProWithEn: |
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | + + | sInfi += " … ?" return sInfi except: traceback.print_exc() return "# erreur" def participePasse (self, sWho): "returns past participle according to <sWho>" try: return self.dConj[":Q"][sWho] except: traceback.print_exc() return "# erreur" def participePresent (self, bPro, bNeg, bTpsCo, bInt, bFem): "returns string (conjugaison du participe présent)" try: if not self.dConj[":P"][":"]: return "" if bTpsCo: sPartPre = _getConjWithTags(self.sVerbAux, self._tTagsAux, ":PQ", ":P") if not bPro else getConj("être", ":PQ", ":P") else: sPartPre = self.dConj[":P"][":"] |
346 347 348 349 350 351 352 353 354 355 356 357 358 359 | 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | + | sPartPre += " … ?" return sPartPre except: traceback.print_exc() return "# erreur" def conjugue (self, sTemps, sWho, bPro, bNeg, bTpsCo, bInt, bFem): "returns string (conjugue le verbe au temps <sTemps> pour <sWho>) " try: if not self.dConj[sTemps][sWho]: return "" if not bTpsCo and bInt and sWho == ":1s" and self.dConj[sTemps].get(":1ś", False): sWho = ":1ś" if bTpsCo: sConj = _getConjWithTags(self.sVerbAux, self._tTagsAux, sTemps, sWho) if not bPro else getConj("être", sTemps, sWho) |
368 369 370 371 372 373 374 | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | - + - + - + + | else: sConj = _dProObjEl[sWho] + "en " + sConj if bNeg: sConj = "n’" + sConj if bEli and not bPro else "ne " + sConj if bInt: if sWho == ":3s" and not _zNeedTeuph.search(sConj): sConj += "-t" |
Modified gc_lang/fr/modules/conj_generator.py from [2e696a65e3] to [ee0a228497].
| 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 | + - - + + + + - + + + | """ |
113 114 115 116 117 118 119 | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | - + | [2, "isses", ":Sp:Sq:2s/*", False], [2, "isse", ":Sp:3s/*", False], [2, "ît", ":Sq:3s/*", False], [2, "is", ":E:2s/*", False], [2, "issons", ":E:1p/*", False], [2, "issez", ":E:2p/*", False] ], |
Modified gc_lang/fr/modules/cregex.py from [a0df0d1397] to [4b9e99ff72].
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | + - + + - + | """ |
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 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 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 143 144 145 146 147 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 247 248 249 250 251 252 253 254 255 256 257 258 259 | + + + - + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + | NPf = re.compile(":(?:M[12P]|T):f") NPe = re.compile(":(?:M[12P]|T):e") #### FONCTIONS def getLemmaOfMorph (s): "return lemma in morphology <s>" return Lemma.search(s).group(1) def checkAgreement (l1, l2): "returns True if agreement in gender and number is possible between morphologies <l1> and <l2>" # check number agreement if not mbInv(l1) and not mbInv(l2): if mbSg(l1) and not mbSg(l2): return False if mbPl(l1) and not mbPl(l2): return False # check gender agreement if mbEpi(l1) or mbEpi(l2): return True if mbMas(l1) and not mbMas(l2): return False if mbFem(l1) and not mbFem(l2): return False return True def checkConjVerb (lMorph, sReqConj): "returns True if <sReqConj> in <lMorph>" return any(sReqConj in s for s in lMorph) def getGender (lMorph): "returns gender of word (':m', ':f', ':e' or empty string)." sGender = "" for sMorph in lMorph: m = Gender.search(sMorph) if m: if not sGender: sGender = m.group(0) elif sGender != m.group(0): return ":e" return sGender def getNumber (lMorph): "returns number of word (':s', ':p', ':i' or empty string)." sNumber = "" for sMorph in lMorph: |
Modified gc_lang/fr/modules/gce_analyseur.py from [39975de0ac] to [57b5310cdc].
1 2 3 4 5 6 | 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 66 67 68 69 70 71 72 73 74 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 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 143 144 145 146 147 148 149 150 151 152 153 154 155 | - + - - + - - + - + - - + - + - + - - + - + - + - - + - + - - + + - + + + + + - + | #### GRAMMAR CHECKING ENGINE PLUGIN: Parsing functions for French language from . import cregex as cr def rewriteSubject (s1, s2): |
Modified gc_lang/fr/modules/gce_suggestions.py from [79835965e4] to [2926468975].
1 2 3 4 5 6 7 8 9 10 11 | 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 | + - + - - + + | #### GRAMMAR CHECKING ENGINE PLUGIN: Suggestion mechanisms from . import conj from . import mfsp from . import phonet ## Verbs def suggVerb (sFlex, sWho, funcSugg2=None): "change <sFlex> conjugation according to <sWho>" aSugg = set() |
36 37 38 39 40 41 42 | 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 66 67 68 69 70 71 72 73 74 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 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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | - + + - + - + - + - + - + - + - + - + + - + + - + + - + + - + + - + - + | if aSugg2: aSugg.add(aSugg2) if aSugg: return "|".join(aSugg) return "" |
189 190 191 192 193 194 195 | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | - - + | if aSugg: return "|".join(aSugg) return "" def suggMasSing (sFlex, bSuggSimil=False): "returns masculine singular forms" |
217 218 219 220 221 222 223 | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | - - + | if aSugg: return "|".join(aSugg) return "" def suggMasPlur (sFlex, bSuggSimil=False): "returns masculine plural forms" |
248 249 250 251 252 253 254 | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | - - + | if aSugg: return "|".join(aSugg) return "" def suggFemSing (sFlex, bSuggSimil=False): "returns feminine singular forms" |
274 275 276 277 278 279 280 | 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | - - + | if aSugg: return "|".join(aSugg) return "" def suggFemPlur (sFlex, bSuggSimil=False): "returns feminine plural forms" |
299 300 301 302 303 304 305 | 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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | + - + + - + - + - + - + - + - + - + + - - + + - - + + + | aSugg.add(e) if aSugg: return "|".join(aSugg) return "" def hasFemForm (sFlex): "return True if there is a feminine form of <sFlex>" |
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | + + | elif nLen == 9 and s.startswith("0"): sRes += "|" + s[0:3] + " " + s[3:5] + " " + s[5:7] + " " + s[7:9] # fixe belge 1 sRes += "|" + s[0:2] + " " + s[2:5] + " " + s[5:7] + " " + s[7:9] # fixe belge 2 return sRes def formatNF (s): "typography: format NF reference (norme française)" try: m = re.match("NF[ -]?(C|E|P|Q|S|X|Z|EN(?:[ -]ISO|))[ -]?([0-9]+(?:[/‑-][0-9]+|))", s) if not m: return "" return "NF " + m.group(1).upper().replace(" ", " ").replace("-", " ") + " " + m.group(2).replace("/", "‑").replace("-", "‑") except: traceback.print_exc() return "# erreur #" def undoLigature (c): "typography: split ligature character <c> in several chars" if c == "fi": return "fi" elif c == "fl": return "fl" elif c == "ff": return "ff" elif c == "ffi": |
468 469 470 471 472 473 474 | 477 478 479 480 481 482 483 484 485 486 487 488 489 | - + + | _xNormalizedCharsForInclusiveWriting = str.maketrans({ '(': '_', ')': '_', '.': '_', '·': '_', '–': '_', '—': '_', '/': '_' |
Modified gc_lang/fr/modules/lexicographe.py from [5e53113f51] to [175c38852d].
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | + - + + + - + | """ |
76 77 78 79 80 81 82 | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | - + | ':O2': (" 2ᵉ pers.,", "Pronom : 2ᵉ personne"), ':O3': (" 3ᵉ pers.,", "Pronom : 3ᵉ personne"), ':C': (" conjonction,", "Conjonction"), ':Ĉ': (" conjonction (él.),", "Conjonction (élément)"), ':Cc': (" conjonction de coordination,", "Conjonction de coordination"), ':Cs': (" conjonction de subordination,", "Conjonction de subordination"), ':Ĉs': (" conjonction de subordination (él.),", "Conjonction de subordination (élément)"), |
123 124 125 126 127 128 129 | 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | - + - + - + + + | 'il': " pronom personnel sujet, 3ᵉ pers. masc. sing.", 'on': " pronom personnel sujet, 3ᵉ pers. sing. ou plur.", 'elle': " pronom personnel sujet, 3ᵉ pers. fém. sing.", 'nous': " pronom personnel sujet/objet, 1ʳᵉ pers. plur.", 'vous': " pronom personnel sujet/objet, 2ᵉ pers. plur.", 'ils': " pronom personnel sujet, 3ᵉ pers. masc. plur.", 'elles': " pronom personnel sujet, 3ᵉ pers. masc. plur.", |
190 191 192 193 194 195 196 | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | - + + | aMorph.append( "{} : {}".format(sWord, self.formatTags(lMorph[0])) ) else: aMorph.append( "{} : inconnu du dictionnaire".format(sWord) ) # suffixe d’un mot composé if m2: aMorph.append( "-{} : {}".format(m2.group(2), self._formatSuffix(m2.group(2).lower())) ) # Verbes |
Modified gc_lang/fr/modules/mfsp.py from [3f4814b5d6] to [8b7759e076].
| 1 2 3 4 5 6 7 8 9 10 | + - + + | """ |
Modified gc_lang/fr/modules/phonet.py from [cc107e0763] to [df9f884192].
| 1 2 3 4 5 6 7 8 9 10 11 | + - + + + | """ |
Modified gc_lang/fr/modules/tests.py from [2e6f413e05] to [d2c5da43dc].
1 | 1 2 3 4 5 6 7 8 9 10 11 12 | - + + + + | #! python3 |
143 144 145 146 147 148 149 | 146 147 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 | + - - - - - - - - + + + + + + + + + + + + + | sExceptedSuggs = sExceptedSuggs[1:-1] else: sErrorText = sLine.strip() sExceptedSuggs = "" sExpectedErrors = self._getExpectedErrors(sErrorText) sTextToCheck = sErrorText.replace("}}", "").replace("{{", "") sFoundErrors, sListErr, sFoundSuggs = self._getFoundErrors(sTextToCheck, sOption) # tests |
Modified gc_lang/fr/modules/textformatter.py from [8fb9ec33bf] to [d3e695233d].
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 9 10 11 12 | + + + + | #!python3 """ Text formatter """ import re dReplTable = { # surnumerary_spaces "start_of_paragraph": [("^[ ]+", "")], |
63 64 65 66 67 68 69 | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | - + | "erase_non_breaking_hyphens": [("", "")], ## typographic signs "ts_apostrophe": [ ("(?i)\\b([ldnjmtscç])['´‘′`](?=\\w)", "\\1’"), ("(?i)(qu|jusqu|lorsqu|puisqu|quoiqu|quelqu|presqu|entr|aujourd|prud)['´‘′`]", "\\1’") ], "ts_ellipsis": [ ("\\.\\.\\.", "…"), ("(?<=…)[.][.]", "…"), ("…[.](?![.])", "…") ], |
Modified gc_lang/fr/rules.grx from [f601a2bdd7] to [956ac9f74f].
more than 10,000 changes
Modified gc_lang/fr/webext/content_scripts/panel_lxg.css from [60aef30035] to [83fe0f37d1].
86 87 88 89 90 91 92 | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | - + | } div.grammalecte_lxg_token_LOC { background-color: hsla(150, 50%, 30%, 1); } div.grammalecte_lxg_token_WORD { background-color: hsla(150, 50%, 50%, 1); } |
Modified gc_lang/fr/webext/manifest.json from [57d55716f4] to [ae48c2c0d8].
1 2 3 4 | 1 2 3 4 5 6 7 8 9 10 11 12 | - + | { "manifest_version": 2, "name": "Grammalecte [fr]", "short_name": "Grammalecte [fr]", |
Modified gc_lang/fr/xpi/data/lxg_panel.css from [3d666aa76c] to [0f0ad23b15].
54 55 56 57 58 59 60 | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | - + | padding: 2px 5px; border-radius: 2px; text-decoration: none; } #wordlist b.WORD { background-color: hsla(150, 50%, 50%, 1); } |
Modified grammalecte-cli.py from [75f47ce217] to [7d4e2050e3].
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 9 10 11 12 | + + + + | #!/usr/bin/env python3 """ Grammalecte CLI (command line interface) """ import sys import os.path import argparse import json import grammalecte |
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | + | iParagraph += 1 if lLine: sText, lLineSet = txt.createParagraphWithLines(lLine) yield iParagraph, sText, lLineSet def output (sText, hDst=None): "write in the console or in a file if <hDst> not null" if not hDst: echo(sText, end="") else: hDst.write(sText) def loadDictionary (spf): |
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | + | return oJSON else: print("# Error: file <" + spf + "> not found.") return None 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("-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") |
230 231 232 233 234 235 236 | 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 271 272 273 274 | - + - + - - + + | oGrammarChecker.gce.ignoreRule(sRule) echo("done") elif sText.startswith("/++ "): for sRule in sText[3:].strip().split(): oGrammarChecker.gce.reactivateRule(sRule) echo("done") elif sText == "/debug" or sText == "/d": |
Modified grammalecte-server.py from [a5cc9d7be7] to [96ceb37885].
1 2 | 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 | - - - + + + + - + | #!/usr/bin/env python3 |
47 48 49 50 51 52 53 | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | - + | <li>"options" (text) : une chaîne au format JSON avec le nom des options comme attributs et un booléen comme valeur. Exemple : {"gv": true, "html": true}</li> </ul> <h3>Remise à zéro de ses options</h3> <p>[adresse_serveur]:8080/reset_options/fr (POST)</p> <h2>TEST</h2> |
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | 90 91 92 93 94 95 96 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 138 139 140 141 142 143 144 145 146 147 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 | + - + + + - + + + + | You were wandering like a lost soul and you arrived here probably by mistake. 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. """ def getServerOptions (): "load server options in <grammalecte-server-options._global.ini>, returns server options as dictionary" xConfig = configparser.SafeConfigParser() try: xConfig.read("grammalecte-server-options._global.ini") dOpt = xConfig._sections['options'] except: echo("Options file [grammalecte-server-options._global.ini] not found or not readable") exit() return dOpt |
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 | 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 | + + + - - + + | sJSON += sText bComma = True sJSON += "\n]}\n" return sJSON @app.route("/set_options/fr", method="POST") def setOptions (): "change options for user_id, returns options as a JSON string" if request.forms.options: sUserId = request.cookies.user_id if request.cookies.user_id else next(userGenerator) dOptions = dUser[sUserId]["gc_options"] if sUserId in dUser else dict(dServerGCOptions) try: dOptions.update(json.loads(request.forms.options)) dUser[sUserId] = { "time": int(time.time()), "gc_options": dOptions } response.set_cookie("user_id", sUserId, path="/", max_age=86400) # 24h return json.dumps(dUser[sUserId]["gc_options"]) except: traceback.print_exc() return '{"error": "options not registered"}' return '{"error": "no options received"}' @app.route("/reset_options/fr", method="POST") def resetOptions (): "erase options stored for user_id" if request.cookies.user_id and request.cookies.user_id in dUser: del dUser[request.cookies.user_id] return "done" @app.route("/format_text/fr", method="POST") def formatText (): "returns text modified via the text formatter" return oTextFormatter.formatText(request.forms.text) #@app.route('/static/<filepath:path>') #def server_static (filepath): # return static_file(filepath, root='./views/static') @app.route("/purge_users", method="POST") def purgeUsers (): "delete user options older than n hours" if not request.forms.password or "password" not in dServerOptions or not request.forms.hours: return "what?" try: if request.forms.password == dServerOptions["password"]: nNowMinusNHours = int(time.time()) - (int(request.forms.hours) * 60 * 60) for nUserId, dValue in dUser.items(): if dValue["time"] < nNowMinusNHours: del dUser[nUserId] return "done" |
Modified graphspell-js/ibdawg.js from [241ce099fe] to [068f06a16d].
510 511 512 513 514 515 516 | 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | - + | let sStem = ">" + this.funcStemming(sWord, this.lArcVal[nArc]); // Now , we go to the next node and retrieve all following arcs values, all of them are tags let iAddr2 = this._convBytesToInteger(this.byDic.slice(iEndArcAddr, iEndArcAddr+this.nBytesNodeAddress)); let nRawArc2 = 0; while (!(nRawArc2 & this._lastArcMask)) { let iEndArcAddr2 = iAddr2 + this.nBytesArc; nRawArc2 = this._convBytesToInteger(this.byDic.slice(iAddr2, iEndArcAddr2)); |
Modified graphspell-js/spellchecker.js from [3df103d578] to [5b9ccbbb56].
39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | + + + + | this.oExtendedDic = this._loadDictionary(extentedDic, sPath); this.oCommunityDic = this._loadDictionary(communityDic, sPath); this.oPersonalDic = this._loadDictionary(personalDic, sPath); this.bExtendedDic = Boolean(this.oExtendedDic); this.bCommunityDic = Boolean(this.oCommunityDic); this.bPersonalDic = Boolean(this.oPersonalDic); this.oTokenizer = null; // storage this.bStorage = false; this._dMorphologies = new Map(); // key: flexion, value: list of morphologies this._dLemmas = new Map(); // key: flexion, value: list of lemmas } _loadDictionary (dictionary, sPath="", bNecessary=false) { // returns an IBDAWG object if (!dictionary) { return null; } |
130 131 132 133 134 135 136 137 138 139 140 141 142 143 | 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 162 163 | + + + + + + + + + + + + + + + + | this.bCommunityDic = false; } deactivatePersonalDictionary () { this.bPersonalDic = false; } // Storage activateStorage () { this.bStorage = true; } deactivateStorage () { this.bStorage = false; } clearStorage () { this._dLemmas.clear(); this._dMorphologies.clear(); } // parse text functions parseParagraph (sText) { if (!this.oTokenizer) { this.loadTokenizer(); } |
201 202 203 204 205 206 207 | 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 | + + + - + - + - + - + + + + + + - + + + + + + + + + + + + | return true; } return false; } getMorph (sWord) { // retrieves morphologies list, different casing allowed if (this.bStorage && this._dMorphologies.has(sWord)) { return this._dMorphologies.get(sWord); } |
Modified graphspell-js/tokenizer.js from [bdd895b918] to [2fadfb42f5].
14 15 16 17 18 19 20 | 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | - - + + + - - + + - + - + + - + - + + - + - - - - - + - - + - - + + | const aTkzPatterns = { // All regexps must start with ^. "default": [ [/^[ \t]+/, 'SPACE'], [/^\/(?:~|bin|boot|dev|etc|home|lib|mnt|opt|root|sbin|tmp|usr|var|Bureau|Documents|Images|Musique|Public|Téléchargements|Vidéos)(?:\/[a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st_.()-]+)*/, 'FOLDERUNIX'], [/^[a-zA-Z]:\\(?:Program Files(?: \(x86\)|)|[a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st.()]+)(?:\\[a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st_.()-]+)*/, 'FOLDERWIN'], |
Modified graphspell/__init__.py from [a53bdfb757] to [7e05700bdd].
1 2 | 1 2 3 4 5 6 7 8 9 10 11 | + + + + + + + + + | """ SPELLCHECKER using a Direct Acyclic Word Graph with a transducer to retrieve - lemma of words - morphologies with a spell suggestion mechanism """ from .spellchecker import * |
Modified graphspell/char_player.py from [0a316c953c] to [8c9fd715c3].
| 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 | + - - + + + + - + | """ |
90 91 92 93 94 95 96 | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | - + | "Ë": "EeÉéÈèÊêËëĒēŒœ", "f": "fF", "F": "Ff", "g": "gGjJĵĴ", "G": "GgJjĴĵ", |
235 236 237 238 239 240 241 242 243 244 245 246 247 248 | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | + | "X": ("CC", "CT", "XX"), "z": ("ss", "zh"), "Z": ("SS", "ZH"), } def get1toXReplacement (cPrev, cCur, cNext): "return tuple of replacements for <cCur>" if cCur in aConsonant and (cPrev in aConsonant or cNext in aConsonant): return () return d1toX.get(cCur, ()) d2toX = { "am": ("an", "en", "em"), |
Modified graphspell/dawg.py from [8afc042909] to [257e064164].
1 2 | 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 | + - - - - - - - - + + + + + + + + + | #!python3 """ |
95 96 97 98 99 100 101 | 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 | - + - + - + | dTag[sTag] = nTag lTag.append(sTag) nTag += 1 dTagOccur[sTag] = dTagOccur.get(sTag, 0) + 1 aEntry.add((sFlex, dAff[sAff], dTag[sTag])) if not aEntry: raise ValueError("# Error. Empty lexicon") |
130 131 132 133 134 135 136 | 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 162 163 164 165 166 167 168 169 170 171 | - + - + - + + - + | self.nAff = nAff self.lArcVal = lVal self.nArcVal = len(lVal) self.nTag = self.nArcVal - self.nChar - nAff self.cStemming = cStemming if cStemming == "A": self.funcStemming = st.changeWordWithAffixCode |
177 178 179 180 181 182 183 | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | - + | oNode = self.lUncheckedNodes[-1][2] iChar = nCommonPrefix for c in aEntry[nCommonPrefix:]: oNextNode = DawgNode() oNode.arcs[c] = oNextNode self.lUncheckedNodes.append((oNode, c, oNextNode)) |
201 202 203 204 205 206 207 208 209 210 211 212 213 | 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | + + - + + - + + + - + - - + + + + + + + | oNode.arcs[char] = self.lMinimizedNodes[oChildNode] else: # add the state to the minimized nodes. self.lMinimizedNodes[oChildNode] = oChildNode self.lUncheckedNodes.pop() def countNodes (self): "count the number of nodes of the whole word graph" self.nNode = len(self.lMinimizedNodes) def countArcs (self): "count the number of arcs in the whole word graph" self.nArc = 0 for oNode in self.lMinimizedNodes: self.nArc += len(oNode.arcs) |
392 393 394 395 396 397 398 399 400 401 402 403 404 405 | 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | + | if 1 < (oNextNode.addr - self.lSortedNodes[i].addr) < self.nMaxOffset: nSize -= nDiff if self.lSortedNodes[i].size != nSize: self.lSortedNodes[i].size = nSize bEnd = False def getBinaryAsJSON (self, nCompressionMethod=1, bBinaryDictAsHexString=True): "return a JSON string containing all necessary data of the dictionary (compressed as a binary string)" self._calculateBinary(nCompressionMethod) byDic = b"" if nCompressionMethod == 1: byDic = self.oRoot.convToBytes1(self.nBytesArc, self.nBytesNodeAddress) for oNode in self.lMinimizedNodes: byDic += oNode.convToBytes1(self.nBytesArc, self.nBytesNodeAddress) elif nCompressionMethod == 2: |
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | + + + - + - + - + - + | # Mozilla’s JS parser don’t like file bigger than 4 Mb! # So, if necessary, we use an hexadecimal string, that we will convert later in Firefox’s extension. # https://github.com/mozilla/addons-linter/issues/1361 "sByDic": byDic.hex() if bBinaryDictAsHexString else [ e for e in byDic ] } def writeAsJSObject (self, spfDst, nCompressionMethod, bInJSModule=False, bBinaryDictAsHexString=True): "write a file (JSON or JS module) with all the necessary data" if not spfDst.endswith(".json"): spfDst += "."+str(nCompressionMethod)+".json" with open(spfDst, "w", encoding="utf-8", newline="\n") as hDst: if bInJSModule: hDst.write('// JavaScript\n// Generated data (do not edit)\n\n"use strict";\n\nconst dictionary = ') hDst.write( json.dumps(self.getBinaryAsJSON(nCompressionMethod, bBinaryDictAsHexString), ensure_ascii=False) ) if bInJSModule: hDst.write(";\n\nexports.dictionary = dictionary;\n") def writeBinary (self, sPathFile, nCompressionMethod, bDebug=False): """ Save as a binary file. Format of the binary indexable dictionary: Each section is separated with 4 bytes of \0 |
518 519 520 521 522 523 524 | 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | - + - + - + - + - + - + + + - + + + - + + + + + - + - - - + + + - - - + + + - - - - + + + + - - + + + + + - + - - - + + + - - - + + + - - - - + + + + | return time.strftime("%Y.%m.%d, %H:%M") def _writeNodes (self, sPathFile, nCompressionMethod): "for debugging only" print(" > Write nodes") with open(sPathFile+".nodes."+str(nCompressionMethod)+".txt", 'w', encoding='utf-8', newline="\n") as hDst: if nCompressionMethod == 1: |
682 683 684 685 686 687 688 | 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | - - + + + - + + + - + - - - + + + - - - - - - + + + + + + - - - - + + + + | if (self.pos + 1) == self.arcs[arc].pos and self.i != 0: val = val | nNextNodeMask by += val.to_bytes(nBytesArc, byteorder='big') else: by += val.to_bytes(nBytesArc, byteorder='big') by += self.arcs[arc].addr.to_bytes(nBytesNodeAddress, byteorder='big') return by |
757 758 759 760 761 762 763 | 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 | - - + + + | val = val | nNextNodeMask by += val.to_bytes(nBytesArc, byteorder='big') by += (self.arcs[arc].addr-self.addr).to_bytes(nBytesOffset, byteorder='big') else: by += val.to_bytes(nBytesArc, byteorder='big') by += self.arcs[arc].addr.to_bytes(nBytesNodeAddress, byteorder='big') return by |
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | + + + | _dCharOrder = { # key: previous char, value: dictionary of chars {c: nValue} "": {} } def addWordToCharDict (sWord): "for each character of <sWord>, count how many times it appears after the previous character, and store result in a <_dCharOrder>" cPrevious = "" for cChar in sWord: if cPrevious not in _dCharOrder: _dCharOrder[cPrevious] = {} _dCharOrder[cPrevious][cChar] = _dCharOrder[cPrevious].get(cChar, 0) + 1 cPrevious = cChar def getCharOrderAfterChar (cChar): "return a dictionary of chars with number of times it appears after character <cChar>" return _dCharOrder.get(cChar, None) def displayCharOrder (): "display how many times each character appear after another one" for key, value in _dCharOrder.items(): print("[" + key + "]: ", ", ".join([ c+":"+str(n) for c, n in sorted(value.items(), key=lambda t: t[1], reverse=True) ])) |
Modified graphspell/echo.py from [6d11a5dda8] to [440b1511e9].
1 2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | + - + + + + | #!python3 """ |
20 21 22 23 24 25 26 | 24 25 26 27 28 29 30 31 32 33 | - + | Encoding depends on Windows locale. No useful standard. Always returns True (useful for debugging).""" if sys.platform != "win32": print(obj, sep=sep, end=end, file=file, flush=flush) return True try: print(str(obj).translate(_CHARMAP), sep=sep, end=end, file=file, flush=flush) |
Added graphspell/fr.py version [963bf7ea5b].
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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | """ Default suggestion for French language """ dSugg = { "bcp": "beaucoup", "ca": "ça", "cad": "c’est-à-dire", "cb": "combien|CB", "cdlt": "cordialement", "construirent": "construire|construisirent|construisent|construiront", "càd": "c’est-à-dire", "dc": "de|donc", "email": "courriel|e-mail|émail", "emails": "courriels|e-mails", "Etes-vous": "Êtes-vous", "Etiez-vous": "Étiez-vous", "Etions-nous": "Étions-nous", "parce-que": "parce que", "pcq": "parce que", "pd": "pendant", "pdq": "pendant que", "pdt": "pendant", "pdtq": "pendant que", "pk": "pourquoi", "pq": "pourquoi|PQ", "prq": "presque", "prsq": "presque", "qcq": "quiconque", "qq": "quelque", "qqch": "quelque chose", "qqn": "quelqu’un", "qqne": "quelqu’une", "qqs": "quelques", "qqunes": "quelques-unes", "qquns": "quelques-uns", "tdq": "tandis que", "tj": "toujours", "tjs": "toujours", "tq": "tant que|tandis que", "ts": "tous", "tt": "tant|tout", "tte": "toute", "ttes": "toutes", "y’a": "y a" } |
Modified graphspell/ibdawg.py from [a255097656] to [0f1b5456be].
1 2 | 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 | + + + + + - + + | #!python3 """ INDEXABLE BINARY DIRECT ACYCLIC WORD GRAPH Implementation of a spellchecker as a transducer (storing transformation code to get lemma and morphologies) and a spell suggestion mechanim """ |
54 55 56 57 58 59 60 | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | - + + | self.dSugg[nDist] = [] self.dSugg[nDist].append(sSugg) self.aSugg.add(sSugg) if nDist < self.nMinDist: self.nMinDist = nDist self.nDistLimit = min(self.nDistLimit, self.nMinDist+2) |
145 146 147 148 149 150 151 | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | - + | raise TypeError("# Error. Not a grammalecte-fsa binary dictionary. Header: {}".format(self.by[0:9])) if not(self.by[17:18] == b"1" or self.by[17:18] == b"2" or self.by[17:18] == b"3"): raise ValueError("# Error. Unknown dictionary version: {}".format(self.by[17:18])) try: header, info, values, bdic = self.by.split(b"\0\0\0\0", 3) except Exception: raise Exception |
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 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 | + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + | def _initJSON (self, oJSON): "initialize with a JSON text file" self.__dict__.update(oJSON) self.byDic = binascii.unhexlify(self.sByDic) self.dCharVal = { v: k for k, v in self.dChar.items() } def getInfo (self): "return string about the IBDAWG" return " Language: {0.sLangName} Lang code: {0.sLangCode} Dictionary name: {0.sDicName}" \ " Compression method: {0.nCompressionMethod:>2} Date: {0.sDate} Stemming: {0.cStemming}FX\n" \ " Arcs values: {0.nArcVal:>10,} = {0.nChar:>5,} characters, {0.nAff:>6,} affixes, {0.nTag:>6,} tags\n" \ " Dictionary: {0.nEntry:>12,} entries, {0.nNode:>11,} nodes, {0.nArc:>11,} arcs\n" \ " Address size: {0.nBytesNodeAddress:>1} bytes, Arc size: {0.nBytesArc:>1} bytes\n".format(self) def writeAsJSObject (self, spfDest, bInJSModule=False, bBinaryDictAsHexString=False): "write IBDAWG as a JavaScript object in a JavaScript module" with open(spfDest, "w", encoding="utf-8", newline="\n") as hDst: if bInJSModule: hDst.write('// JavaScript\n// Generated data (do not edit)\n\n"use strict";\n\nconst dictionary = ') hDst.write(json.dumps({ |
263 264 265 266 267 268 269 | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | - + | def lookup (self, sWord): "returns True if <sWord> in dictionary (strict verification)" iAddr = 0 for c in sWord: if c not in self.dChar: return False iAddr = self._lookupArcNode(self.dChar[c], iAddr) |
342 343 344 345 346 347 348 | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | - + - + | self._suggest(oSuggResult, sRepl, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, iAddr, sNewWord, True) elif len(sRemain) == 1: self._suggest(oSuggResult, "", nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, iAddr, sNewWord, True) # remove last char and go on for sRepl in cp.dFinal1.get(sRemain, ()): self._suggest(oSuggResult, sRepl, nMaxSwitch, nMaxDel, nMaxHardRepl, nMaxJump, nDist, nDeep+1, iAddr, sNewWord, True) #@timethis |
405 406 407 408 409 410 411 | 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | - + - + - + | def drawPath (self, sWord, iAddr=0): "show the path taken by <sWord> in the graph" sWord = cp.spellingNormalization(sWord) c1 = sWord[0:1] if sWord else " " iPos = -1 n = 0 |
467 468 469 470 471 472 473 | 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | - + - + - + - + - + - + - + - + - + - - + + - + | def _morph1 (self, sWord): "returns morphologies of <sWord>" iAddr = 0 for c in sWord: if c not in self.dChar: return [] iAddr = self._lookupArcNode(self.dChar[c], iAddr) |
565 566 567 568 569 570 571 | 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + | def _morph2 (self, sWord): "returns morphologies of <sWord>" iAddr = 0 for c in sWord: if c not in self.dChar: return [] iAddr = self._lookupArcNode(self.dChar[c], iAddr) |
Modified graphspell/keyboard_chars_proximity.py from [8f397a7bbf] to [f71f3b18e4].
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | + + - + + + + | """ |
Modified graphspell/progressbar.py from [5def72a6ce] to [b21d9bfaa8].
| 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 | + - + + + - + - + - + - + | """ |
Modified graphspell/spellchecker.py from [cbd22d2c4d] to [85bf9023fe].
| 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 66 67 68 69 70 71 72 73 74 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 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 143 144 145 146 147 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 | + - + - - + - - - - - - + + + + + + + + + + + + + + + - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - + | """ |
147 148 149 150 151 152 153 | 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 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 274 275 276 277 278 279 280 | - + - + + + - + - + - + - - + + + + + + + + + + - + + + + + + + + - + + + + | def isValid (self, sWord): "checks if sWord is valid (different casing tested if the first letter is a capital)" if self.oMainDic.isValid(sWord): return True if self.bExtendedDic and self.oExtendedDic.isValid(sWord): return True |
Modified graphspell/str_transform.py from [9961c8cbc8] to [c5501f9a5a].
1 2 3 4 5 6 7 8 | 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 | + + + + + + + - - + + - - - - + + + + - - + + | #!python3 """ Operations on strings: - calculate distance between two strings - transform strings with transformation codes """ #### DISTANCE CALCULATIONS def longestCommonSubstring (s1, s2): "longest common substring" # http://en.wikipedia.org/wiki/Longest_common_substring_problem # http://en.wikibooks.org/wiki/Algorithm_implementation/Strings/Longest_common_substring |
52 53 54 55 56 57 58 | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | - + | return len(s1) nLen1, nLen2 = len(s1), len(s2) i1, i2 = 0, 0 # Cursors for each string nLargestCS = 0 # Largest common substring nLocalCS = 0 # Local common substring nTrans = 0 # Number of transpositions ('ab' vs 'ba') lOffset = [] # Offset pair array, for computing the transpositions |
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | 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 143 144 145 146 147 148 149 150 | + + - - + + + + + - - - - - - + + + + + + - + | nLocalCS = 0 i1 = i2 = min(i1, i2) nLargestCS += nLocalCS return round(max(nLen1, nLen2) - nLargestCS + nTrans) def showDistance (s1, s2): "display Damerau-Levenshtein distance and Sift4 distance between <s1> and <s2>" print("Damerau-Levenshtein: " + s1 + "/" + s2 + " = " + distanceDamerauLevenshtein(s1, s2)) print("Sift4:" + s1 + "/" + s2 + " = " + distanceSift4(s1, s2)) #### STEMMING OPERATIONS ## No stemming def noStemming (sFlex, sStem): "return <sStem>" return sStem |
148 149 150 151 152 153 154 | 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 | - + + - + | if sFlex == sStem: return "0" jSfx = 0 for i in range(min(len(sFlex), len(sStem))): if sFlex[i] != sStem[i]: break jSfx += 1 |
187 188 189 190 191 192 193 194 195 196 197 198 | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | + - + - | n = sFlex.find(sSubs) m = len(sFlex) - (len(sSubs)+n) return chr(n+48) + sPfx + "/" + chr(m+48) + sSfx return sStem def changeWordWithAffixCode (sWord, sAffCode): "apply transformation code <sAffCode> on <sWord> and return the result string" if sAffCode == "0": return sWord if '/' not in sAffCode: return sAffCode sPfxCode, sSfxCode = sAffCode.split('/') |
Modified graphspell/tokenizer.py from [17f452887e] to [b1bcfc3595].
| 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 | + - + + + - - + + + - - + + - - + + + + - - - + + + + + + + + + + | """ |
Modified make.py from [14e0172bf2] to [47003996f5].
1 2 3 4 5 | 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 | + + + + - - + + - - + + + + | #!/usr/bin/env python3 # coding: UTF-8 """ Grammalecte builder """ import sys import os |
131 132 133 134 135 136 137 | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | - + | # Installation in Writer profile if bInstall: print("> installation in Writer") if dVars.get('unopkg', False): cmd = '"'+os.path.abspath(dVars.get('unopkg')+'" add -f '+spfZip) print(cmd) |
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 | 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 | + + | "grammalecte-server-options._global.ini", "grammalecte-server-options."+sLang+".ini", \ "README.txt", "LICENSE.txt", "LICENSE.fr.txt"]: hZip.write(spf) hZip.writestr("setup.py", helpers.fileFile("gc_lang/fr/setup.py", dVars)) def copyGrammalectePyPackageInZipFile (hZip, spLangPack, sAddPath=""): "copy Grammalecte Python package in zip file" for sf in os.listdir("grammalecte"): if not os.path.isdir("grammalecte/"+sf): hZip.write("grammalecte/"+sf, sAddPath+"grammalecte/"+sf) for sf in os.listdir("grammalecte/graphspell"): if not os.path.isdir("grammalecte/graphspell/"+sf): hZip.write("grammalecte/graphspell/"+sf, sAddPath+"grammalecte/graphspell/"+sf) for sf in os.listdir("grammalecte/graphspell/_dictionaries"): if not os.path.isdir("grammalecte/graphspell/_dictionaries/"+sf): hZip.write("grammalecte/graphspell/_dictionaries/"+sf, sAddPath+"grammalecte/graphspell/_dictionaries/"+sf) for sf in os.listdir(spLangPack): if not os.path.isdir(spLangPack+"/"+sf): hZip.write(spLangPack+"/"+sf, sAddPath+spLangPack+"/"+sf) def create (sLang, xConfig, bInstallOXT, bJavaScript): "make Grammalecte for project <sLang>" oNow = datetime.datetime.now() print("============== MAKE GRAMMALECTE [{0}] at {1.hour:>2} h {1.minute:>2} min {1.second:>2} s ==============".format(sLang, oNow)) #### READ CONFIGURATION print("> read configuration...") spLang = "gc_lang/" + sLang |
226 227 228 229 230 231 232 233 234 235 236 237 238 239 | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | + | print(sf, end=", ") print() # TEST FILES with open("grammalecte/"+sLang+"/gc_test.txt", "w", encoding="utf-8", newline="\n") as hDstPy: hDstPy.write("# TESTS FOR LANG [" + sLang + "]\n\n") hDstPy.write(dVars['gctests']) hDstPy.write("\n") createOXT(spLang, dVars, xConfig._sections['oxt'], spLangPack, bInstallOXT) createServerOptions(sLang, dVars) createPackageZip(sLang, dVars, spLangPack) #### JAVASCRIPT |
248 249 250 251 252 253 254 | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | - + | print() dVars["pluginsJS"] = sCodePlugins # options data struct dVars["dOptJavaScript"] = json.dumps(list(dVars["dOptJavaScript"].items())) dVars["dOptFirefox"] = json.dumps(list(dVars["dOptFirefox"].items())) dVars["dOptThunderbird"] = json.dumps(list(dVars["dOptThunderbird"].items())) |
271 272 273 274 275 276 277 | 280 281 282 283 284 285 286 287 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 | - + - + + + | for sf in os.listdir(spLang+"/modules-js"): if not sf.startswith("gce_"): helpers.copyAndFileTemplate(spLang+"/modules-js/"+sf, spLangPack+"/"+sf, dVars) print(sf, end=", ") print() try: |
331 332 333 334 335 336 337 338 339 | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | + - - - - + + + + + | file_util.copy_file(spfJSDic, "grammalecte-js/graphspell/_dictionaries") dVars['dic_'+sType+'_filename_js'] = sFileName + '.json' dVars['dic_main_filename_py'] = dVars['dic_default_filename_py'] + ".bdic" dVars['dic_main_filename_js'] = dVars['dic_default_filename_js'] + ".json" def buildDictionary (dVars, sType, bJavaScript=False): "build binary dictionary for Graphspell from lexicons" if sType == "main": spfLexSrc = dVars['lexicon_src'] |
401 402 403 404 405 406 407 | 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | - + - + - - + + - - + + | xArgs.add_extended_dictionary = False if not dVars["lexicon_community_src"]: xArgs.add_community_dictionary = False if not dVars["lexicon_personal_src"]: xArgs.add_personal_dictionary = False # build data |
444 445 446 447 448 449 450 | 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | - - + + - - - - + + + | if xArgs.tests: xTestSuite = unittest.TestLoader().loadTestsFromModule(tests) unittest.TextTestRunner().run(xTestSuite) if xArgs.perf or xArgs.perf_memo: hDst = open("./gc_lang/"+sLang+"/perf_memo.txt", "a", encoding="utf-8", newline="\n") if xArgs.perf_memo else None tests.perf(sVersion, hDst) |
Modified misc/grammalecte.sublime-syntax from [f7dfed6343] to [dcffb60da8].
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | + + + + + + + + + + + + + - + - + + + + + + + + + + + + + | - match: '\b(-)?[0-9.]+\b' scope: constant.numeric # Bookmarks - match: '^!!.*|^\[\+\+\].*' scope: bookmark # Bookmarks - match: '^GRAPH_NAME:.*' scope: bookmark # Graph - match: '^@@@@GRAPH: *(\w+) *' scope: graphline captures: 1: string.graphname - match: '^@@@@(?:END_GRAPH *| *)' scope: graphline # Keywords are if, else. # Note that blackslashes don't need to be escaped within single quoted # strings in YAML. When using single quoted strings, only single quotes # need to be escaped: this is done by using two single quotes next to each # other. - match: '\b(?:if|else|and|or|not|in)\b' scope: keyword.python - match: '\b(?:True|False|None)\b' scope: constant.language |
82 83 84 85 86 87 88 | 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 143 144 145 146 147 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 | - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + | # rule delimiters - match: '<<-|>>>' scope: keyword.action - match: '__also__' scope: keyword.condition.green - match: '__else__' scope: keyword.condition.red |
Modified misc/grammalecte.tmTheme from [7305de87f8] to [76e7f53b09].
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | + + + + + + + + + + + + + + + | <dict> <key>foreground</key> <string>#A0F0FF</string> <key>background</key> <string>#0050A0</string> </dict> </dict> <dict> <key>name</key> <string>Graphline</string> <key>scope</key> <string>graphline</string> <key>settings</key> <dict> <key>foreground</key> <string>hsl(0, 100%, 80%)</string> <key>background</key> <string>hsl(0, 100%, 20%</string> <key>fontStyle</key> <string>bold</string> </dict> </dict> <dict> <key>name</key> <string>String</string> <key>scope</key> <string>string</string> <key>settings</key> <dict> |
231 232 233 234 235 236 237 238 239 240 241 242 243 244 | 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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | <string>#F0F060</string> <key>background</key> <string>#602020</string> <key>fontStyle</key> <string>bold</string> </dict> </dict> <dict> <key>name</key> <string>Keyword tag</string> <key>scope</key> <string>keyword.tag</string> <key>settings</key> <dict> <key>foreground</key> <string>#FF70FF</string> <key>background</key> <string>#602060</string> <key>fontStyle</key> <string>bold</string> </dict> </dict> <dict> <key>name</key> <string>Keyword tag group</string> <key>scope</key> <string>keyword.tag.group</string> <key>settings</key> <dict> <key>foreground</key> <string>#F0B0F0</string> <key>background</key> <string>#602060</string> <key>fontStyle</key> <string>bold</string> </dict> </dict> <dict> <key>name</key> <string>Keyword textprocessor</string> <key>scope</key> <string>keyword.textprocessor</string> <key>settings</key> <dict> |
289 290 291 292 293 294 295 296 297 298 299 300 301 302 | 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | <key>settings</key> <dict> <key>foreground</key> <string>#A0A0A0</string> </dict> </dict> <dict> <key>name</key> <string>Keyword Valid</string> <key>scope</key> <string>keyword.valid</string> <key>settings</key> <dict> <key>fontStyle</key> <string>bold</string> <key>foreground</key> <string>hsl(150, 100%, 80%)</string> <key>background</key> <string>hsl(150, 100%, 20%)</string> </dict> </dict> <dict> <key>name</key> <string>Keyword Invalid</string> <key>scope</key> <string>keyword.invalid</string> <key>settings</key> <dict> <key>fontStyle</key> <string>bold</string> <key>foreground</key> <string>hsl(0, 100%, 80%)</string> <key>background</key> <string>hsl(0, 100%, 20%)</string> </dict> </dict> <dict> <key>name</key> <string>Rule options</string> <key>scope</key> <string>rule.options</string> <key>settings</key> <dict> |
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | <dict> <key>fontStyle</key> <string>italic</string> <key>foreground</key> <string>#A0A0A0</string> </dict> </dict> <dict> <key>name</key> <string>Rule name</string> <key>scope</key> <string>rule.rulename2</string> <key>settings</key> <dict> <key>foreground</key> <string>#F0D080</string> </dict> </dict> <dict> <key>name</key> <string>Rule priority</string> <key>scope</key> <string>rule.priority</string> <key>settings</key> <dict> <key>foreground</key> <string>#F06060</string> </dict> </dict> <dict> <key>name</key> <string>String lemma</string> <key>scope</key> <string>string.lemma</string> <key>settings</key> <dict> <key>foreground</key> <string>hsl(210, 100%, 80%)</string> <key>background</key> <string>hsl(210, 100%, 15%)</string> </dict> </dict> <dict> <key>name</key> <string>String regex</string> <key>scope</key> <string>string.regex</string> <key>settings</key> <dict> <key>foreground</key> <string>hsl(60, 100%, 80%)</string> <key>background</key> <string>hsl(60, 100%, 10%)</string> </dict> </dict> <dict> <key>name</key> <string>String morph pattern</string> <key>scope</key> <string>string.morph.pattern</string> <key>settings</key> <dict> <key>foreground</key> <string>hsl(150, 80%, 90%)</string> <key>background</key> <string>hsl(150, 80%, 10%)</string> </dict> </dict> <dict> <key>name</key> <string>String morph antipattern</string> <key>scope</key> <string>string.morph.antipattern</string> <key>settings</key> <dict> <key>foreground</key> <string>hsl(0, 80%, 90%)</string> <key>background</key> <string>hsl(0, 80%, 10%)</string> </dict> </dict> <dict> <key>name</key> <string>JavaScript Dollar</string> <key>scope</key> <string>variable.other.dollar.only.js</string> <key>settings</key> |