Grammalecte  Check-in [6c9f0b9f2d]

Overview
Comment:[build][core] definititions for the graph + debugging update
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | build | rg
Files: files | file ages | folders
SHA3-256: 6c9f0b9f2df3c32916728cac4e5300fca675764730e2fa946811aa2bc91ace4b
User & Date: olr on 2018-06-17 13:07:32
Other Links: branch diff | manifest | tags
Context
2018-06-17
13:11
[graphspell] tokenizer: update ordinals check-in: 4be13a74c3 user: olr tags: graphspell, rg
13:07
[build][core] definititions for the graph + debugging update check-in: 6c9f0b9f2d user: olr tags: build, core, rg
13:06
[fr] conversion: regex rules -> graph rules check-in: cd761303f8 user: olr tags: fr, rg
Changes

Modified compile_rules.py from [a5c1ea137d] to [06d201754c].

   581    581             "paragraph_rules": mergeRulesByOption(lParagraphRules),
   582    582             "sentence_rules": mergeRulesByOption(lSentenceRules),
   583    583             "paragraph_rules_JS": jsconv.writeRulesToJSArray(mergeRulesByOption(lParagraphRulesJS)),
   584    584             "sentence_rules_JS": jsconv.writeRulesToJSArray(mergeRulesByOption(lSentenceRulesJS)) }
   585    585       d.update(dOptions)
   586    586   
   587    587       # compile graph rules
   588         -    d2 = crg.make(lGraphRule, sLang, bJavaScript)
          588  +    d2 = crg.make(lGraphRule, dDEF, sLang, bJavaScript)
   589    589       d.update(d2)
   590    590   
   591    591       return d

Modified compile_rules_graph.py from [6a40538d43] to [2d984fb6f6].

    30     30           s = re.sub(r"[\\](\d+)", 'lToken[\\1+nTokenOffset]["sValue"]', s)
    31     31       else:
    32     32           # tokens used as parameter
    33     33           s = re.sub(r"[\\](\d+)", 'lToken[\\1+nTokenOffset]', s)
    34     34       return s
    35     35   
    36     36   
    37         -def genTokenLines (sTokenLine):
           37  +def genTokenLines (sTokenLine, dDef):
    38     38       "tokenize a string and return a list of lines of tokens"
    39     39       lToken = sTokenLine.split()
    40     40       lTokenLines = None
    41     41       for i, sToken in enumerate(lToken):
    42         -        if sToken.startswith("{") and sToken.endswith("}") and sToken in dDEF:
    43         -            lToken[i] = dDEF[sToken]
           42  +        if sToken.startswith("{") and sToken.endswith("}") and sToken in dDef:
           43  +            sToken = dDef[sToken]
    44     44           if ( (sToken.startswith("[") and sToken.endswith("]")) or (sToken.startswith("([") and sToken.endswith("])")) ):
    45     45               bSelectedGroup = sToken.startswith("(") and sToken.endswith(")")
    46     46               if bSelectedGroup:
    47     47                   sToken = sToken[1:-1]
    48     48               # multiple token
    49     49               if not lTokenLines:
    50     50                   lTokenLines = [ [s]  for s  in sToken[1:-1].split("|") ]
................................................................................
    70     70               else:
    71     71                   for aRule in lTokenLines:
    72     72                       aRule.append(sToken)
    73     73       for aRule in lTokenLines:
    74     74           yield aRule
    75     75   
    76     76   
    77         -def createRule (iLine, sRuleName, sTokenLine, iActionBlock, sActions, nPriority):
           77  +def createRule (iLine, sRuleName, sTokenLine, iActionBlock, sActions, nPriority, dDef):
    78     78       # print(iLine, "//", sRuleName, "//", sTokenLine, "//", sActions, "//", nPriority)
    79         -    for lToken in genTokenLines(sTokenLine):
           79  +    for lToken in genTokenLines(sTokenLine, dDef):
    80     80           # Calculate positions
    81     81           dPos = {}   # key: iGroup, value: iToken
    82     82           iGroup = 0
    83     83           for i, sToken in enumerate(lToken):
    84     84               if sToken.startswith("(") and sToken.endswith(")"):
    85     85                   lToken[i] = sToken[1:-1]
    86     86                   iGroup += 1
................................................................................
   221    221           ## no action, break loop if condition is False
   222    222           return [sOption, sCondition, cAction, ""]
   223    223       else:
   224    224           print("# Unknown action at line " + sIdAction)
   225    225           return None
   226    226   
   227    227   
   228         -def make (lRule, sLang, bJavaScript):
          228  +def make (lRule, dDef, sLang, bJavaScript):
   229    229       "compile rules, returns a dictionary of values"
   230    230       # for clarity purpose, don’t create any file here
   231    231   
   232    232       # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines
   233    233       print("  parsing rules...")
   234    234       lTokenLine = []
   235    235       sActions = ""
................................................................................
   292    292               print(sLine)
   293    293   
   294    294       # processing rules
   295    295       print("  preparing rules...")
   296    296       for sGraphName, lRuleLine in dAllGraph.items():
   297    297           lPreparedRule = []
   298    298           for i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority in lRuleLine:
   299         -            for lRule in createRule(i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority):
          299  +            for lRule in createRule(i, sRuleGroup, sTokenLine, iActionBlock, sActions, nPriority, dDef):
   300    300                   lPreparedRule.append(lRule)
   301    301           # Show rules
   302    302           for e in lPreparedRule:
   303    303               print(e)
   304    304           # Graph creation
   305    305           oDARG = darg.DARG(lPreparedRule, sLang)
   306    306           dAllGraph[sGraphName] = oDARG.createGraph()

Modified gc_core/py/lang_core/gc_engine.py from [c27f614a0d] to [4c2d49e047].

   706    706                                   if nErrorStart not in dErrs or eAct[2] > dPriority[nErrorStart]:
   707    707                                       dErrs[nErrorStart] = self.createError(sWhat, nTokenOffset, nTokenErrorStart, nErrorStart, nErrorEnd, sLineId, sRuleId, True, eAct[3], eAct[4], bShowRuleId, "notype", bContext)
   708    708                                       dPriority[nErrorStart] = eAct[2]
   709    709                                       if bDebug:
   710    710                                           print("-", sRuleId, dErrs[nErrorStart])
   711    711                               elif cActionType == "~":
   712    712                                   # text processor
   713         -                                self._tagAndPrepareTokenForRewriting(sWhat, nTokenOffset + eAct[0], nTokenOffset + eAct[1])
          713  +                                self._tagAndPrepareTokenForRewriting(sWhat, nTokenOffset + eAct[0], nTokenOffset + eAct[1], bDebug)
   714    714                                   if bDebug:
   715    715                                       print("~", sRuleId)
   716    716                                   bChange = True
   717    717                               elif cActionType == "=":
   718    718                                   # disambiguation
   719    719                                   globals()[sWhat](self.lToken, nTokenOffset)
   720    720                                   if bDebug:
................................................................................
   727    727                               else:
   728    728                                   print("# error: unknown action at " + sLineId)
   729    729                           elif cActionType == ">":
   730    730                               if bDebug:
   731    731                                   print(">!", sRuleId)
   732    732                               break
   733    733                   except Exception as e:
   734         -                    raise Exception(str(e), sLineId)
          734  +                    raise Exception(str(e), sLineId, sRuleId, self.sSentence)
   735    735           return bChange, dErrs
   736    736   
   737    737       def _createWriterError (self, sSugg, nTokenOffset, iFirstToken, nStart, nEnd, sLineId, sRuleId, bUppercase, sMsg, sURL, bShowRuleId, sOption, bContext):
   738    738           "error for Writer (LO/OO)"
   739    739           xErr = SingleProofreadingError()
   740    740           #xErr = uno.createUnoStruct( "com.sun.star.linguistic2.SingleProofreadingError" )
   741    741           xErr.nErrorStart = nStart
................................................................................
   816    816       def _expand (self, sMsg, nTokenOffset):
   817    817           #print("*", sMsg)
   818    818           for m in re.finditer(r"\\([0-9]+)", sMsg):
   819    819               sMsg = sMsg.replace(m.group(0), self.lToken[int(m.group(1))+nTokenOffset]["sValue"])
   820    820           #print(">", sMsg)
   821    821           return sMsg
   822    822   
   823         -    def _tagAndPrepareTokenForRewriting (self, sWhat, nTokenRewriteStart, nTokenRewriteEnd, bUppercase=True):
          823  +    def _tagAndPrepareTokenForRewriting (self, sWhat, nTokenRewriteStart, nTokenRewriteEnd, bUppercase=True, bDebug=False):
   824    824           "text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position"
          825  +        if bDebug:
          826  +            print("REWRITING:", nTokenRewriteStart, nTokenRewriteEnd)
   825    827           if sWhat == "*":
   826    828               # purge text
   827    829               if nTokenRewriteEnd - nTokenRewriteStart == 0:
   828    830                   self.lToken[nTokenRewriteStart]["bToRemove"] = True
   829    831               else:
   830    832                   for i in range(nTokenRewriteStart, nTokenRewriteEnd+1):
   831    833                       self.lToken[i]["bToRemove"] = True