Grammalecte  Check-in [51affbc3d4]

Overview
Comment:[core] better debugging mode
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | rg
Files: files | file ages | folders
SHA3-256: 51affbc3d4f7881dce4b6d902091cc083d7b0cb5045736cf72b027e7f72159e5
User & Date: olr on 2018-06-14 12:31:06
Other Links: branch diff | manifest | tags
Context
2018-06-14
12:35
[core][bug] boolean storing condition result wrongly reset check-in: 30e9ffd98a user: olr tags: core, rg
12:31
[core] better debugging mode check-in: 51affbc3d4 user: olr tags: core, rg
12:09
[core] better debugging mode check-in: 88118a8b73 user: olr tags: core, rg
Changes

Modified gc_core/py/lang_core/gc_engine.py from [9a771ad130] to [e9a038bb63].

   601    601           self.lToken = list(_oTokenizer.genTokens(sSentence, True))
   602    602   
   603    603       def _getNextMatchingNodes (self, dToken, dGraph, dNode, bDebug=False):
   604    604           "generator: return nodes where <dToken> “values” match <dNode> arcs"
   605    605           # token value
   606    606           if dToken["sValue"] in dNode:
   607    607               if bDebug:
   608         -                print("value found: ", dToken["sValue"])
          608  +                print("MATCH:", dToken["sValue"])
   609    609               yield dGraph[dNode[dToken["sValue"]]]
   610    610           # token lemmas
   611    611           if "<lemmas>" in dNode:
   612    612               for sLemma in _oSpellChecker.getLemma(dToken["sValue"]):
   613    613                   if sLemma in dNode["<lemmas>"]:
   614         -                    #print("lemma found: ", sLemma)
          614  +                    if bDebug:
          615  +                        print("MATCH: >" + sLemma)
   615    616                       yield dGraph[dNode["<lemmas>"][sLemma]]
   616    617           # universal arc
   617    618           if "*" in dNode:
   618    619               if bDebug:
   619         -                print("generic arc")
          620  +                print("MATCH: *")
   620    621               yield dGraph[dNode["*"]]
   621    622           # regex value arcs
   622    623           if "<re_value>" in dNode:
   623    624               for sRegex in dNode["<re_value>"]:
   624    625                   if re.search(sRegex, dToken["sValue"]):
   625    626                       if bDebug:
   626         -                        print("value regex matching: ", sRegex)
          627  +                        print("MATCH: ~" + sRegex)
   627    628                       yield dGraph[dNode["<re_value>"][sRegex]]
   628    629           # regex morph arcs
   629    630           if "<re_morph>" in dNode:
   630    631               for sRegex in dNode["<re_morph>"]:
   631    632                   if "¬" not in sRegex:
   632    633                       # no anti-pattern
   633    634                       if any(re.search(sRegex, sMorph)  for sMorph in _oSpellChecker.getMorph(dToken["sValue"])):
   634    635                           if bDebug:
   635         -                            print("morph regex matching: ", sRegex)
          636  +                            print("MATCH: @" + sRegex)
   636    637                           yield dGraph[dNode["<re_morph>"][sRegex]]
   637    638                   else:
   638    639                       # there is an anti-pattern
   639    640                       sPattern, sNegPattern = sRegex.split("¬", 1)
   640    641                       if sNegPattern == "*":
   641    642                           # all morphologies must match with <sPattern>
   642    643                           if all(re.search(sPattern, sMorph)  for sMorph in _oSpellChecker.getMorph(dToken["sValue"])):
   643    644                               if bDebug:
   644         -                                print("morph regex matching: ", sRegex)
          645  +                                print("MATCH: @" + sRegex)
   645    646                               yield dGraph[dNode["<re_morph>"][sRegex]]
   646    647                       else:
   647    648                           if sNegPattern and any(re.search(sNegPattern, sMorph)  for sMorph in _oSpellChecker.getMorph(dToken["sValue"])):
   648    649                               continue
   649    650                           if any(re.search(sPattern, sMorph)  for sMorph in _oSpellChecker.getMorph(dToken["sValue"])):
   650    651                               if bDebug:
   651         -                                print("morph regex matching: ", sRegex)
          652  +                                print("MATCH: @" + sRegex)
   652    653                               yield dGraph[dNode["<re_morph>"][sRegex]]
   653    654   
   654    655       def parse (self, dGraph, dPriority, sCountry="${country_default}", dOptions=None, bShowRuleId=False, bDebug=False, bContext=False):
   655    656           dErr = {}
   656    657           dPriority = {}  # Key = position; value = priority
   657    658           dOpt = _dOptions  if not dOptions  else dOptions
   658    659           lPointer = []
   659    660           bChange = False
   660    661           for dToken in self.lToken:
   661    662               if bDebug:
   662         -                print("=", dToken["sValue"])
          663  +                print("TOKEN:", dToken["sValue"])
   663    664               # check arcs for each existing pointer
   664    665               lNextPointer = []
   665    666               for dPointer in lPointer:
   666    667                   for dNode in self._getNextMatchingNodes(dToken, dGraph, dPointer["dNode"], bDebug):
   667    668                       lNextPointer.append({"iToken": dPointer["iToken"], "dNode": dNode})
   668    669               lPointer = lNextPointer
   669    670               # check arcs of first nodes
   670    671               for dNode in self._getNextMatchingNodes(dToken, dGraph, dGraph[0], bDebug):
   671    672                   lPointer.append({"iToken": dToken["i"], "dNode": dNode})
   672    673               # check if there is rules to check for each pointer
   673    674               for dPointer in lPointer:
   674         -                if bDebug:
   675         -                    print("+", dPointer)
          675  +                #if bDebug:
          676  +                #    print("+", dPointer)
   676    677                   if "<rules>" in dPointer["dNode"]:
   677    678                       bHasChanged, errs = self._executeActions(dGraph, dPointer["dNode"]["<rules>"], dPointer["iToken"]-1, dPriority, dOpt, sCountry, bShowRuleId, bDebug, bContext)
   678    679                       dErr.update(errs)
   679    680                       if bHasChanged:
   680    681                           bChange = True
   681    682           return (bChange, dErr)
   682    683   
................................................................................
   683    684       def _executeActions (self, dGraph, dNode, nTokenOffset, dPriority, dOptions, sCountry, bShowRuleId, bDebug, bContext):
   684    685           "execute actions found in the DARG"
   685    686           dErrs = {}
   686    687           bChange = False
   687    688           for sLineId, nextNodeKey in dNode.items():
   688    689               for sRuleId in dGraph[nextNodeKey]:
   689    690                   try:
          691  +                    if bDebug:
          692  +                        print("ACTION:", sRuleId)
          693  +                        print(dRule[sRuleId])
   690    694                       bCondMemo = None
   691    695                       sOption, sFuncCond, cActionType, sWhat, *eAct = dRule[sRuleId]
   692    696                       # action in lActions: [ condition, action type, replacement/suggestion/action[, iTokenStart, iTokenEnd[, nPriority, message, URL]] ]
   693    697                       if not sOption or dOptions.get(sOption, False):
   694    698                           bCondMemo = not sFuncCond or globals()[sFuncCond](self.lToken, nTokenOffset, sCountry, bCondMemo)
   695    699                           if bCondMemo:
   696    700                               if cActionType == "-":