Dictionary

Struct Dictionary 

Source
pub struct Dictionary {
    pub language: String,
    /* private fields */
}
Expand description

Cifra stores word dictionaries in a local database. This class is a wrapper to not to deal directly with that database.

This class is intended to be used as a context manager so you don’t have to deal with opening and closing this dictionary. So, call this method as a context manager, it will return this instance so you can call further methods to manage its words.

Fields§

§language: String

Implementations§

Source§

impl Dictionary

Source

pub fn remove_dictionary<T>(_language: T) -> Result<()>
where T: AsRef<str>,

Remove given language from database.

Be aware that all its words will be removed too.

§Parameters:
  • language: Language to remove from database.
Source

pub fn get_dictionaries_names() -> Result<Vec<String>>

Get languages dictionaries present at database.

§Returns:
  • A list with names of dictionaries present at database.
Source

pub fn new<T>(_language: T, create: bool) -> Result<Self>
where T: AsRef<str>,

§Parameters:
  • language: Language you want to manage its words.
  • create: Whether this language should be created in database if not present yet. It defaults to False. If it is set to False and language is not already present at database then a dictionaries.NotExistingLanguage exception is raised, but if it is set to True then language is registered in database as a new language.
Source

pub fn session(&self) -> &DatabaseSession

Get open session for current dictionary database.

Source

pub fn add_word<T>(&mut self, _word: T)
where T: AsRef<str>,

Add given word to dictionary.

If word is already present at dictionary, do nothing.

§Parameters:
  • word: word to add to dictionary.
Source

pub fn add_multiple_words(&mut self, _words: &HashSet<String>)

Add given words to dictionary.

§Parameters:
  • words: Set of words to add to dictionary.
Source

pub fn remove_word<T>(&mut self, _word: T)
where T: AsRef<str>,

Remove given word from dictionary.

If word is not already present at dictionary, do nothing.

§Parameters:
  • word: word to remove from dictionary.
Source

pub fn word_exists<T>(&self, _word: T) -> bool
where T: AsRef<str>,

Check if given word exists at this dictionary.

§Parameters:
  • word: word to check.
§Returns:

True if word is already present at dictionary, False otherwise.

Source

pub fn populate<T>(&mut self, file_pathname: T) -> Result<()>
where T: AsRef<Path>,

Read a file’s words and stores them at this language database.

§Parameters:
  • file_pathname: Absolute path to file with text to analyze.
Source

pub fn get_words_with_pattern<T>(&self, pattern: T) -> Result<Vec<String>>
where T: AsRef<str>,

Get a list of every word with given pattern.

§Parameters:
  • pattern: Word patter to search for.
§Returns:
  • List of words at dictionary with given pattern.
Source

pub fn get_words_presence(&self, _words: &HashSet<String>) -> f64

Get how many words of given set are really present in this dictionary.

§Parameters:
  • words: Set of words.
§Returns:
  • A float between 0 and 1 being 1 as every word in set is present at dictionary.
Source

pub fn get_all_words(&self) -> Result<Vec<String>>

Get a list of every word present at dictionary.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression
where Self: Sized + AsExpression<T>,

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V