Index: compile_rules_graph.py ================================================================== --- compile_rules_graph.py +++ compile_rules_graph.py @@ -260,33 +260,10 @@ return [sOption, sCondition, cAction, sAction] else: print("# Unknown action at line " + sActionId) return None - -def rewriteKeysOfDARGs (dAllGraph): - "keys of DARGs are long numbers (hash): this function replace these hashes with smaller numbers (to reduce storing)" - dAllNewGraph = {} - for sGraphName, dGraph in dAllGraph.items(): - # create translation dictionary - dKeyTrans = {} - for i, nKey in enumerate(dGraph): - dKeyTrans[nKey] = i - # replace keys - dNewGraph = {} - for nKey, dVal in dGraph.items(): - dNewGraph[dKeyTrans[nKey]] = dVal - for nKey, dVal in dGraph.items(): - for sArc, val in dVal.items(): - if type(val) is int: - dVal[sArc] = dKeyTrans[val] - else: - for sArc, nKey in val.items(): - val[sArc] = dKeyTrans[nKey] - dAllNewGraph[sGraphName] = dNewGraph - return dAllNewGraph - def make (lRule, dDef, sLang, bJavaScript): "compile rules, returns a dictionary of values" # for clarity purpose, don’t create any file here @@ -404,8 +381,8 @@ print(sPyCallables) # Result return { "graph_callables": sPyCallables, - "rules_graphs": rewriteKeysOfDARGs(dAllGraph), + "rules_graphs": dAllGraph, "rules_actions": dACTIONS } Index: darg.py ================================================================== --- darg.py +++ darg.py @@ -117,12 +117,31 @@ if sHashId not in dGraph: dGraph[sHashId] = oNode.getNodeAsDict() else: print("Error. Double node… same id: ", sHashId) print(str(oNode.getNodeAsDict())) + dGraph = self._rewriteKeysOfDARG(dGraph) return dGraph + def _rewriteKeysOfDARG (self, dGraph): + "keys of DARG are long numbers (hashes): this function replace these hashes with smaller numbers (to reduce storing size)" + # create translation dictionary + dKeyTrans = {} + for i, nKey in enumerate(dGraph): + dKeyTrans[nKey] = i + # replace keys + dNewGraph = {} + for nKey, dVal in dGraph.items(): + dNewGraph[dKeyTrans[nKey]] = dVal + for nKey, dVal in dGraph.items(): + for sArc, val in dVal.items(): + if type(val) is int: + dVal[sArc] = dKeyTrans[val] + else: + for sArc, nKey in val.items(): + val[sArc] = dKeyTrans[nKey] + return dNewGraph class Node: """Node of the rule graph"""