Index: gc_core/js/lang_core/gc_functions.js ================================================================== --- gc_core/js/lang_core/gc_functions.js +++ gc_core/js/lang_core/gc_functions.js @@ -349,11 +349,11 @@ } //////// Disambiguator for regex rules -function select (dTokenPos, nPos, sWord, sPattern, lDefault=null) { +function select (dTokenPos, nPos, sWord, sPattern) { if (!sWord) { return true; } if (!dTokenPos.has(nPos)) { console.log("Error. There should be a token at this position: ", nPos); @@ -362,21 +362,17 @@ let lMorph = gc_engine.oSpellChecker.getMorph(sWord); if (lMorph.length === 0 || lMorph.length === 1) { return true; } let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 ); - if (lSelect.length > 0) { - if (lSelect.length != lMorph.length) { - dTokenPos.get(nPos)["lMorph"] = lSelect; - } - } else if (lDefault) { - dTokenPos.get(nPos)["lMorph"] = lDefault; + if (lSelect.length > 0 && lSelect.length != lMorph.length) { + dTokenPos.get(nPos)["lMorph"] = lSelect; } return true; } -function exclude (dTokenPos, nPos, sWord, sPattern, lDefault=null) { +function exclude (dTokenPos, nPos, sWord, sPattern) { if (!sWord) { return true; } if (!dTokenPos.has(nPos)) { console.log("Error. There should be a token at this position: ", nPos); @@ -385,16 +381,12 @@ let lMorph = gc_engine.oSpellChecker.getMorph(sWord); if (lMorph.length === 0 || lMorph.length === 1) { return true; } let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 ); - if (lSelect.length > 0) { - if (lSelect.length != lMorph.length) { - dTokenPos.get(nPos)["lMorph"] = lSelect; - } - } else if (lDefault) { - dTokenPos.get(nPos)["lMorph"] = lDefault; + if (lSelect.length > 0 && lSelect.length != lMorph.length) { + dTokenPos.get(nPos)["lMorph"] = lSelect; } return true; } function define (dTokenPos, nPos, sMorphs) { @@ -403,46 +395,32 @@ } //// Disambiguation for graph rules -function g_select (oToken, sPattern, lDefault=null) { - // select morphologies for according to , always return true - let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]); - if (lMorph.length === 0 || lMorph.length === 1) { - if (lDefault) { - oToken["lMorph"] = lDefault; - } - return true; - } - let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 ); - if (lSelect.length > 0) { - if (lSelect.length != lMorph.length) { - oToken["lMorph"] = lSelect; - } - } else if (lDefault) { - oToken["lMorph"] = lDefault; - } - return true; -} - -function g_exclude (oToken, sPattern, lDefault=null) { - // select morphologies for according to , always return true - let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]); - if (lMorph.length === 0 || lMorph.length === 1) { - if (lDefault) { - oToken["lMorph"] = lDefault; - } - return true; - } - let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 ); - if (lSelect.length > 0) { - if (lSelect.length != lMorph.length) { - oToken["lMorph"] = lSelect; - } - } else if (lDefault) { - oToken["lMorph"] = lDefault; +function g_select (oToken, sPattern) { + // select morphologies for according to , always return true + let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]); + if (lMorph.length === 0 || lMorph.length === 1) { + return true; + } + let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) !== -1 ); + if (lSelect.length > 0 && lSelect.length != lMorph.length) { + oToken["lMorph"] = lSelect; + } + return true; +} + +function g_exclude (oToken, sPattern) { + // select morphologies for according to , always return true + let lMorph = (oToken.hasOwnProperty("lMorph")) ? oToken["lMorph"] : gc_engine.oSpellChecker.getMorph(oToken["sValue"]); + if (lMorph.length === 0 || lMorph.length === 1) { + return true; + } + let lSelect = lMorph.filter( sMorph => sMorph.search(sPattern) === -1 ); + if (lSelect.length > 0 && lSelect.length != lMorph.length) { + oToken["lMorph"] = lSelect; } return true; } function g_add_morph (oToken, sNewMorph) { Index: gc_core/py/lang_core/gc_functions.py ================================================================== --- gc_core/py/lang_core/gc_functions.py +++ gc_core/py/lang_core/gc_functions.py @@ -296,11 +296,11 @@ #### Disambiguator for regex rules -def select (dTokenPos, nPos, sWord, sPattern, lDefault=None): +def select (dTokenPos, nPos, sWord, sPattern): "Disambiguation: select morphologies of matching " if not sWord: return True if nPos not in dTokenPos: echo("Error. There should be a token at this position: ", nPos) @@ -307,19 +307,16 @@ return True lMorph = _oSpellChecker.getMorph(sWord) if not lMorph or len(lMorph) == 1: return True lSelect = [ sMorph for sMorph in lMorph if re.search(sPattern, sMorph) ] - if lSelect: - if len(lSelect) != len(lMorph): - dTokenPos[nPos]["lMorph"] = lSelect - elif lDefault: - dTokenPos[nPos]["lMorph"] = lDefault + if lSelect and len(lSelect) != len(lMorph): + dTokenPos[nPos]["lMorph"] = lSelect return True -def exclude (dTokenPos, nPos, sWord, sPattern, lDefault=None): +def exclude (dTokenPos, nPos, sWord, sPattern): "Disambiguation: exclude morphologies of matching " if not sWord: return True if nPos not in dTokenPos: echo("Error. There should be a token at this position: ", nPos) @@ -326,15 +323,12 @@ return True lMorph = _oSpellChecker.getMorph(sWord) if not lMorph or len(lMorph) == 1: return True lSelect = [ sMorph for sMorph in lMorph if not re.search(sPattern, sMorph) ] - if lSelect: - if len(lSelect) != len(lMorph): - dTokenPos[nPos]["lMorph"] = lSelect - elif lDefault: - dTokenPos[nPos]["lMorph"] = lDefault + if lSelect and len(lSelect) != len(lMorph): + dTokenPos[nPos]["lMorph"] = lSelect return True def define (dTokenPos, nPos, sMorphs): "Disambiguation: set morphologies of token at with " @@ -345,42 +339,30 @@ return True #### Disambiguation for graph rules -def g_select (dToken, sPattern, lDefault=None): - "Disambiguation: select morphologies for according to , always return True" - lMorph = dToken["lMorph"] if "lMorph" in dToken else _oSpellChecker.getMorph(dToken["sValue"]) - if not lMorph or len(lMorph) == 1: - if lDefault: - dToken["lMorph"] = lDefault - #echo("DA:", dToken["sValue"], dToken["lMorph"]) - return True - lSelect = [ sMorph for sMorph in lMorph if re.search(sPattern, sMorph) ] - if lSelect: - if len(lSelect) != len(lMorph): - dToken["lMorph"] = lSelect - elif lDefault: - dToken["lMorph"] = lDefault - #echo("DA:", dToken["sValue"], dToken["lMorph"]) - return True - - -def g_exclude (dToken, sPattern, lDefault=None): - "Disambiguation: select morphologies for according to , always return True" - lMorph = dToken["lMorph"] if "lMorph" in dToken else _oSpellChecker.getMorph(dToken["sValue"]) - if not lMorph or len(lMorph) == 1: - if lDefault: - dToken["lMorph"] = lDefault - #echo("DA:", dToken["sValue"], dToken["lMorph"]) - return True - lSelect = [ sMorph for sMorph in lMorph if not re.search(sPattern, sMorph) ] - if lSelect: - if len(lSelect) != len(lMorph): - dToken["lMorph"] = lSelect - elif lDefault: - dToken["lMorph"] = lDefault +def g_select (dToken, sPattern): + "Disambiguation: select morphologies for according to , always return True" + lMorph = dToken["lMorph"] if "lMorph" in dToken else _oSpellChecker.getMorph(dToken["sValue"]) + if not lMorph or len(lMorph) == 1: + return True + lSelect = [ sMorph for sMorph in lMorph if re.search(sPattern, sMorph) ] + if lSelect and len(lSelect) != len(lMorph): + dToken["lMorph"] = lSelect + #echo("DA:", dToken["sValue"], dToken["lMorph"]) + return True + + +def g_exclude (dToken, sPattern): + "Disambiguation: select morphologies for according to , always return True" + lMorph = dToken["lMorph"] if "lMorph" in dToken else _oSpellChecker.getMorph(dToken["sValue"]) + if not lMorph or len(lMorph) == 1: + return True + lSelect = [ sMorph for sMorph in lMorph if not re.search(sPattern, sMorph) ] + if lSelect and len(lSelect) != len(lMorph): + dToken["lMorph"] = lSelect #echo("DA:", dToken["sValue"], dToken["lMorph"]) return True def g_add_morph (dToken, sNewMorph):