Grammalecte  Diff

Differences From Artifact [e3a97a1f63]:

To Artifact [02fc45c534]:


     3      3   """
     4      4   RULE GRAPH BUILDER
     5      5   """
     6      6   
     7      7   # by Olivier R.
     8      8   # License: MPL 2
     9      9   
           10  +import re
           11  +import traceback
           12  +
    10     13   
    11     14   from graphspell.progressbar import ProgressBar
    12     15   
    13     16   
    14     17   class DARG:
    15     18       """DIRECT ACYCLIC RULE GRAPH"""
    16     19       # This code is inspired from Steve Hanov’s DAWG, 2011. (http://stevehanov.ca/blog/index.php?id=115)
................................................................................
   138    141                   if type(val) is int:
   139    142                       dVal[sArc] = dKeyTrans[val]
   140    143                   else:
   141    144                       for sArc, nKey in val.items():
   142    145                           val[sArc] = dKeyTrans[nKey]
   143    146           return dNewGraph
   144    147   
   145         -    def _checkRegexes (dGraph):
          148  +    def _checkRegexes (self, dGraph):
   146    149           "check validity of regexes"
   147    150           aRegex = set()
   148    151           for nKey, dVal in dGraph.items():
   149    152               if "<re_value>" in dVal:
   150    153                   for sRegex in dVal["<re_value>"]:
   151    154                       if sRegex not in aRegex:
   152         -                        _checkRegex(sRegex)
          155  +                        self._checkRegex(sRegex)
   153    156                           aRegex.add(sRegex)
   154    157               if "<re_morph>" in dVal:
   155    158                   for sRegex in dVal["<re_morph>"]:
   156    159                       if sRegex not in aRegex:
   157         -                        _checkRegex(sRegex)
          160  +                        self._checkRegex(sRegex)
   158    161                           aRegex.add(sRegex)
   159    162           aRegex.clear()
   160    163   
   161         -    def _checkRegex (sRegex):
          164  +    def _checkRegex (self, sRegex):
   162    165           #print(sRegex)
   163    166           if "¬" in sRegex:
   164    167               sPattern, sNegPattern = sRegex.split("¬")
   165    168               try:
   166    169                   if not sNegPattern:
   167    170                       print("# Warning! Empty negpattern:", sRegex)
   168    171                   re.compile(sPattern)