The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

OpenFST -- Perl bindings for the OpenFST library.

SYNOPSIS

This module provides a Perl interface to the OpenFST finite state transducer library. If you don't know what it is, you probably don't need it.

DESCRIPTION

The interface is very incomplete, since I have only implemented the parts I need right now. At the lowest level, the function and method names are the same as the C++ interface, except that destructive methods have a leading underscore. Non-destructive equivalents are provided without the leading underscore.

Algorithm::OpenFST provides a convenient higher-level interface to OpenFST's basic operations. Methods in this interface have lower_case names, while those in the raw library interface use StudlyCaps.

Constructors

$fst = VectorFST $smr

Create a mutable FST with semiring $smr.

$fsa = acceptor $file, %opts

Create a finite-state acceptor from file $file with options %opts.

$fst = transducer $file, %opts

Create a finite-state transducer from file $file with options %opts.

Options include:

is -- Input symbol file.
os -- Output symbol file.
ss -- State symbol file.
smr -- Semiring name.

$fst = ReadText $file, $smr, $acceptor, $is, $os, $ss

The low-level function implementing acceptor() and transducer().

$fst = from_list $init, $final, \@symbols, @edges

Create a transducer with initial state $init, final state $final (or final states @$final), input and output alphabet @symbols, and edges @edges, where each edge is of the form [FROM, TO, IN, OUT, WEIGHT].

$fst = universal $x

Create a universal acceptor mapping symbols to epsilon. If $x is a number, accept output symbols numbered 1..$max; if it is an array, accept symbols @$x; if it is an FST, accept all of its output symbols.

$fst = compose @fsts

Compose transducers @fsts into a single transducer $fst.

$fst = concat @fsts

Concatenate transducers @fsts into a single transducer $fst.

$fst = union @fsts

Union transducers @fsts into a single transducer $fst.

Acessors and Mutators

$fst->in

$fst->out

$fst->ensure_state($n)

Ensure that states up to $n exist in $fst.

$fst->add_state($n)

Add state $n (and previous states, if necessary).

$fst->add_arc_safe($from, $to [, $in [, $out [, $wt]]])

Add an arc from $from to $to with input and output $in and $out, with weight $wt.

$ofst = $fst->best_paths($n [, $unique])

Compute the best $n paths through $fst. Compute unique paths if $unique is true (UNIMPLEMENTED). If $fst does not use the tropical semiring, it is directly converted to and from the tropical semiring.

$ofst = $fst->prune($w)

Prune $fst so paths worse than $w from the best path are removed.

$fst->normalize

@strings = $fst->strings

@syms = $fst>in_syms

@syms = $fst>out_syms

BUGS AND TODO

    Many OpenFST functions will seg fault when given invalid input such as invalid state numbers.

    Other OpenFST functions will complain fatally when given an FST using the wrong semiring (e.g. Prune()).

    There seem to be memory leaks in some operations, but since both Perl and OpenFST have their own garbage collection schemes, and OpenFST also performs some kind of caching, they are hard to track down.

SEE ALSO

OpenFST -- http://www.openfst.org/

AUTHOR

Sean O'Rourke <seano@cpan.org>

Bug reports welcome, patches even more welcome.

COPYRIGHT

Copyright (C) 2007, 2008, Sean O'Rourke. All rights reserved, some wrongs reversed. This module is distributed under the same terms as Perl itself.