mirror of
https://github.com/instant-labs/instant-segment.git
synced 2025-01-31 21:22:11 +00:00
py: yield score from segment() method
This commit is contained in:
parent
78b37cf7c2
commit
7d29eb27e1
@ -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<f64> {
|
||||
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",
|
||||
|
@ -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__':
|
||||
|
Loading…
Reference in New Issue
Block a user