Grammalecte  Check-in [5a15898d11]

Overview
Comment:[core] rename parameter tags -> aTags
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | rg
Files: files | file ages | folders
SHA3-256: 5a15898d113cdcbf3ade04bd4ea0e563ad34b463fb19dfd68272ba386229449e
User & Date: olr on 2018-09-12 10:38:22
Other Links: branch diff | manifest | tags
Context
2018-09-12
17:21
[core][js] gc engine: fix several issues check-in: 900ff7dc44 user: olr tags: core, rg
10:38
[core] rename parameter tags -> aTags check-in: 5a15898d11 user: olr tags: core, rg
09:49
[core][js] small code cleaning check-in: 05090f91ec user: olr tags: core, rg
Changes

Modified gc_core/js/lang_core/gc_engine.js from [225ec72077] to [eabdda0297].

   183    183           s += "sentence: " + this.sSentence0 + "\n";
   184    184           s += "now:      " + this.sSentence  + "\n";
   185    185           for (let dToken of this.lToken) {
   186    186               s += `#${dToken["i"]}\t${dToken["nStart"]}:${dToken["nEnd"]}\t${dToken["sValue"]}\t${dToken["sType"]}`;
   187    187               if (dToken.hasOwnProperty("lMorph")) {
   188    188                   s += "\t" + dToken["lMorph"].toString();
   189    189               }
   190         -            if (dToken.hasOwnProperty("tags")) {
   191         -                s += "\t" + dToken["tags"].toString();
          190  +            if (dToken.hasOwnProperty("aTags")) {
          191  +                s += "\t" + dToken["aTags"].toString();
   192    192               }
   193    193               s += "\n";
   194    194           }
   195    195           return s;
   196    196       }
   197    197   
   198    198       parse (sCountry="${country_default}", bDebug=false, dOptions=null, bContext=false) {
................................................................................
   336    336           // update <sSentence> and retokenize
   337    337           this.sSentence = sSentence;
   338    338           let lNewToken = Array.from(_oTokenizer.genTokens(sSentence, true));
   339    339           for (let dToken of lNewToken) {
   340    340               if (this.dTokenPos.gl_get(dToken["nStart"], {}).hasOwnProperty("lMorph")) {
   341    341                   dToken["lMorph"] = this.dTokenPos.get(dToken["nStart"])["lMorph"];
   342    342               }
   343         -            if (this.dTokenPos.gl_get(dToken["nStart"], {}).hasOwnProperty("tags")) {
   344         -                dToken["tags"] = this.dTokenPos.get(dToken["nStart"])["tags"];
          343  +            if (this.dTokenPos.gl_get(dToken["nStart"], {}).hasOwnProperty("aTags")) {
          344  +                dToken["aTags"] = this.dTokenPos.get(dToken["nStart"])["aTags"];
   345    345               }
   346    346           }
   347    347           this.lToken = lNewToken;
   348    348           this.dTokenPos.clear();
   349    349           for (let dToken of this.lToken) {
   350    350               if (dToken["sType"] != "INFO") {
   351    351                   this.dTokenPos.set(dToken["nStart"], dToken);
................................................................................
   483    483                                   }
   484    484                               }
   485    485                           }
   486    486                       }
   487    487                   }
   488    488               }
   489    489               // token tags
   490         -            if (dToken.hasOwnProperty("tags") && dNode.hasOwnProperty("<tags>")) {
   491         -                for (let sTag in dToken["tags"]) {
          490  +            if (dToken.hasOwnProperty("aTags") && dNode.hasOwnProperty("<tags>")) {
          491  +                for (let sTag in dToken["aTags"]) {
   492    492                       if (dNode["<tags>"].hasOwnProperty(sTag)) {
   493    493                           if (bDebug) {
   494    494                               console.log("  MATCH: /" + sTag);
   495    495                           }
   496    496                           yield { "iNode1": iNode1, "dNode": dGraph[dNode["<tags>"][sTag]] };
   497    497                           bTokenFound = true;
   498    498                       }
................................................................................
   635    635                                   }
   636    636                               }
   637    637                               else if (cActionType == "/") {
   638    638                                   // Tag
   639    639                                   let nTokenStart = (eAct[0] > 0) ? nTokenOffset + eAct[0] : nLastToken + eAct[0];
   640    640                                   let nTokenEnd = (eAct[1] > 0) ? nTokenOffset + eAct[1] : nLastToken + eAct[1];
   641    641                                   for (let i = nTokenStart; i <= nTokenEnd; i++) {
   642         -                                    if (this.lToken[i].hasOwnProperty("tags")) {
   643         -                                        this.lToken[i]["tags"].add(...sWhat.split("|"))
          642  +                                    if (this.lToken[i].hasOwnProperty("aTags")) {
          643  +                                        this.lToken[i]["aTags"].add(...sWhat.split("|"))
   644    644                                       } else {
   645         -                                        this.lToken[i]["tags"] = new Set(sWhat.split("|"));
          645  +                                        this.lToken[i]["aTags"] = new Set(sWhat.split("|"));
   646    646                                       }
   647    647                                   }
   648    648                                   if (bDebug) {
   649    649                                       console.log(`    TAG:  ${sWhat} > [${this.lToken[nTokenStart]["sValue"]}:${this.lToken[nTokenEnd]["sValue"]}]`);
   650    650                                   }
   651    651                                   if (!this.dTags.has(sWhat)) {
   652    652                                       this.dTags.set(sWhat, [nTokenStart, nTokenStart]);
................................................................................
  1246   1246       if (dToken["i"] < dTags.get(sTag)[1]) {
  1247   1247           return true;
  1248   1248       }
  1249   1249       return false;
  1250   1250   }
  1251   1251   
  1252   1252   function g_tag (dToken, sTag) {
  1253         -    return dToken.hasOwnProperty("tags") && dToken["tags"].has(sTag);
         1253  +    return dToken.hasOwnProperty("aTags") && dToken["aTags"].has(sTag);
  1254   1254   }
  1255   1255   
  1256   1256   function g_space_between_tokens (dToken1, dToken2, nMin, nMax=null) {
  1257   1257       let nSpace = dToken2["nStart"] - dToken1["nEnd"]
  1258   1258       if (nSpace < nMin) {
  1259   1259           return false;
  1260   1260       }

Modified gc_core/py/lang_core/gc_engine.py from [a6af5aa7ed] to [b63b69316e].

   229    229           s = "===== TEXT =====\n"
   230    230           s += "sentence: " + self.sSentence0 + "\n"
   231    231           s += "now:      " + self.sSentence  + "\n"
   232    232           for dToken in self.lToken:
   233    233               s += '#{i}\t{nStart}:{nEnd}\t{sValue}\t{sType}'.format(**dToken)
   234    234               if "lMorph" in dToken:
   235    235                   s += "\t" + str(dToken["lMorph"])
   236         -            if "tags" in dToken:
   237         -                s += "\t" + str(dToken["tags"])
          236  +            if "aTags" in dToken:
          237  +                s += "\t" + str(dToken["aTags"])
   238    238               s += "\n"
   239    239           #for nPos, dToken in self.dTokenPos.items():
   240    240           #    s += "{}\t{}\n".format(nPos, dToken)
   241    241           return s
   242    242   
   243    243       def parse (self, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False):
   244    244           "analyses the paragraph sText and returns list of errors"
................................................................................
   339    339       def update (self, sSentence, bDebug=False):
   340    340           "update <sSentence> and retokenize"
   341    341           self.sSentence = sSentence
   342    342           lNewToken = list(_oTokenizer.genTokens(sSentence, True))
   343    343           for dToken in lNewToken:
   344    344               if "lMorph" in self.dTokenPos.get(dToken["nStart"], {}):
   345    345                   dToken["lMorph"] = self.dTokenPos[dToken["nStart"]]["lMorph"]
   346         -            if "tags" in self.dTokenPos.get(dToken["nStart"], {}):
   347         -                dToken["tags"] = self.dTokenPos[dToken["nStart"]]["tags"]
          346  +            if "aTags" in self.dTokenPos.get(dToken["nStart"], {}):
          347  +                dToken["aTags"] = self.dTokenPos[dToken["nStart"]]["aTags"]
   348    348           self.lToken = lNewToken
   349    349           self.dTokenPos = { dToken["nStart"]: dToken  for dToken in self.lToken  if dToken["sType"] != "INFO" }
   350    350           if bDebug:
   351    351               echo("UPDATE:")
   352    352               echo(self)
   353    353   
   354    354       def _getNextPointers (self, dToken, dGraph, dPointer, bDebug=False):
................................................................................
   440    440                                   continue
   441    441                               if not sPattern or any(re.search(sPattern, sMorph)  for sMorph in lMorph):
   442    442                                   if bDebug:
   443    443                                       echo("  MATCH: @" + sRegex)
   444    444                                   yield { "iNode1": iNode1, "dNode": dGraph[dNode["<re_morph>"][sRegex]] }
   445    445                                   bTokenFound = True
   446    446           # token tags
   447         -        if "tags" in dToken and "<tags>" in dNode:
   448         -            for sTag in dToken["tags"]:
          447  +        if "aTags" in dToken and "<tags>" in dNode:
          448  +            for sTag in dToken["aTags"]:
   449    449                   if sTag in dNode["<tags>"]:
   450    450                       if bDebug:
   451    451                           echo("  MATCH: /" + sTag)
   452    452                       yield { "iNode1": iNode1, "dNode": dGraph[dNode["<tags>"][sTag]] }
   453    453                       bTokenFound = True
   454    454           # meta arc (for token type)
   455    455           if "<meta>" in dNode:
................................................................................
   553    553                                       echo("    COND_OK")
   554    554                                   pass
   555    555                               elif cActionType == "/":
   556    556                                   # Tag
   557    557                                   nTokenStart = nTokenOffset + eAct[0]  if eAct[0] > 0  else nLastToken + eAct[0]
   558    558                                   nTokenEnd = nTokenOffset + eAct[1]  if eAct[1] > 0  else nLastToken + eAct[1]
   559    559                                   for i in range(nTokenStart, nTokenEnd+1):
   560         -                                    if "tags" in self.lToken[i]:
   561         -                                        self.lToken[i]["tags"].update(sWhat.split("|"))
          560  +                                    if "aTags" in self.lToken[i]:
          561  +                                        self.lToken[i]["aTags"].update(sWhat.split("|"))
   562    562                                       else:
   563         -                                        self.lToken[i]["tags"] = set(sWhat.split("|"))
          563  +                                        self.lToken[i]["aTags"] = set(sWhat.split("|"))
   564    564                                   if bDebug:
   565    565                                       echo("    TAG: {} >  [{}:{}]".format(sWhat, self.lToken[nTokenStart]["sValue"], self.lToken[nTokenEnd]["sValue"]))
   566    566                                   if sWhat not in self.dTags:
   567    567                                       self.dTags[sWhat] = [nTokenStart, nTokenStart]
   568    568                                   else:
   569    569                                       self.dTags[sWhat][0] = min(nTokenStart, self.dTags[sWhat][0])
   570    570                                       self.dTags[sWhat][1] = max(nTokenEnd, self.dTags[sWhat][1])
................................................................................
  1035   1035           return False
  1036   1036       if dToken["i"] < dTags[sTag][1]:
  1037   1037           return True
  1038   1038       return False
  1039   1039   
  1040   1040   
  1041   1041   def g_tag (dToken, sTag):
  1042         -    return "tags" in dToken and sTag in dToken["tags"]
         1042  +    return "aTags" in dToken and sTag in dToken["aTags"]
  1043   1043   
  1044   1044   
  1045   1045   def g_space_between_tokens (dToken1, dToken2, nMin, nMax=None):
  1046   1046       nSpace = dToken2["nStart"] - dToken1["nEnd"]
  1047   1047       if nSpace < nMin:
  1048   1048           return False
  1049   1049       if nMax is not None and nSpace > nMax: