Exemplo n.º 1
0
 def _encodeInterps4Type(self, typenum, interpsList):
     res = bytearray()
     res.extend(self._encodeTypeNum(typenum))
     encodedInterpsList = bytearray()
     for interp in sorted(interpsList, key=lambda i: i.getSortKey()):
         encodedInterpsList.extend(serializeString(interp.homonymId))
         encodedInterpsList.extend(serializeString(interp.encodedForm.prefixToAdd))
         encodedInterpsList.append(interp.encodedForm.cutLength)
         encodedInterpsList.extend(serializeString(interp.encodedForm.suffixToAdd))
         encodedInterpsList.extend(htons(interp.tagnum))
         encodedInterpsList.append(interp.namenum)
         encodedInterpsList.extend(htons(interp.qualifiers))
     
     res.extend(htons(len(encodedInterpsList)))
     res.extend(encodedInterpsList)
     return res
Exemplo n.º 2
0
 def _encodeInterps4Type(self, typenum, interpsList):
     res = bytearray()
     res.extend(self._encodeTypeNum(typenum))
     
     encodedInterpsList = bytearray()
     
     orthCasePatterns = set([tuple(interp.orthCasePattern) for interp in interpsList])
     lemmaCasePatterns = set([tuple(interp.encodedForm.casePattern) for interp in interpsList])
     prefixCuts = set([interp.encodedForm.prefixCutLength for interp in interpsList])
     
     encodedInterpsList.append(self._encodeCompressByte(orthCasePatterns, lemmaCasePatterns, prefixCuts))
     
     if not self._casePatternsAreEncodedInCompressByte(orthCasePatterns):
         minOrthCasePatterns = self._getMinOrthCasePatterns(interpsList)
         encodedInterpsList.append(len(minOrthCasePatterns))
         for casePattern in minOrthCasePatterns:
             encodedInterpsList.extend(self._encodeCasePattern(casePattern))
     
     for interp in sorted(interpsList, key=lambda i: i.getSortKey()):
         if not self._casePatternsAreEncodedInCompressByte(orthCasePatterns):
             encodedInterpsList.extend(self._encodeCasePattern(interp.orthCasePattern))
         if not self._prefixCutsAreEncodedInCompressByte(prefixCuts):
             encodedInterpsList.append(interp.encodedForm.prefixCutLength)
         encodedInterpsList.append(interp.encodedForm.cutLength)
         encodedInterpsList.extend(serializeString(interp.encodedForm.suffixToAdd))
         if not self._casePatternsAreEncodedInCompressByte(lemmaCasePatterns):
             encodedInterpsList.extend(self._encodeCasePattern(interp.encodedForm.casePattern))
         encodedInterpsList.extend(htons(interp.tagnum))
         encodedInterpsList.append(interp.namenum)
         encodedInterpsList.extend(htons(interp.qualifiers))
     
     res.extend(htons(len(encodedInterpsList)))
     res.extend(encodedInterpsList)
     return res