pub trait Dictionary: Debug {
// Required methods
fn lookup(
&self,
syllables: &[Syllable],
strategy: LookupStrategy,
) -> Vec<Phrase>;
fn entries(&self) -> Entries<'_>;
fn about(&self) -> DictionaryInfo;
fn path(&self) -> Option<&Path>;
fn set_usage(&mut self, usage: DictionaryUsage);
// Provided methods
fn reopen(&mut self) -> Result<(), UpdateDictionaryError> { ... }
fn flush(&mut self) -> Result<(), UpdateDictionaryError> { ... }
fn add_phrase(
&mut self,
_syllables: &[Syllable],
_phrase: Phrase,
) -> Result<(), UpdateDictionaryError> { ... }
fn update_phrase(
&mut self,
_syllables: &[Syllable],
_phrase: Phrase,
_user_freq: u32,
_time: u64,
) -> Result<(), UpdateDictionaryError> { ... }
fn remove_phrase(
&mut self,
_syllables: &[Syllable],
_phrase_str: &str,
) -> Result<(), UpdateDictionaryError> { ... }
}Expand description
An interface for looking up dictionaries.
This is the main dictionary trait. For more about the concept of dictionaries generally, please see the module-level documentation.
§Examples
use chewing::{dictionary::{Dictionary, LookupStrategy, TrieBuf}, syl, zhuyin::Bopomofo};
let mut dict = TrieBuf::new_in_memory();
dict.add_phrase(&[syl![Bopomofo::C, Bopomofo::E, Bopomofo::TONE4]], ("測", 100).into())?;
for phrase in dict.lookup(
&[syl![Bopomofo::C, Bopomofo::E, Bopomofo::TONE4]], LookupStrategy::Standard
) {
assert_eq!("測", phrase.as_str());
assert_eq!(100, phrase.freq());
}Required Methods§
Sourcefn lookup(
&self,
syllables: &[Syllable],
strategy: LookupStrategy,
) -> Vec<Phrase>
fn lookup( &self, syllables: &[Syllable], strategy: LookupStrategy, ) -> Vec<Phrase>
Returns all phrases matched by the syllables.
The result should use a stable order each time for the same input.
Sourcefn about(&self) -> DictionaryInfo
fn about(&self) -> DictionaryInfo
Returns information about the dictionary instance.
Sourcefn set_usage(&mut self, usage: DictionaryUsage)
fn set_usage(&mut self, usage: DictionaryUsage)
Set the runtime usage of the dictionary
Provided Methods§
Sourcefn reopen(&mut self) -> Result<(), UpdateDictionaryError>
fn reopen(&mut self) -> Result<(), UpdateDictionaryError>
Reopens the dictionary if it was changed by a different process
It should not fail if the dictionary is read-only or able to sync across processes automatically.
Sourcefn flush(&mut self) -> Result<(), UpdateDictionaryError>
fn flush(&mut self) -> Result<(), UpdateDictionaryError>
Flushes all the changes back to the filesystem
The change made to the dictionary might not be persisted without calling this method.
Sourcefn add_phrase(
&mut self,
_syllables: &[Syllable],
_phrase: Phrase,
) -> Result<(), UpdateDictionaryError>
fn add_phrase( &mut self, _syllables: &[Syllable], _phrase: Phrase, ) -> Result<(), UpdateDictionaryError>
An method for updating dictionaries.
For more about the concept of dictionaries generally, please see the module-level documentation.
§Examples
use chewing::{dictionary::{Dictionary, TrieBuf}, syl, zhuyin::Bopomofo};
let mut dict = TrieBuf::new_in_memory();
dict.add_phrase(&[syl![Bopomofo::C, Bopomofo::E, Bopomofo::TONE4]], ("測", 100).into())?;TODO: doc
Sourcefn update_phrase(
&mut self,
_syllables: &[Syllable],
_phrase: Phrase,
_user_freq: u32,
_time: u64,
) -> Result<(), UpdateDictionaryError>
fn update_phrase( &mut self, _syllables: &[Syllable], _phrase: Phrase, _user_freq: u32, _time: u64, ) -> Result<(), UpdateDictionaryError>
TODO: doc
Sourcefn remove_phrase(
&mut self,
_syllables: &[Syllable],
_phrase_str: &str,
) -> Result<(), UpdateDictionaryError>
fn remove_phrase( &mut self, _syllables: &[Syllable], _phrase_str: &str, ) -> Result<(), UpdateDictionaryError>
TODO: doc
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl Dictionary for Layered
impl Dictionary for SqliteDictionary
sqlite only.