pub struct Ngram {
    pub arity: usize,
    pub text: String,
    pub text_padded: String,
    pub grams: HashMap<String, usize>,
}
Expand description

Stores a “word”, with all its n-grams. The “arity” member determines the value of “n” used in generating the n-grams.

Fields

arity: usize

The “symbol size” for the ngrams

text: String

The text for which ngrams were generated

text_padded: String

The text for which ngrams were generated, with the padding used for generating the ngrams

grams: HashMap<String, usize>

A collection of all generated ngrams for the text, with a count of how many times that ngram appears in the text

Implementations

Calculate the similarity of this Ngram and an other, for a given warp factor (clamped to the range 1.0 to 3.0).

let a = NgramBuilder::new("tomato").finish();
let b = NgramBuilder::new("tomacco").finish();
println!("Similarity factor for {} and {}: {:.0}%", a.text, b.text, a.similarity_to(&b, 2.0) *
100.0);

Determines if this Ngram matches a given other Ngram, for a given threshold of certainty. This is equivalent to matches_with_warp and a warp of 2.0.

let a = NgramBuilder::new("tomato").finish();
let b = NgramBuilder::new("tomacco").finish();
if let Some(word_match) = a.matches(&b, 0.40) {
    println!("{} matches {} with {:.0}% certainty", a.text, b.text, word_match.similarity *
    100.0);
} else {
    println!("{} doesn't look anything like {}.", a.text, b.text);
}

Determines if this Ngram matches a given other Ngram, with the specified warp (clamped to the range 1.0 to 3.0), and for a given threshold of certainty.

let a = NgramBuilder::new("tomato").finish();
let b = NgramBuilder::new("tomacco").finish();
if let Some(word_match) = a.matches_with_warp(&b, 2.0, 0.40) {
    println!("{} matches {} with {:.0}% certainty", a.text, b.text, word_match.similarity *
    100.0);
} else {
    println!("{} doesn't look anything like {}.", a.text, b.text);
}

Return the number of times a particular gram appears in the Ngram text.

let a = NgramBuilder::new("tomato").arity(2).finish();
println!("Number of times the 'to' bigram appears in {}: {}", a.text, a.count_gram("to"));

Return the total number of grams generated for the Ngram text.

If the set of grams contains the specified gram.

let a = NgramBuilder::new("tomato").arity(2).finish();
if a.contains("to") {
    println!("{} contains the bigram 'to'!", a.text);
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.