Skip to content

Commit

Permalink
Merge pull request cliqz-oss#111 from narek-cliqz/snappy_and_zlib_usa…
Browse files Browse the repository at this point in the history
…ge_elimination_from_cython

eliminated pykeyvi dependencies on snappy and zlib
  • Loading branch information
hendrikmuhs authored Aug 22, 2016
2 parents 2b6bffc + f2cd717 commit 65a7035
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 745 deletions.
9 changes: 9 additions & 0 deletions keyvi/src/cpp/dictionary/match.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ struct Match {
return fsa_->GetRawValueAsString(state_);
}

std::string GetMsgPackedValueAsString() const {
const std::string raw_value = GetRawValueAsString();
if (raw_value.empty()) {
return raw_value;
}
const compression::decompress_func_t decompressor = compression::decompressor_by_code(raw_value);
return decompressor(raw_value);
}

/**
* being able to set the value, e.g. when keyvi is used over network boundaries
*
Expand Down
1 change: 0 additions & 1 deletion pykeyvi/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def run(self):

install_requires = [
'msgpack-python',
'python-snappy',
]

setup(
Expand Down
15 changes: 3 additions & 12 deletions pykeyvi/src/addons/Match.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,11 @@

def GetValue(self):
"""Decodes a keyvi value and returns it."""
value = self.inst.get().GetRawValueAsString()
if value is None or len(value) == 0:
cdef libcpp_string packed_value = self.inst.get().GetMsgPackedValueAsString()
if packed_value.empty():
return None

elif value[0] == '\x00':
return msgpack.loads(value[1:])

elif value[0] == '\x01':
value = zlib.decompress(value[1:])

elif value[0] == '\x02':
value = snappy.decompress(value[1:])

return msgpack.loads(value)
return msgpack.loads(packed_value)


def dumps(self):
Expand Down
2 changes: 0 additions & 2 deletions pykeyvi/src/addons/autwrap_workarounds.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ from libc.stdint cimport uint32_t

import json
import msgpack
import zlib
import snappy
1 change: 1 addition & 0 deletions pykeyvi/src/pxds/match.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cdef extern from "dictionary/match.h" namespace "keyvi::dictionary":
PyObject* GetAttributePy(libcpp_string) nogil except + # wrap-ignore
libcpp_string GetValueAsString() except +
libcpp_string GetRawValueAsString() except +
libcpp_string GetMsgPackedValueAsString() except + # wrap-ignore
void SetRawValue(libcpp_string) except + # wrap-ignore
void SetAttribute(libcpp_string, libcpp_string) except + # wrap-ignore
void SetAttribute(libcpp_string, float) except + # wrap-ignore
Expand Down
Loading

0 comments on commit 65a7035

Please sign in to comment.