Grammalecte  Check-in [1b8133065d]

Overview
Comment:[graphspell][py] dawg: get JSON object instead of JSON string
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | graphspell | multid
Files: files | file ages | folders
SHA3-256: 1b8133065d4af345daae2530ec6745ee6f300163d68dd2490e33d58c0d3ed8e9
User & Date: olr on 2018-02-28 15:28:20
Other Links: branch diff | manifest | tags
Context
2018-02-28
15:29
[lo] lexicon editor: update check-in: 5cc5b32dc7 user: olr tags: lo, multid
15:28
[graphspell][py] dawg: get JSON object instead of JSON string check-in: 1b8133065d user: olr tags: graphspell, multid
10:34
[graphspell][py] ibdawg: init directly from an object (JSON) check-in: efd7bb0171 user: olr tags: graphspell, multid
Changes

Modified graphspell/dawg.py from [f1e3328ca8] to [5d3489a731].

   395    395               byDic = self.oRoot.convToBytes2(self.nBytesArc, self.nBytesNodeAddress)
   396    396               for oNode in self.lSortedNodes:
   397    397                   byDic += oNode.convToBytes2(self.nBytesArc, self.nBytesNodeAddress)
   398    398           elif nCompressionMethod == 3:
   399    399               byDic = self.oRoot.convToBytes3(self.nBytesArc, self.nBytesNodeAddress, self.nBytesOffset)
   400    400               for oNode in self.lSortedNodes:
   401    401                   byDic += oNode.convToBytes3(self.nBytesArc, self.nBytesNodeAddress, self.nBytesOffset)
   402         -        return json.dumps({ "sHeader": "/pyfsa/",
   403         -                            "sLangCode": self.sLangCode,
   404         -                            "sLangName": self.sLangName,
   405         -                            "sDicName": self.sDicName,
   406         -                            "sFileName": self.sFileName,
   407         -                            "sDate": self._getDate(),
   408         -                            "nEntry": self.nEntry,
   409         -                            "nChar": self.nChar,
   410         -                            "nAff": self.nAff,
   411         -                            "nTag": self.nTag,
   412         -                            "cStemming": self.cStemming,
   413         -                            "dChar": self.dChar,
   414         -                            "nNode": self.nNode,
   415         -                            "nArc": self.nArc,
   416         -                            "nArcVal": self.nArcVal,
   417         -                            "lArcVal": self.lArcVal,
   418         -                            "nCompressionMethod": nCompressionMethod,
   419         -                            "nBytesArc": self.nBytesArc,
   420         -                            "nBytesNodeAddress": self.nBytesNodeAddress,
   421         -                            "nBytesOffset": self.nBytesOffset,
   422         -                            # Mozilla’s JS parser don’t like file bigger than 4 Mb!
   423         -                            # So, if necessary, we use an hexadecimal string, that we will convert later in Firefox’s extension.
   424         -                            # https://github.com/mozilla/addons-linter/issues/1361
   425         -                            "sByDic": byDic.hex()  if bBinaryDictAsHexString  else [ e  for e in byDic ]
   426         -                        }, ensure_ascii=False)
   427         -
          402  +        return {
          403  +            "sHeader": "/pyfsa/",
          404  +            "sLangCode": self.sLangCode,
          405  +            "sLangName": self.sLangName,
          406  +            "sDicName": self.sDicName,
          407  +            "sFileName": self.sFileName,
          408  +            "sDate": self._getDate(),
          409  +            "nEntry": self.nEntry,
          410  +            "nChar": self.nChar,
          411  +            "nAff": self.nAff,
          412  +            "nTag": self.nTag,
          413  +            "cStemming": self.cStemming,
          414  +            "dChar": self.dChar,
          415  +            "nNode": self.nNode,
          416  +            "nArc": self.nArc,
          417  +            "nArcVal": self.nArcVal,
          418  +            "lArcVal": self.lArcVal,
          419  +            "nCompressionMethod": nCompressionMethod,
          420  +            "nBytesArc": self.nBytesArc,
          421  +            "nBytesNodeAddress": self.nBytesNodeAddress,
          422  +            "nBytesOffset": self.nBytesOffset,
          423  +            # Mozilla’s JS parser don’t like file bigger than 4 Mb!
          424  +            # So, if necessary, we use an hexadecimal string, that we will convert later in Firefox’s extension.
          425  +            # https://github.com/mozilla/addons-linter/issues/1361
          426  +            "sByDic": byDic.hex()  if bBinaryDictAsHexString  else [ e  for e in byDic ]
          427  +        }
   428    428   
   429    429       def writeAsJSObject (self, spfDst, nCompressionMethod, bInJSModule=False, bBinaryDictAsHexString=True):
   430    430           if not spfDst.endswith(".json"):
   431    431               spfDst += "."+str(nCompressionMethod)+".json"
   432    432           with open(spfDst, "w", encoding="utf-8", newline="\n") as hDst:
   433    433               if bInJSModule:
   434    434                   hDst.write('// JavaScript\n// Generated data (do not edit)\n\n"use strict";\n\nconst dictionary = ')
   435         -            hDst.write( self.getBinaryAsJSON(nCompressionMethod, bBinaryDictAsHexString) )
          435  +            hDst.write( json.dumps(self.getBinaryAsJSON(nCompressionMethod, bBinaryDictAsHexString), ensure_ascii=False) )
   436    436               if bInJSModule:
   437    437                   hDst.write(";\n\nexports.dictionary = dictionary;\n")
   438    438   
   439    439       def writeBinary (self, sPathFile, nCompressionMethod, bDebug=False):
   440    440           """
   441    441           Format of the binary indexable dictionary:
   442    442           Each section is separated with 4 bytes of \0