def valuedecoder(self, v): if len(v) == _INT_SIZE: return (1.0, unpack_uint(v)[0], 1) elif len(v) == _terminfo_struct0.size: return _terminfo_struct0.unpack(v) elif len(v) == _terminfo_struct1.size: return _terminfo_struct1.unpack(v) else: return _terminfo_struct2.unpack(v)
def decode_positions(self, valuestring): read = StringIO(valuestring).read freq = unpack_uint(read(_INT_SIZE))[0] position = 0 positions = [] for _ in xrange(freq): position = read_varint(read) + position positions.append(position) return positions
def decode_characters(self, valuestring): read = StringIO(valuestring).read freq = unpack_uint(read(_INT_SIZE))[0] 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) posns_chars.append((position, startchar, endchar)) return posns_chars
def decode_position_boosts(self, valuestring): f = StringIO(valuestring) read = f.read freq = unpack_uint(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_positions(self, valuestring): f = StringIO(valuestring) read, seek = f.read, f.seek freq = unpack_uint(read(_INT_SIZE))[0] # Skip summed boost seek(_FLOAT_SIZE, 1) position = 0 positions = [] for _ in xrange(freq): position = read_varint(read) + position # Skip boost seek(1, 1) positions.append(position) return positions
def decode_character_boosts(self, valuestring): f = StringIO(valuestring) read = f.read freq = unpack_uint(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_docboosts(self, valuestring): freq = unpack_uint(valuestring[:_INT_SIZE])[0] docboost = byte_to_float(valuestring[-1]) return (freq, docboost)
def get_uint(self, position): return unpack_uint(self.map[position:position + _INT_SIZE])[0]
def read_uint(self): return unpack_uint(self.file.read(_INT_SIZE))[0]
def decode_frequency(self, valuestring): return unpack_uint(valuestring)[0]
def decode_weight(self, valuestring): freq = unpack_uint(valuestring[:_INT_SIZE])[0] docboost = byte_to_float(valuestring[-1]) return freq * docboost * self.field_boost
def get_uint(self, position): return unpack_uint(self.get(position, _INT_SIZE))[0]
def decode_frequency(self, valuestring): return unpack_uint(valuestring[:_INT_SIZE])[0]
def decode_weight(self, valuestring): freq = unpack_uint(valuestring)[0] return freq * self.field_boost