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 @@ -69,10 +69,17 @@ _oTokenizer = _oSpellChecker.getTokenizer() _oSpellChecker.activateStorage() except: traceback.print_exc() + +def getSpellChecker (): + "return the spellchecker object" + return _oSpellChecker + + +#### Rules def _getRules (bParagraph): try: if not bParagraph: return _rules.lSentenceRules @@ -100,12 +107,10 @@ except: echo("Bad regular expression in # " + str(aRule[2])) aRule[0] = "(?i)" -#### Rules and options - def ignoreRule (sRuleId): "disable rule " _aIgnoredRules.add(sRuleId) @@ -138,10 +143,12 @@ "display the name of rules, with the filter " echo("List of rules. Filter: << " + str(sFilter) + " >>") for sOption, sLineId, sRuleId in listRegexRules(sFilter): echo("{:<10} {:<10} {}".format(sOption, sLineId, sRuleId)) + +#### Options def setOption (sOpt, bVal): "set option with if it exists" if sOpt in _dOptions: _dOptions[sOpt] = bVal @@ -179,15 +186,10 @@ def resetOptions (): "set options to default values" global _dOptions _dOptions = dict(gc_options.getOptions(_sAppContext)) - -def getSpellChecker (): - "return the spellchecker object" - return _oSpellChecker - #### Parsing _zEndOfSentence = re.compile(r'([.?!:;…][ .?!… »”")]*|.$)') _zBeginOfParagraph = re.compile(r"^\W*") @@ -239,11 +241,11 @@ return s def parse (self, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False): "analyses the paragraph sText and returns list of errors" #sText = unicodedata.normalize("NFC", sText) - dOpt = _dOptions if not dOptions else dOptions + dOpt = dOptions or _dOptions bShowRuleId = option('idrule') # parse paragraph try: self.parseText(self.sText, self.sText0, True, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext) @@ -339,10 +341,12 @@ self.sSentence = sSentence lNewToken = list(_oTokenizer.genTokens(sSentence, True)) for dToken in lNewToken: if "lMorph" in self.dTokenPos.get(dToken["nStart"], {}): dToken["lMorph"] = self.dTokenPos[dToken["nStart"]]["lMorph"] + if "tags" in self.dTokenPos.get(dToken["nStart"], {}): + dToken["tags"] = self.dTokenPos[dToken["nStart"]]["tags"] self.lToken = lNewToken self.dTokenPos = { dToken["nStart"]: dToken for dToken in self.lToken if dToken["sType"] != "INFO" } if bDebug: echo("UPDATE:") echo(self) @@ -462,21 +466,20 @@ if dToken["sType"] not in sMeta: if bDebug: echo(" MATCH: *" + sMeta) yield { "iNode1": iNode1, "dNode": dGraph[dNode[""][sMeta]] } bTokenFound = True - if "bKeep" in dPointer and not bTokenFound: + if not bTokenFound and "bKeep" in dPointer: yield dPointer # JUMP # Warning! Recurssion! if "<>" in dNode: dPointer2 = { "iNode1": iNode1, "dNode": dGraph[dNode["<>"]], "bKeep": True } yield from self._getNextPointers(dToken, dGraph, dPointer2, bDebug) def parseGraph (self, dGraph, sCountry="${country_default}", dOptions=None, bShowRuleId=False, bDebug=False, bContext=False): "parse graph with tokens from the text and execute actions encountered" - dOpt = _dOptions if not dOptions else dOptions lPointer = [] bTagAndRewrite = False for iToken, dToken in enumerate(self.lToken): if bDebug: echo("TOKEN: " + dToken["sValue"]) @@ -490,11 +493,11 @@ # check if there is rules to check for each pointer for dPointer in lPointer: #if bDebug: # echo("+", dPointer) if "" in dPointer["dNode"]: - bChange = self._executeActions(dGraph, dPointer["dNode"][""], dPointer["iNode1"]-1, iToken, dOpt, sCountry, bShowRuleId, bDebug, bContext) + bChange = self._executeActions(dGraph, dPointer["dNode"][""], dPointer["iNode1"]-1, iToken, dOptions, sCountry, bShowRuleId, bDebug, bContext) if bChange: bTagAndRewrite = True if bTagAndRewrite: self.rewriteFromTags(bDebug) if bDebug: