Comment: | [core][fr][js] merge webext2_fix: code cleaning + bug fixes + remove Array comprehensions (for compatibility) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | fr | core | webext2 |
Files: | files | file ages | folders |
SHA3-256: |
d0f7053d0ff79ff34d9fa75342ebb2b1 |
User & Date: | olr on 2017-08-06 12:22:25 |
Original Comment: | [core][fr][js] merge webext2: code cleaning + bug fixes + remove Array comprehensions (for compatibility) |
Other Links: | branch diff | manifest | tags |
2017-08-06
| ||
13:27 | [build] don’t use Firefox nightly for Addon-SDK tests -> developper edition check-in: 97544c27f2 user: olr tags: build, webext2 | |
12:22 | [core][fr][js] merge webext2_fix: code cleaning + bug fixes + remove Array comprehensions (for compatibility) check-in: d0f7053d0f user: olr tags: fr, core, webext2 | |
12:14 | [core][js] set echo as console.log if no require available check-in: 7cc552ce5a user: olr tags: core, webext2_fix | |
2017-08-05
| ||
16:01 | [fx] test with Nightly again check-in: 578863e008 user: olr tags: fx, webext2 | |
Modified gc_core/js/helpers.js from [a78485e9a7] to [8fee48eb89].
︙ | ︙ | |||
59 60 61 62 63 64 65 | } xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers xRequest.send(); return xRequest.responseText; } catch (e) { this.logerror(e); | | | | 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 | } xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers xRequest.send(); return xRequest.responseText; } catch (e) { this.logerror(e); return null; } }, // conversions objectToMap: function (obj) { let m = new Map(); for (let param in obj) { //console.log(param + " " + obj[param]); m.set(param, obj[param]); } return m; }, mapToObject: function (m) { let obj = {}; for (let [k, v] of m) { obj[k] = v; } return obj; } }; if (typeof(exports) !== 'undefined') { exports.setLogOutput = helpers.setLogOutput; exports.echo = helpers.echo; exports.logerror = helpers.logerror; exports.inspect = helpers.inspect; exports.loadFile = helpers.loadFile; exports.objectToMap = helpers.objectToMap; exports.mapToObject = helpers.mapToObject; } |
Modified gc_core/js/ibdawg.js from [10dd14ace9] to [cdddd20c84].
︙ | ︙ | |||
72 73 74 75 76 77 78 | break; default: throw ValueError("# Error: unknown code: " + this.nVersion); } //console.log(this.getInfo()); this.bOptNumSigle = true; this.bOptNumAtLast = false; | < > < > < > | 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 | break; default: throw ValueError("# Error: unknown code: " + this.nVersion); } //console.log(this.getInfo()); this.bOptNumSigle = true; this.bOptNumAtLast = false; } getInfo () { return ` Language: ${this.sLang} Version: ${this.nVersion} Stemming: ${this.cStemming}FX\n` + ` Arcs values: ${this.nArcVal} = ${this.nChar} characters, ${this.nAff} affixes, ${this.nTag} tags\n` + ` Dictionary: ${this.nEntries} entries, ${this.nNode} nodes, ${this.nArc} arcs\n` + ` Address size: ${this.nBytesNodeAddress} bytes, Arc size: ${this.nBytesArc} bytes\n`; } isValidToken (sToken) { // checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked) if (this.isValid(sToken)) { return true; } if (sToken.includes("-")) { if (sToken.gl_count("-") > 4) { return true; } return sToken.split("-").every(sWord => this.isValid(sWord)); } return false; } isValid (sWord) { // checks if sWord is valid (different casing tested if the first letter is a capital) if (!sWord) { return null; } if (sWord.includes("’")) { // ugly hack |
︙ | ︙ | |||
123 124 125 126 127 128 129 | } return !!this.lookup(sWord.slice(0, 1).toLowerCase() + sWord.slice(1)); } else { return !!this.lookup(sWord.toLowerCase()); } } return false; | < > < > < > < > | | 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 | } return !!this.lookup(sWord.slice(0, 1).toLowerCase() + sWord.slice(1)); } else { return !!this.lookup(sWord.toLowerCase()); } } return false; } _convBytesToInteger (aBytes) { // Byte order = Big Endian (bigger first) let nVal = 0; let nWeight = (aBytes.length - 1) * 8; for (let n of aBytes) { nVal += n << nWeight; nWeight = nWeight - 8; } return nVal; } lookup (sWord) { // returns true if sWord in dictionary (strict verification) let iAddr = 0; for (let c of sWord) { if (!this.dChar.has(c)) { return false; } iAddr = this._lookupArcNode(this.dChar.get(c), iAddr); if (iAddr === null) { return false; } } return Boolean(this._convBytesToInteger(this.byDic.slice(iAddr, iAddr+this.nBytesArc)) & this._finalNodeMask); } getMorph (sWord) { // retrieves morphologies list, different casing allowed let l = this.morph(sWord); if (sWord[0].gl_isUpperCase()) { l = l.concat(this.morph(sWord.toLowerCase())); if (sWord.gl_isUpperCase() && sWord.length > 1) { l = l.concat(this.morph(sWord.gl_toCapitalize())); } } return l; } // morph (sWord) { // is defined in constructor // } // VERSION 1 _morph1 (sWord) { // returns morphologies of sWord let iAddr = 0; for (let c of sWord) { if (!this.dChar.has(c)) { |
︙ | ︙ | |||
205 206 207 208 209 210 211 | } } iAddr = iEndArcAddr + this.nBytesNodeAddress; } return l; } return []; | < > | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | } } iAddr = iEndArcAddr + this.nBytesNodeAddress; } return l; } return []; } _stem1 (sWord) { // returns stems list of sWord let iAddr = 0; for (let c of sWord) { if (!this.dChar.has(c)) { return []; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | l.push(this.funcStemming(sWord, this.lArcVal[nArc])); } iAddr = iEndArcAddr + this.nBytesNodeAddress; } return l; } return []; | < > < > < > < > < > < > < > < > | 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 | l.push(this.funcStemming(sWord, this.lArcVal[nArc])); } iAddr = iEndArcAddr + this.nBytesNodeAddress; } return l; } return []; } _lookupArcNode1 (nVal, iAddr) { // looks if nVal is an arc at the node at iAddr, if yes, returns address of next node else None while (true) { let iEndArcAddr = iAddr+this.nBytesArc; let nRawArc = this._convBytesToInteger(this.byDic.slice(iAddr, iEndArcAddr)); if (nVal == (nRawArc & this._arcMask)) { // the value we are looking for // we return the address of the next node return this._convBytesToInteger(this.byDic.slice(iEndArcAddr, iEndArcAddr+this.nBytesNodeAddress)); } else { // value not found if (nRawArc & this._lastArcMask) { return null; } iAddr = iEndArcAddr + this.nBytesNodeAddress; } } } // VERSION 2 _morph2 (sWord) { // to do } _stem2 (sWord) { // to do } _lookupArcNode2 (nVal, iAddr) { // to do } // VERSION 3 _morph3 (sWord) { // to do } _stem3 (sWord) { // to do } _lookupArcNode3 (nVal, iAddr) { // to do } } if (typeof(exports) !== 'undefined') { exports.IBDAWG = IBDAWG; } |
Modified gc_core/js/jsex_map.js from [985754ee9e] to [ca76af0666].
1 2 3 4 5 6 7 8 9 10 | // Map if (Map.prototype.grammalecte === undefined) { Map.prototype.gl_shallowCopy = function () { let oNewMap = new Map(); for (let [key, val] of this.entries()) { oNewMap.set(key, val); } return oNewMap; | | | | | | | | 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 | // Map if (Map.prototype.grammalecte === undefined) { Map.prototype.gl_shallowCopy = function () { let oNewMap = new Map(); for (let [key, val] of this.entries()) { oNewMap.set(key, val); } return oNewMap; }; Map.prototype.gl_get = function (key, defaultValue) { let res = this.get(key); if (res !== undefined) { return res; } return defaultValue; }; Map.prototype.gl_toString = function () { // Default .toString() gives nothing useful let sRes = "{ "; for (let [k, v] of this.entries()) { sRes += (typeof k === "string") ? '"' + k + '": ' : k.toString() + ": "; sRes += (typeof v === "string") ? '"' + v + '", ' : v.toString() + ", "; } sRes = sRes.slice(0, -2) + " }"; return sRes; }; Map.prototype.gl_update = function (dDict) { for (let [k, v] of dDict.entries()) { this.set(k, v); } }; Map.prototype.gl_updateOnlyExistingKeys = function (dDict) { for (let [k, v] of dDict.entries()) { if (this.has(k)){ this.set(k, v); } } }; Map.prototype.grammalecte = true; } |
Modified gc_core/js/jsex_regex.js from [b8b02d05dd] to [8feeee694f].
︙ | ︙ | |||
38 39 40 41 42 43 44 | m.end.push(m.index + codePos + m[i].length); } else if (codePos === "$") { // at the end of the pattern m.start.push(this.lastIndex - m[i].length); m.end.push(this.lastIndex); } else if (codePos === "w") { // word in the middle of the pattern | | | | | | 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 | m.end.push(m.index + codePos + m[i].length); } else if (codePos === "$") { // at the end of the pattern m.start.push(this.lastIndex - m[i].length); m.end.push(this.lastIndex); } else if (codePos === "w") { // word in the middle of the pattern iPos = m[0].search("[ ’,()«»“”]"+m[i]+"[ ,’()«»“”]") + 1 + m.index; m.start.push(iPos); m.end.push(iPos + m[i].length); } else if (codePos === "*") { // anywhere iPos = m[0].indexOf(m[i]) + m.index; m.start.push(iPos); m.end.push(iPos + m[i].length); } else if (codePos === "**") { // anywhere after previous group iPos = m[0].indexOf(m[i], m.end[i-1]-m.index) + m.index; m.start.push(iPos); m.end.push(iPos + m[i].length); } else if (codePos.startsWith(">")) { // >x:_ // todo: look in substring x iPos = m[0].indexOf(m[i]) + m.index; m.start.push(iPos); m.end.push(iPos + m[i].length); } else { |
︙ | ︙ | |||
79 80 81 82 83 84 85 | if (typeof(helpers) !== "undefined") { helpers.logerror(e); } else { console.error(e); } } return m; | | | 79 80 81 82 83 84 85 86 87 88 89 | if (typeof(helpers) !== "undefined") { helpers.logerror(e); } else { console.error(e); } } return m; }; RegExp.prototype.grammalecte = true; } |
Modified gc_core/js/jsex_string.js from [1e9c89a872] to [86533aa4da].
︙ | ︙ | |||
11 12 13 14 15 16 17 | let iPos = 0; let nStep = (bOverlapping) ? 1 : sSearch.length; while ((iPos = this.indexOf(sSearch, iPos)) >= 0) { nOccur++; iPos += nStep; } return nOccur; | | | | | | | | | | | | 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 | let iPos = 0; let nStep = (bOverlapping) ? 1 : sSearch.length; while ((iPos = this.indexOf(sSearch, iPos)) >= 0) { nOccur++; iPos += nStep; } return nOccur; }; String.prototype.gl_isDigit = function () { return (this.search(/^[0-9⁰¹²³⁴⁵⁶⁷⁸⁹]+$/) !== -1); }; String.prototype.gl_isLowerCase = function () { return (this.search(/^[a-zà-öø-ÿ0-9-]+$/) !== -1); }; String.prototype.gl_isUpperCase = function () { return (this.search(/^[A-ZÀ-ÖØ-ߌ0-9-]+$/) !== -1); }; String.prototype.gl_isTitle = function () { return (this.search(/^[A-ZÀ-ÖØ-ߌ][a-zà-öø-ÿ'’-]+$/) !== -1); }; String.prototype.gl_toCapitalize = function () { return this.slice(0,1).toUpperCase() + this.slice(1).toLowerCase(); }; String.prototype.gl_expand = function (oMatch) { let sNew = this; for (let i = 0; i < oMatch.length ; i++) { let z = new RegExp("\\\\"+parseInt(i), "g"); sNew = sNew.replace(z, oMatch[i]); } return sNew; }; String.prototype.gl_trimRight = function (sChars) { let z = new RegExp("["+sChars+"]+$"); return this.replace(z, ""); }; String.prototype.gl_trimLeft = function (sChars) { let z = new RegExp("^["+sChars+"]+"); return this.replace(z, ""); }; String.prototype.gl_trim = function (sChars) { let z1 = new RegExp("^["+sChars+"]+"); let z2 = new RegExp("["+sChars+"]+$"); return this.replace(z1, "").replace(z2, ""); }; String.prototype.grammalecte = true; } |
Modified gc_core/js/lang_core/gc_engine.js from [2f4877bef2] to [46602d3f85].
1 2 3 4 5 6 7 8 9 10 11 | // Grammar checker engine "use strict"; ${string} ${regex} ${map} if (typeof(require) !== 'undefined') { var helpers = require("resource://grammalecte/helpers.js"); | < > > > | > > > | 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 | // Grammar checker engine "use strict"; ${string} ${regex} ${map} if (typeof(require) !== 'undefined') { var helpers = require("resource://grammalecte/helpers.js"); var gc_options = require("resource://grammalecte/${lang}/gc_options.js"); var gc_rules = require("resource://grammalecte/${lang}/gc_rules.js"); var cregex = require("resource://grammalecte/${lang}/cregex.js"); var text = require("resource://grammalecte/text.js"); var echo = helpers.echo; } else if (typeof(console) !== "undefined") { var echo = function (o) { console.log(o); return true; }; } else { var echo = function () { return true; } } function capitalizeArray (aArray) { // can’t map on user defined function?? let aNew = []; for (let i = 0; i < aArray.length; i = i + 1) { aNew[i] = aArray[i].gl_toCapitalize(); } |
︙ | ︙ | |||
82 83 84 85 86 87 88 | sText = sText.replace(/‑/g, "-"); // nobreakdash } // parse sentence for (let [iStart, iEnd] of this._getSentenceBoundaries(sText)) { if (4 < (iEnd - iStart) < 2000) { dDA.clear(); | | | | 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 | sText = sText.replace(/‑/g, "-"); // nobreakdash } // parse sentence for (let [iStart, iEnd] of this._getSentenceBoundaries(sText)) { if (4 < (iEnd - iStart) < 2000) { dDA.clear(); //helpers.echo(sText.slice(iStart, iEnd)); try { [, errs] = this._proofread(sText.slice(iStart, iEnd), sAlt.slice(iStart, iEnd), iStart, false, dDA, dPriority, sCountry, bDebug, bContext); dErrors.gl_update(errs); } catch (e) { helpers.logerror(e); } } } return Array.from(dErrors.values()); }, _zEndOfSentence: new RegExp ('([.?!:;…][ .?!… »”")]*|.$)', "g"), _zBeginOfParagraph: new RegExp ("^[- –—.,;?!…]*", "ig"), _zEndOfParagraph: new RegExp ("[- .,;?!…–—]*$", "ig"), _getSentenceBoundaries: function* (sText) { let mBeginOfSentence = this._zBeginOfParagraph.exec(sText); let iStart = this._zBeginOfParagraph.lastIndex; let m; while ((m = this._zEndOfSentence.exec(sText)) !== null) { yield [iStart, this._zEndOfSentence.lastIndex]; iStart = this._zEndOfSentence.lastIndex; } }, |
︙ | ︙ | |||
124 125 126 127 128 129 130 | for (let [sOption, lRuleGroup] of this._getRules(bParagraph)) { if (!sOption || option(sOption)) { for (let [zRegex, bUppercase, sLineId, sRuleId, nPriority, lActions, lGroups, lNegLookBefore] of lRuleGroup) { if (!_aIgnoredRules.has(sRuleId)) { while ((m = zRegex.gl_exec2(s, lGroups, lNegLookBefore)) !== null) { bCondMemo = null; /*if (bDebug) { | | | | | | | | | | | | | 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 | for (let [sOption, lRuleGroup] of this._getRules(bParagraph)) { if (!sOption || option(sOption)) { for (let [zRegex, bUppercase, sLineId, sRuleId, nPriority, lActions, lGroups, lNegLookBefore] of lRuleGroup) { if (!_aIgnoredRules.has(sRuleId)) { while ((m = zRegex.gl_exec2(s, lGroups, lNegLookBefore)) !== null) { bCondMemo = null; /*if (bDebug) { helpers.echo(">>>> Rule # " + sLineId + " - Text: " + s + " opt: "+ sOption); }*/ for (let [sFuncCond, cActionType, sWhat, ...eAct] of lActions) { // action in lActions: [ condition, action type, replacement/suggestion/action[, iGroup[, message, URL]] ] try { //helpers.echo(oEvalFunc[sFuncCond]); bCondMemo = (!sFuncCond || oEvalFunc[sFuncCond](s, sx, m, dDA, sCountry, bCondMemo)); if (bCondMemo) { switch (cActionType) { case "-": // grammar error //helpers.echo("-> error detected in " + sLineId + "\nzRegex: " + zRegex.source); nErrorStart = nOffset + m.start[eAct[0]]; if (!dErrs.has(nErrorStart) || nPriority > dPriority.get(nErrorStart)) { dErrs.set(nErrorStart, this._createError(s, sx, sWhat, nOffset, m, eAct[0], sLineId, sRuleId, bUppercase, eAct[1], eAct[2], bIdRule, sOption, bContext)); dPriority.set(nErrorStart, nPriority); } break; case "~": // text processor //helpers.echo("-> text processor by " + sLineId + "\nzRegex: " + zRegex.source); s = this._rewrite(s, sWhat, eAct[0], m, bUppercase); bChange = true; if (bDebug) { helpers.echo("~ " + s + " -- " + m[eAct[0]] + " # " + sLineId); } break; case "=": // disambiguation //helpers.echo("-> disambiguation by " + sLineId + "\nzRegex: " + zRegex.source); oEvalFunc[sWhat](s, m, dDA); if (bDebug) { helpers.echo("= " + m[0] + " # " + sLineId + "\nDA: " + dDA.gl_toString()); } break; case ">": // we do nothing, this test is just a condition to apply all following actions break; default: helpers.echo("# error: unknown action at " + sLineId); } } else { if (cActionType == ">") { break; } } } catch (e) { helpers.echo(s); helpers.echo("# line id: " + sLineId + "\n# rule id: " + sRuleId); helpers.logerror(e); } } } } } } |
︙ | ︙ | |||
219 220 221 222 223 224 225 | } else { oErr["aSuggestions"] = sRepl.gl_expand(m).split("|"); } } // Message let sMessage = ""; if (sMsg.slice(0,1) === "=") { | | | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | } else { oErr["aSuggestions"] = sRepl.gl_expand(m).split("|"); } } // Message let sMessage = ""; if (sMsg.slice(0,1) === "=") { sMessage = oEvalFunc[sMsg.slice(1)](s, m); } else { sMessage = sMsg.gl_expand(m); } if (bIdRule) { sMessage += " ##" + sLineId + " #" + sRuleId; } oErr["sMessage"] = sMessage; |
︙ | ︙ | |||
258 259 260 261 262 263 264 | if (bUppercase && m[iGroup].slice(0,1).gl_isUpperCase()) { sNew = sNew.gl_toCapitalize(); } } else { sNew = sRepl.gl_expand(m); sNew = sNew + " ".repeat(ln-sNew.length); } | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | if (bUppercase && m[iGroup].slice(0,1).gl_isUpperCase()) { sNew = sNew.gl_toCapitalize(); } } else { sNew = sRepl.gl_expand(m); sNew = sNew + " ".repeat(ln-sNew.length); } //helpers.echo("\n"+s+"\nstart: "+m.start[iGroup]+" end:"+m.end[iGroup]) return s.slice(0, m.start[iGroup]) + sNew + s.slice(m.end[iGroup]); }, // Actions on rules ignoreRule: function (sRuleId) { _aIgnoredRules.add(sRuleId); |
︙ | ︙ | |||
351 352 353 354 355 356 357 | getDefaultOptions: function () { return gc_options.getOptions(_sAppContext).gl_shallowCopy(); }, resetOptions: function () { _dOptions = gc_options.getOptions(_sAppContext).gl_shallowCopy(); } | | | | | | | | | | | | | | | | 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 | getDefaultOptions: function () { return gc_options.getOptions(_sAppContext).gl_shallowCopy(); }, resetOptions: function () { _dOptions = gc_options.getOptions(_sAppContext).gl_shallowCopy(); } }; //////// Common functions function option (sOpt) { // return true if option sOpt is active return _dOptions.get(sOpt); } function displayInfo (dDA, aWord) { // for debugging: info of word if (!aWord) { helpers.echo("> nothing to find"); return true; } if (!_dAnalyses.has(aWord[1]) && !_storeMorphFromFSA(aWord[1])) { helpers.echo("> not in FSA"); return true; } if (dDA.has(aWord[0])) { helpers.echo("DA: " + dDA.get(aWord[0])); } helpers.echo("FSA: " + _dAnalyses.get(aWord[1])); return true; } function _storeMorphFromFSA (sWord) { // retrieves morphologies list from _oDict -> _dAnalyses //helpers.echo("register: "+sWord + " " + _oDict.getMorph(sWord).toString()) _dAnalyses.set(sWord, _oDict.getMorph(sWord)); return !!_dAnalyses.get(sWord); } function morph (dDA, aWord, sPattern, bStrict=true, bNoWord=false) { // analyse a tuple (position, word), return true if sPattern in morphologies (disambiguation on) if (!aWord) { //helpers.echo("morph: noword, returns " + bNoWord); return bNoWord; } //helpers.echo("aWord: "+aWord.toString()); if (!_dAnalyses.has(aWord[1]) && !_storeMorphFromFSA(aWord[1])) { return false; } let lMorph = dDA.has(aWord[0]) ? dDA.get(aWord[0]) : _dAnalyses.get(aWord[1]); //helpers.echo("lMorph: "+lMorph.toString()); if (lMorph.length === 0) { return false; } //helpers.echo("***"); if (bStrict) { return lMorph.every(s => (s.search(sPattern) !== -1)); } return lMorph.some(s => (s.search(sPattern) !== -1)); } function morphex (dDA, aWord, sPattern, sNegPattern, bNoWord=false) { // analyse a tuple (position, word), returns true if not sNegPattern in word morphologies and sPattern in word morphologies (disambiguation on) if (!aWord) { //helpers.echo("morph: noword, returns " + bNoWord); return bNoWord; } //helpers.echo("aWord: "+aWord.toString()); if (!_dAnalyses.has(aWord[1]) && !_storeMorphFromFSA(aWord[1])) { return false; } let lMorph = dDA.has(aWord[0]) ? dDA.get(aWord[0]) : _dAnalyses.get(aWord[1]); //helpers.echo("lMorph: "+lMorph.toString()); if (lMorph.length === 0) { return false; } //helpers.echo("***"); // check negative condition if (lMorph.some(s => (s.search(sNegPattern) !== -1))) { return false; } // search sPattern return lMorph.some(s => (s.search(sPattern) !== -1)); } |
︙ | ︙ | |||
463 464 465 466 467 468 469 | // returns a list of sWord's stems if (!sWord) { return []; } if (!_dAnalyses.has(sWord) && !_storeMorphFromFSA(sWord)) { return []; } | | | 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | // returns a list of sWord's stems if (!sWord) { return []; } if (!_dAnalyses.has(sWord) && !_storeMorphFromFSA(sWord)) { return []; } return _dAnalyses.get(sWord).map( s => s.slice(1, s.indexOf(" ")) ); } //// functions to get text outside pattern scope // warning: check compile_rules.py to understand how it works |
︙ | ︙ | |||
505 506 507 508 509 510 511 | return [iStart + _zNextWord.lastIndex - m[1].length, m[1]]; } const _zPrevWord = new RegExp ("([a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯfi-st_][a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯfi-st_-]*) +$", "i"); function prevword1 (s, iEnd) { // get previous word (optimization) | < < < < | 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | return [iStart + _zNextWord.lastIndex - m[1].length, m[1]]; } const _zPrevWord = new RegExp ("([a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯfi-st_][a-zà-öA-Zø-ÿÀ-Ö0-9Ø-ßĀ-ʯfi-st_-]*) +$", "i"); function prevword1 (s, iEnd) { // get previous word (optimization) let m = _zPrevWord.exec(s.slice(0, iEnd)); if (!m) { return null; } return [m.index, m[1]]; } function look (s, zPattern, zNegPattern=null) { // seek zPattern in s (before/after/fulltext), if antipattern zNegPattern not in s try { if (zNegPattern && zNegPattern.test(s)) { |
︙ | ︙ | |||
563 564 565 566 567 568 569 | } if (dDA.has(nPos)) { return true; } if (!_dAnalyses.has(sWord) && !_storeMorphFromFSA(sWord)) { return true; } | < | < | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | } if (dDA.has(nPos)) { return true; } if (!_dAnalyses.has(sWord) && !_storeMorphFromFSA(sWord)) { return true; } if (_dAnalyses.get(sWord).length === 1) { return true; } let lSelect = _dAnalyses.get(sWord).filter( sMorph => sMorph.search(sPattern) !== -1 ); if (lSelect.length > 0) { if (lSelect.length != _dAnalyses.get(sWord).length) { dDA.set(nPos, lSelect); } } else if (lDefault) { dDA.set(nPos, lDefaul); } |
︙ | ︙ | |||
592 593 594 595 596 597 598 | } if (!_dAnalyses.has(sWord) && !_storeMorphFromFSA(sWord)) { return true; } if (_dAnalyses.get(sWord).length === 1) { return true; } | | < | 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | } if (!_dAnalyses.has(sWord) && !_storeMorphFromFSA(sWord)) { return true; } if (_dAnalyses.get(sWord).length === 1) { return true; } let lSelect = _dAnalyses.get(sWord).filter( sMorph => sMorph.search(sPattern) === -1 ); if (lSelect.length > 0) { if (lSelect.length != _dAnalyses.get(sWord).length) { dDA.set(nPos, lSelect); } } else if (lDefault) { dDA.set(nPos, lDefault); } |
︙ | ︙ |
Modified gc_core/js/str_transform.js from [9b41fc7a14] to [3f33d76266].
︙ | ︙ | |||
19 20 21 22 23 24 25 | if (!sAffCode.includes("/")) { return "# error #"; } let [sPfxCode, sSfxCode] = sAffCode.split('/'); sFlex = sPfxCode.slice(1) + sFlex.slice(sPfxCode.charCodeAt(0)-48); return sSfxCode[0] == '0' ? sFlex + sSfxCode.slice(1) : sFlex.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1); } | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | if (!sAffCode.includes("/")) { return "# error #"; } let [sPfxCode, sSfxCode] = sAffCode.split('/'); sFlex = sPfxCode.slice(1) + sFlex.slice(sPfxCode.charCodeAt(0)-48); return sSfxCode[0] == '0' ? sFlex + sSfxCode.slice(1) : sFlex.slice(0, -(sSfxCode.charCodeAt(0)-48)) + sSfxCode.slice(1); } }; if (typeof(exports) !== 'undefined') { exports.getStemFromSuffixCode = str_transform.getStemFromSuffixCode; exports.getStemFromAffixCode = str_transform.getStemFromAffixCode; } |
Modified gc_core/js/tests.js from [4a9fbec06f] to [abe05a3485].
︙ | ︙ | |||
8 9 10 11 12 13 14 | } class TestGrammarChecking { constructor (gce, spfTests="") { this.gce = gce; | | < > | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | } class TestGrammarChecking { constructor (gce, spfTests="") { this.gce = gce; this.spfTests = spfTests; this._aRuleTested = new Set(); } * testParse (bDebug=false) { const t0 = Date.now(); let sURL = (this.spfTests !== "") ? this.spfTests : "resource://grammalecte/"+this.gce.lang+"/tests_data.json"; const aData = JSON.parse(helpers.loadFile(sURL)).aData; let nInvalid = 0; let nTotal = 0; let sErrorText; let sSugg; let sExpectedErrors; let sTextToCheck; let sFoundErrors; let sListErr; let sLineNum; |
︙ | ︙ | |||
60 61 62 63 64 65 66 | if (sExpectedErrors !== sFoundErrors) { yield "\n" + i.toString() + "\n# Line num: " + sLineNum + "\n> to check: " + sTextToCheck + "\n expected: " + sExpectedErrors + "\n found: " + sFoundErrors + "\n errors: \n" + sListErr; | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | if (sExpectedErrors !== sFoundErrors) { yield "\n" + i.toString() + "\n# Line num: " + sLineNum + "\n> to check: " + sTextToCheck + "\n expected: " + sExpectedErrors + "\n found: " + sFoundErrors + "\n errors: \n" + sListErr; nInvalid = nInvalid + 1; } nTotal = nTotal + 1; } i = i + 1; if (i % 1000 === 0) { yield i.toString(); } |
︙ | ︙ | |||
91 92 93 94 95 96 97 | yield sUntestedRules + "\n[" + i.toString() + " untested rules]"; } } const t1 = Date.now(); yield "Tests parse finished in " + ((t1-t0)/1000).toString() + " s\nTotal errors: " + nInvalid.toString() + " / " + nTotal.toString(); | < > | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | yield sUntestedRules + "\n[" + i.toString() + " untested rules]"; } } const t1 = Date.now(); yield "Tests parse finished in " + ((t1-t0)/1000).toString() + " s\nTotal errors: " + nInvalid.toString() + " / " + nTotal.toString(); } _getExpectedErrors (sLine) { try { let sRes = " ".repeat(sLine.length); let z = /\{\{.+?\}\}/g; let m; let i = 0; |
︙ | ︙ | |||
117 118 119 120 121 122 123 | } return sRes; } catch (e) { helpers.logerror(e); } return " ".repeat(sLine.length); | < > | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | } return sRes; } catch (e) { helpers.logerror(e); } return " ".repeat(sLine.length); } _getFoundErrors (sLine, bDebug, sOption) { try { let aErrs = []; if (sOption) { this.gce.setOption(sOption, true); aErrs = this.gce.parse(sLine, "FR", bDebug); |
︙ | ︙ | |||
142 143 144 145 146 147 148 | } return [sRes, sListErr]; } catch (e) { helpers.logerror(e); } return [" ".repeat(sLine.length), ""]; | < > | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | } return [sRes, sListErr]; } catch (e) { helpers.logerror(e); } return [" ".repeat(sLine.length), ""]; } } if (typeof(exports) !== 'undefined') { exports.TestGrammarChecking = TestGrammarChecking; } |
Modified gc_core/js/text.js from [03f872e8ba] to [46a1749c2b].
︙ | ︙ | |||
55 56 57 58 59 60 61 | return sResult; } catch (e) { helpers.logerror(e); return "\n# Error. Data: " + oErr.toString(); } } | | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | return sResult; } catch (e) { helpers.logerror(e); return "\n# Error. Data: " + oErr.toString(); } } }; if (typeof(exports) !== 'undefined') { exports.getParagraph = text.getParagraph; exports.wrap = text.wrap; exports.getReadableError = text.getReadableError; } |
Modified gc_core/js/tokenizer.js from [02266194ef] to [fcd058bf6a].
︙ | ︙ | |||
35 36 37 38 39 40 41 | [/^&\w+;(?:\w+;|)/, 'HTMLENTITY'], [/^(?:l|d|n|m|t|s|j|c|ç|lorsqu|puisqu|jusqu|quoiqu|qu)['’`]/i, 'ELPFX'], [/^\d\d?[hm]\d\d\b/, 'HOUR'], [/^\d+(?:er|nd|e|de|ième|ème|eme)s?\b/, 'ORDINAL'], [/^-?\d+(?:[.,]\d+|)/, 'NUM'], [/^[a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st]+(?:[’'`-][a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st]+)*/, 'WORD'] ] | | < > | 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 | [/^&\w+;(?:\w+;|)/, 'HTMLENTITY'], [/^(?:l|d|n|m|t|s|j|c|ç|lorsqu|puisqu|jusqu|quoiqu|qu)['’`]/i, 'ELPFX'], [/^\d\d?[hm]\d\d\b/, 'HOUR'], [/^\d+(?:er|nd|e|de|ième|ème|eme)s?\b/, 'ORDINAL'], [/^-?\d+(?:[.,]\d+|)/, 'NUM'], [/^[a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st]+(?:[’'`-][a-zA-Zà-öÀ-Ö0-9ø-ÿØ-ßĀ-ʯfi-st]+)*/, 'WORD'] ] }; class Tokenizer { constructor (sLang) { this.sLang = sLang; if (!aTkzPatterns.hasOwnProperty(sLang)) { this.sLang = "default"; } this.aRules = aTkzPatterns[this.sLang]; } * genTokens (sText) { let m; let i = 0; while (sText) { let nCut = 1; for (let [zRegex, sType] of this.aRules) { |
︙ | ︙ | |||
74 75 76 77 78 79 80 | catch (e) { helpers.logerror(e); } } i += nCut; sText = sText.slice(nCut); } | < > | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | catch (e) { helpers.logerror(e); } } i += nCut; sText = sText.slice(nCut); } } getSpellingErrors (sText, oDict) { let aSpellErr = []; for (let oToken of this.genTokens(sText)) { if (oToken.sType === 'WORD' && !oDict.isValidToken(oToken.sValue)) { aSpellErr.push(oToken); } |
︙ | ︙ |
Modified gc_lang/fr/modules-js/conj.js from [526a57d214] to [ab8249cda2].
︙ | ︙ | |||
95 96 97 98 99 100 101 | aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); } else if (sMorph.includes(":V3")) { aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":1s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":3s")); | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); } else if (sMorph.includes(":V3")) { aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":1s")); aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":3s")); } else if (sMorph.includes(":V0a")) { aSugg.add("eus"); aSugg.add("eut"); } else { aSugg.add("étais"); aSugg.add("était"); } aSugg.delete(""); |
︙ | ︙ | |||
166 167 168 169 170 171 172 | } } catch (e) { console.log(e); return "## erreur, code : " + sSfx + " ##"; } } | | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | } } catch (e) { console.log(e); return "## erreur, code : " + sSfx + " ##"; } } }; class Verb { constructor (sVerb) { if (typeof sVerb !== "string" || sVerb === "") { throw new TypeError ("The value should be a non-empty string"); |
︙ | ︙ | |||
268 269 270 271 272 273 274 | [":E", new Map ([ ["label", "Impératif"], [":2s", conj._getConjWithTags(sVerb, this._tTags, ":E", ":2s")], [":1p", conj._getConjWithTags(sVerb, this._tTags, ":E", ":1p")], [":2p", conj._getConjWithTags(sVerb, this._tTags, ":E", ":2p")] ])] ]); | < > | 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | [":E", new Map ([ ["label", "Impératif"], [":2s", conj._getConjWithTags(sVerb, this._tTags, ":E", ":2s")], [":1p", conj._getConjWithTags(sVerb, this._tTags, ":E", ":1p")], [":2p", conj._getConjWithTags(sVerb, this._tTags, ":E", ":2p")] ])] ]); } _readableInfo () { // returns readable infos this.sVerbAux = (this._sRawInfo.slice(7,8) == "e") ? "être" : "avoir"; let sGroup = conj._dGroup.get(this._sRawInfo[0]); let sInfo = ""; if (this._sRawInfo.slice(3,4) == "t") { |
︙ | ︙ | |||
296 297 298 299 300 301 302 | if (this._sRawInfo.slice(6,7) == "m") { sInfo = sInfo + " impersonnel"; } if (sInfo === "") { sInfo = "# erreur - code : " + this._sRawInfo; } return sGroup + " · " + sInfo; | < > | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | if (this._sRawInfo.slice(6,7) == "m") { sInfo = sInfo + " impersonnel"; } if (sInfo === "") { sInfo = "# erreur - code : " + this._sRawInfo; } return sGroup + " · " + sInfo; } infinitif (bPro, bNeg, bTpsCo, bInt, bFem) { let sInfi; if (bTpsCo) { sInfi = (bPro) ? "être" : this.sVerbAux; } else { sInfi = this.sVerb; |
︙ | ︙ | |||
322 323 324 325 326 327 328 | if (bTpsCo) { sInfi += " " + this._seekPpas(bPro, bFem, (this._sRawInfo[5] == "r")); } if (bInt) { sInfi += " … ?"; } return sInfi; | < > < > | | 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 | if (bTpsCo) { sInfi += " " + this._seekPpas(bPro, bFem, (this._sRawInfo[5] == "r")); } if (bInt) { sInfi += " … ?"; } return sInfi; } participePasse (sWho) { return this.dConj.get(":PQ").get(sWho); } participePresent (bPro, bNeg, bTpsCo, bInt, bFem) { if (!this.dConj.get(":PQ").get(":P")) { return ""; } let sPartPre; if (bTpsCo) { sPartPre = (!bPro) ? conj._getConjWithTags(this.sVerbAux, this._tTagsAux, ":PQ", ":P") : conj.getConj("être", ":PQ", ":P"); } else { sPartPre = this.dConj.get(":PQ").get(":P"); } if (sPartPre === "") { return ""; } let bEli = conj._zStartVoy.test(sPartPre); |
︙ | ︙ | |||
359 360 361 362 363 364 365 | if (bTpsCo) { sPartPre += " " + this._seekPpas(bPro, bFem, this._sRawInfo[5] == "r"); } if (bInt) { sPartPre += " … ?"; } return sPartPre; | < > | | 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 | if (bTpsCo) { sPartPre += " " + this._seekPpas(bPro, bFem, this._sRawInfo[5] == "r"); } if (bInt) { sPartPre += " … ?"; } return sPartPre; } conjugue (sTemps, sWho, bPro, bNeg, bTpsCo, bInt, bFem) { if (!this.dConj.get(sTemps).get(sWho)) { return ""; } let sConj; if (!bTpsCo && bInt && sWho == ":1s" && this.dConj.get(sTemps).gl_get(":1ś", false)) { sWho = ":1ś"; } if (bTpsCo) { sConj = (!bPro) ? conj._getConjWithTags(this.sVerbAux, this._tTagsAux, sTemps, sWho) : conj.getConj("être", sTemps, sWho); } else { sConj = this.dConj.get(sTemps).get(sWho); } if (sConj === "") { return ""; } let bEli = conj._zStartVoy.test(sConj); |
︙ | ︙ | |||
410 411 412 413 414 415 416 | if (bTpsCo) { sConj += " " + this._seekPpas(bPro, bFem, sWho.endsWith("p") || this._sRawInfo[5] == "r"); } if (bInt) { sConj += " … ?"; } return sConj; | < > < > | | 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 | if (bTpsCo) { sConj += " " + this._seekPpas(bPro, bFem, sWho.endsWith("p") || this._sRawInfo[5] == "r"); } if (bInt) { sConj += " … ?"; } return sConj; } _getPronom (sWho, bFem) { if (sWho == ":3s") { if (this._sRawInfo[5] == "r") { return "on"; } else if (bFem) { return "elle"; } } else if (sWho == ":3p" && bFem) { return "elles"; } return conj._dProSuj.get(sWho); } imperatif (sWho, bPro, bNeg, bTpsCo, bFem) { if (!this.dConj.get(":E").get(sWho)) { return ""; } let sImpe; if (bTpsCo) { sImpe = (!bPro) ? conj._getConjWithTags(this.sVerbAux, this._tTagsAux, ":E", sWho) : conj.getConj("être", ":E", sWho); } else { sImpe = this.dConj.get(":E").get(sWho); } if (sImpe === "") { return ""; } let bEli = conj._zStartVoy.test(sImpe); |
︙ | ︙ | |||
456 457 458 459 460 461 462 | } else if (bPro) { sImpe = (this.bProWithEn) ? sImpe + conj._dImpeProEn.get(sWho) : sImpe + conj._dImpePro.get(sWho); } if (bTpsCo) { return sImpe + " " + this._seekPpas(bPro, bFem, sWho.endsWith("p") || this._sRawInfo[5] == "r"); } return sImpe; | < > | 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | } else if (bPro) { sImpe = (this.bProWithEn) ? sImpe + conj._dImpeProEn.get(sWho) : sImpe + conj._dImpePro.get(sWho); } if (bTpsCo) { return sImpe + " " + this._seekPpas(bPro, bFem, sWho.endsWith("p") || this._sRawInfo[5] == "r"); } return sImpe; } _seekPpas (bPro, bFem, bPlur) { if (!bPro && this.sVerbAux == "avoir") { return this.dConj.get(":PQ").get(":Q1"); } if (!bFem) { return (bPlur && this.dConj.get(":PQ").get(":Q2")) ? this.dConj.get(":PQ").get(":Q2") : this.dConj.get(":PQ").get(":Q1"); |
︙ | ︙ |
Modified gc_lang/fr/modules-js/cregex.js from [6a54cddafc] to [7faa9e5e5e].
︙ | ︙ | |||
259 260 261 262 263 264 265 | mbNprMasNotFem: function (lMorph) { if (lMorph.some(s => this._zNPf.test(s))) { return false; } return lMorph.some(s => this._zNPm.test(s)); } | | | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | mbNprMasNotFem: function (lMorph) { if (lMorph.some(s => this._zNPf.test(s))) { return false; } return lMorph.some(s => this._zNPm.test(s)); } }; if (typeof(exports) !== 'undefined') { exports._zLemma = cregex._zLemma; exports._zGender = cregex._zGender; exports._zNumber = cregex._zNumber; exports._zNA = cregex._zNA; |
︙ | ︙ |
Modified gc_lang/fr/modules-js/gce_analyseur.js from [973aa5af1d] to [0ad6fe5843].
︙ | ︙ | |||
71 72 73 74 75 76 77 | } return true; } function isVeryAmbiguousAndWrong (sWord1, sWord2, sReqMorphNA, sReqMorphConj, bLastHopeCond) { //// use it if sWord1 can be also a verb; word2 is assumed to be true via isAmbiguousNAV // We don’t check if word exists in _dAnalyses, for it is assumed it has been done before | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | } return true; } function isVeryAmbiguousAndWrong (sWord1, sWord2, sReqMorphNA, sReqMorphConj, bLastHopeCond) { //// use it if sWord1 can be also a verb; word2 is assumed to be true via isAmbiguousNAV // We don’t check if word exists in _dAnalyses, for it is assumed it has been done before let a2 = _dAnalyses.gl_get(sWord2, null); if (!a2 || a2.length === 0) { return false; } if (cregex.checkConjVerb(a2, sReqMorphConj)) { // verb word2 is ok return false; } |
︙ | ︙ | |||
99 100 101 102 103 104 105 | return true; } return false; } function checkAgreement (sWord1, sWord2) { // We don’t check if word exists in _dAnalyses, for it is assumed it has been done before | | | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | return true; } return false; } function checkAgreement (sWord1, sWord2) { // We don’t check if word exists in _dAnalyses, for it is assumed it has been done before let a2 = _dAnalyses.gl_get(sWord2, null); if (!a2 || a2.length === 0) { return true; } let a1 = _dAnalyses.gl_get(sWord1, null); if (!a1 || a1.length === 0) { return true; } |
︙ | ︙ |
Modified gc_lang/fr/modules-js/gce_suggestions.js from [5dc3101886] to [db0ba9f8a1].
︙ | ︙ | |||
139 140 141 142 143 144 145 | if (aSugg.size > 0) { return Array.from(aSugg).join("|"); } return ""; } function suggVerbInfi (sFlex) { | | < | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | if (aSugg.size > 0) { return Array.from(aSugg).join("|"); } return ""; } function suggVerbInfi (sFlex) { return stem(sFlex).filter(sStem => conj.isVerb(sStem)).join("|"); } const _dQuiEst = new Map ([ ["je", ":1s"], ["j’", ":1s"], ["j’en", ":1s"], ["j’y", ":1s"], ["tu", ":2s"], ["il", ":3s"], ["on", ":3s"], ["elle", ":3s"], ["nous", ":1p"], ["vous", ":2p"], ["ils", ":3p"], ["elles", ":3p"] |
︙ | ︙ |
Modified gc_lang/fr/modules-js/lexicographe.js from [cfbfcc7fa9] to [a348883011].
︙ | ︙ | |||
195 196 197 198 199 200 201 | class Lexicographe { constructor (oDict) { this.oDict = oDict; this._zElidedPrefix = new RegExp ("^([dljmtsncç]|quoiqu|lorsqu|jusqu|puisqu|qu)['’](.+)", "i"); this._zCompoundWord = new RegExp ("([a-zA-Zà-ö0-9À-Öø-ÿØ-ßĀ-ʯ]+)-((?:les?|la)-(?:moi|toi|lui|[nv]ous|leur)|t-(?:il|elle|on)|y|en|[mts][’'](?:y|en)|les?|l[aà]|[mt]oi|leur|lui|je|tu|ils?|elles?|on|[nv]ous)$", "i"); this._zTag = new RegExp ("[:;/][a-zA-Zà-ö0-9À-Öø-ÿØ-ßĀ-ʯ*][^:;/]*", "g"); | < > | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | class Lexicographe { constructor (oDict) { this.oDict = oDict; this._zElidedPrefix = new RegExp ("^([dljmtsncç]|quoiqu|lorsqu|jusqu|puisqu|qu)['’](.+)", "i"); this._zCompoundWord = new RegExp ("([a-zA-Zà-ö0-9À-Öø-ÿØ-ßĀ-ʯ]+)-((?:les?|la)-(?:moi|toi|lui|[nv]ous|leur)|t-(?:il|elle|on)|y|en|[mts][’'](?:y|en)|les?|l[aà]|[mt]oi|leur|lui|je|tu|ils?|elles?|on|[nv]ous)$", "i"); this._zTag = new RegExp ("[:;/][a-zA-Zà-ö0-9À-Öø-ÿØ-ßĀ-ʯ*][^:;/]*", "g"); } getInfoForToken (oToken) { // Token: .sType, .sValue, .nStart, .nEnd // return a list [type, token_string, values] let m = null; try { switch (oToken.sType) { |
︙ | ︙ | |||
222 223 224 225 226 227 228 | break; case 'WORD': if (oToken.sValue.gl_count("-") > 4) { return { sType: "COMPLEX", sValue: oToken.sValue, aLabel: ["élément complexe indéterminé"] }; } else if (this.oDict.isValidToken(oToken.sValue)) { let lMorph = this.oDict.getMorph(oToken.sValue); | | > > > | > > > < > < > < > | 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 | break; case 'WORD': if (oToken.sValue.gl_count("-") > 4) { return { sType: "COMPLEX", sValue: oToken.sValue, aLabel: ["élément complexe indéterminé"] }; } else if (this.oDict.isValidToken(oToken.sValue)) { let lMorph = this.oDict.getMorph(oToken.sValue); let aElem = []; for (let s of lMorph){ if (s.includes(":")) aElem.push( this._formatTags(s) ); } return { sType: oToken.sType, sValue: oToken.sValue, aLabel: aElem}; } else if (m = this._zCompoundWord.exec(oToken.sValue)) { // mots composés let lMorph = this.oDict.getMorph(m[1]); let aElem = []; for (let s of lMorph){ if (s.includes(":")) aElem.push( this._formatTags(s) ); } aElem.push("-" + m[2] + ": " + this._formatSuffix(m[2].toLowerCase())); return { sType: oToken.sType, sValue: oToken.sValue, aLabel: aElem }; } else { return { sType: "UNKNOWN", sValue: oToken.sValue, aLabel: ["inconnu du dictionnaire"] }; } break; } } catch (e) { helpers.logerror(e); } return null; } _formatTags (sTags) { let sRes = ""; sTags = sTags.replace(/V([0-3][ea]?)[itpqnmr_eaxz]+/, "V$1"); let m; while ((m = this._zTag.exec(sTags)) !== null) { sRes += _dTAGS.get(m[0]); if (sRes.length > 100) { break; } } if (sRes.startsWith(" verbe") && !sRes.endsWith("infinitif")) { sRes += " [" + sTags.slice(1, sTags.indexOf(" ")) + "]"; } if (!sRes) { sRes = "#Erreur. Étiquette inconnue : [" + sTags + "]"; helpers.echo(sRes); return sRes; } return sRes.gl_trimRight(","); } _formatSuffix (s) { if (s.startsWith("t-")) { return "“t” euphonique +" + _dAD.get(s.slice(2)); } if (!s.includes("-")) { return _dAD.get(s.replace("’", "'")); } if (s.endsWith("ous")) { s += '2'; } let nPos = s.indexOf("-"); return _dAD.get(s.slice(0, nPos)) + " +" + _dAD.get(s.slice(nPos+1)); } } if (typeof(exports) !== 'undefined') { exports.Lexicographe = Lexicographe; } |
Modified gc_lang/fr/modules-js/mfsp.js from [efd19b51da] to [5ce8b4f9f6].
︙ | ︙ | |||
34 35 36 37 38 39 40 | // returns True if sWord exists in this._dMasForm return this._dMasForm.has(sWord); }, getMasForm: function (sWord, bPlur) { // returns masculine form with feminine form if (this._dMasForm.has(sWord)) { | > > | > > > | > > > | 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 | // returns True if sWord exists in this._dMasForm return this._dMasForm.has(sWord); }, getMasForm: function (sWord, bPlur) { // returns masculine form with feminine form if (this._dMasForm.has(sWord)) { let aMasForm = []; for (let sTag of this._whatSuffixCode(sWord, bPlur)){ aMasForm.push( this._modifyStringWithSuffixCode(sWord, sTag) ); } return aMasForm; } return []; }, hasMiscPlural: function (sWord) { // returns True if sWord exists in dMiscPlur return this._dMiscPlur.has(sWord); }, getMiscPlural: function (sWord) { // returns plural form with singular form if (this._dMiscPlur.has(sWord)) { let aMiscPlural = []; for (let sTag of this._lTagMiscPlur[this._dMiscPlur.get(sWord)].split("|")){ aMiscPlural.push( this._modifyStringWithSuffixCode(sWord, sTag) ); } return aMiscPlural; } return []; }, _whatSuffixCode: function (sWord, bPlur) { // necessary only for dMasFW let sSfx = this._lTagMasForm[this._dMasForm.get(sWord)]; |
︙ | ︙ | |||
84 85 86 87 88 89 90 | } } catch (e) { console.log(e); return "## erreur, code : " + sSfx + " ##"; } } | | | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | } } catch (e) { console.log(e); return "## erreur, code : " + sSfx + " ##"; } } }; // Initialization if (typeof(browser) !== 'undefined') { // WebExtension mfsp.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/mfsp_data.json"))); } else if (typeof(require) !== 'undefined') { |
︙ | ︙ |
Modified gc_lang/fr/modules-js/phonet.js from [8f4c2c4be2] to [742b1a34db].
︙ | ︙ | |||
73 74 75 76 77 78 79 | if (sMorph.search(sPattern) >= 0) { aSelect.add(sSimil); } } } return aSelect; } | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | if (sMorph.search(sPattern) >= 0) { aSelect.add(sSimil); } } } return aSelect; } }; // Initialization if (typeof(browser) !== 'undefined') { // WebExtension phonet.init(helpers.loadFile(browser.extension.getURL("grammalecte/fr/phonet_data.json"))); } else if (typeof(require) !== 'undefined') { |
︙ | ︙ |
Modified gc_lang/fr/modules-js/textformatter.js from [6dfa91f96e] to [c6e77daf98].
︙ | ︙ | |||
254 255 256 257 258 259 260 | const dTFOptions = dTFDefaultOptions.gl_shallowCopy(); class TextFormatter { constructor () { this.sLang = "fr"; | < > < > | 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 | const dTFOptions = dTFDefaultOptions.gl_shallowCopy(); class TextFormatter { constructor () { this.sLang = "fr"; } formatText (sText, dOpt=null) { if (dOpt !== null) { dTFOptions.gl_updateOnlyExistingKeys(dOpt); } for (let [sOptName, bVal] of dTFOptions) { if (bVal && oReplTable.has(sOptName)) { for (let [zRgx, sRep] of oReplTable[sOptName]) { sText = sText.replace(zRgx, sRep); } } } return sText; } getDefaultOptions () { return dTFDefaultOptions; } } |
︙ | ︙ |