Expand description
A weighted finite-state transducer library, file-compatible with OpenFst.
An FST is a graph whose arcs carry an input label, an output label and a weight, so it holds a relation between strings together with a cost for each pairing. Composing two of them applies one after the other, and searching one answers what the cheapest pairing is. Speech recognition, morphology and text normalisation are the usual reasons to want that.
use sicada::prelude::*;
let mut fst = StdVectorFst::new();
let start = fst.add_state();
let middle = fst.add_state();
let end = fst.add_state();
fst.set_start(start);
fst.set_final(end, TropicalWeight::one());
// Two ways from the start to the end, one cheaper than the other.
fst.add_arc(start, StdArc::new(1, 1, TropicalWeight(0.5), middle));
fst.add_arc(middle, StdArc::new(2, 2, TropicalWeight(0.5), end));
fst.add_arc(start, StdArc::new(1, 1, TropicalWeight(3.0), end));
let mut best = StdVectorFst::new();
shortest_path(&fst, &mut best, &ShortestPathOptions::default())?;
assert_eq!(best.num_states(), 3);§How it is put together
Everything is generic over an Arc, which fixes the weight and
the integer types the labels and state ids use, rather than over the weight
alone. StdArc is the usual one: tropical weights with
32-bit labels.
fstholds the trait hierarchy.Fstis what an algorithm reads,ExpandedFstadds a state count in constant time, andMutableFstadds building.fstsholds the implementations:VectorFstto build one,ConstFstto map a file,CompactFstto hold one compressed, andExpanderFstto produce states as they are asked for.weightis the semiring trait andweightsthe semirings themselves, from the tropical and log weights up to the product, string, lexicographic and expectation ones.algorithmsholds the operations, each stating in its bounds which semiring properties it needs.propertiescarries the bitmask OpenFst files record, and on top of itVerified, which checks a property once and then holds it in the type.preludeis all of the above that a caller normally names, in oneuse.
§Reading and writing OpenFst’s files
The binary format is upstream’s, so an FST written by OpenFst can be read
here and one written here can be read there. read and write on each FST
type take the byte stream; AnyFst reads one whose
type is only known from its header.
Re-exports§
pub use properties::Acceptor;pub use properties::Acyclic;pub use properties::DetEpsFreeAcceptor;pub use properties::StringFst;pub use properties::UnweightedDetEpsFreeAcceptor;pub use properties::Verified;pub use properties::VerifyExt;pub use fsts::*;pub use weights::*;
Modules§
- add_on
- Attaching an arbitrary serializable object to an FST.
- algorithms
- arc
- arc_
filter - cache
- A cache for FSTs whose states are computed on demand.
- data_
structures - Container types the FST algorithms are built on.
- error
- expander_
cache - Caches for FSTs that are produced a state at a time.
- fst
- The FST interface, and the options and shared header handling around it.
- fst_
header - The header every FST file begins with.
- fst_
type - Strongly-typed names for the FST, arc and weight types a file header carries.
- fsts
- macros
- matcher
- memory
- Allocation helpers.
- prelude
- Everything a user of the library normally wants, in one
use. - properties
- queue
- Disciplines for choosing which state to visit next.
- string
- Compiling a string into a linear FST, and reading one back out.
- symbol_
table - symbol_
table_ ops - Operations over symbol tables.
- utils
- weight
- weights
Macros§
- fst_
linear - Creates a linear FST from a string or a list of labels.