py: add Segmenter::sentence_score() method

This commit is contained in:
Dirkjan Ochtman 2021-04-22 15:04:06 +02:00
parent 85035a9b34
commit 62f5b79d6d
1 changed files with 11 additions and 0 deletions

View File

@ -90,6 +90,17 @@ impl Segmenter {
)),
}
}
/// Returns the sentence's score
///
/// Returns the relative probability for the given sentence in the the corpus represented by
/// this `Segmenter`. Will return `None` iff given an empty iterator argument.
fn sentence_score(&self, words: &PyIterator) -> PyResult<Option<f64>> {
let words = words
.map(|s| s?.extract::<&str>())
.collect::<Result<Vec<_>, _>>()?;
Ok(self.inner.sentence_score(words.into_iter()))
}
}
/// Search buffer and result set