def getInflectionGroups(self, mainEntry, controlByteCount, tagTable, dinfl, inflectionNames, groupList): ''' Create string which contains the inflection groups with inflection rules as mobipocket tags. @param mainEntry: The word to inflect. @param controlByteCount: The number of control bytes. @param tagTable: The tag table. @param data: The Inflection data object to properly select the right inflection data section to use @param inflectionNames: The inflection rule name data. @param groupList: The list of inflection groups to process. @return: String with inflection groups and rules or empty string if required tags are not available. ''' result = "" for value in groupList: offset, nextOffset, data = dinfl.offsets(value) # First byte seems to be always 0x00 and must be skipped. assert ord(data[offset]) == 0x00 tagMap = getTagMap(controlByteCount, tagTable, data, offset + 1, nextOffset) # Make sure that the required tags are available. if 0x05 not in tagMap: print "Error: Required tag 0x05 not found in tagMap" return "" if 0x1a not in tagMap: print "Error: Required tag 0x1a not found in tagMap" return "" result += "<idx:infl>" for i in range(len(tagMap[0x05])): # Get name of inflection rule. value = tagMap[0x05][i] consumed, textLength = getVariableWidthValue( inflectionNames, value) inflectionName = inflectionNames[value + consumed:value + consumed + textLength] # Get and apply inflection rule across possibly multiple inflection data sections value = tagMap[0x1a][i] rvalue, start, count, data = dinfl.lookup(value) offset, = struct.unpack_from('>H', data, start + 4 + (2 * rvalue)) textLength = ord(data[offset]) inflection = self.applyInflectionRule(mainEntry, data, offset + 1, offset + 1 + textLength) if inflection is not None: result += ' <idx:iform name="%s" value="%s"/>' % ( inflectionName, inflection) result += "</idx:infl>" return result
def getInflectionGroups(self, mainEntry, controlByteCount, tagTable, data, inflectionNames, groupList): ''' Create string which contains the inflection groups with inflection rules as mobipocket tags. @param mainEntry: The word to inflect. @param controlByteCount: The number of control bytes. @param tagTable: The tag table. @param data: The inflection index data. @param inflectionNames: The inflection rule name data. @param groupList: The list of inflection groups to process. @return: String with inflection groups and rules or empty string if required tags are not available. ''' result = "" idxtPos, = struct.unpack_from('>L', data, 0x14) entryCount, = struct.unpack_from('>L', data, 0x18) for value in groupList: offset, = struct.unpack_from('>H', data, idxtPos + 4 + (2 * value)) if value + 1 < entryCount: nextOffset, = struct.unpack_from('>H', data, idxtPos + 4 + (2 * (value + 1))) else: nextOffset = None # First byte seems to be always 0x00 and must be skipped. assert ord(data[offset]) == 0x00 tagMap = getTagMap(controlByteCount, tagTable, data, offset + 1, nextOffset) # Make sure that the required tags are available. if 0x05 not in tagMap: print "Error: Required tag 0x05 not found in tagMap" return "" if 0x1a not in tagMap: print "Error: Required tag 0x1a not found in tagMap" return "" result += "<idx:infl>" for i in range(len(tagMap[0x05])): # Get name of inflection rule. value = tagMap[0x05][i] consumed, textLength = getVariableWidthValue(inflectionNames, value) inflectionName = inflectionNames[value+consumed:value+consumed+textLength] # Get and apply inflection rule. value = tagMap[0x1a][i] offset, = struct.unpack_from('>H', data, idxtPos + 4 + (2 * value)) textLength = ord(data[offset]) inflection = self.applyInflectionRule(mainEntry, data, offset+1, offset+1+textLength) if inflection != None: result += ' <idx:iform name="%s" value="%s"/>' % (inflectionName, inflection) result += "</idx:infl>" return result
def getInflectionGroups(self, mainEntry, controlByteCount, tagTable, dinfl, inflectionNames, groupList): ''' Create string which contains the inflection groups with inflection rules as mobipocket tags. @param mainEntry: The word to inflect. @param controlByteCount: The number of control bytes. @param tagTable: The tag table. @param data: The Inflection data object to properly select the right inflection data section to use @param inflectionNames: The inflection rule name data. @param groupList: The list of inflection groups to process. @return: String with inflection groups and rules or empty string if required tags are not available. ''' result = "" for value in groupList: offset, nextOffset, data = dinfl.offsets(value) # First byte seems to be always 0x00 and must be skipped. assert ord(data[offset]) == 0x00 tagMap = getTagMap(controlByteCount, tagTable, data, offset + 1, nextOffset) # Make sure that the required tags are available. if 0x05 not in tagMap: print "Error: Required tag 0x05 not found in tagMap" return "" if 0x1a not in tagMap: print "Error: Required tag 0x1a not found in tagMap" return "" result += "<idx:infl>" for i in range(len(tagMap[0x05])): # Get name of inflection rule. value = tagMap[0x05][i] consumed, textLength = getVariableWidthValue(inflectionNames, value) inflectionName = inflectionNames[value+consumed:value+consumed+textLength] # Get and apply inflection rule across possibly multiple inflection data sections value = tagMap[0x1a][i] rvalue, start, count, data = dinfl.lookup(value) offset, = struct.unpack_from('>H', data, start + 4 + (2 * rvalue)) textLength = ord(data[offset]) inflection = self.applyInflectionRule(mainEntry, data, offset+1, offset+1+textLength) if inflection is not None: result += ' <idx:iform name="%s" value="%s"/>' % (inflectionName, inflection) result += "</idx:infl>" return result
def getInflectionGroups(self, mainEntry, controlByteCount, tagTable, data, inflectionNames, groupList): ''' Create string which contains the inflection groups with inflection rules as mobipocket tags. @param mainEntry: The word to inflect. @param controlByteCount: The number of control bytes. @param tagTable: The tag table. @param data: The inflection index data. @param inflectionNames: The inflection rule name data. @param groupList: The list of inflection groups to process. @return: String with inflection groups and rules or empty string if required tags are not available. ''' result = "" idxtPos, = struct.unpack_from('>L', data, 0x14) entryCount, = struct.unpack_from('>L', data, 0x18) for value in groupList: offset, = struct.unpack_from('>H', data, idxtPos + 4 + (2 * value)) if value + 1 < entryCount: nextOffset, = struct.unpack_from( '>H', data, idxtPos + 4 + (2 * (value + 1))) else: nextOffset = None # First byte seems to be always 0x00 and must be skipped. assert ord(data[offset]) == 0x00 tagMap = getTagMap(controlByteCount, tagTable, data, offset + 1, nextOffset) # Make sure that the required tags are available. if 0x05 not in tagMap: print "Error: Required tag 0x05 not found in tagMap" return "" if 0x1a not in tagMap: print "Error: Required tag 0x1a not found in tagMap" return "" result += "<idx:infl>" for i in range(len(tagMap[0x05])): # Get name of inflection rule. value = tagMap[0x05][i] consumed, textLength = getVariableWidthValue( inflectionNames, value) inflectionName = inflectionNames[value + consumed:value + consumed + textLength] # Get and apply inflection rule. value = tagMap[0x1a][i] offset, = struct.unpack_from('>H', data, idxtPos + 4 + (2 * value)) textLength = ord(data[offset]) inflection = self.applyInflectionRule(mainEntry, data, offset + 1, offset + 1 + textLength) if inflection != None: result += ' <idx:iform name="%s" value="%s"/>' % ( inflectionName, inflection) result += "</idx:infl>" return result