Grammalecte  Check-in [89a4f01579]

Overview
Comment:[core] debugging mode clarity
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | rg
Files: files | file ages | folders
SHA3-256: 89a4f01579c191accfac980eb2d306a2cb94ed4265d45981a1222680cc4efccd
User & Date: olr on 2018-08-15 09:22:40
Other Links: branch diff | manifest | tags
Context
2018-08-17
21:43
[fr] conversion: regex rules -> graph rules check-in: 95247d8211 user: olr tags: fr, rg
2018-08-15
09:22
[core] debugging mode clarity check-in: 89a4f01579 user: olr tags: core, rg
2018-08-14
16:51
[core][fr] suggestions: split verb for imperative forms check-in: 2031faacbd user: olr tags: core, fr, rg
Changes

Modified gc_core/py/lang_core/gc_engine.py from [d5983e0d9b] to [6415b59c9d].

   576    576           self.nOffsetWithinParagraph = nOffset
   577    577           self.lToken = list(_oTokenizer.genTokens(sSentence, True))
   578    578           self.dTokenPos = { dToken["nStart"]: dToken  for dToken in self.lToken  if dToken["sType"] != "INFO" }
   579    579           self.dTags = {}
   580    580           self.dError = {}
   581    581   
   582    582       def __str__ (self):
   583         -        s = "TEXT ==========\n"
          583  +        s = "===== TEXT =====\n"
   584    584           s += "sentence: " + self.sSentence0 + "\n"
   585    585           s += "now:      " + self.sSentence  + "\n"
   586    586           for dToken in self.lToken:
   587         -            s += f'{dToken["nStart"]}\t{dToken["nEnd"]}\t{dToken["sValue"]}'
          587  +            s += f'#{dToken["i"]}\t{dToken["nStart"]}:{dToken["nEnd"]}\t{dToken["sValue"]}\t{dToken["sType"]}'
   588    588               if "lMorph" in dToken:
   589    589                   s += "\t" + str(dToken["lMorph"])
          590  +            if "tags" in dToken:
          591  +                s += "\t" + str(dToken["tags"])
   590    592               s += "\n"
   591         -        for nPos, dToken in self.dTokenPos.items():
   592         -            s += f"{nPos}\t{dToken}\n"
          593  +        #for nPos, dToken in self.dTokenPos.items():
          594  +        #    s += f"{nPos}\t{dToken}\n"
   593    595           return s
   594    596   
   595    597       def update (self, sSentence, bDebug=False):
   596    598           "update <sSentence> and retokenize"
   597    599           self.sSentence = sSentence
   598    600           lNewToken = list(_oTokenizer.genTokens(sSentence, True))
   599    601           for dToken in lNewToken:
................................................................................
   768    770           "execute actions found in the DARG"
   769    771           bChange = False
   770    772           for sLineId, nextNodeKey in dNode.items():
   771    773               bCondMemo = None
   772    774               for sRuleId in dGraph[nextNodeKey]:
   773    775                   try:
   774    776                       if bDebug:
   775         -                        print("  TRY:", sRuleId)
          777  +                        print("   >TRY:", sRuleId)
   776    778                       sOption, sFuncCond, cActionType, sWhat, *eAct = dRule[sRuleId]
   777    779                       # Suggestion    [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL ]
   778    780                       # TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ]
   779    781                       # Disambiguator [ option, condition, "=", replacement/suggestion/action ]
   780         -                    # Sentence Tag  [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ]
          782  +                    # Tag           [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ]
          783  +                    # Immunity      [ option, condition, "%", "",                            iTokenStart, iTokenEnd ]
   781    784                       # Test          [ option, condition, ">", "" ]
   782    785                       if not sOption or dOptions.get(sOption, False):
   783    786                           bCondMemo = not sFuncCond or globals()[sFuncCond](self.lToken, nTokenOffset, nLastToken, sCountry, bCondMemo, self.dTags, self.sSentence, self.sSentence0)
   784    787                           if bCondMemo:
   785    788                               if cActionType == "-":
   786    789                                   # grammar error
   787    790                                   iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, sURL = eAct
................................................................................
   790    793                                       nTokenErrorEnd = nTokenOffset + iTokenEnd  if iTokenEnd > 0  else nLastToken + iTokenEnd
   791    794                                       nErrorStart = self.nOffsetWithinParagraph + (self.lToken[nTokenErrorStart]["nStart"] if cStartLimit == "<"  else self.lToken[nTokenErrorStart]["nEnd"])
   792    795                                       nErrorEnd = self.nOffsetWithinParagraph + (self.lToken[nTokenErrorEnd]["nEnd"] if cEndLimit == ">"  else self.lToken[nTokenErrorEnd]["nStart"])
   793    796                                       if nErrorStart not in self.dError or nPriority > dPriority.get(nErrorStart, -1):
   794    797                                           self.dError[nErrorStart] = self._createError(sWhat, nTokenOffset, nLastToken, nTokenErrorStart, nErrorStart, nErrorEnd, sLineId, sRuleId, bCaseSvty, sMessage, sURL, bShowRuleId, "notype", bContext)
   795    798                                           dPriority[nErrorStart] = nPriority
   796    799                                           if bDebug:
   797         -                                            print("  NEW_ERROR:", self.dError[nErrorStart], "\n  ", dRule[sRuleId])
          800  +                                            print("    NEW_ERROR:  ", sRuleId, sLineId, ": ", self.dError[nErrorStart])
   798    801                               elif cActionType == "~":
   799    802                                   # text processor
   800         -                                if bDebug:
   801         -                                    print("  TAG_PREPARE:\n  ", dRule[sRuleId])
   802    803                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   803    804                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   804    805                                   self._tagAndPrepareTokenForRewriting(sWhat, nTokenStart, nTokenEnd, nTokenOffset, nLastToken, eAct[2], bDebug)
   805    806                                   bChange = True
          807  +                                if bDebug:
          808  +                                    print("    TEXT_PROCESSOR:  ", sRuleId, sLineId)
          809  +                                    print("      ", self.lToken[nTokenStart]["sValue"], ":", self.lToken[nTokenEnd]["sValue"], " >", sWhat)
   806    810                               elif cActionType == "=":
   807    811                                   # disambiguation
          812  +                                globals()[sWhat](self.lToken, nTokenOffset, nLastToken)
   808    813                                   if bDebug:
   809         -                                    print("  DISAMBIGUATOR:\n  ", dRule[sRuleId])
   810         -                                globals()[sWhat](self.lToken, nTokenOffset, nLastToken)
          814  +                                    print("    DISAMBIGUATOR:  ", sRuleId, sLineId, "("+sWhat+")", self.lToken[nTokenOffset+1]["sValue"], ":", self.lToken[nLastToken]["sValue"])
   811    815                               elif cActionType == ">":
   812    816                                   # we do nothing, this test is just a condition to apply all following actions
   813    817                                   if bDebug:
   814         -                                    print("  COND_OK: ", sRuleId)
          818  +                                    print("    COND_OK:  ", sRuleId, sLineId)
   815    819                                   pass
   816    820                               elif cActionType == "/":
   817    821                                   # Tag
   818         -                                if bDebug:
   819         -                                    print("  TAG:\n  ", dRule[sRuleId])
   820    822                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   821    823                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   822    824                                   for i in range(nTokenStart, nTokenEnd+1):
   823    825                                       if "tags" in self.lToken[i]:
   824    826                                           self.lToken[i]["tags"].update(sWhat.split("|"))
   825    827                                       else:
   826    828                                           self.lToken[i]["tags"] = set(sWhat.split("|"))
          829  +                                if bDebug:
          830  +                                    print("    TAG:  ", sRuleId, sLineId)
          831  +                                    print("      ", sWhat, " >", self.lToken[nTokenStart]["sValue"], ":", self.lToken[nTokenEnd]["sValue"])
   827    832                                   if sWhat not in self.dTags:
   828    833                                       self.dTags[sWhat] = [nTokenStart, nTokenStart]
   829    834                                   else:
   830    835                                       self.dTags[sWhat][0] = min(nTokenStart, self.dTags[sWhat][0])
   831    836                                       self.dTags[sWhat][1] = max(nTokenEnd, self.dTags[sWhat][1])
   832    837                               elif cActionType == "%":
   833    838                                   # immunity
   834    839                                   if bDebug:
   835         -                                    print("  IMMUNITY:\n  ", dRule[sRuleId])
          840  +                                    print("    IMMUNITY:\n  ", dRule[sRuleId])
   836    841                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   837    842                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   838    843                                   if nTokenEnd - nTokenStart == 0:
   839    844                                       self.lToken[nTokenStart]["bImmune"] = True
   840    845                                       nErrorStart = self.nOffsetWithinParagraph + self.lToken[nTokenStart]["nStart"]
   841    846                                       if nErrorStart in self.dError:
   842    847                                           del self.dError[nErrorStart]
................................................................................
   846    851                                           nErrorStart = self.nOffsetWithinParagraph + self.lToken[i]["nStart"]
   847    852                                           if nErrorStart in self.dError:
   848    853                                               del self.dError[nErrorStart]
   849    854                               else:
   850    855                                   print("# error: unknown action at " + sLineId)
   851    856                           elif cActionType == ">":
   852    857                               if bDebug:
   853         -                                print("  COND_BREAK")
          858  +                                print("    COND_BREAK:  ", sRuleId, sLineId)
   854    859                               break
   855    860                   except Exception as e:
   856    861                       raise Exception(str(e), sLineId, sRuleId, self.sSentence)
   857    862           return bChange
   858    863   
   859    864       def _createError (self, sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext):
   860    865           # suggestions