From 847a2ff7860381b9c598a09282bc21337c82a024 Mon Sep 17 00:00:00 2001 From: Meigyoku Thmn Date: Tue, 4 Dec 2018 11:40:57 +0700 Subject: [PATCH 1/2] fix cython build error --- src/dawg.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dawg.pyx b/src/dawg.pyx index 133c7fc..eb20c9f 100644 --- a/src/dawg.pyx +++ b/src/dawg.pyx @@ -86,7 +86,7 @@ cdef class DAWG: cpdef bint b_has_key(self, bytes key) except -1: return self.dct.Contains(key, len(key)) - cpdef bytes tobytes(self): + cpdef bytes tobytes(self) except +: """ Return raw DAWG content as bytes. """ From 4dbfe0a69a0415009b3b8b0c36a51e83bae7822d Mon Sep 17 00:00:00 2001 From: Meigyoku Thmn Date: Tue, 4 Dec 2018 11:43:18 +0700 Subject: [PATCH 2/2] expose root(), follow() and has_value() useful for keyword scanning and highlighting --- src/dawg.pyx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dawg.pyx b/src/dawg.pyx index eb20c9f..94ed327 100644 --- a/src/dawg.pyx +++ b/src/dawg.pyx @@ -176,6 +176,17 @@ cdef class DAWG: def _file_size(self): return self.dct.file_size() + + cpdef BaseType root(self): + return self.dct.root() + + cpdef (bint, BaseType) follow(self, unicode label, BaseType index): + cdef bytes _label = label.encode('utf8') + rs = self.dct.Follow(_label, &index) + return rs, index + + def has_value(self, index: BaseType) -> bool: + return self._has_value(index) cdef bint _has_value(self, BaseType index): return self.dct.has_value(index)