Skip to content

Commit

Permalink
refactor MultiwordCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikmuhs committed Jan 26, 2025
1 parent 6755a04 commit 3d0b30f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions python/src/addons/MultiWordCompletion.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


def GetCompletions(self, *args):
return call_deprecated_method("GetCompletions", "get_completions", self.get_completions, *args)
4 changes: 2 additions & 2 deletions python/src/pxds/multi_word_completion.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from match_iterator cimport MatchIteratorPair as _MatchIteratorPair
cdef extern from "keyvi/dictionary/completion/multiword_completion.h" namespace "keyvi::dictionary::completion":
cdef cppclass MultiWordCompletion:
MultiWordCompletion(shared_ptr[Dictionary]) except +
_MatchIteratorPair GetCompletions(libcpp_utf8_string)
_MatchIteratorPair GetCompletions(libcpp_utf8_string, int)
_MatchIteratorPair GetCompletions(libcpp_utf8_string) # wrap-as:get_completions
_MatchIteratorPair GetCompletions(libcpp_utf8_string, int) # wrap-as:get_completions


6 changes: 3 additions & 3 deletions python/tests/completion/multiword_completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_mw_completion():
with tmp_dictionary(c, 'mw_completion.kv') as d:
mw = MultiWordCompletion(d)
matches = sorted([(match['weight'], match.matched_string)
for match in mw.GetCompletions("mozilla f")], reverse=True)
for match in mw.get_completions("mozilla f")], reverse=True)
assert len(matches) == 4
assert matches[0][1] == 'mozilla firefox'
assert matches[1][1] == 'mozilla fans'
Expand All @@ -46,7 +46,7 @@ def test_overlong_completion():
with tmp_dictionary(c, 'mw_overlong_completion.kv') as d:
mw = MultiWordCompletion(d)
matches = sorted([(match['weight'], match.matched_string)
for match in mw.GetCompletions("html dis")], reverse=True)
for match in mw.get_completions("html dis")], reverse=True)
assert len(matches) == 3
assert matches[0][1] == 'html disable'
assert matches[1][1] == 'html disabled'
Expand All @@ -60,5 +60,5 @@ def test_exact_match_without_completion():
c["maa" + '\x1b' + "maa"] = 80
with tmp_dictionary(c, 'test_exact_match_without_completion.kv') as d:
mw = MultiWordCompletion(d)
for m in mw.GetCompletions("mr "):
for m in mw.get_completions("mr "):
assert m.matched_string == b'mr'

0 comments on commit 3d0b30f

Please sign in to comment.