def read_8bitfloat(self, mantissabits=5, zeroexp=2): """Reads a byte-sized representation of a floating point value. :param mantissabits: the number of bits to use for the mantissa (with the rest used for the exponent). :param zeroexp: the zero point for the exponent. """ return byte_to_float(self.read_byte(), mantissabits, zeroexp)
def decode_position_boosts(self, valuestring): f = six.StringIO(valuestring) read = f.read freq = unpack("!I", read(_INT_SIZE))[0] # Skip summed boost f.seek(_FLOAT_SIZE, 1) position = 0 posns_boosts = [] for _ in range(freq): position = read_varint(read) + position boost = byte_to_float(read(1)) posns_boosts.append((position, boost)) return posns_boosts
def decode_position_boosts(self, valuestring): f = StringIO(valuestring) read = f.read freq = unpack("!I", read(_INT_SIZE))[0] # Skip summed boost f.seek(_FLOAT_SIZE, 1) position = 0 posns_boosts = [] for _ in xrange(freq): position = read_varint(read) + position boost = byte_to_float(read(1)) posns_boosts.append((position, boost)) return posns_boosts
def decode_character_boosts(self, valuestring): f = six.StringIO(valuestring) read = f.read freq = unpack("!I", read(_INT_SIZE))[0] # Skip summed boost f.seek(_FLOAT_SIZE, 1) position = 0 endchar = 0 posns_chars = [] for _ in range(freq): position = read_varint(read) + position startchar = endchar + read_varint(read) endchar = startchar + read_varint(read) boost = byte_to_float(read(1)) posns_chars.append((position, startchar, endchar, boost)) return posns_chars
def decode_character_boosts(self, valuestring): f = StringIO(valuestring) read = f.read freq = unpack("!I", read(_INT_SIZE))[0] # Skip summed boost f.seek(_FLOAT_SIZE, 1) position = 0 endchar = 0 posns_chars = [] for _ in xrange(freq): position = read_varint(read) + position startchar = endchar + read_varint(read) endchar = startchar + read_varint(read) boost = byte_to_float(read(1)) posns_chars.append((position, startchar, endchar, boost)) return posns_chars
def decode_weight(self, valuestring): freq = unpack("!I", valuestring[:_INT_SIZE])[0] docboost = byte_to_float(valuestring[-1]) return freq * docboost * self.field_boost
def decode_docboosts(self, valuestring): freq = unpack("!I", valuestring[:_INT_SIZE])[0] docboost = byte_to_float(valuestring[-1]) return (freq, docboost)