Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -21,11 +21,11 @@ s = re.sub(r"isEnd *\(\)", 'after(["", ","])', s) s = re.sub(r"isRealEnd *\(\)", 'after([""])', s) s = re.sub(r"isEnd0 *\(\)", 'after0(["", ","])', s) s = re.sub(r"isRealEnd0 *\(\)", 'after0([""])', s) s = re.sub(r"(select|exclude|define)[(][\\](\d+)", 'g_\\1(lToken[\\2+nTokenOffset]', s) - s = re.sub(r"(morph|morphex|displayInfo)[(]\\(\d+)", 'g_\\1(lToken[\\2+nTokenOffset]', s) + s = re.sub(r"(morph|displayInfo)[(]\\(\d+)", 'g_\\1(lToken[\\2+nTokenOffset]', s) s = re.sub(r"token\(\s*(\d)", 'nextToken(\\1', s) # token(n) s = re.sub(r"token\(\s*-(\d)", 'prevToken(\\1', s) # token(-n) s = re.sub(r"before\(\s*", 'look(s[:m.start()], ', s) # before(s) s = re.sub(r"after\(\s*", 'look(s[m.end():], ', s) # after(s) s = re.sub(r"textarea\(\s*", 'look(s, ', s) # textarea(s) Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -817,59 +817,47 @@ return #### Analyse tokens -def g_morph (dToken, sPattern, bStrict=True): - "analyse a token, return True if in morphologies" - if "lMorph" in dToken: - lMorph = dToken["lMorph"] - else: - lMorph = _oSpellChecker.getMorph(dToken["sValue"]) - if not lMorph: - return False - zPattern = re.compile(sPattern) - if bStrict: - return all(zPattern.search(sMorph) for sMorph in lMorph) - return any(zPattern.search(sMorph) for sMorph in lMorph) - -def g_morphex (dToken, sPattern, sNegPattern): +def g_morph (dToken, sPattern, sNegPattern=""): "analyse a token, return True if not in morphologies and in morphologies" if "lMorph" in dToken: lMorph = dToken["lMorph"] else: lMorph = _oSpellChecker.getMorph(dToken["sValue"]) if not lMorph: return False # check negative condition - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + if sNegPattern: + if sNegPattern == "*": + # all morph must match sPattern + zPattern = re.compile(sPattern) + return all(zPattern.search(sMorph) for sMorph in lMorph) + else: + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) -def g_analyse (dToken, sPattern, bStrict=True): - "analyse a token, return True if in morphologies (disambiguation off)" - lMorph = _oSpellChecker.getMorph(dToken["sValue"]) - if not lMorph: - return False - zPattern = re.compile(sPattern) - if bStrict: - return all(zPattern.search(sMorph) for sMorph in lMorph) - return any(zPattern.search(sMorph) for sMorph in lMorph) - - -def g_analysex (dToken, sPattern, sNegPattern): + +def g_analyse (dToken, sPattern, sNegPattern=""): "analyse a token, return True if not in morphologies and in morphologies (disambiguation off)" lMorph = _oSpellChecker.getMorph(dToken["sValue"]) if not lMorph: return False # check negative condition - zNegPattern = re.compile(sNegPattern) - if any(zNegPattern.search(sMorph) for sMorph in lMorph): - return False + if sNegPattern: + if sNegPattern == "*": + zPattern = re.compile(sPattern) + return all(zPattern.search(sMorph) for sMorph in lMorph) + else: + zNegPattern = re.compile(sNegPattern) + if any(zNegPattern.search(sMorph) for sMorph in lMorph): + return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) Index: gc_lang/fr/rules_graph.grx ================================================================== --- gc_lang/fr/rules_graph.grx +++ gc_lang/fr/rules_graph.grx @@ -69,8 +69,8 @@ TEST: Ça me fait {{plaisirs}}. __test__ je ~préf[éè]r [que|qu’] @(?::Os|:M)¬:X @:I - <<- morph(\1, ":V", False) and morphex(\4, ":Os|:M", ":X") -5>> SUBJONCTIF # SUBJONCTIF. + <<- morph(\1, ":V") and morph(\4, ":Os|:M", ":X") -5>> SUBJONCTIF # SUBJONCTIF. TEST: je préférerais qu’Isabelle {{est}} partie.