-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1st version of a python binding for index
- Loading branch information
Hendrik Muhs
committed
Jan 11, 2018
1 parent
1b94e55
commit b64feaf
Showing
11 changed files
with
144 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
|
||
def get (self, key, default = None): | ||
if isinstance(key, unicode): | ||
key = key.encode('utf-8') | ||
assert isinstance(key, bytes), 'arg in_0 wrong type' | ||
|
||
cdef shared_ptr[_Match] _r = shared_ptr[_Match](new _Match(deref(self.inst.get())[(<libcpp_string>key)])) | ||
|
||
if _r.get().IsEmpty(): | ||
return default | ||
cdef Match py_result = Match.__new__(Match) | ||
py_result.inst = _r | ||
return py_result | ||
|
||
def __contains__(self, key): | ||
if isinstance(key, unicode): | ||
key = key.encode('utf-8') | ||
|
||
assert isinstance(key, bytes), 'arg in_0 wrong type' | ||
|
||
return self.inst.get().Contains(key) | ||
|
||
def __getitem__ (self, key): | ||
if isinstance(key, unicode): | ||
key = key.encode('utf-8') | ||
|
||
assert isinstance(key, bytes), 'arg in_0 wrong type' | ||
|
||
cdef shared_ptr[_Match] _r = shared_ptr[_Match](new _Match(deref(self.inst.get())[(<libcpp_string>key)])) | ||
|
||
if _r.get().IsEmpty(): | ||
raise KeyError(key) | ||
cdef Match py_result = Match.__new__(Match) | ||
py_result.inst = _r | ||
return py_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from libcpp.string cimport string as libcpp_utf8_string | ||
|
||
cdef extern from "index/index.h" namespace "keyvi::index": | ||
cdef cppclass Index: | ||
Index(libcpp_utf8_string) except+ | ||
void Set(libcpp_utf8_string, libcpp_utf8_string) except+ | ||
void Flush() |
Oops, something went wrong.