Skip to content

Commit

Permalink
Updated test suite and expanded doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaCappelletti94 committed Apr 11, 2024
1 parent 57dac7b commit 45a097e
Show file tree
Hide file tree
Showing 17 changed files with 238 additions and 141 deletions.
20 changes: 10 additions & 10 deletions src/bi_webgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
#[inline(always)]
/// Returns the number of source nodes.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand All @@ -171,7 +171,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
#[inline(always)]
/// Returns the number of destination nodes.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand All @@ -196,7 +196,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
#[inline(always)]
/// Returns the number of edges.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -224,7 +224,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
/// # Arguments
/// * `src_id`: A `usize` which is the source node identifier.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -257,7 +257,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
/// # Arguments
/// * `dst_id`: A `usize` which is the destination node identifier.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -292,7 +292,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
/// # Arguments
/// * `dst_id`: A `usize` which is the destination node identifier.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -330,7 +330,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
/// # Arguments
/// * `src_id`: A `usize` which is the source node identifier.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -371,7 +371,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
/// # Arguments
/// * `dst_id`: A `usize` which is the destination node identifier.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -407,7 +407,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
#[inline(always)]
/// Returns the weights of the edges.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down Expand Up @@ -442,7 +442,7 @@ impl WeightedBipartiteGraph for BiWebgraph {
#[inline(always)]
/// Returns the degrees of the nodes.
///
/// # Example
/// # Examples
/// In this example, we create the trigram corpus associated
/// to the ANIMALS dataset which we provide within this crate,
/// and then we convert it to webgraph format. Secondarily,
Expand Down
44 changes: 22 additions & 22 deletions src/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ where

/// Returns a reference to underlying graph.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand Down Expand Up @@ -127,7 +127,7 @@ where
#[inline(always)]
/// Returns the number of keys in the corpus.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -145,7 +145,7 @@ where
#[inline(always)]
/// Returns the number of ngrams in the corpus.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -166,16 +166,16 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
///
/// let animals: Corpus<_, TriGram<ASCIIChar>> = Corpus::from(ANIMALS);
///
/// assert_eq!(animals.key_from_id(0), "Aardvark");
/// assert_eq!(animals.key_from_id(1), "Abyssinian");
/// assert_eq!(animals.key_from_id(20), "Alligator");
/// assert_eq!(animals.key_from_id(0), &"Aardvark");
/// assert_eq!(animals.key_from_id(1), &"Abyssinian");
/// assert_eq!(animals.key_from_id(20), &"Alligator");
/// ```
pub fn key_from_id(
&self,
Expand All @@ -190,7 +190,7 @@ where
/// # Arguments
/// * `ngram_id` - The id of the ngram to get.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand Down Expand Up @@ -218,7 +218,7 @@ where
/// # Arguments
/// * `ngram` - The ngram to get the id from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -245,7 +245,7 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get the number of ngrams from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -266,7 +266,7 @@ where
/// # Arguments
/// * `ngram_id` - The id of the ngram to get the number of keys from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -287,7 +287,7 @@ where
/// # Arguments
/// * `ngram_id` - The id of the ngram to get the key ids from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -308,7 +308,7 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get the ngram ids from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -329,7 +329,7 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get the ngram co-occurrences from.
///
/// # Example
/// # Examples
/// We check that all values are greater than 0.
///
/// ```rust
Expand All @@ -355,7 +355,7 @@ where
#[inline(always)]
/// Returns all co-occurrences.
///
/// # Example
/// # Examples
/// We check that all values are greater than 0.
///
/// ```rust
Expand All @@ -376,7 +376,7 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get the ngrams and their co-occurrences from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand All @@ -401,7 +401,7 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get the ngrams and their co-occurrences from.
///
/// # Example
/// # Examples
/// We check that all of the ngrams returned appear in the corpus and
/// that all of the co-occurrences are greater than 0.
///
Expand Down Expand Up @@ -442,7 +442,7 @@ where
/// # Arguments
/// * `key_id` - The id of the key to get the ngrams from.
///
/// # Example
/// # Examples
/// We check that all of the ngrams returned appear in the corpus.
///
/// ```rust
Expand Down Expand Up @@ -480,7 +480,7 @@ where
/// # Returns
/// An iterator over the keys associated to the ngram.
///
/// # Example
/// # Examples
/// We check that the keys returned by the keys_from_ngram_id method are the
/// exactly same keys returned keys_from_ngram method.
///
Expand Down Expand Up @@ -515,7 +515,7 @@ where
/// # Arguments
/// * `ngram` - The ngram to get the number of keys from.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand Down Expand Up @@ -568,7 +568,7 @@ where
/// # Returns
/// An iterator over the keys associated to the ngram.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand Down Expand Up @@ -606,7 +606,7 @@ where
/// # Implementative details
/// This function is implemented using a Binary Heap.
///
/// # Example
/// # Examples
///
/// ```rust
/// use ngrammatic::prelude::*;
Expand Down
68 changes: 34 additions & 34 deletions src/corpus_par_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
/// # Arguments
/// * `keys` - The keys to create the corpus from.
///
/// # Example
/// # Examples
/// In the following example, we create a corpus from the set of keys
/// defined by the `ANIMALS` constant array. We provide several synonims
/// for arrays, such as MonoGrams, BiGrams, TriGrams, and so on. This is
Expand Down Expand Up @@ -64,13 +64,13 @@ where
///
/// let animals = vec!["cat", "dog", "bird", "fish", "lion"];
///
/// let bigram_corpus: Corpus<&[&str], BiGram<char>> = Corpus::par_from(&animals);
/// let trigram_corpus: Corpus<&[&str], TriGram<char>> = Corpus::par_from(&animals);
/// let tetragram_corpus: Corpus<&[&str], TetraGram<char>> = Corpus::par_from(&animals);
/// let pentagram_corpus: Corpus<&[&str], PentaGram<char>> = Corpus::par_from(&animals);
/// let hexagram_corpus: Corpus<&[&str], HexaGram<char>> = Corpus::par_from(&animals);
/// let heptagram_corpus: Corpus<&[&str], HeptaGram<char>> = Corpus::par_from(&animals);
/// let octagram_corpus: Corpus<&[&str], OctaGram<char>> = Corpus::par_from(&animals);
/// let bigram_corpus: Corpus<Vec<&str>, BiGram<char>> = Corpus::par_from(animals.clone());
/// let trigram_corpus: Corpus<Vec<&str>, TriGram<char>> = Corpus::par_from(animals.clone());
/// let tetragram_corpus: Corpus<Vec<&str>, TetraGram<char>> = Corpus::par_from(animals.clone());
/// let pentagram_corpus: Corpus<Vec<&str>, PentaGram<char>> = Corpus::par_from(animals.clone());
/// let hexagram_corpus: Corpus<Vec<&str>, HexaGram<char>> = Corpus::par_from(animals.clone());
/// let heptagram_corpus: Corpus<Vec<&str>, HeptaGram<char>> = Corpus::par_from(animals.clone());
/// let octagram_corpus: Corpus<Vec<&str>, OctaGram<char>> = Corpus::par_from(animals.clone());
/// ```
///
/// And references of arrays:
Expand All @@ -80,13 +80,13 @@ where
///
/// let animals = ["cat", "dog", "bird", "fish", "lion"];
///
/// let bigram_corpus: Corpus<&[&str; 5], BiGram<char>> = Corpus::par_from(&animals);
/// let trigram_corpus: Corpus<&[&str; 5], TriGram<char>> = Corpus::par_from(&animals);
/// let tetragram_corpus: Corpus<&[&str; 5], TetraGram<char>> = Corpus::par_from(&animals);
/// let pentagram_corpus: Corpus<&[&str; 5], PentaGram<char>> = Corpus::par_from(&animals);
/// let hexagram_corpus: Corpus<&[&str; 5], HexaGram<char>> = Corpus::par_from(&animals);
/// let heptagram_corpus: Corpus<&[&str; 5], HeptaGram<char>> = Corpus::par_from(&animals);
/// let octagram_corpus: Corpus<&[&str; 5], OctaGram<char>> = Corpus::par_from(&animals);
/// let bigram_corpus: Corpus<[&str; 5], BiGram<char>> = Corpus::par_from(animals);
/// let trigram_corpus: Corpus<[&str; 5], TriGram<char>> = Corpus::par_from(animals);
/// let tetragram_corpus: Corpus<[&str; 5], TetraGram<char>> = Corpus::par_from(animals);
/// let pentagram_corpus: Corpus<[&str; 5], PentaGram<char>> = Corpus::par_from(animals);
/// let hexagram_corpus: Corpus<[&str; 5], HexaGram<char>> = Corpus::par_from(animals);
/// let heptagram_corpus: Corpus<[&str; 5], HeptaGram<char>> = Corpus::par_from(animals);
/// let octagram_corpus: Corpus<[&str; 5], OctaGram<char>> = Corpus::par_from(animals);
/// ```
///
/// In all of these examples, we have used char-based grams. We can also use u8-based grams:
Expand All @@ -96,13 +96,13 @@ where
///
/// let animals = vec!["cat", "dog", "bird", "fish", "lion"];
///
/// let bigram_corpus: Corpus<&[&str], BiGram<u8>> = Corpus::par_from(&animals);
/// let trigram_corpus: Corpus<&[&str], TriGram<u8>> = Corpus::par_from(&animals);
/// let tetragram_corpus: Corpus<&[&str], TetraGram<u8>> = Corpus::par_from(&animals);
/// let pentagram_corpus: Corpus<&[&str], PentaGram<u8>> = Corpus::par_from(&animals);
/// let hexagram_corpus: Corpus<&[&str], HexaGram<u8>> = Corpus::par_from(&animals);
/// let heptagram_corpus: Corpus<&[&str], HeptaGram<u8>> = Corpus::par_from(&animals);
/// let octagram_corpus: Corpus<&[&str], OctaGram<u8>> = Corpus::par_from(&animals);
/// let bigram_corpus: Corpus<Vec<&str>, BiGram<u8>> = Corpus::par_from(animals.clone());
/// let trigram_corpus: Corpus<Vec<&str>, TriGram<u8>> = Corpus::par_from(animals.clone());
/// let tetragram_corpus: Corpus<Vec<&str>, TetraGram<u8>> = Corpus::par_from(animals.clone());
/// let pentagram_corpus: Corpus<Vec<&str>, PentaGram<u8>> = Corpus::par_from(animals.clone());
/// let hexagram_corpus: Corpus<Vec<&str>, HexaGram<u8>> = Corpus::par_from(animals.clone());
/// let heptagram_corpus: Corpus<Vec<&str>, HeptaGram<u8>> = Corpus::par_from(animals.clone());
/// let octagram_corpus: Corpus<Vec<&str>, OctaGram<u8>> = Corpus::par_from(animals.clone());
/// ```
///
/// It is also pretty easy to define normalizations for the keys. For instance, you can
Expand All @@ -113,18 +113,18 @@ where
///
/// let animals = vec!["cat", "dog", "bIrd", "Fish", "Lion"];
///
/// let bigram_corpus: Corpus<&[&str], BiGram<char>, Lowercase<str>> = Corpus::par_from(&animals);
/// let trigram_corpus: Corpus<&[&str], TriGram<char>, Lowercase<str>> = Corpus::par_from(&animals);
/// let tetragram_corpus: Corpus<&[&str], TetraGram<char>, Lowercase<str>> =
/// Corpus::par_from(&animals);
/// let pentagram_corpus: Corpus<&[&str], PentaGram<char>, Lowercase<str>> =
/// Corpus::par_from(&animals);
/// let hexagram_corpus: Corpus<&[&str], HexaGram<char>, Lowercase<str>> =
/// Corpus::par_from(&animals);
/// let heptagram_corpus: Corpus<&[&str], HeptaGram<char>, Lowercase<str>> =
/// Corpus::par_from(&animals);
/// let octagram_corpus: Corpus<&[&str], OctaGram<char>, Lowercase<str>> =
/// Corpus::par_from(&animals);
/// let bigram_corpus: Corpus<Vec<&str>, BiGram<char>, Lowercase<str>> = Corpus::par_from(animals.clone());
/// let trigram_corpus: Corpus<Vec<&str>, TriGram<char>, Lowercase<str>> = Corpus::par_from(animals.clone());
/// let tetragram_corpus: Corpus<Vec<&str>, TetraGram<char>, Lowercase<str>> =
/// Corpus::par_from(animals.clone());
/// let pentagram_corpus: Corpus<Vec<&str>, PentaGram<char>, Lowercase<str>> =
/// Corpus::par_from(animals.clone());
/// let hexagram_corpus: Corpus<Vec<&str>, HexaGram<char>, Lowercase<str>> =
/// Corpus::par_from(animals.clone());
/// let heptagram_corpus: Corpus<Vec<&str>, HeptaGram<char>, Lowercase<str>> =
/// Corpus::par_from(animals.clone());
/// let octagram_corpus: Corpus<Vec<&str>, OctaGram<char>, Lowercase<str>> =
/// Corpus::par_from(animals.clone());
/// ```
pub fn par_from(keys: KS) -> Self {
// We start by parsing the keys to extract the ngrams, the cooccurrences, the key offsets,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ pub mod prelude {
pub use crate::bi_webgraph::*;
pub use crate::ngram_search::*;
pub use crate::tfidf::*;
pub use crate::search::*;
}
Loading

0 comments on commit 45a097e

Please sign in to comment.