Grammalecte  Check-in [471f63e7ad]

Overview
Comment:[core][js] gc engine: code clarification, stop using prefix d for object variables
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: 471f63e7ad7355bae39490bdc6e214dc282518913eed464514797d758e4e6bfd
User & Date: olr on 2019-07-01 12:02:12
Other Links: manifest | tags
Context
2019-07-01
12:05
[core][js] gc engine: code clarification, stop using prefix d for object variables check-in: 3860f0b62f user: olr tags: core, trunk
12:02
[core][js] gc engine: code clarification, stop using prefix d for object variables check-in: 471f63e7ad user: olr tags: core, trunk
11:19
[fr] conj: fix set update check-in: f1e0071b0c user: olr tags: fr, trunk
Changes

Modified gc_core/js/lang_core/gc_engine.js from [418e2031a5] to [53ea8f6dbf].

   393    393           }
   394    394           if (bDebug) {
   395    395               console.log("UPDATE:");
   396    396               console.log(this.asString());
   397    397           }
   398    398       }
   399    399   
   400         -    * _getNextPointers (dToken, dGraph, dPointer, bDebug=false) {
   401         -        // generator: return nodes where <dToken> “values” match <dNode> arcs
          400  +    * _getNextPointers (dToken, oGraph, oPointer, bDebug=false) {
          401  +        // generator: return nodes where <dToken> “values” match <oNode> arcs
   402    402           try {
   403         -            let dNode = dGraph[dPointer["iNode"]];
   404         -            let iToken1 = dPointer["iToken1"];
          403  +            let oNode = oGraph[oPointer["iNode"]];
          404  +            let iToken1 = oPointer["iToken1"];
   405    405               let bTokenFound = false;
   406    406               // token value
   407         -            if (dNode.hasOwnProperty(dToken["sValue"])) {
          407  +            if (oNode.hasOwnProperty(dToken["sValue"])) {
   408    408                   if (bDebug) {
   409    409                       console.log("  MATCH: " + dToken["sValue"]);
   410    410                   }
   411         -                yield { "iToken1": iToken1, "iNode": dNode[dToken["sValue"]] };
          411  +                yield { "iToken1": iToken1, "iNode": oNode[dToken["sValue"]] };
   412    412                   bTokenFound = true;
   413    413               }
   414    414               if (dToken["sValue"].slice(0,2).gl_isTitle()) { // we test only 2 first chars, to make valid words such as "Laissez-les", "Passe-partout".
   415    415                   let sValue = dToken["sValue"].toLowerCase();
   416         -                if (dNode.hasOwnProperty(sValue)) {
          416  +                if (oNode.hasOwnProperty(sValue)) {
   417    417                       if (bDebug) {
   418    418                           console.log("  MATCH: " + sValue);
   419    419                       }
   420         -                    yield { "iToken1": iToken1, "iNode": dNode[sValue] };
          420  +                    yield { "iToken1": iToken1, "iNode": oNode[sValue] };
   421    421                       bTokenFound = true;
   422    422                   }
   423    423               }
   424    424               else if (dToken["sValue"].gl_isUpperCase()) {
   425    425                   let sValue = dToken["sValue"].toLowerCase();
   426         -                if (dNode.hasOwnProperty(sValue)) {
          426  +                if (oNode.hasOwnProperty(sValue)) {
   427    427                       if (bDebug) {
   428    428                           console.log("  MATCH: " + sValue);
   429    429                       }
   430         -                    yield { "iToken1": iToken1, "iNode": dNode[sValue] };
          430  +                    yield { "iToken1": iToken1, "iNode": oNode[sValue] };
   431    431                       bTokenFound = true;
   432    432                   }
   433    433                   sValue = dToken["sValue"].gl_toCapitalize();
   434         -                if (dNode.hasOwnProperty(sValue)) {
          434  +                if (oNode.hasOwnProperty(sValue)) {
   435    435                       if (bDebug) {
   436    436                           console.log("  MATCH: " + sValue);
   437    437                       }
   438         -                    yield { "iToken1": iToken1, "iNode": dNode[sValue] };
          438  +                    yield { "iToken1": iToken1, "iNode": oNode[sValue] };
   439    439                       bTokenFound = true;
   440    440                   }
   441    441               }
   442    442               // regex value arcs
   443    443               if (dToken["sType"] != "INFO"  &&  dToken["sType"] != "PUNC"  &&  dToken["sType"] != "SIGN") {
   444         -                if (dNode.hasOwnProperty("<re_value>")) {
   445         -                    for (let sRegex in dNode["<re_value>"]) {
          444  +                if (oNode.hasOwnProperty("<re_value>")) {
          445  +                    for (let sRegex in oNode["<re_value>"]) {
   446    446                           if (!sRegex.includes("¬")) {
   447    447                               // no anti-pattern
   448    448                               if (dToken["sValue"].search(sRegex) !== -1) {
   449    449                                   if (bDebug) {
   450    450                                       console.log("  MATCH: ~" + sRegex);
   451    451                                   }
   452         -                                yield { "iToken1": iToken1, "iNode": dNode["<re_value>"][sRegex] };
          452  +                                yield { "iToken1": iToken1, "iNode": oNode["<re_value>"][sRegex] };
   453    453                                   bTokenFound = true;
   454    454                               }
   455    455                           } else {
   456    456                               // there is an anti-pattern
   457    457                               let [sPattern, sNegPattern] = sRegex.split("¬", 2);
   458    458                               if (sNegPattern && dToken["sValue"].search(sNegPattern) !== -1) {
   459    459                                   continue;
   460    460                               }
   461    461                               if (!sPattern || dToken["sValue"].search(sPattern) !== -1) {
   462    462                                   if (bDebug) {
   463    463                                       console.log("  MATCH: ~" + sRegex);
   464    464                                   }
   465         -                                yield { "iToken1": iToken1, "iNode": dNode["<re_value>"][sRegex] };
          465  +                                yield { "iToken1": iToken1, "iNode": oNode["<re_value>"][sRegex] };
   466    466                                   bTokenFound = true;
   467    467                               }
   468    468                           }
   469    469                       }
   470    470                   }
   471    471               }
   472    472               // analysable tokens
   473    473               if (dToken["sType"].slice(0,4) == "WORD") {
   474    474                   // token lemmas
   475         -                if (dNode.hasOwnProperty("<lemmas>")) {
          475  +                if (oNode.hasOwnProperty("<lemmas>")) {
   476    476                       for (let sLemma of _oSpellChecker.getLemma(dToken["sValue"])) {
   477         -                        if (dNode["<lemmas>"].hasOwnProperty(sLemma)) {
          477  +                        if (oNode["<lemmas>"].hasOwnProperty(sLemma)) {
   478    478                               if (bDebug) {
   479    479                                   console.log("  MATCH: >" + sLemma);
   480    480                               }
   481         -                            yield { "iToken1": iToken1, "iNode": dNode["<lemmas>"][sLemma] };
          481  +                            yield { "iToken1": iToken1, "iNode": oNode["<lemmas>"][sLemma] };
   482    482                               bTokenFound = true;
   483    483                           }
   484    484                       }
   485    485                   }
   486    486                   // regex morph arcs
   487         -                if (dNode.hasOwnProperty("<re_morph>")) {
          487  +                if (oNode.hasOwnProperty("<re_morph>")) {
   488    488                       let lMorph = (dToken.hasOwnProperty("lMorph")) ? dToken["lMorph"] : _oSpellChecker.getMorph(dToken["sValue"]);
   489    489                       if (lMorph.length > 0) {
   490         -                        for (let sRegex in dNode["<re_morph>"]) {
          490  +                        for (let sRegex in oNode["<re_morph>"]) {
   491    491                               if (!sRegex.includes("¬")) {
   492    492                                   // no anti-pattern
   493    493                                   if (lMorph.some(sMorph  =>  (sMorph.search(sRegex) !== -1))) {
   494    494                                       if (bDebug) {
   495    495                                           console.log("  MATCH: @" + sRegex);
   496    496                                       }
   497         -                                    yield { "iToken1": iToken1, "iNode": dNode["<re_morph>"][sRegex] };
          497  +                                    yield { "iToken1": iToken1, "iNode": oNode["<re_morph>"][sRegex] };
   498    498                                       bTokenFound = true;
   499    499                                   }
   500    500                               } else {
   501    501                                   // there is an anti-pattern
   502    502                                   let [sPattern, sNegPattern] = sRegex.split("¬", 2);
   503    503                                   if (sNegPattern == "*") {
   504    504                                       // all morphologies must match with <sPattern>
   505    505                                       if (sPattern) {
   506    506                                           if (lMorph.every(sMorph  =>  (sMorph.search(sPattern) !== -1))) {
   507    507                                               if (bDebug) {
   508    508                                                   console.log("  MATCH: @" + sRegex);
   509    509                                               }
   510         -                                            yield { "iToken1": iToken1, "iNode": dNode["<re_morph>"][sRegex] };
          510  +                                            yield { "iToken1": iToken1, "iNode": oNode["<re_morph>"][sRegex] };
   511    511                                               bTokenFound = true;
   512    512                                           }
   513    513                                       }
   514    514                                   } else {
   515    515                                       if (sNegPattern  &&  lMorph.some(sMorph  =>  (sMorph.search(sNegPattern) !== -1))) {
   516    516                                           continue;
   517    517                                       }
   518    518                                       if (!sPattern  ||  lMorph.some(sMorph  =>  (sMorph.search(sPattern) !== -1))) {
   519    519                                           if (bDebug) {
   520    520                                               console.log("  MATCH: @" + sRegex);
   521    521                                           }
   522         -                                        yield { "iToken1": iToken1, "iNode": dNode["<re_morph>"][sRegex] };
          522  +                                        yield { "iToken1": iToken1, "iNode": oNode["<re_morph>"][sRegex] };
   523    523                                           bTokenFound = true;
   524    524                                       }
   525    525                                   }
   526    526                               }
   527    527                           }
   528    528                       }
   529    529                   }
   530    530               }
   531    531               // token tags
   532         -            if (dToken.hasOwnProperty("aTags") && dNode.hasOwnProperty("<tags>")) {
          532  +            if (dToken.hasOwnProperty("aTags") && oNode.hasOwnProperty("<tags>")) {
   533    533                   for (let sTag of dToken["aTags"]) {
   534         -                    if (dNode["<tags>"].hasOwnProperty(sTag)) {
          534  +                    if (oNode["<tags>"].hasOwnProperty(sTag)) {
   535    535                           if (bDebug) {
   536    536                               console.log("  MATCH: /" + sTag);
   537    537                           }
   538         -                        yield { "iToken1": iToken1, "iNode": dNode["<tags>"][sTag] };
          538  +                        yield { "iToken1": iToken1, "iNode": oNode["<tags>"][sTag] };
   539    539                           bTokenFound = true;
   540    540                       }
   541    541                   }
   542    542               }
   543    543               // meta arc (for token type)
   544         -            if (dNode.hasOwnProperty("<meta>")) {
   545         -                for (let sMeta in dNode["<meta>"]) {
   546         -                    // no regex here, we just search if <dNode["sType"]> exists within <sMeta>
          544  +            if (oNode.hasOwnProperty("<meta>")) {
          545  +                for (let sMeta in oNode["<meta>"]) {
          546  +                    // no regex here, we just search if <oNode["sType"]> exists within <sMeta>
   547    547                       if (sMeta == "*" || dToken["sType"] == sMeta) {
   548    548                           if (bDebug) {
   549    549                               console.log("  MATCH: *" + sMeta);
   550    550                           }
   551         -                        yield { "iToken1": iToken1, "iNode": dNode["<meta>"][sMeta] };
          551  +                        yield { "iToken1": iToken1, "iNode": oNode["<meta>"][sMeta] };
   552    552                           bTokenFound = true;
   553    553                       }
   554    554                       else if (sMeta.includes("¬")) {
   555    555                           if (!sMeta.includes(dToken["sType"])) {
   556    556                               if (bDebug) {
   557    557                                   console.log("  MATCH: *" + sMeta);
   558    558                               }
   559         -                            yield { "iToken1": iToken1, "iNode": dNode["<meta>"][sMeta] };
          559  +                            yield { "iToken1": iToken1, "iNode": oNode["<meta>"][sMeta] };
   560    560                               bTokenFound = true;
   561    561                           }
   562    562                       }
   563    563                   }
   564    564               }
   565         -            if (!bTokenFound  &&  dPointer.hasOwnProperty("bKeep")) {
   566         -                yield dPointer;
          565  +            if (!bTokenFound  &&  oPointer.hasOwnProperty("bKeep")) {
          566  +                yield oPointer;
   567    567               }
   568    568               // JUMP
   569    569               // Warning! Recurssion!
   570         -            if (dNode.hasOwnProperty("<>")) {
   571         -                let dPointer2 = { "iToken1": iToken1, "iNode": dNode["<>"], "bKeep": true };
   572         -                yield* this._getNextPointers(dToken, dGraph, dPointer2, bDebug);
          570  +            if (oNode.hasOwnProperty("<>")) {
          571  +                let oPointer2 = { "iToken1": iToken1, "iNode": oNode["<>"], "bKeep": true };
          572  +                yield* this._getNextPointers(dToken, oGraph, oPointer2, bDebug);
   573    573               }
   574    574           }
   575    575           catch (e) {
   576    576               console.error(e);
   577    577           }
   578    578       }
   579    579   
   580         -    parseGraph (dGraph, sCountry="${country_default}", dOptions=null, bShowRuleId=false, bDebug=false, bContext=false) {
          580  +    parseGraph (oGraph, sCountry="${country_default}", dOptions=null, bShowRuleId=false, bDebug=false, bContext=false) {
   581    581           // parse graph with tokens from the text and execute actions encountered
   582    582           let lPointer = [];
   583    583           let bTagAndRewrite = false;
   584    584           try {
   585    585               for (let [iToken, dToken] of this.lToken.entries()) {
   586    586                   if (bDebug) {
   587    587                       console.log("TOKEN: " + dToken["sValue"]);
   588    588                   }
   589    589                   // check arcs for each existing pointer
   590    590                   let lNextPointer = [];
   591         -                for (let dPointer of lPointer) {
   592         -                    lNextPointer.push(...this._getNextPointers(dToken, dGraph, dPointer, bDebug));
          591  +                for (let oPointer of lPointer) {
          592  +                    lNextPointer.push(...this._getNextPointers(dToken, oGraph, oPointer, bDebug));
   593    593                   }
   594    594                   lPointer = lNextPointer;
   595    595                   // check arcs of first nodes
   596         -                lPointer.push(...this._getNextPointers(dToken, dGraph, { "iToken1": iToken, "iNode": 0 }, bDebug));
          596  +                lPointer.push(...this._getNextPointers(dToken, oGraph, { "iToken1": iToken, "iNode": 0 }, bDebug));
   597    597                   // check if there is rules to check for each pointer
   598         -                for (let dPointer of lPointer) {
   599         -                    if (dGraph[dPointer["iNode"]].hasOwnProperty("<rules>")) {
   600         -                        let bChange = this._executeActions(dGraph, dGraph[dPointer["iNode"]]["<rules>"], dPointer["iToken1"]-1, iToken, dOptions, sCountry, bShowRuleId, bDebug, bContext);
          598  +                for (let oPointer of lPointer) {
          599  +                    if (oGraph[oPointer["iNode"]].hasOwnProperty("<rules>")) {
          600  +                        let bChange = this._executeActions(oGraph, oGraph[oPointer["iNode"]]["<rules>"], oPointer["iToken1"]-1, iToken, dOptions, sCountry, bShowRuleId, bDebug, bContext);
   601    601                           if (bChange) {
   602    602                               bTagAndRewrite = true;
   603    603                           }
   604    604                       }
   605    605                   }
   606    606               }
   607    607           } catch (e) {
................................................................................
   612    612           }
   613    613           if (bDebug) {
   614    614               console.log(this.asString());
   615    615           }
   616    616           return this.sSentence;
   617    617       }
   618    618   
   619         -    _executeActions (dGraph, dNode, nTokenOffset, nLastToken, dOptions, sCountry, bShowRuleId, bDebug, bContext) {
          619  +    _executeActions (oGraph, oNode, nTokenOffset, nLastToken, dOptions, sCountry, bShowRuleId, bDebug, bContext) {
   620    620           // execute actions found in the DARG
   621    621           let bChange = false;
   622         -        for (let [sLineId, nextNodeKey] of Object.entries(dNode)) {
          622  +        for (let [sLineId, nextNodeKey] of Object.entries(oNode)) {
   623    623               let bCondMemo = null;
   624         -            for (let sRuleId of dGraph[nextNodeKey]) {
          624  +            for (let sRuleId of oGraph[nextNodeKey]) {
   625    625                   try {
   626    626                       if (bDebug) {
   627    627                           console.log("   >TRY: " + sRuleId + " " + sLineId);
   628    628                       }
   629    629                       let [sOption, sFuncCond, cActionType, sWhat, ...eAct] = gc_rules_graph.dRule[sRuleId];
   630    630                       // Suggestion    [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL ]
   631    631                       // TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ]