Skip to content

Commit d19f3d6

Browse files
committed
add method
1 parent 08e1164 commit d19f3d6

File tree

1 file changed

+80
-4
lines changed

1 file changed

+80
-4
lines changed

python-pybind/src/dictionary/py_dictionary.cpp

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,88 @@ void init_keyvi_dictionary(const py::module_ &m) {
4242

4343
py::class_<kd::Dictionary>(m, "Dictionary")
4444
.def(py::init<const std::string &>())
45+
.def(
46+
"complete_fuzzy_multiword",
47+
[](const kd::Dictionary &d, const std::string &query, const int32_t max_edit_distance,
48+
const size_t minimum_exact_prefix = 0, const unsigned char multiword_separator = 0x1b) {
49+
auto m = d.GetFuzzyMultiwordCompletion(query, max_edit_distance, minimum_exact_prefix, multiword_separator);
50+
return kpy::make_match_iterator(m.begin(), m.end());
51+
},
52+
py::arg("query"), py::arg("max_edit_distance"), py::arg("minimum_exact_prefix") = 0,
53+
py::arg("multiword_separator") = 0x1b,
54+
R"pbdoc(Complete the given key to full matches after whitespace tokenizing,
55+
allowing up to max_edit_distance distance(Levenshtein).
56+
In case the used dictionary supports inner weights, the
57+
completer traverses the dictionary according to weights,
58+
otherwise byte-order.
59+
)pbdoc")
60+
.def(
61+
"complete_multiword",
62+
[](const kd::Dictionary &d, const std::string &query, const unsigned char multiword_separator = 0x1b) {
63+
auto m = d.GetMultiwordCompletion(query, multiword_separator);
64+
return kpy::make_match_iterator(m.begin(), m.end());
65+
},
66+
py::arg("query"), py::arg("multiword_separator") = 0x1b,
67+
R"pbdoc(Complete the given key to full matches after whitespace tokenizing
68+
and return the top n completions.
69+
In case the used dictionary supports inner weights, the
70+
completer traverses the dictionary according to weights,
71+
otherwise byte-order.
72+
73+
Note, due to depth-first traversal the traverser
74+
immediately yields results when it visits them. The results are
75+
neither in order nor limited to n. It is up to the caller to resort
76+
and truncate the lists of results.
77+
Only the number of top completions is guaranteed.
78+
)pbdoc")
79+
.def(
80+
"complete_prefix",
81+
[](const kd::Dictionary &d, const std::string &query) {
82+
auto m = d.GetPrefixCompletion(query);
83+
return kpy::make_match_iterator(m.begin(), m.end());
84+
},
85+
py::arg("query"),
86+
R"pbdoc(Complete the given key to full matches after whitespace tokenizing
87+
and return the top n completions.
88+
In case the used dictionary supports inner weights, the
89+
completer traverses the dictionary according to weights,
90+
otherwise byte-order.
91+
92+
Note, due to depth-first traversal the traverser
93+
immediately yields results when it visits them. The results are
94+
neither in order nor limited to n. It is up to the caller to resort
95+
and truncate the lists of results.
96+
Only the number of top completions is guaranteed.
97+
)pbdoc")
98+
.def(
99+
"complete_prefix",
100+
[](const kd::Dictionary &d, const std::string &query, size_t top_n) {
101+
auto m = d.GetPrefixCompletion(query, top_n);
102+
return kpy::make_match_iterator(m.begin(), m.end());
103+
},
104+
py::arg("query"), py::arg("top_n"),
105+
R"pbdoc(Complete the given key to full matches after whitespace tokenizing
106+
and return the top n completions.
107+
In case the used dictionary supports inner weights, the
108+
completer traverses the dictionary according to weights,
109+
otherwise byte-order.
110+
111+
Note, due to depth-first traversal the traverser
112+
immediately yields results when it visits them. The results are
113+
neither in order nor limited to n. It is up to the caller to resort
114+
and truncate the lists of results.
115+
Only the number of top completions is guaranteed.
116+
)pbdoc")
45117
.def("get", &kd::Dictionary::operator[], R"pbdoc(
46118
Get an entry from the dictionary.
47119
)pbdoc")
120+
// 'items', 'keys', 'manifest', 'match_fuzzy', 'match_near',
121+
.def("match",
122+
[](const kd::Dictionary &d, const std::string &key) {
123+
auto m = d.Get(key);
124+
return kpy::make_match_iterator(m.begin(), m.end());
125+
})
48126
.def("search", &kd::Dictionary::Lookup)
49-
.def("match", [](const kd::Dictionary &d, const std::string &key) {
50-
auto m = d.Get(key);
51-
return kpy::make_match_iterator(m.begin(), m.end());
52-
});
127+
// 'search_tokenized', 'statistics', 'values'
128+
;
53129
}

0 commit comments

Comments
 (0)