Changes In Branch salxg Through [ebdbe42659] Excluding Merge-Ins
This is equivalent to a diff from 11a61c0c94 to ebdbe42659
2020-08-23
| ||
06:26 | merge trunk check-in: b4b3569231 user: olr tags: salxg | |
05:38 | [fx] fix lexicon editor check-in: b14f8f2526 user: olr tags: trunk, fx | |
05:28 | [graphspell] function readableMorph() check-in: ebdbe42659 user: olr tags: graphspell, salxg | |
05:28 | [graphspell][js] update tags check-in: f6092331a8 user: olr tags: graphspell, salxg | |
2020-08-22
| ||
15:23 | [core][fx][cli] syntax analysis and new lexicographer check-in: 79e9913b4f user: olr tags: cli, core, fx, salxg | |
2020-08-20
| ||
12:02 | [fr] faux positifs et ajustements check-in: 11a61c0c94 user: olr tags: trunk, fr | |
2020-08-19
| ||
15:57 | [graphspell][js] remove importation dirt... check-in: 48d2a67a6a user: olr tags: trunk, graphspell | |
Modified gc_core/js/lang_core/gc_engine.js from [1328582cce] to [a10785f066].
︙ | ︙ | |||
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | // parse paragraph try { this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext); } catch (e) { console.error(e); } let lParagraphErrors = null; if (bFullInfo) { lParagraphErrors = Array.from(this.dError.values()); this.dSentenceError.clear(); } // parse sentence let sText = this._getCleanText(); let lSentences = []; let oSentence = null; for (let [iStart, iEnd] of text.getSentenceBoundaries(sText)) { try { this.sSentence = sText.slice(iStart, iEnd); this.sSentence0 = this.sText0.slice(iStart, iEnd); this.nOffsetWithinParagraph = iStart; | > > | | | < < < < < | > > > > > > > | > > > > > > | 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 | // parse paragraph try { this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext); } catch (e) { console.error(e); } this.lTokens = null; this.lTokens0 = null; let lParagraphErrors = null; if (bFullInfo) { lParagraphErrors = Array.from(this.dError.values()); this.dSentenceError.clear(); } // parse sentence let sText = this._getCleanText(); let lSentences = []; let oSentence = null; for (let [iStart, iEnd] of text.getSentenceBoundaries(sText)) { try { this.sSentence = sText.slice(iStart, iEnd); this.sSentence0 = this.sText0.slice(iStart, iEnd); this.nOffsetWithinParagraph = iStart; this.lTokens = Array.from(gc_engine.oTokenizer.genTokens(this.sSentence, true)); this.dTokenPos.clear(); for (let dToken of this.lTokens) { if (dToken["sType"] != "INFO") { this.dTokenPos.set(dToken["nStart"], dToken); } } if (bFullInfo) { this.lTokens0 = Array.from(this.lTokens); // the list of tokens is duplicated, to keep all tokens from being deleted when analysis } this.parseText(this.sSentence, this.sSentence0, false, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext); if (bFullInfo) { for (let oToken of this.lTokens0) { if (oToken["sType"] == "WORD") { oToken["bValidToken"] = gc_engine.oSpellChecker.isValidToken(oToken["sValue"]); } if (!oToken.hasOwnProperty("lMorph")) { oToken["lMorph"] = gc_engine.oSpellChecker.getMorph(oToken["sValue"]); } } lSentences.push({ "nStart": iStart, "nEnd": iEnd, "sSentence": this.sSentence0, "lTokens": this.lTokens0, "lGrammarErrors": Array.from(this.dSentenceError.values()) }); this.dSentenceError.clear(); } } catch (e) { console.error(e); } } |
︙ | ︙ | |||
370 371 372 373 374 375 376 | if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("lMorph")) { oToken["lMorph"] = this.dTokenPos.get(oToken["nStart"])["lMorph"]; } if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("aTags")) { oToken["aTags"] = this.dTokenPos.get(oToken["nStart"])["aTags"]; } } | | | | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("lMorph")) { oToken["lMorph"] = this.dTokenPos.get(oToken["nStart"])["lMorph"]; } if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("aTags")) { oToken["aTags"] = this.dTokenPos.get(oToken["nStart"])["aTags"]; } } this.lTokens = lNewToken; this.dTokenPos.clear(); for (let oToken of this.lTokens) { if (oToken["sType"] != "INFO") { this.dTokenPos.set(oToken["nStart"], oToken); } } if (bDebug) { console.log("UPDATE:"); console.log(this.asString()); |
︙ | ︙ | |||
612 613 614 615 616 617 618 | } parseGraph (oGraph, sCountry="${country_default}", dOptions=null, bShowRuleId=false, bDebug=false, bContext=false) { // parse graph with tokens from the text and execute actions encountered let lPointer = []; let bTagAndRewrite = false; try { | | | 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | } parseGraph (oGraph, sCountry="${country_default}", dOptions=null, bShowRuleId=false, bDebug=false, bContext=false) { // parse graph with tokens from the text and execute actions encountered let lPointer = []; let bTagAndRewrite = false; try { for (let [iToken, oToken] of this.lTokens.entries()) { if (bDebug) { console.log("TOKEN: " + oToken["sValue"]); } // check arcs for each existing pointer let lNextPointer = []; for (let oPointer of lPointer) { lNextPointer.push(...this._getNextPointers(oToken, oGraph, oPointer, bDebug)); |
︙ | ︙ | |||
664 665 666 667 668 669 670 | // Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL ] // TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] // Disambiguator [ option, condition, "=", replacement/suggestion/action ] // Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] // Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] // Test [ option, condition, ">", "" ] if (!sOption || dOptions.gl_get(sOption, false)) { | | | | | | | | | | | | | | | | | | | 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 | // Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL ] // TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] // Disambiguator [ option, condition, "=", replacement/suggestion/action ] // Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] // Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] // Test [ option, condition, ">", "" ] if (!sOption || dOptions.gl_get(sOption, false)) { bCondMemo = !sFuncCond || gc_functions[sFuncCond](this.lTokens, nTokenOffset, nLastToken, sCountry, bCondMemo, this.dTags, this.sSentence, this.sSentence0); //bCondMemo = !sFuncCond || oEvalFunc[sFuncCond](this.lTokens, nTokenOffset, nLastToken, sCountry, bCondMemo, this.dTags, this.sSentence, this.sSentence0); if (bCondMemo) { if (cActionType == "-") { // grammar error let [iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL] = eAct; let nTokenErrorStart = (iTokenStart > 0) ? nTokenOffset + iTokenStart : nLastToken + iTokenStart; if (!this.lTokens[nTokenErrorStart].hasOwnProperty("bImmune")) { let nTokenErrorEnd = (iTokenEnd > 0) ? nTokenOffset + iTokenEnd : nLastToken + iTokenEnd; let nErrorStart = this.nOffsetWithinParagraph + ((cStartLimit == "<") ? this.lTokens[nTokenErrorStart]["nStart"] : this.lTokens[nTokenErrorStart]["nEnd"]); let nErrorEnd = this.nOffsetWithinParagraph + ((cEndLimit == ">") ? this.lTokens[nTokenErrorEnd]["nEnd"] : this.lTokens[nTokenErrorEnd]["nStart"]); if (!this.dError.has(nErrorStart) || nPriority > this.dErrorPriority.gl_get(nErrorStart, -1)) { this.dError.set(nErrorStart, this._createErrorFromTokens(sWhat, nTokenOffset, nLastToken, nTokenErrorStart, nErrorStart, nErrorEnd, sLineId, sRuleId, bCaseSvty, sMessage, gc_rules_graph.dURL[iURL], bShowRuleId, sOption, bContext)); this.dErrorPriority.set(nErrorStart, nPriority); this.dSentenceError.set(nErrorStart, this.dError.get(nErrorStart)); if (bDebug) { console.log(" NEW_ERROR: ", this.dError.get(nErrorStart)); } } } } else if (cActionType == "~") { // text processor let nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0]; let nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1]; this._tagAndPrepareTokenForRewriting(sWhat, nTokenStart, nTokenEnd, nTokenOffset, nLastToken, eAct[2], bDebug); bChange = true; if (bDebug) { console.log(` TEXT_PROCESSOR: [${this.lTokens[nTokenStart]["sValue"]}:${this.lTokens[nTokenEnd]["sValue"]}] > ${sWhat}`); } } else if (cActionType == "=") { // disambiguation gc_functions[sWhat](this.lTokens, nTokenOffset, nLastToken); //oEvalFunc[sWhat](this.lTokens, nTokenOffset, nLastToken); if (bDebug) { console.log(` DISAMBIGUATOR: (${sWhat}) [${this.lTokens[nTokenOffset+1]["sValue"]}:${this.lTokens[nLastToken]["sValue"]}]`); } } else if (cActionType == ">") { // we do nothing, this test is just a condition to apply all following actions if (bDebug) { console.log(" COND_OK"); } } else if (cActionType == "/") { // Tag let nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0]; let nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1]; for (let i = nTokenStart; i <= nTokenEnd; i++) { if (this.lTokens[i].hasOwnProperty("aTags")) { this.lTokens[i]["aTags"].add(...sWhat.split("|")) } else { this.lTokens[i]["aTags"] = new Set(sWhat.split("|")); } } if (bDebug) { console.log(` TAG: ${sWhat} > [${this.lTokens[nTokenStart]["sValue"]}:${this.lTokens[nTokenEnd]["sValue"]}]`); } for (let sTag of sWhat.split("|")) { if (!this.dTags.has(sTag)) { this.dTags.set(sTag, [nTokenStart, nTokenEnd]); } else { this.dTags.set(sTag, [Math.min(nTokenStart, this.dTags.get(sTag)[0]), Math.max(nTokenEnd, this.dTags.get(sTag)[1])]); } } } else if (cActionType == "!") { // immunity if (bDebug) { console.log(" IMMUNITY: " + sLineId + " / " + sRuleId); } let nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0]; let nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1]; if (nTokenEnd - nTokenStart == 0) { this.lTokens[nTokenStart]["bImmune"] = true; let nErrorStart = this.nOffsetWithinParagraph + this.lTokens[nTokenStart]["nStart"]; if (this.dError.has(nErrorStart)) { this.dError.delete(nErrorStart); } } else { for (let i = nTokenStart; i <= nTokenEnd; i++) { this.lTokens[i]["bImmune"] = true; let nErrorStart = this.nOffsetWithinParagraph + this.lTokens[i]["nStart"]; if (this.dError.has(nErrorStart)) { this.dError.delete(nErrorStart); } } } } else { console.log("# error: unknown action at " + sLineId); |
︙ | ︙ | |||
806 807 808 809 810 811 812 | return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); } _createErrorFromTokens (sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext) { // suggestions let lSugg = []; if (sSugg.startsWith("=")) { | | | | | | | 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 | return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); } _createErrorFromTokens (sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext) { // suggestions let lSugg = []; if (sSugg.startsWith("=")) { sSugg = gc_functions[sSugg.slice(1)](this.lTokens, nTokenOffset, nLastToken); //sSugg = oEvalFunc[sSugg.slice(1)](this.lTokens, nTokenOffset, nLastToken); lSugg = (sSugg) ? sSugg.split("|") : []; } else if (sSugg == "_") { lSugg = []; } else { lSugg = this._expand(sSugg, nTokenOffset, nLastToken).split("|"); } if (bCaseSvty && lSugg.length > 0 && this.lTokens[iFirstToken]["sValue"].slice(0,1).gl_isUpperCase()) { lSugg = (this.sSentence.slice(nStart, nEnd).gl_isUpperCase()) ? lSugg.map((s) => s.toUpperCase()) : capitalizeArray(lSugg); } // Message let sMessage = (sMsg.startsWith("=")) ? gc_functions[sMsg.slice(1)](this.lTokens, nTokenOffset, nLastToken) : this._expand(sMsg, nTokenOffset, nLastToken); //let sMessage = (sMsg.startsWith("=")) ? oEvalFunc[sMsg.slice(1)](this.lTokens, nTokenOffset, nLastToken) : this._expand(sMsg, nTokenOffset, nLastToken); if (bShowRuleId) { sMessage += " #" + sLineId + " / " + sRuleId; } // return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); } |
︙ | ︙ | |||
851 852 853 854 855 856 857 | return oErr; } _expand (sText, nTokenOffset, nLastToken) { let m; while ((m = /\\(-?[0-9]+)/.exec(sText)) !== null) { if (m[1].slice(0,1) == "-") { | | | | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | return oErr; } _expand (sText, nTokenOffset, nLastToken) { let m; while ((m = /\\(-?[0-9]+)/.exec(sText)) !== null) { if (m[1].slice(0,1) == "-") { sText = sText.replace(m[0], this.lTokens[nLastToken+parseInt(m[1],10)+1]["sValue"]); } else { sText = sText.replace(m[0], this.lTokens[nTokenOffset+parseInt(m[1],10)]["sValue"]); } } return sText; } rewriteText (sText, sRepl, iGroup, m, bUppercase) { // text processor: write sRepl in sText at iGroup position" |
︙ | ︙ | |||
892 893 894 895 896 897 898 | } _tagAndPrepareTokenForRewriting (sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug) { // text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position if (sWhat === "*") { // purge text if (nTokenRewriteEnd - nTokenRewriteStart == 0) { | | | | | | | | | | | | > | > > | 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 | } _tagAndPrepareTokenForRewriting (sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug) { // text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position if (sWhat === "*") { // purge text if (nTokenRewriteEnd - nTokenRewriteStart == 0) { this.lTokens[nTokenRewriteStart]["bToRemove"] = true; } else { for (let i = nTokenRewriteStart; i <= nTokenRewriteEnd; i++) { this.lTokens[i]["bToRemove"] = true; } } } else if (sWhat === "␣") { // merge tokens this.lTokens[nTokenRewriteStart]["nMergeUntil"] = nTokenRewriteEnd; } else if (sWhat === "_") { // neutralized token if (nTokenRewriteEnd - nTokenRewriteStart == 0) { this.lTokens[nTokenRewriteStart]["sNewValue"] = "_"; } else { for (let i = nTokenRewriteStart; i <= nTokenRewriteEnd; i++) { this.lTokens[i]["sNewValue"] = "_"; } } } else { if (sWhat.startsWith("=")) { sWhat = gc_functions[sWhat.slice(1)](this.lTokens, nTokenOffset, nLastToken); //sWhat = oEvalFunc[sWhat.slice(1)](this.lTokens, nTokenOffset, nLastToken); } else { sWhat = this._expand(sWhat, nTokenOffset, nLastToken); } let bUppercase = bCaseSvty && this.lTokens[nTokenRewriteStart]["sValue"].slice(0,1).gl_isUpperCase(); if (nTokenRewriteEnd - nTokenRewriteStart == 0) { // one token if (bUppercase) { sWhat = sWhat.gl_toCapitalize(); } this.lTokens[nTokenRewriteStart]["sNewValue"] = sWhat; } else { // several tokens let lTokenValue = sWhat.split("|"); if (lTokenValue.length != (nTokenRewriteEnd - nTokenRewriteStart + 1)) { if (bDebug) { console.log("Error. Text processor: number of replacements != number of tokens."); } return; } let j = 0; for (let i = nTokenRewriteStart; i <= nTokenRewriteEnd; i++) { let sValue = lTokenValue[j]; if (!sValue || sValue === "*") { this.lTokens[i]["bToRemove"] = true; } else { if (bUppercase) { sValue = sValue.gl_toCapitalize(); } this.lTokens[i]["sNewValue"] = sValue; } j++; } } } } rewriteFromTags (bDebug=false) { // rewrite the sentence, modify tokens, purge the token list if (bDebug) { console.log("REWRITE"); } let lNewToken = []; let lNewTokens0 = []; let nMergeUntil = 0; let oMergingToken = null; for (let [iToken, oToken] of this.lTokens.entries()) { let bKeepToken = true; let bKeepToken0 = true; if (oToken["sType"] != "INFO") { if (nMergeUntil && iToken <= nMergeUntil) { oMergingToken["sValue"] += " ".repeat(oToken["nStart"] - oMergingToken["nEnd"]) + oToken["sValue"]; oMergingToken["nEnd"] = oToken["nEnd"]; if (bDebug) { console.log(" MERGED TOKEN: " + oMergingToken["sValue"]); } bKeepToken = false; bKeepToken0 = false; } if (oToken.hasOwnProperty("nMergeUntil")) { if (iToken > nMergeUntil) { // this token is not already merged with a previous token oMergingToken = oToken; } if (oToken["nMergeUntil"] > nMergeUntil) { nMergeUntil = oToken["nMergeUntil"]; |
︙ | ︙ | |||
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | this.dTokenPos.delete(oToken["nStart"]); } catch (e) { console.log(this.asString()); console.log(oToken); } } } if (bDebug) { console.log(" TEXT REWRITED: " + this.sSentence); } | > > > | | > > > > | 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 | this.dTokenPos.delete(oToken["nStart"]); } catch (e) { console.log(this.asString()); console.log(oToken); } } if (this.lTokens0 !== null && bKeepToken0) { lNewTokens0.push(oToken); } } if (bDebug) { console.log(" TEXT REWRITED: " + this.sSentence); } this.lTokens.length = 0; this.lTokens = lNewToken; if (this.lTokens0 !== null) { this.lTokens0.length = 0; this.lTokens0 = lNewTokens0; } } }; if (typeof(exports) !== 'undefined') { exports.lang = gc_engine.lang; exports.locales = gc_engine.locales; |
︙ | ︙ |
Modified gc_core/py/lang_core/gc_engine.py from [472d04d897] to [dc7c0547ff].
︙ | ︙ | |||
231 232 233 234 235 236 237 | def __init__ (self, sText): self.sText = sText self.sText0 = sText self.sSentence = "" self.sSentence0 = "" self.nOffsetWithinParagraph = 0 | | | > > | | < < < < | | > > > > | > > > > > > | 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 | def __init__ (self, sText): self.sText = sText self.sText0 = sText self.sSentence = "" self.sSentence0 = "" self.nOffsetWithinParagraph = 0 self.lTokens = [] self.dTokenPos = {} # {position: token} self.dTags = {} # {position: tags} self.dError = {} # {position: error} self.dSentenceError = {} # {position: error} (for the current sentence only) self.dErrorPriority = {} # {position: priority of the current error} def __str__ (self): s = "===== TEXT =====\n" s += "sentence: " + self.sSentence0 + "\n" s += "now: " + self.sSentence + "\n" for dToken in self.lTokens: s += '#{i}\t{nStart}:{nEnd}\t{sValue}\t{sType}'.format(**dToken) if "lMorph" in dToken: s += "\t" + str(dToken["lMorph"]) if "aTags" in dToken: s += "\t" + str(dToken["aTags"]) s += "\n" #for nPos, dToken in self.dTokenPos.items(): # s += "{}\t{}\n".format(nPos, dToken) return s def parse (self, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False, bFullInfo=False): "analyses <sText> and returns an iterable of errors or (with option <bFullInfo>) paragraphs errors and sentences with tokens and errors" #sText = unicodedata.normalize("NFC", sText) dOpt = dOptions or gc_options.dOptions bShowRuleId = gc_options.dOptions.get('idrule', False) # parse paragraph try: self.parseText(self.sText, self.sText0, True, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext) except: raise self.lTokens = None self.lTokens0 = None if bFullInfo: lParagraphErrors = list(self.dError.values()) lSentences = [] self.dSentenceError.clear() # parse sentences sText = self._getCleanText() for iStart, iEnd in text.getSentenceBoundaries(sText): if 4 < (iEnd - iStart) < 2000: try: self.sSentence = sText[iStart:iEnd] self.sSentence0 = self.sText0[iStart:iEnd] self.nOffsetWithinParagraph = iStart self.lTokens = list(_oTokenizer.genTokens(self.sSentence, True)) self.dTokenPos = { dToken["nStart"]: dToken for dToken in self.lTokens if dToken["sType"] != "INFO" } if bFullInfo: self.lTokens0 = list(self.lTokens) # the list of tokens is duplicated, to keep all tokens from being deleted when analysis self.parseText(self.sSentence, self.sSentence0, False, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext) if bFullInfo: for dToken in self.lTokens0: if dToken["sType"] == "WORD": dToken["bValidToken"] = _oSpellChecker.isValidToken(dToken["sValue"]) if "lMorph" not in dToken: dToken["lMorph"] = _oSpellChecker.getMorph(dToken["sValue"]) lSentences.append({ "nStart": iStart, "nEnd": iEnd, "sSentence": self.sSentence0, "lTokens": self.lTokens0, "lGrammarErrors": list(self.dSentenceError.values()) }) self.dSentenceError.clear() except: raise if bFullInfo: # Grammar checking and sentence analysis return lParagraphErrors, lSentences else: |
︙ | ︙ | |||
377 378 379 380 381 382 383 | self.sText = sText else: self.sSentence = sText def update (self, sSentence, bDebug=False): "update <sSentence> and retokenize" self.sSentence = sSentence | | | | | | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | self.sText = sText else: self.sSentence = sText def update (self, sSentence, bDebug=False): "update <sSentence> and retokenize" self.sSentence = sSentence lNewTokens = list(_oTokenizer.genTokens(sSentence, True)) for dToken in lNewTokens: if "lMorph" in self.dTokenPos.get(dToken["nStart"], {}): dToken["lMorph"] = self.dTokenPos[dToken["nStart"]]["lMorph"] if "aTags" in self.dTokenPos.get(dToken["nStart"], {}): dToken["aTags"] = self.dTokenPos[dToken["nStart"]]["aTags"] self.lTokens = lNewTokens self.dTokenPos = { dToken["nStart"]: dToken for dToken in self.lTokens if dToken["sType"] != "INFO" } if bDebug: echo("UPDATE:") echo(self) def _getNextPointers (self, dToken, dGraph, dPointer, bDebug=False): "generator: return nodes where <dToken> “values” match <dNode> arcs" dNode = dGraph[dPointer["iNode"]] |
︙ | ︙ | |||
548 549 550 551 552 553 554 | dPointer2 = { "iToken1": iToken1, "iNode": dNode["<>"], "bKeep": True } yield from self._getNextPointers(dToken, dGraph, dPointer2, bDebug) def parseGraph (self, dGraph, sCountry="${country_default}", dOptions=None, bShowRuleId=False, bDebug=False, bContext=False): "parse graph with tokens from the text and execute actions encountered" lPointer = [] bTagAndRewrite = False | | | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | dPointer2 = { "iToken1": iToken1, "iNode": dNode["<>"], "bKeep": True } yield from self._getNextPointers(dToken, dGraph, dPointer2, bDebug) def parseGraph (self, dGraph, sCountry="${country_default}", dOptions=None, bShowRuleId=False, bDebug=False, bContext=False): "parse graph with tokens from the text and execute actions encountered" lPointer = [] bTagAndRewrite = False for iToken, dToken in enumerate(self.lTokens): if bDebug: echo("TOKEN: " + dToken["sValue"]) # check arcs for each existing pointer lNextPointer = [] for dPointer in lPointer: lNextPointer.extend(self._getNextPointers(dToken, dGraph, dPointer, bDebug)) lPointer = lNextPointer |
︙ | ︙ | |||
589 590 591 592 593 594 595 | # Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL ] # TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] # Disambiguator [ option, condition, "=", replacement/suggestion/action ] # Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] # Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] # Test [ option, condition, ">", "" ] if not sOption or dOptions.get(sOption, False): | | | | | | | | | | | | | | | | | 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 | # Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL ] # TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] # Disambiguator [ option, condition, "=", replacement/suggestion/action ] # Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] # Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] # Test [ option, condition, ">", "" ] if not sOption or dOptions.get(sOption, False): bCondMemo = not sFuncCond or getattr(gc_functions, sFuncCond)(self.lTokens, nTokenOffset, nLastToken, sCountry, bCondMemo, self.dTags, self.sSentence, self.sSentence0) if bCondMemo: if cActionType == "-": # grammar error iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL = eAct nTokenErrorStart = nTokenOffset + iTokenStart if iTokenStart > 0 else nLastToken + iTokenStart if "bImmune" not in self.lTokens[nTokenErrorStart]: nTokenErrorEnd = nTokenOffset + iTokenEnd if iTokenEnd > 0 else nLastToken + iTokenEnd nErrorStart = self.nOffsetWithinParagraph + (self.lTokens[nTokenErrorStart]["nStart"] if cStartLimit == "<" else self.lTokens[nTokenErrorStart]["nEnd"]) nErrorEnd = self.nOffsetWithinParagraph + (self.lTokens[nTokenErrorEnd]["nEnd"] if cEndLimit == ">" else self.lTokens[nTokenErrorEnd]["nStart"]) if nErrorStart not in self.dError or nPriority > self.dErrorPriority.get(nErrorStart, -1): self.dError[nErrorStart] = self._createErrorFromTokens(sWhat, nTokenOffset, nLastToken, nTokenErrorStart, nErrorStart, nErrorEnd, sLineId, sRuleId, bCaseSvty, \ sMessage, _rules_graph.dURL.get(iURL, ""), bShowRuleId, sOption, bContext) self.dErrorPriority[nErrorStart] = nPriority self.dSentenceError[nErrorStart] = self.dError[nErrorStart] if bDebug: echo(" NEW_ERROR: {}".format(self.dError[nErrorStart])) elif cActionType == "~": # text processor nTokenStart = nTokenOffset + eAct[0] if eAct[0] > 0 else nLastToken + eAct[0] nTokenEnd = nTokenOffset + eAct[1] if eAct[1] > 0 else nLastToken + eAct[1] self._tagAndPrepareTokenForRewriting(sWhat, nTokenStart, nTokenEnd, nTokenOffset, nLastToken, eAct[2], bDebug) bChange = True if bDebug: echo(" TEXT_PROCESSOR: [{}:{}] > {}".format(self.lTokens[nTokenStart]["sValue"], self.lTokens[nTokenEnd]["sValue"], sWhat)) elif cActionType == "=": # disambiguation getattr(gc_functions, sWhat)(self.lTokens, nTokenOffset, nLastToken) if bDebug: echo(" DISAMBIGUATOR: ({}) [{}:{}]".format(sWhat, self.lTokens[nTokenOffset+1]["sValue"], self.lTokens[nLastToken]["sValue"])) elif cActionType == ">": # we do nothing, this test is just a condition to apply all following actions if bDebug: echo(" COND_OK") elif cActionType == "/": # Tag nTokenStart = nTokenOffset + eAct[0] if eAct[0] > 0 else nLastToken + eAct[0] nTokenEnd = nTokenOffset + eAct[1] if eAct[1] > 0 else nLastToken + eAct[1] for i in range(nTokenStart, nTokenEnd+1): if "aTags" in self.lTokens[i]: self.lTokens[i]["aTags"].update(sWhat.split("|")) else: self.lTokens[i]["aTags"] = set(sWhat.split("|")) if bDebug: echo(" TAG: {} > [{}:{}]".format(sWhat, self.lTokens[nTokenStart]["sValue"], self.lTokens[nTokenEnd]["sValue"])) for sTag in sWhat.split("|"): if sTag not in self.dTags: self.dTags[sTag] = [nTokenStart, nTokenEnd] else: self.dTags[sTag][0] = min(nTokenStart, self.dTags[sTag][0]) self.dTags[sTag][1] = max(nTokenEnd, self.dTags[sTag][1]) elif cActionType == "!": # immunity if bDebug: echo(" IMMUNITY: " + sLineId + " / " + sRuleId) nTokenStart = nTokenOffset + eAct[0] if eAct[0] > 0 else nLastToken + eAct[0] nTokenEnd = nTokenOffset + eAct[1] if eAct[1] > 0 else nLastToken + eAct[1] if nTokenEnd - nTokenStart == 0: self.lTokens[nTokenStart]["bImmune"] = True nErrorStart = self.nOffsetWithinParagraph + self.lTokens[nTokenStart]["nStart"] if nErrorStart in self.dError: del self.dError[nErrorStart] else: for i in range(nTokenStart, nTokenEnd+1): self.lTokens[i]["bImmune"] = True nErrorStart = self.nOffsetWithinParagraph + self.lTokens[i]["nStart"] if nErrorStart in self.dError: del self.dError[nErrorStart] else: echo("# error: unknown action at " + sLineId) elif cActionType == ">": if bDebug: echo(" COND_BREAK") |
︙ | ︙ | |||
692 693 694 695 696 697 698 | if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) def _createErrorFromTokens (self, sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext): # suggestions if sSugg[0:1] == "=": | | | | | 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) def _createErrorFromTokens (self, sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext): # suggestions if sSugg[0:1] == "=": sSugg = getattr(gc_functions, sSugg[1:])(self.lTokens, nTokenOffset, nLastToken) lSugg = sSugg.split("|") if sSugg else [] elif sSugg == "_": lSugg = [] else: lSugg = self._expand(sSugg, nTokenOffset, nLastToken).split("|") if bCaseSvty and lSugg and self.lTokens[iFirstToken]["sValue"][0:1].isupper(): lSugg = list(map(lambda s: s.upper(), lSugg)) if self.sSentence[nStart:nEnd].isupper() else list(map(lambda s: s[0:1].upper()+s[1:], lSugg)) # Message sMessage = getattr(gc_functions, sMsg[1:])(self.lTokens, nTokenOffset, nLastToken) if sMsg[0:1] == "=" else self._expand(sMsg, nTokenOffset, nLastToken) if bShowRuleId: sMessage += " #" + sLineId + " / " + sRuleId # if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) |
︙ | ︙ | |||
750 751 752 753 754 755 756 | dErr['sBefore'] = self.sText0[max(0,nStart-80):nStart] dErr['sAfter'] = self.sText0[nEnd:nEnd+80] return dErr def _expand (self, sText, nTokenOffset, nLastToken): for m in re.finditer(r"\\(-?[0-9]+)", sText): if m.group(1)[0:1] == "-": | | | | 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | dErr['sBefore'] = self.sText0[max(0,nStart-80):nStart] dErr['sAfter'] = self.sText0[nEnd:nEnd+80] return dErr def _expand (self, sText, nTokenOffset, nLastToken): for m in re.finditer(r"\\(-?[0-9]+)", sText): if m.group(1)[0:1] == "-": sText = sText.replace(m.group(0), self.lTokens[nLastToken+int(m.group(1))+1]["sValue"]) else: sText = sText.replace(m.group(0), self.lTokens[nTokenOffset+int(m.group(1))]["sValue"]) return sText def rewriteText (self, sText, sRepl, iGroup, m, bUppercase): "text processor: write <sRepl> in <sText> at <iGroup> position" nLen = m.end(iGroup) - m.start(iGroup) if sRepl == "*": sNew = " " * nLen |
︙ | ︙ | |||
779 780 781 782 783 784 785 | return sText[0:m.start(iGroup)] + sNew + sText[m.end(iGroup):] def _tagAndPrepareTokenForRewriting (self, sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug): "text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position" if sWhat == "*": # purge text if nTokenRewriteEnd - nTokenRewriteStart == 0: | | | | | | | | | | | > | | > > > > | > | > > | > > | > | 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 | return sText[0:m.start(iGroup)] + sNew + sText[m.end(iGroup):] def _tagAndPrepareTokenForRewriting (self, sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug): "text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position" if sWhat == "*": # purge text if nTokenRewriteEnd - nTokenRewriteStart == 0: self.lTokens[nTokenRewriteStart]["bToRemove"] = True else: for i in range(nTokenRewriteStart, nTokenRewriteEnd+1): self.lTokens[i]["bToRemove"] = True elif sWhat == "␣": # merge tokens self.lTokens[nTokenRewriteStart]["nMergeUntil"] = nTokenRewriteEnd elif sWhat == "_": # neutralized token if nTokenRewriteEnd - nTokenRewriteStart == 0: self.lTokens[nTokenRewriteStart]["sNewValue"] = "_" else: for i in range(nTokenRewriteStart, nTokenRewriteEnd+1): self.lTokens[i]["sNewValue"] = "_" else: if sWhat.startswith("="): sWhat = getattr(gc_functions, sWhat[1:])(self.lTokens, nTokenOffset, nLastToken) else: sWhat = self._expand(sWhat, nTokenOffset, nLastToken) bUppercase = bCaseSvty and self.lTokens[nTokenRewriteStart]["sValue"][0:1].isupper() if nTokenRewriteEnd - nTokenRewriteStart == 0: # one token if bUppercase: sWhat = sWhat[0:1].upper() + sWhat[1:] self.lTokens[nTokenRewriteStart]["sNewValue"] = sWhat else: # several tokens lTokenValue = sWhat.split("|") if len(lTokenValue) != (nTokenRewriteEnd - nTokenRewriteStart + 1): if (bDebug): echo("Error. Text processor: number of replacements != number of tokens.") return for i, sValue in zip(range(nTokenRewriteStart, nTokenRewriteEnd+1), lTokenValue): if not sValue or sValue == "*": self.lTokens[i]["bToRemove"] = True else: if bUppercase: sValue = sValue[0:1].upper() + sValue[1:] self.lTokens[i]["sNewValue"] = sValue def rewriteFromTags (self, bDebug=False): "rewrite the sentence, modify tokens, purge the token list" if bDebug: echo("REWRITE") lNewTokens = [] lNewTokens0 = [] nMergeUntil = 0 dTokenMerger = {} for iToken, dToken in enumerate(self.lTokens): bKeepToken = True bKeepToken0 = True if dToken["sType"] != "INFO": if nMergeUntil and iToken <= nMergeUntil: # token to merge dTokenMerger["sValue"] += " " * (dToken["nStart"] - dTokenMerger["nEnd"]) + dToken["sValue"] dTokenMerger["nEnd"] = dToken["nEnd"] if bDebug: echo(" MERGED TOKEN: " + dTokenMerger["sValue"]) bKeepToken = False bKeepToken0 = False if "nMergeUntil" in dToken: # first token to be merge with if iToken > nMergeUntil: # this token is not to be merged with a previous token dTokenMerger = dToken if dToken["nMergeUntil"] > nMergeUntil: nMergeUntil = dToken["nMergeUntil"] del dToken["nMergeUntil"] elif "bToRemove" in dToken: # deletion required if bDebug: echo(" REMOVED: " + dToken["sValue"]) self.sSentence = self.sSentence[:dToken["nStart"]] + " " * (dToken["nEnd"] - dToken["nStart"]) + self.sSentence[dToken["nEnd"]:] bKeepToken = False # if bKeepToken: lNewTokens.append(dToken) if "sNewValue" in dToken: # rewrite token and sentence if bDebug: echo(dToken["sValue"] + " -> " + dToken["sNewValue"]) dToken["sRealValue"] = dToken["sValue"] dToken["sValue"] = dToken["sNewValue"] nDiffLen = len(dToken["sRealValue"]) - len(dToken["sNewValue"]) sNewRepl = (dToken["sNewValue"] + " " * nDiffLen) if nDiffLen >= 0 else dToken["sNewValue"][:len(dToken["sRealValue"])] self.sSentence = self.sSentence[:dToken["nStart"]] + sNewRepl + self.sSentence[dToken["nEnd"]:] del dToken["sNewValue"] else: try: del self.dTokenPos[dToken["nStart"]] except KeyError: echo(self) echo(dToken) if self.lTokens0 is not None and bKeepToken0: lNewTokens0.append(dToken) if bDebug: echo(" TEXT REWRITED: " + self.sSentence) self.lTokens.clear() self.lTokens = lNewTokens if self.lTokens0 is not None: self.lTokens0.clear() self.lTokens0 = lNewTokens0 |
Modified gc_lang/fr/webext/content_scripts/init.js from [d6a977e5a7] to [b54947b0d1].
︙ | ︙ | |||
340 341 342 343 344 345 346 | this.send("parseAndSpellcheck", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination }); }, parseAndSpellcheck1: function (sText, sDestination, sParagraphId) { this.send("parseAndSpellcheck1", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination, sParagraphId: sParagraphId }); }, | | | | | | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | this.send("parseAndSpellcheck", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination }); }, parseAndSpellcheck1: function (sText, sDestination, sParagraphId) { this.send("parseAndSpellcheck1", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination, sParagraphId: sParagraphId }); }, parseFull: function (sText, sDestination, sParagraphId) { this.send("parseFull", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination }); }, getListOfTokens: function (sText, sDestination) { this.send("getListOfTokens", { sText: sText }, { sDestination: sDestination }); }, getVerb: function (sVerb, bStart=true, bPro=false, bNeg=false, bTpsCo=false, bInt=false, bFem=false) { this.send("getVerb", { sVerb: sVerb, bPro: bPro, bNeg: bNeg, bTpsCo: bTpsCo, bInt: bInt, bFem: bFem }, { bStart: bStart }); }, getSpellSuggestions: function (sWord, sDestination, sErrorId) { |
︙ | ︙ | |||
418 419 420 421 422 423 424 | break; case "parseAndSpellcheck1": if (oInfo.sDestination == "__GrammalectePanel__") { oGrammalecte.oGCPanel.refreshParagraph(oInfo.sParagraphId, result); } break; case "parseFull": | | > > > | | | | | > | 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 | break; case "parseAndSpellcheck1": if (oInfo.sDestination == "__GrammalectePanel__") { oGrammalecte.oGCPanel.refreshParagraph(oInfo.sParagraphId, result); } break; case "parseFull": if (oInfo.sDestination == "__GrammalectePanel__") { oGrammalecte.oGCPanel.showParagraphAnalysis(result); } break; case "getListOfTokens": if (oInfo.sDestination == "__GrammalectePanel__") { if (!bEnd) { oGrammalecte.oGCPanel.addListOfTokens(result); } else { oGrammalecte.oGCPanel.stopWaitIcon(); oGrammalecte.oGCPanel.endTimer(); } } break; case "getSpellSuggestions": if (oInfo.sDestination == "__GrammalectePanel__") { oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, oInfo.sErrorId); } else if (oInfo.sDestination && document.getElementById(oInfo.sDestination)) { |
︙ | ︙ |
Modified gc_lang/fr/webext/content_scripts/panel_gc.css from [9a73dd19f8] to [89a25fc756].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /* Grammar checker */ div#grammalecte_gc_panel_content { position: absolute; height: 100%; width: 100%; margin: 0; overflow: auto; } div.grammalecte_paragraph_block { margin: 5px 5px 0 5px; } | > > < < < < | 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 | /* Grammar checker */ div#grammalecte_gc_panel_content { position: absolute; height: 100%; width: 100%; margin: 0; overflow: auto; } div.grammalecte_paragraph_block { margin: 5px 5px 0 5px; background-color: hsl(0, 0%, 96%); border-radius: 2px; } p.grammalecte_paragraph { margin: 0; padding: 12px; line-height: 1.3; text-align: left; font-size: 14px; font-family: "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; color: hsl(0, 0%, 0%); hyphens: none; } /* Action buttons */ div.grammalecte_paragraph_actions { float: right; margin: 0 0 5px 10px; |
︙ | ︙ | |||
43 44 45 46 47 48 49 50 51 52 53 54 55 56 | cursor: pointer; font-family: "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif; font-size: 14px; color: hsl(0, 0%, 96%); border-radius: 2px; } div.grammalecte_paragraph_actions .grammalecte_green { color: hsl(0, 0%, 80%); } div.grammalecte_paragraph_actions .grammalecte_green:hover { background-color: hsl(120, 50%, 40%); color: hsl(0, 0%, 100%); } | > > > > > > > | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | cursor: pointer; font-family: "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif; font-size: 14px; color: hsl(0, 0%, 96%); border-radius: 2px; } div.grammalecte_paragraph_actions .grammalecte_blue { color: hsl(0, 0%, 80%); } div.grammalecte_paragraph_actions .grammalecte_blue:hover { background-color: hsl(210, 50%, 40%); color: hsl(0, 0%, 100%); } div.grammalecte_paragraph_actions .grammalecte_green { color: hsl(0, 0%, 80%); } div.grammalecte_paragraph_actions .grammalecte_green:hover { background-color: hsl(120, 50%, 40%); color: hsl(0, 0%, 100%); } |
︙ | ︙ |
Modified gc_lang/fr/webext/content_scripts/panel_gc.js from [5158e88aeb] to [14ecf7a831].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // JavaScript /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global GrammalectePanel, oGrammalecte, oGrammalecteBackgroundPort, showError, window, document, console */ "use strict"; function onGrammalecteGCPanelClick (xEvent) { try { let xElem = xEvent.target; if (xElem.id) { if (xElem.id.startsWith("grammalecte_sugg")) { oGrammalecte.oGCPanel.applySuggestion(xElem.id); } else if (xElem.id === "grammalecte_tooltip_ignore") { oGrammalecte.oGCPanel.ignoreError(xElem.id); } else if (xElem.id.startsWith("grammalecte_check")) { oGrammalecte.oGCPanel.recheckParagraph(parseInt(xElem.dataset.para_num, 10)); } else if (xElem.id.startsWith("grammalecte_hide")) { xElem.parentNode.parentNode.style.display = "none"; } else if (xElem.id.startsWith("grammalecte_err") && xElem.className !== "grammalecte_error_corrected" && xElem.className !== "grammalecte_error_ignored") { | > > > | 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 | // JavaScript /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global GrammalectePanel, oGrammalecte, oGrammalecteBackgroundPort, showError, window, document, console */ "use strict"; function onGrammalecteGCPanelClick (xEvent) { try { let xElem = xEvent.target; if (xElem.id) { if (xElem.id.startsWith("grammalecte_sugg")) { oGrammalecte.oGCPanel.applySuggestion(xElem.id); } else if (xElem.id === "grammalecte_tooltip_ignore") { oGrammalecte.oGCPanel.ignoreError(xElem.id); } else if (xElem.id.startsWith("grammalecte_analysis")) { oGrammalecte.oGCPanel.sendParagraphToGrammaticalAnalysis(parseInt(xElem.dataset.para_num, 10)); } else if (xElem.id.startsWith("grammalecte_check")) { oGrammalecte.oGCPanel.recheckParagraph(parseInt(xElem.dataset.para_num, 10)); } else if (xElem.id.startsWith("grammalecte_hide")) { xElem.parentNode.parentNode.style.display = "none"; } else if (xElem.id.startsWith("grammalecte_err") && xElem.className !== "grammalecte_error_corrected" && xElem.className !== "grammalecte_error_ignored") { |
︙ | ︙ | |||
62 63 64 65 66 67 68 69 70 71 72 73 74 75 | this.oTextControl = null; this.nLastResult = 0; this.iLastEditedParagraph = -1; this.nParagraph = 0; // Lexicographer this.nLxgCount = 0; this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); this.xPanelContent.appendChild(this.xLxgPanelContent); // Conjugueur this.xConjPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_conj_panel_content"}); this.xConjPanelContent.innerHTML = sGrammalecteConjugueurHTML; // @Reviewers: sGrammalecteConjugueurHTML is a const value defined in <content_scripts/html_src.js> this.xPanelContent.appendChild(this.xConjPanelContent); this.sVerb = ""; this.bListenConj = false; | > > > > > > > > > > > > | 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 | this.oTextControl = null; this.nLastResult = 0; this.iLastEditedParagraph = -1; this.nParagraph = 0; // Lexicographer this.nLxgCount = 0; this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"}); this.xLxgInputBlock = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input_block"}); this.xLxgInput = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input", lang: "fr", contentEditable: "true"}); this.xLxgInputButton = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input_button", textContent: "Analyse grammaticale"}); this.xLxgInputButton.addEventListener("click", () => { this.grammaticalAnalysis(); }, false); this.xLxgInputButton2 = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input_button", textContent: "Analyse lexicale"}); this.xLxgInputButton2.addEventListener("click", () => { this.getListOfTokens(); }, false); this.xLxgInputBlock.appendChild(this.xLxgInput); this.xLxgInputBlock.appendChild(this.xLxgInputButton); this.xLxgInputBlock.appendChild(this.xLxgInputButton2); this.xLxgPanelContent.appendChild(this.xLxgInputBlock); this.xLxgResultZone = oGrammalecte.createNode("div", {id: "grammalecte_lxg_result_zone"}); this.xLxgPanelContent.appendChild(this.xLxgResultZone); this.xPanelContent.appendChild(this.xLxgPanelContent); // Conjugueur this.xConjPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_conj_panel_content"}); this.xConjPanelContent.innerHTML = sGrammalecteConjugueurHTML; // @Reviewers: sGrammalecteConjugueurHTML is a const value defined in <content_scripts/html_src.js> this.xPanelContent.appendChild(this.xConjPanelContent); this.sVerb = ""; this.bListenConj = false; |
︙ | ︙ | |||
110 111 112 113 114 115 116 | oGrammalecte.bAutoRefresh = this.bAutoRefresh; browser.storage.local.set({"autorefresh_option": this.bAutoRefresh}); this.setAutoRefreshButton(); } this.xLxgButton.onclick = () => { if (!this.bWorking) { this.showLexicographer(); | < < < < | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | oGrammalecte.bAutoRefresh = this.bAutoRefresh; browser.storage.local.set({"autorefresh_option": this.bAutoRefresh}); this.setAutoRefreshButton(); } this.xLxgButton.onclick = () => { if (!this.bWorking) { this.showLexicographer(); } }; this.xConjButton.onclick = () => { if (!this.bWorking) { this.showConjugueur(); } }; |
︙ | ︙ | |||
236 237 238 239 240 241 242 | this.oTextControl.clear(); } addParagraphResult (oResult) { try { this.resetTimer(); if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { | < > > | | | | 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 | this.oTextControl.clear(); } addParagraphResult (oResult) { try { this.resetTimer(); if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { // actions let xActionsBar = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_actions"}); xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum})); xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_analysis" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_blue", textContent: "»", title: "Analyse grammaticale…"}, {para_num: oResult.iParaNum})); xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"})); // paragraph let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum}); xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute. xParagraph.dataset.timer_id = "0"; xParagraph.addEventListener("input", function (xEvent) { if (this.bAutoRefresh) { // timer for refreshing analysis window.clearTimeout(parseInt(xParagraph.dataset.timer_id, 10)); xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum); this.iLastEditedParagraph = oResult.iParaNum; } // write text this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num, 10), xEvent.target.textContent); }.bind(this) , true); this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr); // creation let xParagraphBlock = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_block"}); xParagraphBlock.appendChild(xActionsBar); xParagraphBlock.appendChild(xParagraph); this.xParagraphList.appendChild(xParagraphBlock); this.nParagraph += 1; } } catch (e) { showError(e); } } |
︙ | ︙ | |||
528 529 530 531 532 533 534 | } } // Lexicographer clearLexicographer () { this.nLxgCount = 0; | | > > > | > | > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > | > | > > > > > > > | > | > | | > > > > > > > > > > > > > | > > > | | > | > > > > > > > > > > > > > > > > > > | | | | > > | | > | 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 | } } // Lexicographer clearLexicographer () { this.nLxgCount = 0; while (this.xLxgResultZone.firstChild) { this.xLxgResultZone.removeChild(this.xLxgResultZone.firstChild); } } // Grammatical analysis sendParagraphToGrammaticalAnalysis (iParaNum) { let xParagraph = this.xParent.getElementById("grammalecte_paragraph" + iParaNum); this.xLxgInput.textContent = xParagraph.textContent; this.grammaticalAnalysis(); this.showLexicographer(); } grammaticalAnalysis (iParaNum) { if (!this.bOpened || this.bWorking) { return; } this.startWaitIcon(); this.clearLexicographer(); let sText = this.xLxgInput.innerText.replace(/\n/g, " "); console.log(sText); oGrammalecteBackgroundPort.parseFull(sText, "__GrammalectePanel__"); } showParagraphAnalysis (oResult) { if (!this.bOpened || oResult === null) { return; } try { for (let oSentence of oResult.lSentences) { this.nLxgCount += 1; if (oSentence.sSentence.trim() !== "") { let xSentenceBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_paragraph_sentence_block"}); xSentenceBlock.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this.nLxgCount})); xSentenceBlock.appendChild(oGrammalecte.createNode("p", {className: "grammalecte_lxg_paragraph_sentence", textContent: oSentence.sSentence})); let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); for (let oToken of oSentence.lTokens) { if (oToken["sType"] != "INFO") { xTokenList.appendChild(this._createTokenBlock2(oToken)); } } xSentenceBlock.appendChild(xTokenList); this.xLxgResultZone.appendChild(xSentenceBlock); } } } catch (e) { showError(e); } this.stopWaitIcon(); } _createTokenBlock2 (oToken) { let xTokenBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_block"}); // token description xTokenBlock.appendChild(this._createTokenDescr2(oToken)); // subtoken description if (oToken.aSubElem) { let xSubBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_subblock"}); for (let oSubElem of oToken.aSubElem) { xSubBlock.appendChild(this._createTokenDescr2(oSubElem)); } xTokenBlock.appendChild(xSubBlock); } return xTokenBlock; } _createTokenDescr2 (oToken) { try { let xTokenDescr = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_descr"}); if (oToken.sType == "LOCP") { xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_also", textContent: "possiblement › "})); } xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token grammalecte_lxg_token_" + oToken.sType, textContent: oToken.sValue})); xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_colon", textContent: ":"})); if (oToken.lMorph.length < 2) { // one morphology only xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem_inline", textContent: oToken.lMorph[0]})); } else { // several morphology let xMorphList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_list"}); for (let sLabel of oToken.lMorph) { xMorphList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem", textContent: "• " + sLabel})); } xTokenDescr.appendChild(xMorphList); } return xTokenDescr; } catch (e) { showError(e); } } // Lexical analysis getListOfTokens () { if (!this.bOpened || this.bWorking) { return; } this.startWaitIcon(); this.clearLexicographer(); let sText = this.xLxgInput.innerText; // to get carriage return (\n) console.log(sText); oGrammalecteBackgroundPort.getListOfTokens(sText, "__GrammalectePanel__"); } addListOfTokens (oResult) { try { if (oResult && oResult.sParagraph != "") { this.nLxgCount += 1; let xSentenceBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_paragraph_sentence_block"}); xSentenceBlock.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this.nLxgCount})); xSentenceBlock.appendChild(oGrammalecte.createNode("p", {className: "grammalecte_lxg_paragraph_sentence", textContent: oResult.sParagraph})); let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"}); for (let oToken of oResult.lTokens) { xTokenList.appendChild(this._createTokenBlock(oToken)); } xSentenceBlock.appendChild(xTokenList); this.xLxgResultZone.appendChild(xSentenceBlock); } } catch (e) { showError(e); } } |
︙ | ︙ | |||
598 599 600 601 602 603 604 | return xTokenDescr; } catch (e) { showError(e); } } | < < < < < < | 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | return xTokenDescr; } catch (e) { showError(e); } } // Conjugueur listenConj () { if (!this.bListenConj) { // button this.xParent.getElementById('grammalecte_conj_button').addEventListener("click", (e) => { this.conjugateVerb(); }); |
︙ | ︙ |
Modified gc_lang/fr/webext/content_scripts/panel_lxg.css from [ae4f6ddf8d] to [1a476d12b0].
1 2 3 4 5 6 7 8 9 10 11 | /* Lexicographer */ div#grammalecte_lxg_panel_content { display: none; position: absolute; height: 100%; width: 100%; font-size: 13px; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | > > > > > > > > > > > > > | | | 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 | /* Lexicographer */ div#grammalecte_lxg_panel_content { display: none; position: absolute; height: 100%; width: 100%; font-size: 13px; } div#grammalecte_lxg_input_block { padding: 10px; /*background-color: hsl(210, 50%, 95%);*/ /*border-bottom: solid 1px hsl(210, 0%, 90%);*/ text-align: right; } div#grammalecte_lxg_result_zone { } div#grammalecte_lxg_input { min-height: 100px; padding: 10px; background-color: hsl(210, 0%, 100%); border: solid 1px hsl(210, 20%, 80%); border-radius: 3px; font-family: "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; text-align: left; } div#grammalecte_lxg_input_button { display: inline-block; margin: 0 10px 0 0; padding: 3px 10px; background-color: hsl(210, 50%, 50%); color: hsl(210, 50%, 98%); text-align: center; cursor: pointer; border-radius: 0 0 3px 3px; } div.grammalecte_lxg_paragraph_sentence_block { margin: 5px 0px 20px 0px; background-color: hsl(210, 50%, 95%); border-radius: 3px; border-top: solid 1px hsl(210, 50%, 90%); border-bottom: solid 1px hsl(210, 50%, 90%); hyphens: none; } p.grammalecte_lxg_paragraph_sentence { padding: 3px 10px; font-weight: bold; color: hsl(210, 50%, 40%); } div.grammalecte_lxg_list_of_tokens { padding: 10px; background-color: hsl(210, 50%, 99%); border-radius: 5px; } div.grammalecte_lxg_list_num { float: right; margin: -2px 5px 5px 10px; padding: 5px 10px; font-family: "Trebuchet MS", "Fira Sans", "Ubuntu Condensed", "Liberation Sans", sans-serif; font-size: 14px; font-weight: bold; border-radius: 0 0 4px 4px; background-color: hsl(0, 50%, 50%); color: hsl(0, 10%, 96%); |
︙ | ︙ |
Modified gc_lang/fr/webext/gce_worker.js from [e351d5e6fd] to [b9ffc9c0b7].
︙ | ︙ | |||
227 228 229 230 231 232 233 | function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, oInfo={}) { sParagraph = sParagraph.replace(//g, "").normalize("NFC"); let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); let aSpellErr = oSpellChecker.parseParagraph(sParagraph); postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, true)); } | | < | < | | < < < | | | 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 | function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, oInfo={}) { sParagraph = sParagraph.replace(//g, "").normalize("NFC"); let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); let aSpellErr = oSpellChecker.parseParagraph(sParagraph); postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, true)); } function parseFull (sParagraph, sCountry, bDebug, bContext, oInfo={}) { sParagraph = sParagraph.replace(//g, "").normalize("NFC"); let [lParagraphErrors, lSentences] = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext, true); //console.log(lSentences); postMessage(createResponse("parseFull", { lParagraphErrors: lParagraphErrors, lSentences: lSentences }, oInfo, true)); } function getListOfTokens (sText, oInfo={}) { // lexicographer try { sText = sText.replace(//g, "").normalize("NFC"); for (let sParagraph of text.getParagraph(sText)) { if (sParagraph.trim() !== "") { postMessage(createResponse("getListOfTokens", { sParagraph: sParagraph, lTokens: lexgraph_fr.getListOfTokensReduc(sParagraph, true) }, oInfo, false)); } } postMessage(createResponse("getListOfTokens", null, oInfo, true)); } catch (e) { console.error(e); postMessage(createResponse("getListOfTokens", createErrorResult(e, "no tokens"), oInfo, true, true)); |
︙ | ︙ |
Modified grammalecte-cli.py from [0e5de0a660] to [d8f015f794].
︙ | ︙ | |||
338 339 340 341 342 343 344 | if xArgs.textformatter: sParagraph = oTextFormatter.formatText(sParagraph) lParagraphErrors, lSentences = oGrammarChecker.gce.parse(sParagraph, bDebug=xArgs.debug, bFullInfo=True) echo(txt.getReadableErrors(lParagraphErrors, xArgs.width)) for dSentence in lSentences: echo("{nStart}:{nEnd}".format(**dSentence)) echo(" <" + dSentence["sSentence"]+">") | | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | if xArgs.textformatter: sParagraph = oTextFormatter.formatText(sParagraph) lParagraphErrors, lSentences = oGrammarChecker.gce.parse(sParagraph, bDebug=xArgs.debug, bFullInfo=True) echo(txt.getReadableErrors(lParagraphErrors, xArgs.width)) for dSentence in lSentences: echo("{nStart}:{nEnd}".format(**dSentence)) echo(" <" + dSentence["sSentence"]+">") for dToken in dSentence["lTokens"]: echo(" {0[nStart]:>3}:{0[nEnd]:<3} {1} {0[sType]:<14} {2} {0[sValue]:<16} {3:<10} {4}".format(dToken, \ "×" if dToken.get("bToRemove", False) else " ", "!" if dToken["sType"] == "WORD" and not dToken.get("bValidToken", False) else " ", " ".join(dToken.get("lMorph", "")), \ "·".join(dToken.get("aTags", "")) ) ) echo(txt.getReadableErrors(dSentence["lGrammarErrors"], xArgs.width)) else: |
︙ | ︙ |
Modified graphspell-js/lexgraph_fr.js from [9858773647] to [b820c71513].
︙ | ︙ | |||
219 220 221 222 223 224 225 | [':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)"]], | | | | | | | | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | [':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)"]], [':ÉN', [" locution nominale (él.),", "Locution nominale (élément)"]], [':ÉA', [" locution adjectivale (él.),", "Locution adjectivale (élément)"]], [':ÉV', [" locution verbale (él.),", "Locution verbale (élément)"]], [':ÉW', [" locution adverbiale (él.),", "Locution adverbiale (élément)"]], [':ÉR', [" locution prépositive (él.),", "Locution prépositive (élément)"]], [':ÉJ', [" locution interjective (él.),", "Locution interjective (élément)"]], [':Zp', [" préfixe,", "Préfixe"]], [':Zs', [" suffixe,", "Suffixe"]], [':H', ["", "<Hors-norme, inclassable>"]], [':@', ["", "<Caractère non alpha-numérique>"]], |
︙ | ︙ |
Modified graphspell-js/spellchecker.js from [be4f6fe289] to [e42b82b880].
︙ | ︙ | |||
130 131 132 133 134 135 136 | // Lexicographer loadLexicographer (sLangCode) { // load default suggestion module for <sLangCode> if (typeof(process) !== 'undefined') { this.lexicographer = require(`./lexgraph_${sLangCode}.js`); } | > > > > | > > | > > > > > > > > > > > > | | > > > > > > > > > > > > > > | 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 | // Lexicographer loadLexicographer (sLangCode) { // load default suggestion module for <sLangCode> if (typeof(process) !== 'undefined') { this.lexicographer = require(`./lexgraph_${sLangCode}.js`); } else if (self && self.hasOwnProperty("lexgraph_"+sLangCode)) { // self is the Worker this.lexicographer = self["lexgraph_"+sLangCode]; } } analyze (sWord) { // returns a list of words and their morphologies if (!this.lexicographer) { return []; } let lWordAndMorph = []; for (let sElem of this.lexicographer.split(sWord)) { if (sElem) { let lMorph = this.getMorph(sElem); let sLex = this.lexicographer.analyze(sElem) let aRes = []; if (sLex) { aRes = [ [lMorph.join(" | "), sLex] ]; } else { for (let sMorph of lMorph) { aRes.push([sMorph, this.lexicographer.formatTags(sMorph)]); } } if (aRes.length > 0) { lWordAndMorph.push([sElem, aRes]); } } } return lWordAndMorph; } readableMorph (sMorph) { if (!this.lexicographer) { return []; } return this.lexicographer.formatTags(sMorph); } // Storage activateStorage () { this.bStorage = true; } |
︙ | ︙ |
Modified graphspell/spellchecker.py from [b9cca64fbd] to [ca24473f67].
︙ | ︙ | |||
96 97 98 99 100 101 102 | self.bCommunityDic = False def deactivatePersonalDictionary (self): "deactivate personal dictionary" self.bPersonalDic = False | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | self.bCommunityDic = False def deactivatePersonalDictionary (self): "deactivate personal dictionary" self.bPersonalDic = False # Lexicographer def loadLexicographer (self, sLangCode): "load default suggestion module for <sLangCode>" try: self.lexicographer = importlib.import_module(".lexgraph_"+sLangCode, "grammalecte.graphspell") except ImportError: print("No suggestion module for language <"+sLangCode+">") |
︙ | ︙ | |||
123 124 125 126 127 128 129 130 131 132 133 134 135 136 | aRes = [ (" | ".join(lMorph), sLex) ] else: aRes = [ (sMorph, self.lexicographer.formatTags(sMorph)) for sMorph in lMorph ] if aRes: lWordAndMorph.append((sElem, aRes)) return lWordAndMorph # Storage def activateStorage (self): "store all lemmas and morphologies retrieved from the word graph" self.bStorage = True | > > > > > | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | aRes = [ (" | ".join(lMorph), sLex) ] else: aRes = [ (sMorph, self.lexicographer.formatTags(sMorph)) for sMorph in lMorph ] if aRes: lWordAndMorph.append((sElem, aRes)) return lWordAndMorph def readableMorph (self, sMorph): if not self.lexicographer: return [] return self.lexicographer.formatTags(sMorph) # Storage def activateStorage (self): "store all lemmas and morphologies retrieved from the word graph" self.bStorage = True |
︙ | ︙ | |||
231 232 233 234 235 236 237 | if sWord not in self._dLemmas: self.getMorph(sWord) return self._dLemmas[sWord] return { s[1:s.find("/")] for s in self.getMorph(sWord) } def suggest (self, sWord, nSuggLimit=10): "generator: returns 1, 2 or 3 lists of suggestions" | | | 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | if sWord not in self._dLemmas: self.getMorph(sWord) return self._dLemmas[sWord] return { s[1:s.find("/")] for s in self.getMorph(sWord) } def suggest (self, sWord, nSuggLimit=10): "generator: returns 1, 2 or 3 lists of suggestions" if self.lexicographer: if sWord in self.lexicographer.dSugg: yield self.lexicographer.dSugg[sWord].split("|") elif sWord.istitle() and sWord.lower() in self.lexicographer.dSugg: lRes = self.lexicographer.dSugg[sWord.lower()].split("|") yield list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes)) else: yield self.oMainDic.suggest(sWord, nSuggLimit, True) |
︙ | ︙ |