sif_embedding/wordfreq.rs
1//! WordProbabilities implementations for [`wordfreq::WordFreq`].
2//! This module is available if the `wordfreq` feature is enabled.
3use crate::Float;
4use crate::WordProbabilities;
5
6use wordfreq::WordFreq;
7
8impl WordProbabilities for WordFreq {
9 fn probability(&self, word: &str) -> Float {
10 self.word_frequency(word)
11 }
12
13 fn n_words(&self) -> usize {
14 self.word_frequency_map().len()
15 }
16
17 fn entries(&self) -> Box<dyn Iterator<Item = (String, Float)> + '_> {
18 Box::new(
19 self.word_frequency_map()
20 .iter()
21 .map(|(k, v)| (k.to_owned(), *v)),
22 )
23 }
24}