pub struct WordFreq { /* private fields */ }
Expand description
Implementation of wordfreq.
Implementations§
Source§impl WordFreq
impl WordFreq
Sourcepub fn minimum(self, minimum: Float) -> Result<Self>
pub fn minimum(self, minimum: Float) -> Result<Self>
Sets the lower bound of returned frequencies (default is 0.0).
An error is returned if the input is negative.
Sourcepub fn standardizer(self, standardizer: Standardizer) -> Self
pub fn standardizer(self, standardizer: Standardizer) -> Self
Sets the standardizer for preprocessing words.
If set, the standardizer is always applied to words before looking up their frequencies.
Sourcepub fn word_frequency<W>(&self, word: W) -> Float
pub fn word_frequency<W>(&self, word: W) -> Float
Returns the word’s frequency, normalized between 0.0 and 1.0.
§Examples
use approx::assert_relative_eq;
use wordfreq::WordFreq;
let word_weights = [("las", 10.), ("vegas", 30.)];
let wf = WordFreq::new(word_weights);
assert_relative_eq!(wf.word_frequency("las"), 0.25);
assert_relative_eq!(wf.word_frequency("vegas"), 0.75);
assert_relative_eq!(wf.word_frequency("Las"), 0.00);
Sourcepub fn zipf_frequency<W>(&self, word: W) -> Float
pub fn zipf_frequency<W>(&self, word: W) -> Float
Returns the Zipf frequency of a word as a human-friendly logarithmic scale.
§Examples
use approx::assert_relative_eq;
use wordfreq::WordFreq;
let word_weights = [("las", 10.), ("vegas", 30.)];
let wf = WordFreq::new(word_weights);
assert_relative_eq!(wf.zipf_frequency("las"), 8.4);
assert_relative_eq!(wf.zipf_frequency("vegas"), 8.88);
assert_relative_eq!(wf.zipf_frequency("Las"), 0.00);
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
Exports the model data.
Note that the format is distinct from the one used in the oritinal Python package.
Sourcepub fn deserialize(bytes: &[u8]) -> Result<Self>
pub fn deserialize(bytes: &[u8]) -> Result<Self>
Deserializes the model, which is exported by WordFreq::serialize()
.
Sourcepub const fn word_frequency_map(&self) -> &HashMap<String, Float>
pub const fn word_frequency_map(&self) -> &HashMap<String, Float>
Returns the reference to the internal word-frequency map.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WordFreq
impl RefUnwindSafe for WordFreq
impl Send for WordFreq
impl Sync for WordFreq
impl Unpin for WordFreq
impl UnwindSafe for WordFreq
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more