1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//! WordProbabilities implementations for [`wordfreq::WordFreq`].
//! This module is available if the `wordfreq` feature is enabled.
use crate::Float;
use crate::WordProbabilities;

use wordfreq::WordFreq;

impl WordProbabilities for WordFreq {
    fn probability(&self, word: &str) -> Float {
        self.word_frequency(word)
    }

    fn n_words(&self) -> usize {
        self.word_frequency_map().len()
    }

    fn entries(&self) -> Box<dyn Iterator<Item = (String, Float)> + '_> {
        Box::new(
            self.word_frequency_map()
                .iter()
                .map(|(k, v)| (k.to_owned(), *v)),
        )
    }
}