Grammalecte  Check-in [c6b8ff879e]

Overview
Comment:[build] move code about DARGs in darg.py
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | build | rg
Files: files | file ages | folders
SHA3-256: c6b8ff879e8cd12f8b9dec8e6e67e70849d4261cb0f9953936ca8cc09e7bebf9
User & Date: olr on 2018-06-26 04:44:17
Other Links: branch diff | manifest | tags
Context
2018-06-26
06:23
[fr] conversion: regex rules -> graph rules check-in: f576d56463 user: olr tags: fr, rg
04:44
[build] move code about DARGs in darg.py check-in: c6b8ff879e user: olr tags: build, rg
04:42
[fr] erreurs de frappe check-in: 9ecb48dd7f user: olr tags: fr, rg
Changes

Modified compile_rules_graph.py from [9d41dade40] to [ad40703abe].

   258    258           dFUNCTIONS["_g_d_"+sActionId] = sAction
   259    259           sAction = "_g_d_"+sActionId
   260    260           return [sOption, sCondition, cAction, sAction]
   261    261       else:
   262    262           print("# Unknown action at line " + sActionId)
   263    263           return None
   264    264   
   265         -
   266         -def rewriteKeysOfDARGs (dAllGraph):
   267         -    "keys of DARGs are long numbers (hash): this function replace these hashes with smaller numbers (to reduce storing)"
   268         -    dAllNewGraph = {}
   269         -    for sGraphName, dGraph in dAllGraph.items():
   270         -        # create translation dictionary
   271         -        dKeyTrans = {}
   272         -        for i, nKey in enumerate(dGraph):
   273         -            dKeyTrans[nKey] = i
   274         -        # replace keys
   275         -        dNewGraph = {}
   276         -        for nKey, dVal in dGraph.items():
   277         -            dNewGraph[dKeyTrans[nKey]] = dVal
   278         -        for nKey, dVal in dGraph.items():
   279         -            for sArc, val in dVal.items():
   280         -                if type(val) is int:
   281         -                    dVal[sArc] = dKeyTrans[val]
   282         -                else:
   283         -                    for sArc, nKey in val.items():
   284         -                        val[sArc] = dKeyTrans[nKey]
   285         -        dAllNewGraph[sGraphName] = dNewGraph
   286         -    return dAllNewGraph
   287         -
   288    265   
   289    266   def make (lRule, dDef, sLang, bJavaScript):
   290    267       "compile rules, returns a dictionary of values"
   291    268       # for clarity purpose, don’t create any file here
   292    269   
   293    270       # removing comments, zeroing empty lines, creating definitions, storing tests, merging rule lines
   294    271       print("  parsing rules...")
................................................................................
   402    379               print(sActionName, aAction)
   403    380           print("\nFunctions:")
   404    381           print(sPyCallables)
   405    382   
   406    383       # Result
   407    384       return {
   408    385           "graph_callables": sPyCallables,
   409         -        "rules_graphs": rewriteKeysOfDARGs(dAllGraph),
          386  +        "rules_graphs": dAllGraph,
   410    387           "rules_actions": dACTIONS
   411    388       }

Modified darg.py from [5a6ef5f70e] to [5064c8e027].

   115    115           for oNode in self.lMinimizedNodes:
   116    116               sHashId = oNode.__hash__()
   117    117               if sHashId not in dGraph:
   118    118                   dGraph[sHashId] = oNode.getNodeAsDict()
   119    119               else:
   120    120                   print("Error. Double node… same id: ", sHashId)
   121    121                   print(str(oNode.getNodeAsDict()))
          122  +        dGraph = self._rewriteKeysOfDARG(dGraph)
   122    123           return dGraph
   123    124   
          125  +    def _rewriteKeysOfDARG (self, dGraph):
          126  +        "keys of DARG are long numbers (hashes): this function replace these hashes with smaller numbers (to reduce storing size)"
          127  +        # create translation dictionary
          128  +        dKeyTrans = {}
          129  +        for i, nKey in enumerate(dGraph):
          130  +            dKeyTrans[nKey] = i
          131  +        # replace keys
          132  +        dNewGraph = {}
          133  +        for nKey, dVal in dGraph.items():
          134  +            dNewGraph[dKeyTrans[nKey]] = dVal
          135  +        for nKey, dVal in dGraph.items():
          136  +            for sArc, val in dVal.items():
          137  +                if type(val) is int:
          138  +                    dVal[sArc] = dKeyTrans[val]
          139  +                else:
          140  +                    for sArc, nKey in val.items():
          141  +                        val[sArc] = dKeyTrans[nKey]
          142  +        return dNewGraph
   124    143   
   125    144   
   126    145   class Node:
   127    146       """Node of the rule graph"""
   128    147   
   129    148       NextId = 0
   130    149