[][src]Struct rustfst::SymbolTable

pub struct SymbolTable { /* fields omitted */ }

A symbol table stores a bidirectional mapping between transition labels and "symbols" (strings).

Implementations

impl SymbolTable[src]

pub fn new() -> Self[src]

Creates a SymbolTable with a single element in it: the pair (EPS_LABEL, EPS_SYMBOL).

Examples

let mut symt = SymbolTable::new();

pub fn empty() -> Self[src]

pub fn is_empty(&self) -> bool[src]

pub fn add_symbol<S: Into<String>>(&mut self, sym: S) -> Label[src]

Adds a symbol to the symbol table. The corresponding label is returned.

Examples

let mut symt = symt!["a", "b"];

// Elements in the table : `<eps>`, `a`, `b`
assert_eq!(symt.len(), 3);

// Add a single symbol
symt.add_symbol("c");

// Elements in the table : `<eps>`, `a`, `b`, `c`
assert_eq!(symt.len(), 4);

pub fn add_symbols<S: Into<String>, P: IntoIterator<Item = S>>(
    &mut self,
    symbols: P
)
[src]

pub fn len(&self) -> usize[src]

Returns the number of symbols stored in the symbol table.

Examples

let mut symt = symt!["a", "b"];
assert_eq!(symt.len(), 3);

pub fn get_label<S: Into<String>>(&self, sym: S) -> Option<Label>[src]

Given a symbol, returns the label corresponding. If the symbol is not stored in the table then None is returned.

Examples

let mut symt = symt!["a", "b"];
let label = symt.add_symbol("c");
assert_eq!(symt.get_label("c"), Some(label));
assert_eq!(symt.get_label("d"), None);

pub fn get_symbol(&self, label: Label) -> Option<&str>[src]

Given a label, returns the symbol corresponding. If no there is no symbol with this label in the table then None is returned.

Examples

let mut symt = symt!["a", "b"];
let label = symt.add_symbol("c");
assert_eq!(symt.get_symbol(label), Some("c"));
assert_eq!(symt.get_symbol(label + 1), None);

pub fn contains_symbol<S: Into<String>>(&self, sym: S) -> bool[src]

Given a symbol, returns whether it is present in the table.

Examples

let symt = symt!["a", "b"];
assert!(symt.contains_symbol("a"));

pub fn contains_label(&self, label: Label) -> bool[src]

Given a label, returns whether it is present in the table.

Examples

let mut symt = symt!["a", "b"];
let label = symt.add_symbol("c");
assert!(symt.contains_label(label));
assert!(!symt.contains_label(label+1));

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more elements to be inserted in the SymbolTable. The collection may reserve more space to avoid frequent reallocations.

pub fn labels(&self) -> Keys<'_, Label, Symbol>[src]

An iterator on all the labels stored in the SymbolTable. The iterator element is &'a Label.

Examples

let symt = symt!["a", "b"];
let mut iterator = symt.labels();

pub fn symbols(&self) -> Keys<'_, Symbol, Label>[src]

An iterator on all the symbols stored in the SymbolTable. The iterator element is &'a Symbol.

Examples

let symt = symt!["a", "b"];
let mut iterator = symt.symbols();

for symbol in symt.symbols() {
    println!("Symbol : {:?}", symbol);
}

pub fn iter(&self) -> Iter<'_, Label, Symbol>[src]

An iterator on all the labels stored in the SymbolTable. The iterator element is (&'a Label, &'a Symbol).

pub fn add_table(&mut self, other: &SymbolTable)[src]

Adds another SymbolTable to this table.

pub fn from_text_string(symt_string: &str) -> Result<Self>[src]

pub fn read_text<P: AsRef<Path>>(path_text_symt: P) -> Result<Self>[src]

pub fn write_text<P: AsRef<Path>>(&self, path_output: P) -> Result<()>[src]

pub fn read<P: AsRef<Path>>(path_bin_symt: P) -> Result<Self>[src]

pub fn write<P: AsRef<Path>>(&self, path_bin_symt: P) -> Result<()>[src]

pub fn text(&self) -> Result<String>[src]

Writes the text_fst representation of the symbol table into a String.

Trait Implementations

impl Clone for SymbolTable[src]

impl Debug for SymbolTable[src]

impl Default for SymbolTable[src]

impl Display for SymbolTable[src]

impl PartialEq<SymbolTable> for SymbolTable[src]

impl StructuralPartialEq for SymbolTable[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.