Index: gc_core/js/lang_core/gc_engine.js ================================================================== --- gc_core/js/lang_core/gc_engine.js +++ gc_core/js/lang_core/gc_engine.js @@ -395,63 +395,63 @@ console.log("UPDATE:"); console.log(this.asString()); } } - * _getNextPointers (dToken, dGraph, dPointer, bDebug=false) { - // generator: return nodes where “values” match arcs + * _getNextPointers (dToken, oGraph, oPointer, bDebug=false) { + // generator: return nodes where “values” match arcs try { - let dNode = dGraph[dPointer["iNode"]]; - let iToken1 = dPointer["iToken1"]; + let oNode = oGraph[oPointer["iNode"]]; + let iToken1 = oPointer["iToken1"]; let bTokenFound = false; // token value - if (dNode.hasOwnProperty(dToken["sValue"])) { + if (oNode.hasOwnProperty(dToken["sValue"])) { if (bDebug) { console.log(" MATCH: " + dToken["sValue"]); } - yield { "iToken1": iToken1, "iNode": dNode[dToken["sValue"]] }; + yield { "iToken1": iToken1, "iNode": oNode[dToken["sValue"]] }; bTokenFound = true; } if (dToken["sValue"].slice(0,2).gl_isTitle()) { // we test only 2 first chars, to make valid words such as "Laissez-les", "Passe-partout". let sValue = dToken["sValue"].toLowerCase(); - if (dNode.hasOwnProperty(sValue)) { + if (oNode.hasOwnProperty(sValue)) { if (bDebug) { console.log(" MATCH: " + sValue); } - yield { "iToken1": iToken1, "iNode": dNode[sValue] }; + yield { "iToken1": iToken1, "iNode": oNode[sValue] }; bTokenFound = true; } } else if (dToken["sValue"].gl_isUpperCase()) { let sValue = dToken["sValue"].toLowerCase(); - if (dNode.hasOwnProperty(sValue)) { + if (oNode.hasOwnProperty(sValue)) { if (bDebug) { console.log(" MATCH: " + sValue); } - yield { "iToken1": iToken1, "iNode": dNode[sValue] }; + yield { "iToken1": iToken1, "iNode": oNode[sValue] }; bTokenFound = true; } sValue = dToken["sValue"].gl_toCapitalize(); - if (dNode.hasOwnProperty(sValue)) { + if (oNode.hasOwnProperty(sValue)) { if (bDebug) { console.log(" MATCH: " + sValue); } - yield { "iToken1": iToken1, "iNode": dNode[sValue] }; + yield { "iToken1": iToken1, "iNode": oNode[sValue] }; bTokenFound = true; } } // regex value arcs if (dToken["sType"] != "INFO" && dToken["sType"] != "PUNC" && dToken["sType"] != "SIGN") { - if (dNode.hasOwnProperty("")) { - for (let sRegex in dNode[""]) { + if (oNode.hasOwnProperty("")) { + for (let sRegex in oNode[""]) { if (!sRegex.includes("¬")) { // no anti-pattern if (dToken["sValue"].search(sRegex) !== -1) { if (bDebug) { console.log(" MATCH: ~" + sRegex); } - yield { "iToken1": iToken1, "iNode": dNode[""][sRegex] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sRegex] }; bTokenFound = true; } } else { // there is an anti-pattern let [sPattern, sNegPattern] = sRegex.split("¬", 2); @@ -460,43 +460,43 @@ } if (!sPattern || dToken["sValue"].search(sPattern) !== -1) { if (bDebug) { console.log(" MATCH: ~" + sRegex); } - yield { "iToken1": iToken1, "iNode": dNode[""][sRegex] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sRegex] }; bTokenFound = true; } } } } } // analysable tokens if (dToken["sType"].slice(0,4) == "WORD") { // token lemmas - if (dNode.hasOwnProperty("")) { + if (oNode.hasOwnProperty("")) { for (let sLemma of _oSpellChecker.getLemma(dToken["sValue"])) { - if (dNode[""].hasOwnProperty(sLemma)) { + if (oNode[""].hasOwnProperty(sLemma)) { if (bDebug) { console.log(" MATCH: >" + sLemma); } - yield { "iToken1": iToken1, "iNode": dNode[""][sLemma] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sLemma] }; bTokenFound = true; } } } // regex morph arcs - if (dNode.hasOwnProperty("")) { + if (oNode.hasOwnProperty("")) { let lMorph = (dToken.hasOwnProperty("lMorph")) ? dToken["lMorph"] : _oSpellChecker.getMorph(dToken["sValue"]); if (lMorph.length > 0) { - for (let sRegex in dNode[""]) { + for (let sRegex in oNode[""]) { if (!sRegex.includes("¬")) { // no anti-pattern if (lMorph.some(sMorph => (sMorph.search(sRegex) !== -1))) { if (bDebug) { console.log(" MATCH: @" + sRegex); } - yield { "iToken1": iToken1, "iNode": dNode[""][sRegex] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sRegex] }; bTokenFound = true; } } else { // there is an anti-pattern let [sPattern, sNegPattern] = sRegex.split("¬", 2); @@ -505,11 +505,11 @@ if (sPattern) { if (lMorph.every(sMorph => (sMorph.search(sPattern) !== -1))) { if (bDebug) { console.log(" MATCH: @" + sRegex); } - yield { "iToken1": iToken1, "iNode": dNode[""][sRegex] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sRegex] }; bTokenFound = true; } } } else { if (sNegPattern && lMorph.some(sMorph => (sMorph.search(sNegPattern) !== -1))) { @@ -517,69 +517,69 @@ } if (!sPattern || lMorph.some(sMorph => (sMorph.search(sPattern) !== -1))) { if (bDebug) { console.log(" MATCH: @" + sRegex); } - yield { "iToken1": iToken1, "iNode": dNode[""][sRegex] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sRegex] }; bTokenFound = true; } } } } } } } // token tags - if (dToken.hasOwnProperty("aTags") && dNode.hasOwnProperty("")) { + if (dToken.hasOwnProperty("aTags") && oNode.hasOwnProperty("")) { for (let sTag of dToken["aTags"]) { - if (dNode[""].hasOwnProperty(sTag)) { + if (oNode[""].hasOwnProperty(sTag)) { if (bDebug) { console.log(" MATCH: /" + sTag); } - yield { "iToken1": iToken1, "iNode": dNode[""][sTag] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sTag] }; bTokenFound = true; } } } // meta arc (for token type) - if (dNode.hasOwnProperty("")) { - for (let sMeta in dNode[""]) { - // no regex here, we just search if exists within + if (oNode.hasOwnProperty("")) { + for (let sMeta in oNode[""]) { + // no regex here, we just search if exists within if (sMeta == "*" || dToken["sType"] == sMeta) { if (bDebug) { console.log(" MATCH: *" + sMeta); } - yield { "iToken1": iToken1, "iNode": dNode[""][sMeta] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sMeta] }; bTokenFound = true; } else if (sMeta.includes("¬")) { if (!sMeta.includes(dToken["sType"])) { if (bDebug) { console.log(" MATCH: *" + sMeta); } - yield { "iToken1": iToken1, "iNode": dNode[""][sMeta] }; + yield { "iToken1": iToken1, "iNode": oNode[""][sMeta] }; bTokenFound = true; } } } } - if (!bTokenFound && dPointer.hasOwnProperty("bKeep")) { - yield dPointer; + if (!bTokenFound && oPointer.hasOwnProperty("bKeep")) { + yield oPointer; } // JUMP // Warning! Recurssion! - if (dNode.hasOwnProperty("<>")) { - let dPointer2 = { "iToken1": iToken1, "iNode": dNode["<>"], "bKeep": true }; - yield* this._getNextPointers(dToken, dGraph, dPointer2, bDebug); + if (oNode.hasOwnProperty("<>")) { + let oPointer2 = { "iToken1": iToken1, "iNode": oNode["<>"], "bKeep": true }; + yield* this._getNextPointers(dToken, oGraph, oPointer2, bDebug); } } catch (e) { console.error(e); } } - parseGraph (dGraph, sCountry="${country_default}", dOptions=null, bShowRuleId=false, bDebug=false, bContext=false) { + 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, dToken] of this.lToken.entries()) { @@ -586,20 +586,20 @@ if (bDebug) { console.log("TOKEN: " + dToken["sValue"]); } // check arcs for each existing pointer let lNextPointer = []; - for (let dPointer of lPointer) { - lNextPointer.push(...this._getNextPointers(dToken, dGraph, dPointer, bDebug)); + for (let oPointer of lPointer) { + lNextPointer.push(...this._getNextPointers(dToken, oGraph, oPointer, bDebug)); } lPointer = lNextPointer; // check arcs of first nodes - lPointer.push(...this._getNextPointers(dToken, dGraph, { "iToken1": iToken, "iNode": 0 }, bDebug)); + lPointer.push(...this._getNextPointers(dToken, oGraph, { "iToken1": iToken, "iNode": 0 }, bDebug)); // check if there is rules to check for each pointer - for (let dPointer of lPointer) { - if (dGraph[dPointer["iNode"]].hasOwnProperty("")) { - let bChange = this._executeActions(dGraph, dGraph[dPointer["iNode"]][""], dPointer["iToken1"]-1, iToken, dOptions, sCountry, bShowRuleId, bDebug, bContext); + for (let oPointer of lPointer) { + if (oGraph[oPointer["iNode"]].hasOwnProperty("")) { + let bChange = this._executeActions(oGraph, oGraph[oPointer["iNode"]][""], oPointer["iToken1"]-1, iToken, dOptions, sCountry, bShowRuleId, bDebug, bContext); if (bChange) { bTagAndRewrite = true; } } } @@ -614,16 +614,16 @@ console.log(this.asString()); } return this.sSentence; } - _executeActions (dGraph, dNode, nTokenOffset, nLastToken, dOptions, sCountry, bShowRuleId, bDebug, bContext) { + _executeActions (oGraph, oNode, nTokenOffset, nLastToken, dOptions, sCountry, bShowRuleId, bDebug, bContext) { // execute actions found in the DARG let bChange = false; - for (let [sLineId, nextNodeKey] of Object.entries(dNode)) { + for (let [sLineId, nextNodeKey] of Object.entries(oNode)) { let bCondMemo = null; - for (let sRuleId of dGraph[nextNodeKey]) { + for (let sRuleId of oGraph[nextNodeKey]) { try { if (bDebug) { console.log(" >TRY: " + sRuleId + " " + sLineId); } let [sOption, sFuncCond, cActionType, sWhat, ...eAct] = gc_rules_graph.dRule[sRuleId];