Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

truprecht/openfsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openfsa

This library crate is a wrapper around a small part of openfst that offers basic functions to work with finite state automata.

The installation requires the shared libraries and headers of openfst installed in the search path of your compiler. Please follow the instructions listed here to download and install openfst. Keep in mind that openfst itself is licensed using the Apache license v2.

Usage

We can construct an Automaton using an initial state, a list of final states and a list of Arcs.

use openfsa::fsa::{Arc, Automaton};
let arcs: Vec<Arc<&str, &str>>
    = vec![
        Arc {
            from: "q1",
            to: "q2",
            label: "a",
            weight: LogDomain::new(0.9).unwrap(),
        },
        Arc {
            from: "q2",
            to: "q1",
            label: "word",
            weight: LogDomain::one(),
        },
    ];
let fsa: Automaton<&str> = Automaton::from_arcs("q", vec!["q"], arcs);

We can intersect Automata,

let intersection = fsa.intersect(&fsa);

remove the language recognized by a second fsa from the first one,

let nothing = intersection.difference(&fsa);

dump automata to, and read them from binary strings using the serde framework,

extern crate serde_json;
println!("{}", serde_json::to_string(&intersection).unwrap());

and finally, we can also enumerate all words recognized by an automaton.

use openfsa::fsa::generator::BatchGenerator;
for word in BatchGenerator::new(fsa, 1).flat_map(|batch| batch) {
    println!("{}", word);
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published