diff --git a/instant-segment-py/src/lib.rs b/instant-segment-py/src/lib.rs index 607d88d..acd5e90 100644 --- a/instant-segment-py/src/lib.rs +++ b/instant-segment-py/src/lib.rs @@ -90,11 +90,12 @@ impl Segmenter { /// iterate over the `Search` to get the resulting words. /// /// For best performance, reusing `Search` objects is recommended. - fn segment(&self, s: &str, search: &mut Search) -> PyResult<()> { + fn segment(&self, s: &str, search: &mut Search) -> PyResult { match self.inner.segment(s, &mut search.inner) { - Ok(_) => { + Ok(iter) => { + let score = iter.score(); search.cur = Some(0); - Ok(()) + Ok(score) } Err(_) => Err(PyValueError::new_err( "only lowercase ASCII letters allowed", diff --git a/instant-segment-py/test/test.py b/instant-segment-py/test/test.py index fa85cdf..c69821c 100644 --- a/instant-segment-py/test/test.py +++ b/instant-segment-py/test/test.py @@ -16,7 +16,8 @@ def bigrams(): def main(): segmenter = instant_segment.Segmenter(unigrams(), bigrams()) search = instant_segment.Search() - segmenter.segment('thisisatest', search) + score = segmenter.segment('thisisatest', search) + print(f"{score=}") print([word for word in search]) if __name__ == '__main__':