pub struct Dictionary { /* private fields */ }
Expand description

Dictionary for tokenization.

Implementations§

source§

impl Dictionary

source

pub fn word_feature(&self, word_idx: WordIdx) -> &str

Gets the reference to the feature string.

source

pub fn write<W>(&self, wtr: W) -> Result<usize>where W: Write,

Exports the dictionary data.

Examples
use std::fs::File;

use vibrato::SystemDictionaryBuilder;

let dict = SystemDictionaryBuilder::from_readers(
    File::open("src/tests/resources/lex.csv")?,
    File::open("src/tests/resources/matrix.def")?,
    File::open("src/tests/resources/char.def")?,
    File::open("src/tests/resources/unk.def")?,
)?;

let writer = File::create("path/to/system.dic")?;
dict.write(writer)?;
Errors

When bincode generates an error, it will be returned as is.

source

pub fn read<R>(rdr: R) -> Result<Self>where R: Read,

Creates a dictionary from raw dictionary data.

The argument must be a byte sequence exported by the Dictionary::write() function.

Examples
use std::fs::File;

use vibrato::Dictionary;

let reader = File::open("path/to/system.dic")?;
let dict = Dictionary::read(reader)?;
Errors

When bincode generates an error, it will be returned as is.

source

pub unsafe fn read_unchecked<R>(rdr: R) -> Result<Self>where R: Read,

Creates a dictionary from raw dictionary data.

The argument must be a byte sequence exported by the Dictionary::write() function.

Unlike the Dictionary::read() function, this function does not check the correctness of the dictionary.

Examples
use std::fs::File;

use vibrato::Dictionary;

let reader = File::open("path/to/system.dic")?;
let dict = unsafe { Dictionary::read_unchecked(reader)? } ;
Safety

The given reader must be a correct file exported by Dictionary::write().

Errors

When bincode generates an error, it will be returned as is.

source

pub fn reset_user_lexicon_from_reader<R>( self, user_lexicon_rdr: Option<R> ) -> Result<Self>where R: Read,

Resets the user dictionary from a reader.

Arguments
  • user_lexicon_rdr: A reader of a lexicon file *.csv in the MeCab format. If None, clear the current user dictionary.
Errors

VibratoError is returned when an input format is invalid.

source

pub fn map_connection_ids_from_iter<L, R>( self, lmap: L, rmap: R ) -> Result<Self>where L: IntoIterator<Item = u16>, R: IntoIterator<Item = u16>,

Edits connection ids with the given mappings.

Arguments
  • lmap/rmap: An iterator of mappings of left/right ids, where the i-th item (1-origin) indicates a new id mapped from id i.
Errors

VibratoError is returned when

  • a new id of BOS_EOS_CONNECTION_ID is included,
  • new ids are duplicated, or
  • the set of new ids are not same as that of old ids.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

fn vzip(self) -> V

§

impl<T> SendAlias for T

§

impl<T> SendSyncUnwindSafe for Twhere T: Send + Sync + UnwindSafe + ?Sized,

§

impl<T> SyncAlias for T