├── src ├── Makefile.am ├── include │ └── fst │ │ ├── config.h │ │ ├── config.h.in │ │ ├── script │ │ ├── invert.h │ │ ├── connect.h │ │ ├── topsort.h │ │ ├── verify.h │ │ ├── fstscript-decl.h │ │ ├── project.h │ │ ├── closure.h │ │ ├── union.h │ │ ├── synchronize.h │ │ ├── text-io.h │ │ ├── reverse.h │ │ ├── equal.h │ │ ├── epsnormalize.h │ │ ├── convert.h │ │ ├── arcsort.h │ │ ├── equivalent.h │ │ ├── isomorphic.h │ │ ├── minimize.h │ │ ├── compose.h │ │ ├── arc-class.h │ │ ├── intersect.h │ │ ├── concat.h │ │ ├── difference.h │ │ ├── arg-packs.h │ │ ├── reweight.h │ │ └── decode.h │ │ ├── extensions │ │ ├── pdt │ │ │ ├── getters.h │ │ │ ├── pdtlib.h │ │ │ └── reverse.h │ │ ├── far │ │ │ ├── script-impl.h │ │ │ ├── farlib.h │ │ │ ├── getters.h │ │ │ └── create.h │ │ ├── mpdt │ │ │ └── mpdtlib.h │ │ └── ngram │ │ │ └── nthbit.h │ │ └── types.h ├── bin │ ├── fstunion.cc │ ├── fstconcat.cc │ ├── fstconnect.cc │ ├── fstinvert.cc │ ├── fsttopsort.cc │ ├── fstsynchronize.cc │ ├── fstconvert.cc │ ├── fstproject.cc │ ├── fstreverse.cc │ ├── fstepsnormalize.cc │ ├── fstreweight.cc │ ├── fstequal.cc │ ├── fstclosure.cc │ ├── fstisomorphic.cc │ ├── fstarcsort.cc │ ├── fstminimize.cc │ ├── fstintersect.cc │ ├── fstprune.cc │ ├── fstdifference.cc │ ├── fstencode.cc │ ├── fstcompose.cc │ ├── fstdisambiguate.cc │ ├── fstpush.cc │ ├── fstshortestdistance.cc │ ├── fstrmepsilon.cc │ ├── fstreplace.cc │ ├── fstshortestpath.cc │ ├── fstinfo.cc │ ├── fstmap.cc │ ├── fstrandgen.cc │ ├── fstequivalent.cc │ ├── fstcompile.cc │ ├── fstrelabel.cc │ ├── fstsymbols.cc │ ├── fstdeterminize.cc │ ├── fstinvert-main.cc │ ├── fstprint.cc │ ├── fstsynchronize-main.cc │ ├── fstconnect-main.cc │ ├── fsttopsort-main.cc │ ├── fstclosure-main.cc │ ├── bin.vcxproj │ ├── fstreverse-main.cc │ ├── fstconvert-main.cc │ ├── fstproject-main.cc │ ├── fstepsnormalize-main.cc │ ├── fstinfo-main.cc │ ├── fstarcsort-main.cc │ ├── fstreweight-main.cc │ ├── fstconcat-main.cc │ ├── fstprune-main.cc │ ├── fstunion-main.cc │ ├── fstequal-main.cc │ ├── fstdraw.cc │ ├── fstencode-main.cc │ ├── fstisomorphic-main.cc │ ├── fstdisambiguate-main.cc │ └── fstpush-main.cc ├── extensions │ ├── special │ │ ├── fstspecial.cc │ │ ├── Makefile.am │ │ ├── rho-fst.cc │ │ ├── sigma-fst.cc │ │ └── phi-fst.cc │ ├── python │ │ ├── memory.pxd │ │ ├── basictypes.pxd │ │ └── Makefile.am │ ├── linear │ │ ├── linear-tagger-fst.cc │ │ ├── linear-classifier-fst.cc │ │ ├── Makefile.am │ │ ├── fstlinear.cc │ │ └── fstloglinearapply.cc │ ├── ngram │ │ ├── ngram-fst.cc │ │ ├── Makefile.am │ │ └── CMakeLists.txt │ ├── far │ │ ├── sttable.cc │ │ ├── stlist.cc │ │ ├── strings.cc │ │ ├── script-impl.cc │ │ ├── Makefile.am │ │ ├── farequal.cc │ │ ├── farisomorphic.cc │ │ └── farinfo.cc │ ├── const │ │ ├── const8-fst.cc │ │ ├── const16-fst.cc │ │ ├── const64-fst.cc │ │ ├── Makefile.am │ │ └── CMakeLists.txt │ ├── compact │ │ ├── compact8_string-fst.cc │ │ ├── compact16_string-fst.cc │ │ ├── compact64_string-fst.cc │ │ ├── compact8_acceptor-fst.cc │ │ ├── compact16_acceptor-fst.cc │ │ ├── compact64_acceptor-fst.cc │ │ ├── compact8_unweighted-fst.cc │ │ ├── compact64_unweighted-fst.cc │ │ ├── compact16_unweighted-fst.cc │ │ ├── compact8_weighted_string-fst.cc │ │ ├── compact16_weighted_string-fst.cc │ │ ├── compact64_weighted_string-fst.cc │ │ ├── compact8_unweighted_acceptor-fst.cc │ │ ├── compact16_unweighted_acceptor-fst.cc │ │ └── compact64_unweighted_acceptor-fst.cc │ ├── lookahead │ │ ├── arc_lookahead-fst.cc │ │ ├── Makefile.am │ │ ├── ilabel_lookahead-fst.cc │ │ ├── olabel_lookahead-fst.cc │ │ └── CMakeLists.txt │ ├── compress │ │ ├── Makefile.am │ │ ├── CMakeLists.txt │ │ └── compress-script.cc │ ├── mpdt │ │ ├── Makefile.am │ │ └── CMakeLists.txt │ ├── pdt │ │ ├── getters.cc │ │ ├── Makefile.am │ │ ├── CMakeLists.txt │ │ ├── pdtinfo.cc │ │ └── pdtreverse.cc │ ├── Makefile.am │ └── CMakeLists.txt ├── lib │ ├── Makefile.am │ ├── CMakeLists.txt │ ├── fst-types.cc │ └── compat.cc ├── CMakeLists.txt ├── script │ ├── libfstscript.vcxproj.filters │ ├── invert.cc │ ├── connect.cc │ ├── verify.cc │ ├── topsort.cc │ ├── arcsort.cc │ ├── closure.cc │ ├── project.cc │ ├── convert.cc │ ├── reweight.cc │ ├── union.cc │ ├── equal.cc │ ├── rmepsilon.cc │ ├── map.cc │ ├── synchronize.cc │ ├── equivalent.cc │ ├── isomorphic.cc │ ├── reverse.cc │ ├── randgen.cc │ ├── Makefile.am │ ├── epsnormalize.cc │ ├── shortest-path.cc │ ├── libfstscript.vcxproj │ ├── stateiterator-class.cc │ ├── compose.cc │ ├── minimize.cc │ ├── intersect.cc │ ├── determinize.cc │ ├── difference.cc │ ├── disambiguate.cc │ ├── encodemapper-class.cc │ ├── randequivalent.cc │ ├── print.cc │ ├── replace.cc │ ├── decode.cc │ ├── encode.cc │ ├── push.cc │ ├── CMakeLists.txt │ ├── draw.cc │ ├── concat.cc │ ├── info.cc │ ├── shortest-distance.cc │ ├── prune.cc │ ├── relabel.cc │ └── arciterator-class.cc └── test │ └── Makefile.am ├── Makefile.am ├── .editorconfig ├── .gitignore ├── COPYING ├── AUTHORS ├── m4 └── ltversion.m4 ├── BUGS.md └── CMakeLists.txt /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = include lib script bin test extensions 2 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | EXTRA_DIST = BUILD.bazel 5 | -------------------------------------------------------------------------------- /src/include/fst/config.h: -------------------------------------------------------------------------------- 1 | // Windows-specific OpenFst config file 2 | // No dynamic registration. 3 | #define FST_NO_DYNAMIC_LINKING 1 4 | -------------------------------------------------------------------------------- /src/bin/fstunion.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | int fstunion_main(int argc, char **argv); 5 | 6 | int main(int argc, char **argv) { return fstunion_main(argc, argv); } 7 | -------------------------------------------------------------------------------- /src/bin/fstconcat.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | int fstconcat_main(int argc, char **argv); 5 | 6 | int main(int argc, char **argv) { return fstconcat_main(argc, argv); } 7 | -------------------------------------------------------------------------------- /src/bin/fstconnect.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | int fstconnect_main(int argc, char **argv); 5 | 6 | int main(int argc, char **argv) { return fstconnect_main(argc, argv); } 7 | -------------------------------------------------------------------------------- /src/bin/fstinvert.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | int fstinvert_main(int argc, char **argv); 5 | 6 | int main(int argc, char **argv) { return fstinvert_main(argc, argv); } 7 | -------------------------------------------------------------------------------- /src/bin/fsttopsort.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | int fsttopsort_main(int argc, char **argv); 5 | 6 | int main(int argc, char **argv) { return fsttopsort_main(argc, argv); } 7 | -------------------------------------------------------------------------------- /src/bin/fstsynchronize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | int fstsynchronize_main(int argc, char **argv); 5 | 6 | int main(int argc, char **argv) { return fstsynchronize_main(argc, argv); } 7 | -------------------------------------------------------------------------------- /src/extensions/special/fstspecial.cc: -------------------------------------------------------------------------------- 1 | // Work-around to correctly build (e.g. distclean) with autotools 2 | // using files in another directory that are also built there. 3 | // See https://stackoverflow.com/questions/30379837. 4 | 5 | #include "fstconvert-main.cc" // NOLINT 6 | #include "fstconvert.cc" // NOLINT 7 | -------------------------------------------------------------------------------- /src/bin/fstconvert.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(fst_type, "vector", "Output FST type"); 7 | 8 | int fstconvert_main(int argc, char **argv); 9 | 10 | int main(int argc, char **argv) { return fstconvert_main(argc, argv); } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; EditorConfig to support per-solution formatting. 2 | ; Use the EditorConfig VS add-in to make this work before VS 2017 3 | 4 | ; This is the default for the codeline. 5 | root = true 6 | 7 | [*] 8 | charset = utf-8 ; Remove the pesky BOM from files. 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /src/bin/fstproject.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(project_output, false, "Project on output (vs. input)"); 7 | 8 | int fstproject_main(int argc, char **argv); 9 | 10 | int main(int argc, char **argv) { return fstproject_main(argc, argv); } 11 | -------------------------------------------------------------------------------- /src/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../include $(ICU_CPPFLAGS) 2 | 3 | lib_LTLIBRARIES = libfst.la 4 | libfst_la_SOURCES = compat.cc flags.cc fst.cc fst-types.cc mapped-file.cc \ 5 | properties.cc symbol-table.cc symbol-table-ops.cc \ 6 | weight.cc util.cc 7 | libfst_la_LDFLAGS = -version-info 16:0:0 8 | libfst_la_LIBADD = $(DL_LIBS) 9 | -------------------------------------------------------------------------------- /src/bin/fstreverse.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(require_superinitial, true, "Always create a superinitial state"); 7 | 8 | int fstreverse_main(int argc, char **argv); 9 | 10 | int main(int argc, char **argv) { return fstreverse_main(argc, argv); } 11 | -------------------------------------------------------------------------------- /src/bin/fstepsnormalize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(eps_norm_output, false, "Normalize output epsilons"); 7 | 8 | int fstepsnormalize_main(int argc, char **argv); 9 | 10 | int main(int argc, char **argv) { return fstepsnormalize_main(argc, argv); } 11 | -------------------------------------------------------------------------------- /src/bin/fstreweight.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(to_final, false, "Push/reweight to final (vs. to initial) states"); 7 | 8 | int fstreweight_main(int argc, char **argv); 9 | 10 | int main(int argc, char **argv) { return fstreweight_main(argc, argv); } 11 | -------------------------------------------------------------------------------- /src/extensions/python/memory.pxd: -------------------------------------------------------------------------------- 1 | # See www.openfst.org for extensive documentation on this weighted 2 | # finite-state transducer library. 3 | 4 | 5 | from libcpp.memory cimport shared_ptr 6 | 7 | 8 | # This is mysteriously missing from libcpp.memory. 9 | 10 | cdef extern from "" namespace "std" nogil: 11 | 12 | shared_ptr[T] static_pointer_cast[T, U](const shared_ptr[U] &) 13 | -------------------------------------------------------------------------------- /src/bin/fstequal.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 8 | 9 | int fstequal_main(int argc, char **argv); 10 | 11 | int main(int argc, char **argv) { return fstequal_main(argc, argv); } 12 | -------------------------------------------------------------------------------- /src/include/fst/config.h.in: -------------------------------------------------------------------------------- 1 | // OpenFst config file 2 | 3 | /* Define to 1 if you have the ICU library. */ 4 | #undef HAVE_ICU 5 | 6 | /* Define to 1 if the system has the type `std::tr1::hash'. */ 8 | #define HAVE_STD__TR1__HASH_LONG_LONG_UNSIGNED_ 1 9 | 10 | /* Define to 1 if the system has the type `__gnu_cxx::slist'. */ 11 | #define HAVE___GNU_CXX__SLIST_INT_ 1 12 | -------------------------------------------------------------------------------- /src/bin/fstclosure.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(closure_plus, false, 7 | "Do not add the empty path (T+ instead of T*)?"); 8 | 9 | int fstclosure_main(int argc, char **argv); 10 | 11 | int main(int argc, char **argv) { return fstclosure_main(argc, argv); } 12 | -------------------------------------------------------------------------------- /src/bin/fstisomorphic.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 8 | 9 | int fstisomorphic_main(int argc, char **argv); 10 | 11 | int main(int argc, char **argv) { return fstisomorphic_main(argc, argv); } 12 | -------------------------------------------------------------------------------- /src/extensions/linear/linear-tagger-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | using fst::LinearTaggerFst; 8 | using fst::StdArc; 9 | using fst::LogArc; 10 | 11 | REGISTER_FST(LinearTaggerFst, StdArc); 12 | REGISTER_FST(LinearTaggerFst, LogArc); 13 | -------------------------------------------------------------------------------- /src/extensions/linear/linear-classifier-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | using fst::LinearClassifierFst; 8 | using fst::StdArc; 9 | using fst::LogArc; 10 | 11 | REGISTER_FST(LinearClassifierFst, StdArc); 12 | REGISTER_FST(LinearClassifierFst, LogArc); 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore extensionless files 2 | * 3 | !*.* 4 | !*/ 5 | 6 | # Other patterns 7 | /config.h 8 | /config.log 9 | /config.status 10 | .deps/ 11 | .libs/ 12 | .dirstamp 13 | *.la 14 | *.lo 15 | *.o 16 | 17 | # Windows-specific files 18 | .vs/ 19 | *.VC.db 20 | Win32/ 21 | x64/ 22 | Debug/ 23 | Release/ 24 | obj/ 25 | /bin/ 26 | *.binlog 27 | *proj.user 28 | /cmake 29 | /cmake64 30 | /CMakeSettings.json 31 | /*.zip 32 | src/libfst.log -------------------------------------------------------------------------------- /src/bin/fstarcsort.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | DEFINE_string(sort_type, "ilabel", 8 | "Comparison method, one of: \"ilabel\", \"olabel\""); 9 | 10 | int fstarcsort_main(int argc, char **argv); 11 | 12 | int main(int argc, char **argv) { return fstarcsort_main(argc, argv); } 13 | -------------------------------------------------------------------------------- /src/extensions/ngram/ngram-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | using fst::NGramFst; 12 | using fst::StdArc; 13 | using fst::LogArc; 14 | 15 | REGISTER_FST(NGramFst, StdArc); 16 | REGISTER_FST(NGramFst, LogArc); 17 | -------------------------------------------------------------------------------- /src/extensions/python/basictypes.pxd: -------------------------------------------------------------------------------- 1 | # See www.openfst.org for extensive documentation on this weighted 2 | # finite-state transducer library. 3 | 4 | 5 | from libc.stdint cimport * 6 | 7 | 8 | cdef extern from "" nogil: 9 | 10 | ctypedef int8_t int8 11 | ctypedef int16_t int16 12 | ctypedef int32_t int32 13 | ctypedef int64_t int64 14 | ctypedef uint8_t uint8 15 | ctypedef uint16_t uint16 16 | ctypedef uint32_t uint32 17 | ctypedef uint64_t uint64 18 | -------------------------------------------------------------------------------- /src/extensions/ngram/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | libfstdir = @libfstdir@ 4 | libfst_LTLIBRARIES = ngram-fst.la 5 | 6 | lib_LTLIBRARIES = libfstngram.la 7 | 8 | ngram_fst_la_SOURCES = bitmap-index.cc ngram-fst.cc nthbit.cc 9 | ngram_fst_la_LDFLAGS = -module 10 | 11 | libfstngram_la_SOURCES = bitmap-index.cc ngram-fst.cc nthbit.cc 12 | libfstngram_la_LDFLAGS = -version-info 16:0:0 13 | libfstngram_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 14 | -------------------------------------------------------------------------------- /src/extensions/far/sttable.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | bool IsSTTable(const string &filename) { 10 | std::ifstream strm(filename); 11 | if (!strm.good()) return false; 12 | 13 | int32 magic_number = 0; 14 | ReadType(strm, &magic_number); 15 | return magic_number == kSTTableMagicNumber; 16 | } 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/bin/fstminimize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | DEFINE_double(delta, fst::kShortestDelta, "Comparison/quantization delta"); 9 | DEFINE_bool(allow_nondet, false, "Minimize non-deterministic FSTs"); 10 | 11 | int fstminimize_main(int argc, char **argv); 12 | 13 | int main(int argc, char **argv) { return fstminimize_main(argc, argv); } 14 | -------------------------------------------------------------------------------- /src/extensions/const/const8-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> ConstFst_StdArc_uint8_registerer; 10 | static FstRegisterer> ConstFst_LogArc_uint8_registerer; 11 | static FstRegisterer> 12 | ConstFst_Log64Arc_uint8_registerer; 13 | 14 | } // namespace fst 15 | -------------------------------------------------------------------------------- /src/bin/fstintersect.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(compose_filter, "auto", 7 | "Composition filter, one of: \"alt_sequence\", \"auto\", " 8 | "\"match\", \"null\", \"sequence\", \"trivial\""); 9 | DEFINE_bool(connect, true, "Trim output"); 10 | 11 | int fstintersect_main(int argc, char **argv); 12 | 13 | int main(int argc, char **argv) { return fstintersect_main(argc, argv); } 14 | -------------------------------------------------------------------------------- /src/bin/fstprune.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 9 | DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 10 | DEFINE_string(weight, "", "Weight threshold"); 11 | 12 | int fstprune_main(int argc, char **argv); 13 | 14 | int main(int argc, char **argv) { return fstprune_main(argc, argv); } 15 | -------------------------------------------------------------------------------- /src/bin/fstdifference.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(compose_filter, "auto", 7 | "Composition filter, one of: \"alt_sequence\", \"auto\", " 8 | "\"match\", \"null\", \"sequence\", \"trivial\""); 9 | DEFINE_bool(connect, true, "Trim output"); 10 | 11 | int fstdifference_main(int argc, char **argv); 12 | 13 | int main(int argc, char **argv) { return fstdifference_main(argc, argv); } 14 | -------------------------------------------------------------------------------- /src/bin/fstencode.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(encode_labels, false, "Encode output labels"); 7 | DEFINE_bool(encode_weights, false, "Encode weights"); 8 | DEFINE_bool(encode_reuse, false, "Re-use existing codex"); 9 | DEFINE_bool(decode, false, "Decode labels and/or weights"); 10 | 11 | int fstencode_main(int argc, char **argv); 12 | 13 | int main(int argc, char **argv) { return fstencode_main(argc, argv); } 14 | -------------------------------------------------------------------------------- /src/bin/fstcompose.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(compose_filter, "auto", 7 | "Composition filter, one of: \"alt_sequence\", \"auto\", " 8 | "\"match\", \"no_match\", \"null\", \"sequence\", \"trivial\""); 9 | DEFINE_bool(connect, true, "Trim output"); 10 | 11 | int fstcompose_main(int argc, char **argv); 12 | 13 | int main(int argc, char **argv) { return fstcompose_main(argc, argv); } 14 | -------------------------------------------------------------------------------- /src/extensions/const/const16-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | ConstFst_StdArc_uint16_registerer; 11 | static FstRegisterer> 12 | ConstFst_LogArc_uint16_registerer; 13 | static FstRegisterer> 14 | ConstFst_Log64Arc_uint16_registerer; 15 | 16 | } // namespace fst 17 | -------------------------------------------------------------------------------- /src/extensions/const/const64-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | ConstFst_StdArc_uint64_registerer; 11 | static FstRegisterer> 12 | ConstFst_LogArc_uint64_registerer; 13 | static FstRegisterer> 14 | ConstFst_Log64Arc_uint64_registerer; 15 | 16 | } // namespace fst 17 | -------------------------------------------------------------------------------- /src/extensions/far/stlist.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace fst { 10 | 11 | bool IsSTList(const string &filename) { 12 | std::ifstream strm(filename, std::ios_base::in | std::ios_base::binary); 13 | if (!strm) return false; 14 | int32 magic_number = 0; 15 | ReadType(strm, &magic_number); 16 | return magic_number == kSTListMagicNumber; 17 | } 18 | 19 | } // namespace fst 20 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #-DHAVE_CONFIG_H -I./../include -fno-exceptions -funsigned-char -std=c++11 -MT symbol-table.lo -MD -MP -MF .deps/symbol-table.Tpo -c symbol-table.cc -fno-common -DPIC -o .libs/symbol-table.o 3 | 4 | include_directories(./include/) 5 | install(DIRECTORY include/ DESTINATION include/ 6 | FILES_MATCHING PATTERN "*.h") 7 | 8 | add_subdirectory(lib) 9 | add_subdirectory(script) 10 | 11 | if(HAVE_BIN) 12 | add_subdirectory(bin) 13 | endif(HAVE_BIN) 14 | 15 | add_subdirectory(extensions) 16 | 17 | enable_testing() 18 | add_subdirectory(test) 19 | -------------------------------------------------------------------------------- /src/include/fst/script/invert.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_INVERT_H_ 5 | #define FST_SCRIPT_INVERT_H_ 6 | 7 | #include 8 | #include 9 | 10 | namespace fst { 11 | namespace script { 12 | 13 | template 14 | void Invert(MutableFstClass *fst) { 15 | Invert(fst->GetMutableFst()); 16 | } 17 | 18 | void Invert(MutableFstClass *fst); 19 | 20 | } // namespace script 21 | } // namespace fst 22 | 23 | #endif // FST_SCRIPT_INVERT_H_ 24 | -------------------------------------------------------------------------------- /src/include/fst/script/connect.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_CONNECT_H_ 5 | #define FST_SCRIPT_CONNECT_H_ 6 | 7 | #include 8 | #include 9 | 10 | namespace fst { 11 | namespace script { 12 | 13 | template 14 | void Connect(MutableFstClass *fst) { 15 | Connect(fst->GetMutableFst()); 16 | } 17 | 18 | void Connect(MutableFstClass *fst); 19 | 20 | } // namespace script 21 | } // namespace fst 22 | 23 | #endif // FST_SCRIPT_CONNECT_H_ 24 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); 2 | you may not use these files except in compliance with the License. 3 | You may obtain a copy of the License at 4 | 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | 13 | Copyright 2005-2018 Google, Inc. 14 | -------------------------------------------------------------------------------- /src/extensions/compact/compact8_string-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactStringFst_StdArc_uint8_registerer; 11 | 12 | static FstRegisterer> 13 | CompactStringFst_LogArc_uint8_registerer; 14 | 15 | static FstRegisterer> 16 | CompactStringFst_Log64Arc_uint8_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/extensions/compact/compact16_string-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactStringFst_StdArc_uint16_registerer; 11 | 12 | static FstRegisterer> 13 | CompactStringFst_LogArc_uint16_registerer; 14 | 15 | static FstRegisterer> 16 | CompactStringFst_Log64Arc_uint16_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/extensions/compact/compact64_string-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactStringFst_StdArc_uint64_registerer; 11 | 12 | static FstRegisterer> 13 | CompactStringFst_LogArc_uint64_registerer; 14 | 15 | static FstRegisterer> 16 | CompactStringFst_Log64Arc_uint64_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB HEADER_FILES ../include/fst/*.h) 2 | 3 | 4 | add_library(fst 5 | compat.cc 6 | flags.cc 7 | fst-types.cc 8 | fst.cc 9 | mapped-file.cc 10 | properties.cc 11 | symbol-table.cc 12 | symbol-table-ops.cc 13 | util.cc 14 | weight.cc 15 | ${HEADER_FILES} 16 | ) 17 | set_target_properties(fst PROPERTIES 18 | SOVERSION "${SOVERSION}" 19 | ) 20 | 21 | if(WIN32) 22 | target_link_options(fst INTERFACE /WHOLEARCHIVE:$) 23 | endif() 24 | 25 | install(TARGETS fst 26 | LIBRARY DESTINATION lib 27 | ARCHIVE DESTINATION lib 28 | RUNTIME DESTINATION lib) 29 | -------------------------------------------------------------------------------- /src/extensions/compact/compact8_acceptor-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactAcceptorFst_StdArc_uint8_registerer; 11 | 12 | static FstRegisterer> 13 | CompactAcceptorFst_LogArc_uint8_registerer; 14 | 15 | static FstRegisterer> 16 | CompactAcceptorFst_Log64Arc_uint8_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Principal Contacts: 2 | 3 | Cyril Allauzen 4 | Michael Riley 5 | 6 | Contributors: 7 | 8 | These contributions range from fundamental algorithmic contributions (e.g., 9 | Mehryar Mohri) to implementation of core components and extensions. 10 | 11 | Tom Bagby 12 | Dan Bikel 13 | Kyle Gorman 14 | Martin Jansche 15 | Boulos Harb 16 | Mehryar Mohri 17 | Dan Povey 18 | Kasturi Raghavan 19 | Jacob Ratkiewicz 20 | Jesse Rosenstock 21 | Johan Schalkwyk 22 | Masha Shugrina 23 | Wojtek Skut 24 | Jeffrey Sorensen 25 | Richard Sproat 26 | Ananda Theertha Suresh 27 | Terry Tai 28 | Ke Wu 29 | -------------------------------------------------------------------------------- /src/extensions/compact/compact16_acceptor-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactAcceptorFst_StdArc_uint16_registerer; 11 | 12 | static FstRegisterer> 13 | CompactAcceptorFst_LogArc_uint16_registerer; 14 | 15 | static FstRegisterer> 16 | CompactAcceptorFst_Log64Arc_uint16_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/extensions/compact/compact64_acceptor-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactAcceptorFst_StdArc_uint64_registerer; 11 | 12 | static FstRegisterer> 13 | CompactAcceptorFst_LogArc_uint64_registerer; 14 | 15 | static FstRegisterer> 16 | CompactAcceptorFst_Log64Arc_uint64_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/script/libfstscript.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/extensions/compact/compact8_unweighted-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactUnweightedFst_StdArc_uint8_registerer; 11 | 12 | static FstRegisterer> 13 | CompactUnweightedFst_LogArc_uint8_registerer; 14 | 15 | static FstRegisterer> 16 | CompactUnweightedFst_Log64Arc_uint8_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/extensions/compact/compact64_unweighted-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactUnweightedFst_StdArc_uint64_registerer; 11 | 12 | static FstRegisterer> 13 | CompactUnweightedFst_LogArc_uint64_registerer; 14 | 15 | static FstRegisterer> 16 | CompactUnweightedFst_Log64Arc_uint64_registerer; 17 | 18 | } // namespace fst 19 | -------------------------------------------------------------------------------- /src/extensions/compact/compact16_unweighted-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer> 10 | CompactUnweightedFst_StdArc_uint16_registerer; 11 | 12 | static FstRegisterer> 13 | CompactUnweightedFst_LogArc_uint16_registerer; 14 | 15 | static FstRegisterer> 16 | CompactUnweightedFst_Log64Arc_uint16_registerer; 17 | 18 | 19 | } // namespace fst 20 | -------------------------------------------------------------------------------- /src/include/fst/extensions/pdt/getters.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_EXTENSIONS_PDT_GETTERS_H_ 5 | #define FST_EXTENSIONS_PDT_GETTERS_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | bool GetPdtComposeFilter(const string &str, PdtComposeFilter *cf); 16 | 17 | bool GetPdtParserType(const string &str, PdtParserType *pt); 18 | 19 | } // namespace script 20 | } // namespace fst 21 | 22 | #endif // FST_EXTENSIONS_PDT_GETTERS_H_ 23 | -------------------------------------------------------------------------------- /src/script/invert.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Invert(MutableFstClass *fst) { 12 | Apply>("Invert", fst->ArcType(), fst); 13 | } 14 | 15 | REGISTER_FST_OPERATION(Invert, StdArc, MutableFstClass); 16 | REGISTER_FST_OPERATION(Invert, LogArc, MutableFstClass); 17 | REGISTER_FST_OPERATION(Invert, Log64Arc, MutableFstClass); 18 | 19 | } // namespace script 20 | } // namespace fst 21 | -------------------------------------------------------------------------------- /src/script/connect.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Connect(MutableFstClass *fst) { 12 | Apply>("Connect", fst->ArcType(), fst); 13 | } 14 | 15 | REGISTER_FST_OPERATION(Connect, StdArc, MutableFstClass); 16 | REGISTER_FST_OPERATION(Connect, LogArc, MutableFstClass); 17 | REGISTER_FST_OPERATION(Connect, Log64Arc, MutableFstClass); 18 | 19 | } // namespace script 20 | } // namespace fst 21 | -------------------------------------------------------------------------------- /src/extensions/const/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | libfstdir = @libfstdir@ 4 | libfst_LTLIBRARIES = const8-fst.la const16-fst.la const64-fst.la 5 | 6 | lib_LTLIBRARIES = libfstconst.la 7 | 8 | libfstconst_la_SOURCES = const8-fst.cc const16-fst.cc const64-fst.cc 9 | libfstconst_la_LDFLAGS = -version-info 16:0:0 -lm $(DL_LIBS) 10 | libfstconst_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 11 | 12 | const8_fst_la_SOURCES = const8-fst.cc 13 | const8_fst_la_LDFLAGS = -module 14 | 15 | const16_fst_la_SOURCES = const16-fst.cc 16 | const16_fst_la_LDFLAGS = -module 17 | 18 | const64_fst_la_SOURCES = const64-fst.cc 19 | const64_fst_la_LDFLAGS = -module 20 | -------------------------------------------------------------------------------- /src/extensions/compact/compact8_weighted_string-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer< 10 | CompactWeightedStringFst> 11 | CompactWeightedStringFst_StdArc_uint8_registerer; 12 | 13 | static FstRegisterer< 14 | CompactWeightedStringFst> 15 | CompactWeightedStringFst_LogArc_uint8_registerer; 16 | 17 | static FstRegisterer< 18 | CompactWeightedStringFst> 19 | CompactWeightedStringFst_Log64Arc_uint8_registerer; 20 | 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/script/verify.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | bool Verify(const FstClass &fst) { 12 | VerifyArgs args(fst); 13 | Apply>("Verify", fst.ArcType(), &args); 14 | return args.retval; 15 | } 16 | 17 | REGISTER_FST_OPERATION(Verify, StdArc, VerifyArgs); 18 | REGISTER_FST_OPERATION(Verify, LogArc, VerifyArgs); 19 | REGISTER_FST_OPERATION(Verify, Log64Arc, VerifyArgs); 20 | 21 | } // namespace script 22 | } // namespace fst 23 | -------------------------------------------------------------------------------- /src/extensions/compact/compact16_weighted_string-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer< 10 | CompactWeightedStringFst> 11 | CompactWeightedStringFst_StdArc_uint16_registerer; 12 | 13 | static FstRegisterer< 14 | CompactWeightedStringFst> 15 | CompactWeightedStringFst_LogArc_uint16_registerer; 16 | 17 | static FstRegisterer< 18 | CompactWeightedStringFst> 19 | CompactWeightedStringFst_Log64Arc_uint16_registerer; 20 | 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/extensions/compact/compact64_weighted_string-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer< 10 | CompactWeightedStringFst> 11 | CompactWeightedStringFst_StdArc_uint64_registerer; 12 | 13 | static FstRegisterer< 14 | CompactWeightedStringFst> 15 | CompactWeightedStringFst_LogArc_uint64_registerer; 16 | 17 | static FstRegisterer< 18 | CompactWeightedStringFst> 19 | CompactWeightedStringFst_Log64Arc_uint64_registerer; 20 | 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/script/topsort.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | bool TopSort(MutableFstClass *fst) { 12 | TopSortArgs args(fst); 13 | Apply>("TopSort", fst->ArcType(), &args); 14 | return args.retval; 15 | } 16 | 17 | REGISTER_FST_OPERATION(TopSort, StdArc, TopSortArgs); 18 | REGISTER_FST_OPERATION(TopSort, LogArc, TopSortArgs); 19 | REGISTER_FST_OPERATION(TopSort, Log64Arc, TopSortArgs); 20 | 21 | } // namespace script 22 | } // namespace fst 23 | -------------------------------------------------------------------------------- /src/script/arcsort.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void ArcSort(MutableFstClass *fst, ArcSortType sort_type) { 12 | ArcSortArgs args(fst, sort_type); 13 | Apply>("ArcSort", fst->ArcType(), &args); 14 | } 15 | 16 | REGISTER_FST_OPERATION(ArcSort, StdArc, ArcSortArgs); 17 | REGISTER_FST_OPERATION(ArcSort, LogArc, ArcSortArgs); 18 | REGISTER_FST_OPERATION(ArcSort, Log64Arc, ArcSortArgs); 19 | 20 | } // namespace script 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/extensions/compact/compact8_unweighted_acceptor-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer< 10 | CompactUnweightedAcceptorFst> 11 | CompactUnweightedAcceptorFst_StdArc_uint8_registerer; 12 | 13 | static FstRegisterer< 14 | CompactUnweightedAcceptorFst> 15 | CompactUnweightedAcceptorFst_LogArc_uint8_registerer; 16 | 17 | static FstRegisterer< 18 | CompactUnweightedAcceptorFst> 19 | CompactUnweightedAcceptorFst_Log64Arc_uint8_registerer; 20 | 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/include/fst/extensions/far/script-impl.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Classes and functions for registering and invoking Far main 5 | // functions that support multiple and extensible arc types. 6 | 7 | #ifndef FST_EXTENSIONS_FAR_SCRIPT_IMPL_H_ 8 | #define FST_EXTENSIONS_FAR_SCRIPT_IMPL_H_ 9 | 10 | #include 11 | 12 | #include 13 | namespace fst { 14 | namespace script { 15 | 16 | string LoadArcTypeFromFar(const string &far_fname); 17 | 18 | string LoadArcTypeFromFst(const string &fst_fname); 19 | 20 | } // namespace script 21 | } // namespace fst 22 | 23 | #endif // FST_EXTENSIONS_FAR_SCRIPT_IMPL_H_ 24 | -------------------------------------------------------------------------------- /src/script/closure.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Closure(MutableFstClass *fst, ClosureType closure_type) { 12 | ClosureArgs args(fst, closure_type); 13 | Apply>("Closure", fst->ArcType(), &args); 14 | } 15 | 16 | REGISTER_FST_OPERATION(Closure, StdArc, ClosureArgs); 17 | REGISTER_FST_OPERATION(Closure, LogArc, ClosureArgs); 18 | REGISTER_FST_OPERATION(Closure, Log64Arc, ClosureArgs); 19 | 20 | } // namespace script 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/extensions/compact/compact16_unweighted_acceptor-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer< 10 | CompactUnweightedAcceptorFst> 11 | CompactUnweightedAcceptorFst_StdArc_uint16_registerer; 12 | 13 | static FstRegisterer< 14 | CompactUnweightedAcceptorFst> 15 | CompactUnweightedAcceptorFst_LogArc_uint16_registerer; 16 | 17 | static FstRegisterer< 18 | CompactUnweightedAcceptorFst> 19 | CompactUnweightedAcceptorFst_Log64Arc_uint16_registerer; 20 | 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/extensions/compact/compact64_unweighted_acceptor-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer< 10 | CompactUnweightedAcceptorFst> 11 | CompactUnweightedAcceptorFst_StdArc_uint64_registerer; 12 | 13 | static FstRegisterer< 14 | CompactUnweightedAcceptorFst> 15 | CompactUnweightedAcceptorFst_LogArc_uint64_registerer; 16 | 17 | static FstRegisterer< 18 | CompactUnweightedAcceptorFst> 19 | CompactUnweightedAcceptorFst_Log64Arc_uint64_registerer; 20 | 21 | } // namespace fst 22 | -------------------------------------------------------------------------------- /src/include/fst/script/topsort.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_TOPSORT_H_ 5 | #define FST_SCRIPT_TOPSORT_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fst { 12 | namespace script { 13 | 14 | using TopSortArgs = WithReturnValue; 15 | 16 | template 17 | void TopSort(TopSortArgs *args) { 18 | args->retval = TopSort(args->args->GetMutableFst()); 19 | } 20 | 21 | bool TopSort(MutableFstClass *fst); 22 | 23 | } // namespace script 24 | } // namespace fst 25 | 26 | #endif // FST_SCRIPT_TOPSORT_H_ 27 | -------------------------------------------------------------------------------- /src/script/project.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | 12 | void Project(MutableFstClass *ofst, ProjectType project_type) { 13 | ProjectArgs args(ofst, project_type); 14 | Apply>("Project", ofst->ArcType(), &args); 15 | } 16 | 17 | REGISTER_FST_OPERATION(Project, StdArc, ProjectArgs); 18 | REGISTER_FST_OPERATION(Project, LogArc, ProjectArgs); 19 | REGISTER_FST_OPERATION(Project, Log64Arc, ProjectArgs); 20 | 21 | } // namespace script 22 | } // namespace fst 23 | -------------------------------------------------------------------------------- /src/bin/fstdisambiguate.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 9 | DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 10 | DEFINE_string(weight, "", "Weight threshold"); 11 | DEFINE_int64(subsequential_label, 0, 12 | "Input label of arc corresponding to residual final output when" 13 | " producing a subsequential transducer"); 14 | 15 | int fstdisambiguate_main(int argc, char **argv); 16 | 17 | int main(int argc, char **argv) { return fstdisambiguate_main(argc, argv); } 18 | -------------------------------------------------------------------------------- /src/extensions/lookahead/arc_lookahead-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer ArcLookAheadFst_StdArc_registerer; 10 | static FstRegisterer, ArcLookAheadMatcher>>, 12 | arc_lookahead_fst_type>> 13 | ArcLookAheadFst_LogArc_registerer; 14 | static FstRegisterer, ArcLookAheadMatcher>>, 16 | arc_lookahead_fst_type>> 17 | ArcLookAheadFst_Log64Arc_registerer; 18 | 19 | } // namespace fst 20 | -------------------------------------------------------------------------------- /src/include/fst/script/verify.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_VERIFY_H_ 5 | #define FST_SCRIPT_VERIFY_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fst { 12 | namespace script { 13 | 14 | using VerifyArgs = WithReturnValue; 15 | 16 | template 17 | void Verify(VerifyArgs *args) { 18 | const Fst &fst = *(args->args.GetFst()); 19 | args->retval = Verify(fst); 20 | } 21 | 22 | bool Verify(const FstClass &fst); 23 | 24 | } // namespace script 25 | } // namespace fst 26 | 27 | #endif // FST_SCRIPT_VERIFY_H_ 28 | -------------------------------------------------------------------------------- /src/extensions/compress/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | if HAVE_BIN 4 | bin_PROGRAMS = fstcompress fstrandmod 5 | 6 | LDADD = libfstcompressscript.la \ 7 | ../../script/libfstscript.la \ 8 | ../../lib/libfst.la \ 9 | -lm $(DL_LIBS) 10 | 11 | fstcompress_SOURCES = fstcompress.cc 12 | fstrandmod_SOURCES = fstrandmod.cc 13 | endif 14 | 15 | if HAVE_SCRIPT 16 | libfstcompressscript_la_SOURCES = compress-script.cc 17 | libfstcompressscript_la_LDFLAGS = -version-info 16:0:0 18 | libfstcompressscript_la_LIBADD = \ 19 | ../../script/libfstscript.la \ 20 | ../../lib/libfst.la -lz -lm $(DL_LIBS) 21 | endif 22 | 23 | if HAVE_SCRIPT 24 | lib_LTLIBRARIES = libfstcompressscript.la 25 | endif 26 | -------------------------------------------------------------------------------- /src/include/fst/script/fstscript-decl.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Forward declarations for the FST and FST script classes. 5 | 6 | #ifndef FST_SCRIPT_FSTSCRIPT_DECL_H_ 7 | #define FST_SCRIPT_FSTSCRIPT_DECL_H_ 8 | 9 | #include 10 | 11 | namespace fst { 12 | namespace script { 13 | 14 | class ArcClass; 15 | 16 | class ArcIteratorClass; 17 | class MutableArcIteratorClass; 18 | 19 | class EncodeMapperClass; 20 | 21 | class FstClass; 22 | class MutableFstClass; 23 | class VectorFstClass; 24 | 25 | class StateIteratorClass; 26 | 27 | class WeightClass; 28 | 29 | } // namespace script 30 | } // namespace fst; 31 | 32 | #endif // FST_SCRIPT_FSTSCRIPT_DECL_H_ 33 | -------------------------------------------------------------------------------- /src/script/convert.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | FstClass *Convert(const FstClass &ifst, const string &new_type) { 12 | ConvertInnerArgs iargs(ifst, new_type); 13 | ConvertArgs args(iargs); 14 | Apply>("Convert", ifst.ArcType(), &args); 15 | return args.retval; 16 | } 17 | 18 | REGISTER_FST_OPERATION(Convert, StdArc, ConvertArgs); 19 | REGISTER_FST_OPERATION(Convert, LogArc, ConvertArgs); 20 | REGISTER_FST_OPERATION(Convert, Log64Arc, ConvertArgs); 21 | 22 | } // namespace script 23 | } // namespace fst 24 | -------------------------------------------------------------------------------- /src/include/fst/script/project.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_PROJECT_H_ 5 | #define FST_SCRIPT_PROJECT_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using ProjectArgs = std::pair; 16 | 17 | template 18 | void Project(ProjectArgs *args) { 19 | MutableFst *fst = std::get<0>(*args)->GetMutableFst(); 20 | Project(fst, std::get<1>(*args)); 21 | } 22 | 23 | void Project(MutableFstClass *fst, ProjectType project_type); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | 28 | #endif // FST_SCRIPT_PROJECT_H_ 29 | -------------------------------------------------------------------------------- /src/bin/fstpush.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 8 | DEFINE_bool(push_weights, false, "Push weights"); 9 | DEFINE_bool(push_labels, false, "Push output labels"); 10 | DEFINE_bool(remove_total_weight, false, 11 | "Remove total weight when pushing weights"); 12 | DEFINE_bool(remove_common_affix, false, 13 | "Remove common prefix/suffix when pushing labels"); 14 | DEFINE_bool(to_final, false, "Push/reweight to final (vs. to initial) states"); 15 | 16 | int fstpush_main(int argc, char **argv); 17 | 18 | int main(int argc, char **argv) { return fstpush_main(argc, argv); } 19 | -------------------------------------------------------------------------------- /src/bin/fstshortestdistance.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | DEFINE_bool(reverse, false, "Perform in the reverse direction"); 10 | DEFINE_double(delta, fst::kShortestDelta, "Comparison/quantization delta"); 11 | DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 12 | DEFINE_string(queue_type, "auto", 13 | "Queue type: one of: \"auto\", " 14 | "\"fifo\", \"lifo\", \"shortest\", \"state\", \"top\""); 15 | 16 | int fstshortestdistance_main(int argc, char **argv); 17 | 18 | int main(int argc, char **argv) { return fstshortestdistance_main(argc, argv); } 19 | -------------------------------------------------------------------------------- /src/include/fst/script/closure.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_CLOSURE_H_ 5 | #define FST_SCRIPT_CLOSURE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using ClosureArgs = std::pair; 16 | 17 | template 18 | void Closure(ClosureArgs *args) { 19 | MutableFst *fst = std::get<0>(*args)->GetMutableFst(); 20 | Closure(fst, std::get<1>(*args)); 21 | } 22 | 23 | void Closure(MutableFstClass *ofst, ClosureType closure_type); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | 28 | #endif // FST_SCRIPT_CLOSURE_H_ 29 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 4179 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.6]) 16 | m4_define([LT_PACKAGE_REVISION], [2.4.6]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.6' 20 | macro_revision='2.4.6' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /src/bin/fstrmepsilon.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | DEFINE_bool(connect, true, "Trim output"); 10 | DEFINE_double(delta, fst::kShortestDelta, "Comparison/quantization delta"); 11 | DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 12 | DEFINE_string(queue_type, "auto", 13 | "Queue type: one of: \"auto\", " 14 | "\"fifo\", \"lifo\", \"shortest\", \"state\", \"top\""); 15 | DEFINE_string(weight, "", "Weight threshold"); 16 | 17 | int fstrmepsilon_main(int argc, char **argv); 18 | 19 | int main(int argc, char **argv) { return fstrmepsilon_main(argc, argv); } 20 | -------------------------------------------------------------------------------- /src/include/fst/extensions/mpdt/mpdtlib.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // This is an experimental multipush-down transducer (MPDT) library. An MPDT is 5 | // encoded as an FST, where some transitions are labeled with open or close 6 | // parentheses, each mated pair of which is associated to one stack. To be 7 | // interpreted as an MPDT, the parentheses within a stack must balance on a 8 | // path. 9 | 10 | #ifndef FST_EXTENSIONS_MPDT_MPDTLIB_H_ 11 | #define FST_EXTENSIONS_MPDT_MPDTLIB_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #endif // FST_EXTENSIONS_MPDT_MPDTLIB_H_ 19 | -------------------------------------------------------------------------------- /src/include/fst/extensions/pdt/pdtlib.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // This is an experimental push-down transducer (PDT) library. A PDT is 5 | // encoded as an FST, where some transitions are labeled with open or close 6 | // parentheses. To be interpreted as a PDT, the parentheses must balance on a 7 | // path. 8 | 9 | #ifndef FST_EXTENSIONS_PDT_PDTLIB_H_ 10 | #define FST_EXTENSIONS_PDT_PDTLIB_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif // FST_EXTENSIONS_PDT_PDTLIB_H_ 20 | -------------------------------------------------------------------------------- /src/script/reweight.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Reweight(MutableFstClass *fst, const std::vector &potential, 12 | ReweightType reweight_type) { 13 | ReweightArgs args(fst, potential, reweight_type); 14 | Apply>("Reweight", fst->ArcType(), &args); 15 | } 16 | 17 | REGISTER_FST_OPERATION(Reweight, StdArc, ReweightArgs); 18 | REGISTER_FST_OPERATION(Reweight, LogArc, ReweightArgs); 19 | REGISTER_FST_OPERATION(Reweight, Log64Arc, ReweightArgs); 20 | 21 | } // namespace script 22 | } // namespace fst 23 | -------------------------------------------------------------------------------- /src/script/union.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Union(MutableFstClass *fst1, const FstClass &fst2) { 12 | if (!internal::ArcTypesMatch(*fst1, fst2, "Union")) { 13 | fst1->SetProperties(kError, kError); 14 | return; 15 | } 16 | UnionArgs args(fst1, fst2); 17 | Apply>("Union", fst1->ArcType(), &args); 18 | } 19 | 20 | REGISTER_FST_OPERATION(Union, StdArc, UnionArgs); 21 | REGISTER_FST_OPERATION(Union, LogArc, UnionArgs); 22 | REGISTER_FST_OPERATION(Union, Log64Arc, UnionArgs); 23 | 24 | } // namespace script 25 | } // namespace fst 26 | -------------------------------------------------------------------------------- /src/include/fst/script/union.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_UNION_H_ 5 | #define FST_SCRIPT_UNION_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using UnionArgs = std::pair; 16 | 17 | template 18 | void Union(UnionArgs *args) { 19 | MutableFst *fst1 = std::get<0>(*args)->GetMutableFst(); 20 | const Fst &fst2 = *(std::get<1>(*args).GetFst()); 21 | Union(fst1, fst2); 22 | } 23 | 24 | void Union(MutableFstClass *fst1, const FstClass &fst2); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | 29 | #endif // FST_SCRIPT_UNION_H_ 30 | -------------------------------------------------------------------------------- /src/include/fst/extensions/far/farlib.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // A finite-state archive (FAR) is used to store an indexable collection of 5 | // FSTs in a single file. Utilities are provided to create FARs from FSTs, 6 | // to iterate over FARs, and to extract specific FSTs from FARs. 7 | 8 | #ifndef FST_EXTENSIONS_FAR_FARLIB_H_ 9 | #define FST_EXTENSIONS_FAR_FARLIB_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif // FST_EXTENSIONS_FAR_FARLIB_H_ 20 | -------------------------------------------------------------------------------- /src/extensions/mpdt/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | if HAVE_BIN 4 | bin_PROGRAMS = mpdtcompose mpdtexpand mpdtinfo mpdtreverse 5 | 6 | LDADD = libfstmpdtscript.la \ 7 | ../pdt/libfstpdtscript.la \ 8 | ../../script/libfstscript.la \ 9 | ../../lib/libfst.la -lm $(DL_LIBS) 10 | 11 | mpdtcompose_SOURCES = mpdtcompose.cc 12 | 13 | mpdtexpand_SOURCES = mpdtexpand.cc 14 | 15 | mpdtinfo_SOURCES = mpdtinfo.cc 16 | 17 | mpdtreverse_SOURCES = mpdtreverse.cc 18 | endif 19 | 20 | if HAVE_SCRIPT 21 | lib_LTLIBRARIES = libfstmpdtscript.la 22 | libfstmpdtscript_la_SOURCES = mpdtscript.cc 23 | libfstmpdtscript_la_LDFLAGS = -version-info 16:0:0 24 | libfstmpdtscript_la_LIBADD = ../../script/libfstscript.la \ 25 | ../../lib/libfst.la -lm $(DL_LIBS) 26 | endif 27 | -------------------------------------------------------------------------------- /src/extensions/far/strings.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | DEFINE_string(far_field_separator, "\t", 12 | "Set of characters used as a separator between printed fields"); 13 | 14 | namespace fst { 15 | 16 | // Computes the minimal length required to encode each line number as a decimal 17 | // number. 18 | int KeySize(const char *filename) { 19 | std::ifstream istrm(filename); 20 | istrm.seekg(0); 21 | string s; 22 | int nline = 0; 23 | while (getline(istrm, s)) ++nline; 24 | istrm.seekg(0); 25 | return nline ? ceil(log10(nline + 1)) : 1; 26 | } 27 | 28 | } // namespace fst 29 | -------------------------------------------------------------------------------- /src/script/equal.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | bool Equal(const FstClass &fst1, const FstClass &fst2, float delta) { 12 | if (!internal::ArcTypesMatch(fst1, fst2, "Equal")) return false; 13 | EqualInnerArgs iargs(fst1, fst2, delta); 14 | EqualArgs args(iargs); 15 | Apply>("Equal", fst1.ArcType(), &args); 16 | return args.retval; 17 | } 18 | 19 | REGISTER_FST_OPERATION(Equal, StdArc, EqualArgs); 20 | REGISTER_FST_OPERATION(Equal, LogArc, EqualArgs); 21 | REGISTER_FST_OPERATION(Equal, Log64Arc, EqualArgs); 22 | 23 | } // namespace script 24 | } // namespace fst 25 | -------------------------------------------------------------------------------- /src/bin/fstreplace.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(call_arc_labeling, "input", 7 | "Which labels to make non-epsilon on the call arc. " 8 | "One of: \"input\" (default), \"output\", \"both\", \"neither\""); 9 | DEFINE_string(return_arc_labeling, "neither", 10 | "Which labels to make non-epsilon on the return arc. " 11 | "One of: \"input\", \"output\", \"both\", \"neither\" (default)"); 12 | DEFINE_int64(return_label, 0, "Label to put on return arc"); 13 | DEFINE_bool(epsilon_on_replace, false, "Call/return arcs are epsilon arcs?"); 14 | 15 | int fstreplace_main(int argc, char **argv); 16 | 17 | int main(int argc, char **argv) { return fstreplace_main(argc, argv); } 18 | -------------------------------------------------------------------------------- /src/extensions/lookahead/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | libfstdir = @libfstdir@ 4 | libfst_LTLIBRARIES = arc_lookahead-fst.la \ 5 | ilabel_lookahead-fst.la olabel_lookahead-fst.la 6 | 7 | lib_LTLIBRARIES = libfstlookahead.la 8 | 9 | libfstlookahead_la_SOURCES = arc_lookahead-fst.cc ilabel_lookahead-fst.cc \ 10 | olabel_lookahead-fst.cc 11 | libfstlookahead_la_LDFLAGS = -version-info 16:0:0 12 | libfstlookahead_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 13 | 14 | arc_lookahead_fst_la_SOURCES = arc_lookahead-fst.cc 15 | arc_lookahead_fst_la_LDFLAGS = -module 16 | 17 | ilabel_lookahead_fst_la_SOURCES = ilabel_lookahead-fst.cc 18 | ilabel_lookahead_fst_la_LDFLAGS = -module 19 | 20 | olabel_lookahead_fst_la_SOURCES = olabel_lookahead-fst.cc 21 | olabel_lookahead_fst_la_LDFLAGS = -module 22 | -------------------------------------------------------------------------------- /src/bin/fstshortestpath.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | DEFINE_double(delta, fst::kShortestDelta, "Comparison/quantization delta"); 10 | DEFINE_int32(nshortest, 1, "Return N-shortest paths"); 11 | DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 12 | DEFINE_string(queue_type, "auto", 13 | "Queue type: one of \"auto\", " 14 | "\"fifo\", \"lifo\", \"shortest\', \"state\", \"top\""); 15 | DEFINE_bool(unique, false, "Return unique strings"); 16 | DEFINE_string(weight, "", "Weight threshold"); 17 | 18 | int fstshortestpath_main(int argc, char **argv); 19 | 20 | int main(int argc, char **argv) { return fstshortestpath_main(argc, argv); } 21 | -------------------------------------------------------------------------------- /src/extensions/python/Makefile.am: -------------------------------------------------------------------------------- 1 | # NB: we use the Cython-generated .cc files rather than the *.pxd/.pyx sources 2 | # used to generate them. Consequently, modifications to the .pyx files will not 3 | # influence the build unless the .cc files are regenerated using Cython. 4 | 5 | python_LTLIBRARIES = pywrapfst.la 6 | 7 | pyexec_LTILIBRARIES = pywrapfst.la 8 | 9 | pywrapfst_la_SOURCES = pywrapfst.cc 10 | pywrapfst_la_CPPFLAGS = -I$(srcdir)/../../include $(PYTHON_CPPFLAGS) 11 | pywrapfst_la_LDFLAGS = $(PYTHON_LDFLAGS) -avoid-version -module 12 | pywrapfst_la_LIBADD = ../far/libfstfarscript.la ../far/libfstfar.la \ 13 | ../../script/libfstscript.la ../../lib/libfst.la \ 14 | -lm $(DL_LIBS) 15 | 16 | # Exports the *.pxd/*.pxd source files. 17 | EXTRA_DIST = basictypes.pxd fst.pxd ios.pxd memory.pxd pywrapfst.pxd \ 18 | pywrapfst.pyx 19 | -------------------------------------------------------------------------------- /src/include/fst/script/synchronize.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_SYNCHRONIZE_H_ 5 | #define FST_SCRIPT_SYNCHRONIZE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using SynchronizeArgs = std::pair; 16 | 17 | template 18 | void Synchronize(SynchronizeArgs *args) { 19 | const Fst &ifst = *(std::get<0>(*args).GetFst()); 20 | MutableFst *ofst = std::get<1>(*args)->GetMutableFst(); 21 | Synchronize(ifst, ofst); 22 | } 23 | 24 | void Synchronize(const FstClass &ifst, MutableFstClass *ofst); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | 29 | #endif // FST_SCRIPT_SYNCHRONIZE_H_ 30 | -------------------------------------------------------------------------------- /src/script/rmepsilon.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void RmEpsilon(MutableFstClass *fst, const RmEpsilonOptions &opts) { 12 | if (!fst->WeightTypesMatch(opts.weight_threshold, "RmEpsilon")) { 13 | fst->SetProperties(kError, kError); 14 | return; 15 | } 16 | RmEpsilonArgs args(fst, opts); 17 | Apply>("RmEpsilon", fst->ArcType(), &args); 18 | } 19 | 20 | REGISTER_FST_OPERATION(RmEpsilon, StdArc, RmEpsilonArgs); 21 | REGISTER_FST_OPERATION(RmEpsilon, LogArc, RmEpsilonArgs); 22 | REGISTER_FST_OPERATION(RmEpsilon, Log64Arc, RmEpsilonArgs); 23 | 24 | } // namespace script 25 | } // namespace fst 26 | -------------------------------------------------------------------------------- /src/script/map.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | FstClass *Map(const FstClass &ifst, MapType map_type, float delta, double power, 12 | const WeightClass &weight) { 13 | if (!ifst.WeightTypesMatch(weight, "Map")) return nullptr; 14 | MapInnerArgs iargs(ifst, map_type, delta, power, weight); 15 | MapArgs args(iargs); 16 | Apply>("Map", ifst.ArcType(), &args); 17 | return args.retval; 18 | } 19 | 20 | REGISTER_FST_OPERATION(Map, StdArc, MapArgs); 21 | REGISTER_FST_OPERATION(Map, LogArc, MapArgs); 22 | REGISTER_FST_OPERATION(Map, Log64Arc, MapArgs); 23 | 24 | } // namespace script 25 | } // namespace fst 26 | -------------------------------------------------------------------------------- /src/script/synchronize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Synchronize(const FstClass &ifst, MutableFstClass *ofst) { 12 | if (!internal::ArcTypesMatch(ifst, *ofst, "Synchronize")) { 13 | ofst->SetProperties(kError, kError); 14 | return; 15 | } 16 | SynchronizeArgs args(ifst, ofst); 17 | Apply>("Synchronize", ifst.ArcType(), &args); 18 | } 19 | 20 | REGISTER_FST_OPERATION(Synchronize, StdArc, SynchronizeArgs); 21 | REGISTER_FST_OPERATION(Synchronize, LogArc, SynchronizeArgs); 22 | REGISTER_FST_OPERATION(Synchronize, Log64Arc, SynchronizeArgs); 23 | 24 | } // namespace script 25 | } // namespace fst 26 | -------------------------------------------------------------------------------- /src/script/equivalent.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | bool Equivalent(const FstClass &fst1, const FstClass &fst2, float delta) { 12 | if (!internal::ArcTypesMatch(fst1, fst2, "Equivalent")) return false; 13 | EquivalentInnerArgs iargs(fst1, fst2, delta); 14 | EquivalentArgs args(iargs); 15 | Apply>("Equivalent", fst1.ArcType(), &args); 16 | return args.retval; 17 | } 18 | 19 | REGISTER_FST_OPERATION(Equivalent, StdArc, EquivalentArgs); 20 | REGISTER_FST_OPERATION(Equivalent, LogArc, EquivalentArgs); 21 | REGISTER_FST_OPERATION(Equivalent, Log64Arc, EquivalentArgs); 22 | 23 | } // namespace script 24 | } // namespace fst 25 | -------------------------------------------------------------------------------- /src/script/isomorphic.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | bool Isomorphic(const FstClass &fst1, const FstClass &fst2, float delta) { 12 | if (!internal::ArcTypesMatch(fst1, fst2, "Isomorphic")) return false; 13 | IsomorphicInnerArgs iargs(fst1, fst2, delta); 14 | IsomorphicArgs args(iargs); 15 | Apply>("Isomorphic", fst1.ArcType(), &args); 16 | return args.retval; 17 | } 18 | 19 | REGISTER_FST_OPERATION(Isomorphic, StdArc, IsomorphicArgs); 20 | REGISTER_FST_OPERATION(Isomorphic, LogArc, IsomorphicArgs); 21 | REGISTER_FST_OPERATION(Isomorphic, Log64Arc, IsomorphicArgs); 22 | 23 | } // namespace script 24 | } // namespace fst 25 | -------------------------------------------------------------------------------- /src/script/reverse.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Reverse(const FstClass &ifst, MutableFstClass *ofst, 12 | bool require_superinitial) { 13 | if (!internal::ArcTypesMatch(ifst, *ofst, "Reverse")) { 14 | ofst->SetProperties(kError, kError); 15 | return; 16 | } 17 | ReverseArgs args(ifst, ofst, require_superinitial); 18 | Apply>("Reverse", ifst.ArcType(), &args); 19 | } 20 | 21 | REGISTER_FST_OPERATION(Reverse, StdArc, ReverseArgs); 22 | REGISTER_FST_OPERATION(Reverse, LogArc, ReverseArgs); 23 | REGISTER_FST_OPERATION(Reverse, Log64Arc, ReverseArgs); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | -------------------------------------------------------------------------------- /src/extensions/pdt/getters.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | namespace fst { 7 | namespace script { 8 | 9 | bool GetPdtComposeFilter(const string &str, PdtComposeFilter *cf) { 10 | if (str == "expand") { 11 | *cf = EXPAND_FILTER; 12 | } else if (str == "expand_paren") { 13 | *cf = EXPAND_PAREN_FILTER; 14 | } else if (str == "paren") { 15 | *cf = PAREN_FILTER; 16 | } else { 17 | return false; 18 | } 19 | return true; 20 | } 21 | 22 | bool GetPdtParserType(const string &str, PdtParserType *pt) { 23 | if (str == "left") { 24 | *pt = PDT_LEFT_PARSER; 25 | } else if (str == "left_sr") { 26 | *pt = PDT_LEFT_SR_PARSER; 27 | } else { 28 | return false; 29 | } 30 | return true; 31 | } 32 | 33 | } // namespace script 34 | } // namespace fst 35 | -------------------------------------------------------------------------------- /src/include/fst/script/text-io.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Utilities for reading and writing textual strings representing states, 5 | // labels, and weights and files specifying label-label pairs and potentials 6 | // (state-weight pairs). 7 | 8 | #ifndef FST_SCRIPT_TEXT_IO_H__ 9 | #define FST_SCRIPT_TEXT_IO_H__ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace fst { 17 | namespace script { 18 | 19 | bool ReadPotentials(const string &weight_type, const string &filename, 20 | std::vector *potentials); 21 | 22 | bool WritePotentials(const string &filename, 23 | const std::vector &potentials); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | 28 | #endif // FST_SCRIPT_TEXT_IO_H__ 29 | -------------------------------------------------------------------------------- /src/bin/fstinfo.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(arc_filter, "any", 7 | "Arc filter: one of:" 8 | " \"any\", \"epsilon\", \"iepsilon\", \"oepsilon\"; " 9 | "this only affects the counts of (co)accessible states, " 10 | "connected states, and (strongly) connected components"); 11 | DEFINE_string(info_type, "auto", 12 | "Info format: one of: \"auto\", \"long\", \"short\""); 13 | DEFINE_bool(pipe, false, "Send info to stderr, input to stdout"); 14 | DEFINE_bool(test_properties, true, 15 | "Compute property values (if unknown to FST)"); 16 | DEFINE_bool(fst_verify, true, "Verify FST sanity"); 17 | 18 | int fstinfo_main(int argc, char **argv); 19 | 20 | int main(int argc, char **argv) { return fstinfo_main(argc, argv); } 21 | -------------------------------------------------------------------------------- /src/include/fst/script/reverse.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_REVERSE_H_ 5 | #define FST_SCRIPT_REVERSE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using ReverseArgs = std::tuple; 16 | 17 | template 18 | void Reverse(ReverseArgs *args) { 19 | const Fst &ifst = *(std::get<0>(*args).GetFst()); 20 | MutableFst *ofst = std::get<1>(*args)->GetMutableFst(); 21 | Reverse(ifst, ofst, std::get<2>(*args)); 22 | } 23 | 24 | void Reverse(const FstClass &ifst, MutableFstClass *ofst, 25 | bool require_superinitial = true); 26 | 27 | } // namespace script 28 | } // namespace fst 29 | 30 | #endif // FST_SCRIPT_REVERSE_H_ 31 | -------------------------------------------------------------------------------- /src/include/fst/extensions/far/getters.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Classes and functions for registering and invoking FAR main 5 | // functions that support multiple and extensible arc types. 6 | 7 | #ifndef FST_EXTENSIONS_FAR_GETTERS_H_ 8 | #define FST_EXTENSIONS_FAR_GETTERS_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace fst { 14 | namespace script { 15 | 16 | FarType GetFarType(const string &str); 17 | 18 | bool GetFarEntryType(const string &str, FarEntryType *entry_type); 19 | 20 | bool GetFarTokenType(const string &str, FarTokenType *token_type); 21 | 22 | void ExpandArgs(int argc, char **argv, int *argcp, char ***argvp); 23 | 24 | } // namespace script 25 | 26 | string GetFarTypeString(FarType type); 27 | 28 | } // namespace fst 29 | 30 | #endif // FST_EXTENSIONS_FAR_GETTERS_H_ 31 | -------------------------------------------------------------------------------- /src/script/randgen.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void RandGen(const FstClass &ifst, MutableFstClass *ofst, time_t seed, 12 | const RandGenOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst, *ofst, "RandGen")) { 14 | ofst->SetProperties(kError, kError); 15 | return; 16 | } 17 | RandGenArgs args(ifst, ofst, seed, opts); 18 | Apply>("RandGen", ifst.ArcType(), &args); 19 | } 20 | 21 | REGISTER_FST_OPERATION(RandGen, StdArc, RandGenArgs); 22 | REGISTER_FST_OPERATION(RandGen, LogArc, RandGenArgs); 23 | REGISTER_FST_OPERATION(RandGen, Log64Arc, RandGenArgs); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | -------------------------------------------------------------------------------- /src/extensions/pdt/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | if HAVE_BIN 4 | bin_PROGRAMS = pdtcompose pdtexpand pdtinfo pdtreplace pdtreverse \ 5 | pdtshortestpath 6 | 7 | LDADD = libfstpdtscript.la \ 8 | ../../script/libfstscript.la \ 9 | ../../lib/libfst.la -lm $(DL_LIBS) 10 | 11 | pdtcompose_SOURCES = pdtcompose.cc 12 | 13 | pdtexpand_SOURCES = pdtexpand.cc 14 | 15 | pdtinfo_SOURCES = pdtinfo.cc 16 | 17 | pdtreplace_SOURCES = pdtreplace.cc 18 | 19 | pdtreverse_SOURCES = pdtreverse.cc 20 | 21 | pdtshortestpath_SOURCES = pdtshortestpath.cc 22 | endif 23 | 24 | if HAVE_SCRIPT 25 | lib_LTLIBRARIES = libfstpdtscript.la 26 | libfstpdtscript_la_SOURCES = getters.cc pdtscript.cc 27 | libfstpdtscript_la_LDFLAGS = -version-info 16:0:0 28 | libfstpdtscript_la_LIBADD = ../../script/libfstscript.la \ 29 | ../../lib/libfst.la -lm $(DL_LIBS) 30 | endif 31 | -------------------------------------------------------------------------------- /src/bin/fstmap.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 8 | DEFINE_string(map_type, "identity", 9 | "Map operation, one of: \"arc_sum\", \"arc_unique\", " 10 | "\"float_power\" (--power)\", \"identity\", \"input_epsilon\", " 11 | "\"invert\", \"output_epsilon\", \"plus (--weight)\", " 12 | "\"quantize (--delta)\", \"rmweight\", \"superfinal\", " 13 | "\"power (--power)\", \"times (--weight)\", \"to_log\", " 14 | "\"to_log64\", \"to_std\""); 15 | DEFINE_double(power, 1.0, "Power parameter"); 16 | DEFINE_string(weight, "", "Weight parameter"); 17 | 18 | int fstmap_main(int argc, char **argv); 19 | 20 | int main(int argc, char **argv) { return fstmap_main(argc, argv); } 21 | -------------------------------------------------------------------------------- /src/extensions/ngram/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB HEADER_FILES ../../include/fst/extensions/ngram/*.h) 2 | message(STATUS "${HEADER_FILES}") 3 | 4 | add_library(fstngram 5 | bitmap-index.cc 6 | ngram-fst.cc 7 | nthbit.cc 8 | ${HEADER_FILES} 9 | ) 10 | 11 | target_link_libraries(fstngram 12 | fst 13 | ) 14 | 15 | set_target_properties(fstngram PROPERTIES 16 | SOVERSION "${SOVERSION}" 17 | FOLDER ngram 18 | ) 19 | 20 | install(TARGETS fstngram 21 | LIBRARY DESTINATION lib 22 | ARCHIVE DESTINATION lib 23 | RUNTIME DESTINATION lib 24 | ) 25 | 26 | add_library(ngram_fst MODULE 27 | bitmap-index.cc 28 | ngram-fst.cc 29 | nthbit.cc 30 | ) 31 | 32 | set_target_properties(ngram_fst PROPERTIES 33 | WINDOWS_EXPORT_ALL_SYMBOLS true 34 | FOLDER ngram/modules 35 | ) 36 | 37 | target_link_libraries(ngram_fst 38 | fst 39 | ) 40 | 41 | install(TARGETS ngram_fst 42 | LIBRARY DESTINATION lib/fst 43 | ) 44 | 45 | -------------------------------------------------------------------------------- /src/bin/fstrandgen.cc: -------------------------------------------------------------------------------- 1 | #ifndef _MSC_VER 2 | #include 3 | #else 4 | #include 5 | #define getpid _getpid 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | DEFINE_int32(max_length, INT32_MAX, "Maximum path length"); 14 | DEFINE_int32(npath, 1, "Number of paths to generate"); 15 | DEFINE_int32(seed, time(nullptr) + getpid(), "Random seed"); 16 | DEFINE_string(select, "uniform", 17 | "Selection type: one of: " 18 | " \"uniform\", \"log_prob\" (when appropriate)," 19 | " \"fast_log_prob\" (when appropriate)"); 20 | DEFINE_bool(weighted, false, 21 | "Output tree weighted by path count vs. unweighted paths"); 22 | DEFINE_bool(remove_total_weight, false, 23 | "Remove total weight when output weighted"); 24 | 25 | int fstrandgen_main(int argc, char **argv); 26 | 27 | int main(int argc, char **argv) { return fstrandgen_main(argc, argv); } 28 | -------------------------------------------------------------------------------- /src/script/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../include $(ICU_CPPFLAGS) 2 | 3 | if HAVE_SCRIPT 4 | lib_LTLIBRARIES = libfstscript.la 5 | libfstscript_la_SOURCES = arciterator-class.cc arcsort.cc closure.cc \ 6 | compile.cc compose.cc concat.cc connect.cc convert.cc decode.cc \ 7 | determinize.cc difference.cc disambiguate.cc draw.cc encode.cc \ 8 | encodemapper-class.cc epsnormalize.cc equal.cc equivalent.cc fst-class.cc \ 9 | getters.cc info-impl.cc info.cc intersect.cc invert.cc isomorphic.cc map.cc \ 10 | minimize.cc print.cc project.cc prune.cc push.cc randequivalent.cc \ 11 | randgen.cc relabel.cc replace.cc reverse.cc reweight.cc rmepsilon.cc \ 12 | shortest-distance.cc shortest-path.cc stateiterator-class.cc synchronize.cc \ 13 | text-io.cc topsort.cc union.cc weight-class.cc verify.cc 14 | 15 | libfstscript_la_LIBADD = ../lib/libfst.la -lm $(DL_LIBS) 16 | libfstscript_la_LDFLAGS = -version-info 16:0:0 17 | endif 18 | -------------------------------------------------------------------------------- /src/script/epsnormalize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void EpsNormalize(const FstClass &ifst, MutableFstClass *ofst, 12 | EpsNormalizeType norm_type) { 13 | if (!internal::ArcTypesMatch(ifst, *ofst, "EpsNormalize")) { 14 | ofst->SetProperties(kError, kError); 15 | return; 16 | } 17 | EpsNormalizeArgs args(ifst, ofst, norm_type); 18 | Apply>("EpsNormalize", ifst.ArcType(), &args); 19 | } 20 | 21 | REGISTER_FST_OPERATION(EpsNormalize, StdArc, EpsNormalizeArgs); 22 | REGISTER_FST_OPERATION(EpsNormalize, LogArc, EpsNormalizeArgs); 23 | REGISTER_FST_OPERATION(EpsNormalize, Log64Arc, EpsNormalizeArgs); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | -------------------------------------------------------------------------------- /src/bin/fstequivalent.cc: -------------------------------------------------------------------------------- 1 | #ifndef _MSC_VER 2 | #include 3 | #else 4 | #include 5 | #define getpid _getpid 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 15 | DEFINE_bool(random, false, 16 | "Test equivalence by randomly selecting paths in the input FSTs"); 17 | DEFINE_int32(max_length, INT32_MAX, "Maximum path length"); 18 | DEFINE_int32(npath, 1, "Number of paths to generate"); 19 | DEFINE_int32(seed, time(nullptr) + getpid(), "Random seed"); 20 | DEFINE_string(select, "uniform", 21 | "Selection type: one of: " 22 | " \"uniform\", \"log_prob\" (when appropriate)," 23 | " \"fast_log_prob\" (when appropriate)"); 24 | 25 | int fstequivalent_main(int argc, char **argv); 26 | 27 | int main(int argc, char **argv) { return fstequivalent_main(argc, argv); } 28 | -------------------------------------------------------------------------------- /src/extensions/const/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | function (add_module _name) 2 | add_library(${ARGV}) 3 | if (TARGET ${_name}) 4 | target_link_libraries(${_name} fst) 5 | set_target_properties(${_name} PROPERTIES 6 | WINDOWS_EXPORT_ALL_SYMBOLS true 7 | FOLDER constant/modules 8 | ) 9 | endif() 10 | 11 | install(TARGETS ${_name} LIBRARY DESTINATION lib/fst) 12 | endfunction() 13 | 14 | 15 | add_module(const8-fst MODULE const8-fst.cc) 16 | 17 | add_module(const16-fst MODULE const16-fst.cc) 18 | 19 | add_module(const64-fst MODULE const64-fst.cc) 20 | 21 | add_library(fstconst 22 | const8-fst.cc 23 | const16-fst.cc 24 | const64-fst.cc) 25 | target_link_libraries(fstconst fst) 26 | set_target_properties(fstconst PROPERTIES 27 | SOVERSION "${SOVERSION}" 28 | FOLDER constant 29 | ) 30 | 31 | install(TARGETS fstconst 32 | LIBRARY DESTINATION lib 33 | ARCHIVE DESTINATION lib 34 | RUNTIME DESTINATION lib 35 | ) 36 | -------------------------------------------------------------------------------- /src/script/shortest-path.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void ShortestPath(const FstClass &ifst, MutableFstClass *ofst, 12 | const ShortestPathOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst, *ofst, "ShortestPath")) { 14 | ofst->SetProperties(kError, kError); 15 | return; 16 | } 17 | ShortestPathArgs args(ifst, ofst, opts); 18 | Apply>("ShortestPath", ifst.ArcType(), &args); 19 | } 20 | 21 | REGISTER_FST_OPERATION(ShortestPath, StdArc, ShortestPathArgs); 22 | REGISTER_FST_OPERATION(ShortestPath, LogArc, ShortestPathArgs); 23 | REGISTER_FST_OPERATION(ShortestPath, Log64Arc, ShortestPathArgs); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | -------------------------------------------------------------------------------- /src/extensions/Makefile.am: -------------------------------------------------------------------------------- 1 | if HAVE_COMPACT 2 | compactdir = compact 3 | endif 4 | 5 | if HAVE_COMPRESS 6 | compressdir = compress 7 | endif 8 | 9 | if HAVE_CONST 10 | constdir = const 11 | endif 12 | 13 | if HAVE_FAR 14 | fardir = far 15 | endif 16 | 17 | if HAVE_GRM 18 | fardir = far 19 | pdtdir = pdt 20 | mpdtdir = mpdt 21 | endif 22 | 23 | if HAVE_LINEAR 24 | lineardir = linear 25 | endif 26 | 27 | if HAVE_LOOKAHEAD 28 | lookaheaddir = lookahead 29 | endif 30 | 31 | if HAVE_MPDT 32 | pdtdir = pdt 33 | mpdtdir = mpdt 34 | endif 35 | 36 | if HAVE_NGRAM 37 | ngramdir = ngram 38 | endif 39 | 40 | if HAVE_PYTHON 41 | fardir = far 42 | pywrapfstdir = python 43 | endif 44 | 45 | if HAVE_PDT 46 | pdtdir = pdt 47 | endif 48 | 49 | if HAVE_SPECIAL 50 | specialdir = special 51 | endif 52 | 53 | SUBDIRS = $(compactdir) $(compressdir) $(constdir) $(fardir) $(lineardir) \ 54 | $(lookaheaddir) $(pdtdir) $(mpdtdir) $(ngramdir) $(pywrapfstdir) \ 55 | $(specialdir) 56 | -------------------------------------------------------------------------------- /src/script/libfstscript.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | {111F46ED-DA1F-469B-B912-BA2ACC2FF8E6} 8 | StaticLibrary 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/script/stateiterator-class.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | namespace script { 9 | 10 | StateIteratorClass::StateIteratorClass(const FstClass &fst) : impl_(nullptr) { 11 | InitStateIteratorClassArgs args(fst, this); 12 | Apply>("InitStateIteratorClass", 13 | fst.ArcType(), &args); 14 | } 15 | 16 | REGISTER_FST_OPERATION(InitStateIteratorClass, StdArc, 17 | InitStateIteratorClassArgs); 18 | REGISTER_FST_OPERATION(InitStateIteratorClass, LogArc, 19 | InitStateIteratorClassArgs); 20 | REGISTER_FST_OPERATION(InitStateIteratorClass, Log64Arc, 21 | InitStateIteratorClassArgs); 22 | 23 | } // namespace script 24 | } // namespace fst 25 | -------------------------------------------------------------------------------- /src/script/compose.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Compose(const FstClass &ifst1, const FstClass &ifst2, 12 | MutableFstClass *ofst, const ComposeOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst1, ifst2, "Compose") || 14 | !internal::ArcTypesMatch(*ofst, ifst1, "Compose")) { 15 | ofst->SetProperties(kError, kError); 16 | return; 17 | } 18 | ComposeArgs args(ifst1, ifst2, ofst, opts); 19 | Apply>("Compose", ifst1.ArcType(), &args); 20 | } 21 | 22 | REGISTER_FST_OPERATION(Compose, StdArc, ComposeArgs); 23 | REGISTER_FST_OPERATION(Compose, LogArc, ComposeArgs); 24 | REGISTER_FST_OPERATION(Compose, Log64Arc, ComposeArgs); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | -------------------------------------------------------------------------------- /src/script/minimize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Minimize(MutableFstClass *ofst1, MutableFstClass *ofst2, float delta, 12 | bool allow_nondet) { 13 | if (ofst2 && !internal::ArcTypesMatch(*ofst1, *ofst2, "Minimize")) { 14 | ofst1->SetProperties(kError, kError); 15 | ofst2->SetProperties(kError, kError); 16 | return; 17 | } 18 | MinimizeArgs args(ofst1, ofst2, delta, allow_nondet); 19 | Apply>("Minimize", ofst1->ArcType(), &args); 20 | } 21 | 22 | REGISTER_FST_OPERATION(Minimize, StdArc, MinimizeArgs); 23 | REGISTER_FST_OPERATION(Minimize, LogArc, MinimizeArgs); 24 | REGISTER_FST_OPERATION(Minimize, Log64Arc, MinimizeArgs); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | -------------------------------------------------------------------------------- /src/include/fst/script/equal.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_EQUAL_H_ 5 | #define FST_SCRIPT_EQUAL_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace fst { 14 | namespace script { 15 | 16 | using EqualInnerArgs = std::tuple; 17 | 18 | using EqualArgs = WithReturnValue; 19 | 20 | template 21 | void Equal(EqualArgs *args) { 22 | const Fst &fst1 = *(std::get<0>(args->args).GetFst()); 23 | const Fst &fst2 = *(std::get<1>(args->args).GetFst()); 24 | args->retval = Equal(fst1, fst2, std::get<2>(args->args)); 25 | } 26 | 27 | bool Equal(const FstClass &fst1, const FstClass &fst2, float delta = kDelta); 28 | 29 | } // namespace script 30 | } // namespace fst 31 | 32 | #endif // FST_SCRIPT_EQUAL_H_ 33 | -------------------------------------------------------------------------------- /src/script/intersect.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Intersect(const FstClass &ifst1, const FstClass &ifst2, 12 | MutableFstClass *ofst, const ComposeOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst1, ifst2, "Intersect") || 14 | !internal::ArcTypesMatch(*ofst, ifst1, "Intersect")) { 15 | ofst->SetProperties(kError, kError); 16 | return; 17 | } 18 | IntersectArgs args(ifst1, ifst2, ofst, opts); 19 | Apply>("Intersect", ifst1.ArcType(), &args); 20 | } 21 | 22 | REGISTER_FST_OPERATION(Intersect, StdArc, IntersectArgs); 23 | REGISTER_FST_OPERATION(Intersect, LogArc, IntersectArgs); 24 | REGISTER_FST_OPERATION(Intersect, Log64Arc, IntersectArgs); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | -------------------------------------------------------------------------------- /src/bin/fstcompile.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(acceptor, false, "Input in acceptor format"); 7 | DEFINE_string(arc_type, "standard", "Output arc type"); 8 | DEFINE_string(fst_type, "vector", "Output FST type"); 9 | DEFINE_string(isymbols, "", "Input label symbol table"); 10 | DEFINE_string(osymbols, "", "Output label symbol table"); 11 | DEFINE_string(ssymbols, "", "State label symbol table"); 12 | DEFINE_bool(keep_isymbols, false, "Store input label symbol table with FST"); 13 | DEFINE_bool(keep_osymbols, false, "Store output label symbol table with FST"); 14 | DEFINE_bool(keep_state_numbering, false, "Do not renumber input states"); 15 | DEFINE_bool(allow_negative_labels, false, 16 | "Allow negative labels (not recommended; may cause conflicts)"); 17 | 18 | int fstcompile_main(int argc, char **argv); 19 | 20 | int main(int argc, char **argv) { return fstcompile_main(argc, argv); } 21 | -------------------------------------------------------------------------------- /src/extensions/lookahead/ilabel_lookahead-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer 10 | ILabelLookAheadFst_StdArc_registerer; 11 | static FstRegisterer, 13 | LabelLookAheadMatcher>, 14 | ilabel_lookahead_flags, FastLogAccumulator>, 15 | ilabel_lookahead_fst_type, LabelLookAheadRelabeler>> 16 | ILabelLookAheadFst_LogArc_registerer; 17 | static FstRegisterer, 19 | LabelLookAheadMatcher>, 20 | ilabel_lookahead_flags, FastLogAccumulator>, 21 | ilabel_lookahead_fst_type, LabelLookAheadRelabeler>> 22 | ILabelLookAheadFst_Log64Arc_registerer; 23 | 24 | } // namespace fst 25 | -------------------------------------------------------------------------------- /src/extensions/lookahead/olabel_lookahead-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | 9 | static FstRegisterer 10 | OLabelLookAheadFst_StdArc_registerer; 11 | static FstRegisterer, 13 | LabelLookAheadMatcher>, 14 | olabel_lookahead_flags, FastLogAccumulator>, 15 | olabel_lookahead_fst_type, LabelLookAheadRelabeler>> 16 | OLabelLookAheadFst_LogArc_registerer; 17 | static FstRegisterer, 19 | LabelLookAheadMatcher>, 20 | olabel_lookahead_flags, FastLogAccumulator>, 21 | olabel_lookahead_fst_type, LabelLookAheadRelabeler>> 22 | OLabelLookAheadFst_Log64Arc_registerer; 23 | 24 | } // namespace fst 25 | -------------------------------------------------------------------------------- /src/script/determinize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Determinize(const FstClass &ifst, MutableFstClass *ofst, 12 | const DeterminizeOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst, *ofst, "Determinize") || 14 | !ofst->WeightTypesMatch(opts.weight_threshold, "Determinize")) { 15 | ofst->SetProperties(kError, kError); 16 | return; 17 | } 18 | DeterminizeArgs args(ifst, ofst, opts); 19 | Apply>("Determinize", ifst.ArcType(), &args); 20 | } 21 | 22 | REGISTER_FST_OPERATION(Determinize, StdArc, DeterminizeArgs); 23 | REGISTER_FST_OPERATION(Determinize, LogArc, DeterminizeArgs); 24 | REGISTER_FST_OPERATION(Determinize, Log64Arc, DeterminizeArgs); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | -------------------------------------------------------------------------------- /src/extensions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(HAVE_COMPACT) 3 | add_subdirectory(compact) 4 | endif(HAVE_COMPACT) 5 | 6 | if(HAVE_COMPRESS) 7 | add_subdirectory(compress) 8 | endif(HAVE_COMPRESS) 9 | 10 | if(HAVE_CONST) 11 | add_subdirectory(const) 12 | endif(HAVE_CONST) 13 | 14 | if(HAVE_FAR OR HAVE_GRM) 15 | add_subdirectory(far) 16 | endif(HAVE_FAR OR HAVE_GRM) 17 | 18 | if(HAVE_LINEAR) 19 | add_subdirectory(linear) 20 | endif(HAVE_LINEAR) 21 | 22 | if(HAVE_LOOKAHEAD) 23 | add_subdirectory(lookahead) 24 | endif(HAVE_LOOKAHEAD) 25 | 26 | if(HAVE_MPDT OR HAVE_GRM) 27 | add_subdirectory(mpdt) 28 | endif(HAVE_MPDT OR HAVE_GRM) 29 | 30 | if(HAVE_NGRAM) 31 | add_subdirectory(ngram) 32 | endif(HAVE_NGRAM) 33 | 34 | #if(HAVE_PYTHON) 35 | # add_subdirectory(far) 36 | # add_subdirectory(python) 37 | #endif(HAVE_PDT) 38 | # 39 | if(HAVE_PDT OR HAVE_MPDT OR HAVE_GRM) 40 | add_subdirectory(pdt) 41 | endif(HAVE_PDT OR HAVE_MPDT OR HAVE_GRM) 42 | 43 | if(HAVE_SPECIAL) 44 | add_subdirectory(special) 45 | endif(HAVE_SPECIAL) 46 | 47 | -------------------------------------------------------------------------------- /src/include/fst/script/epsnormalize.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_EPSNORMALIZE_H_ 5 | #define FST_SCRIPT_EPSNORMALIZE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using EpsNormalizeArgs = std::tuple; 17 | 18 | template 19 | void EpsNormalize(EpsNormalizeArgs *args) { 20 | const Fst &ifst = *(std::get<0>(*args).GetFst()); 21 | MutableFst *ofst = std::get<1>(*args)->GetMutableFst(); 22 | EpsNormalize(ifst, ofst, std::get<2>(*args)); 23 | } 24 | 25 | void EpsNormalize(const FstClass &ifst, MutableFstClass *ofst, 26 | EpsNormalizeType norm_type = EPS_NORM_INPUT); 27 | 28 | } // namespace script 29 | } // namespace fst 30 | 31 | #endif // FST_SCRIPT_EPSNORMALIZE_H_ 32 | -------------------------------------------------------------------------------- /src/script/difference.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Difference(const FstClass &ifst1, const FstClass &ifst2, 12 | MutableFstClass *ofst, const ComposeOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst1, ifst2, "Difference") || 14 | !internal::ArcTypesMatch(*ofst, ifst1, "Difference")) { 15 | ofst->SetProperties(kError, kError); 16 | return; 17 | } 18 | DifferenceArgs args(ifst1, ifst2, ofst, opts); 19 | Apply>("Difference", ifst1.ArcType(), &args); 20 | } 21 | 22 | REGISTER_FST_OPERATION(Difference, StdArc, DifferenceArgs); 23 | REGISTER_FST_OPERATION(Difference, LogArc, DifferenceArgs); 24 | REGISTER_FST_OPERATION(Difference, Log64Arc, DifferenceArgs); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | -------------------------------------------------------------------------------- /src/script/disambiguate.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Disambiguate(const FstClass &ifst, MutableFstClass *ofst, 12 | const DisambiguateOptions &opts) { 13 | if (!internal::ArcTypesMatch(ifst, *ofst, "Disambiguate") || 14 | !ofst->WeightTypesMatch(opts.weight_threshold, "Disambiguate")) { 15 | ofst->SetProperties(kError, kError); 16 | return; 17 | } 18 | DisambiguateArgs args(ifst, ofst, opts); 19 | Apply>("Disambiguate", ifst.ArcType(), &args); 20 | } 21 | 22 | REGISTER_FST_OPERATION(Disambiguate, StdArc, DisambiguateArgs); 23 | REGISTER_FST_OPERATION(Disambiguate, LogArc, DisambiguateArgs); 24 | REGISTER_FST_OPERATION(Disambiguate, Log64Arc, DisambiguateArgs); 25 | 26 | } // namespace script 27 | } // namespace fst 28 | -------------------------------------------------------------------------------- /src/script/encodemapper-class.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | namespace script { 9 | 10 | EncodeMapperClass::EncodeMapperClass(const string &arc_type, uint32 flags, 11 | EncodeType type) : impl_(nullptr) { 12 | InitEncodeMapperClassArgs args(flags, type, this); 13 | Apply>("InitEncodeMapperClass", 14 | arc_type, &args); 15 | } 16 | 17 | REGISTER_FST_OPERATION(InitEncodeMapperClass, StdArc, 18 | InitEncodeMapperClassArgs); 19 | REGISTER_FST_OPERATION(InitEncodeMapperClass, LogArc, 20 | InitEncodeMapperClassArgs); 21 | REGISTER_FST_OPERATION(InitEncodeMapperClass, Log64Arc, 22 | InitEncodeMapperClassArgs); 23 | 24 | } // namespace script 25 | } // namespace fst 26 | -------------------------------------------------------------------------------- /src/bin/fstrelabel.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(isymbols, "", "Input label symbol table"); 7 | DEFINE_string(osymbols, "", "Output label symbol table"); 8 | DEFINE_string(relabel_isymbols, "", "Input symbol set to relabel to"); 9 | DEFINE_string(relabel_osymbols, "", "Output symbol set to relabel to"); 10 | DEFINE_string(relabel_ipairs, "", "Input relabel pairs (numeric)"); 11 | DEFINE_string(relabel_opairs, "", "Output relabel pairs (numeric)"); 12 | DEFINE_string(unknown_isymbol, "", 13 | "Input symbol to use to relabel OOVs (default: OOVs are errors)"); 14 | DEFINE_string(unknown_osymbol, "", 15 | "Output symbol to use to relabel OOVs (default: OOVs are errors)"); 16 | DEFINE_bool(allow_negative_labels, false, 17 | "Allow negative labels (not recommended; may cause conflicts)"); 18 | 19 | int fstrelabel_main(int argc, char **argv); 20 | 21 | int main(int argc, char **argv) { return fstrelabel_main(argc, argv); } 22 | -------------------------------------------------------------------------------- /src/bin/fstsymbols.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_string(isymbols, "", "Input label symbol table"); 7 | DEFINE_string(osymbols, "", "Output label symbol table"); 8 | DEFINE_bool(clear_isymbols, false, "Clear input symbol table"); 9 | DEFINE_bool(clear_osymbols, false, "Clear output symbol table"); 10 | DEFINE_string(relabel_ipairs, "", "Input relabel pairs (numeric)"); 11 | DEFINE_string(relabel_opairs, "", "Output relabel pairs (numeric)"); 12 | DEFINE_string(save_isymbols, "", "Save fst file's input symbol table to file"); 13 | DEFINE_string(save_osymbols, "", "Save fst file's output symbol table to file"); 14 | DEFINE_bool(allow_negative_labels, false, 15 | "Allow negative labels (not recommended; may cause conflicts)"); 16 | DEFINE_bool(verify, false, "Verify fst properities before saving"); 17 | 18 | int fstsymbols_main(int argc, char **argv); 19 | 20 | int main(int argc, char **argv) { return fstsymbols_main(argc, argv); } 21 | -------------------------------------------------------------------------------- /BUGS.md: -------------------------------------------------------------------------------- 1 | # OpenFST Windows Port Bugs And Limitations 2 | 3 | "Fixed in" means that all previous releases are likely affected. 4 | 5 | ## Fixed in win/1.7.2.1+01 6 | 7 | * stdout newline conversion of binary data (#20) 8 | 9 | ## Unimplemented features 10 | 11 | * Memory-mapped files are not supported (we may add the support in the future 12 | though), because it is very system-dependent. OpenFST supports reading e. g. 13 | CompactFST files into allocated memory when memory mapping is not compiled in. 14 | Since Kaldi is now using it, this is on an implementation track, issue #31. 15 | 16 | * Dynamic registration of arc and FST types is not supported in the Visual Studio 17 | project versions (as they build only static libraries). CMake build does not 18 | have this limitation. Due to ABI being specific to Microsoft compiler version, 19 | dynamically registered types must be compiled with strictly the same compiler 20 | of the same major version, and mostly same build flags. This is quite hard to 21 | get right, and is not recommended. No current plans to implement. 22 | -------------------------------------------------------------------------------- /src/bin/fstdeterminize.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 9 | DEFINE_string(weight, "", "Weight threshold"); 10 | DEFINE_int64(nstate, fst::kNoStateId, "State number threshold"); 11 | DEFINE_int64(subsequential_label, 0, 12 | "Input label of arc corresponding to residual final output when" 13 | " producing a subsequential transducer"); 14 | DEFINE_string(det_type, "functional", 15 | "Type of determinization: \"functional\", " 16 | "\"nonfunctional\", \"disambiguate\""); 17 | DEFINE_bool(increment_subsequential_label, false, 18 | "Increment subsequential_label to obtain distinct labels for " 19 | " subsequential arcs at a given state"); 20 | 21 | int fstdeterminize_main(int argc, char **argv); 22 | 23 | int main(int argc, char **argv) { return fstdeterminize_main(argc, argv); } 24 | -------------------------------------------------------------------------------- /src/bin/fstinvert-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Inverts a transduction. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | int fstinvert_main(int argc, char **argv) { 15 | namespace s = fst::script; 16 | using fst::script::MutableFstClass; 17 | 18 | string usage = "Inverts a transduction.\n\n Usage: "; 19 | usage += argv[0]; 20 | usage += " [in.fst [out.fst]]\n"; 21 | 22 | std::set_new_handler(FailedNewHandler); 23 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 24 | if (argc > 3) { 25 | ShowUsage(); 26 | return 1; 27 | } 28 | 29 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 30 | const string out_name = argc > 2 ? argv[2] : ""; 31 | 32 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 33 | if (!fst) return 1; 34 | 35 | s::Invert(fst.get()); 36 | 37 | return !fst->Write(out_name); 38 | } 39 | -------------------------------------------------------------------------------- /src/extensions/lookahead/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_library(fstlookahead 3 | arc_lookahead-fst.cc 4 | ilabel_lookahead-fst.cc 5 | olabel_lookahead-fst.cc 6 | ) 7 | target_link_libraries(fstlookahead fst) 8 | set_target_properties(fstlookahead PROPERTIES 9 | SOVERSION "${SOVERSION}" 10 | FOLDER lookahead 11 | ) 12 | 13 | install(TARGETS fstlookahead 14 | LIBRARY DESTINATION lib 15 | ARCHIVE DESTINATION lib 16 | RUNTIME DESTINATION lib 17 | ) 18 | 19 | function (add_module _name) 20 | add_library(${ARGV}) 21 | if (TARGET ${_name}) 22 | target_link_libraries(${_name} fst) 23 | endif() 24 | set_target_properties(${_name} PROPERTIES 25 | WINDOWS_EXPORT_ALL_SYMBOLS true 26 | FOLDER lookahead/modules 27 | ) 28 | 29 | install(TARGETS ${_name} LIBRARY DESTINATION lib/fst) 30 | endfunction() 31 | 32 | add_module(arc_lookahead-fst MODULE 33 | arc_lookahead-fst.cc) 34 | 35 | add_module(ilabel_lookahead-fst MODULE 36 | ilabel_lookahead-fst.cc) 37 | 38 | add_module(olabel_lookahead-fst MODULE 39 | olabel_lookahead-fst.cc) 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/include/fst/script/convert.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_CONVERT_H_ 5 | #define FST_SCRIPT_CONVERT_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace fst { 16 | namespace script { 17 | 18 | using ConvertInnerArgs = std::pair; 19 | 20 | using ConvertArgs = WithReturnValue; 21 | 22 | template 23 | void Convert(ConvertArgs *args) { 24 | const Fst &fst = *(std::get<0>(args->args).GetFst()); 25 | const string &new_type = std::get<1>(args->args); 26 | std::unique_ptr> result(Convert(fst, new_type)); 27 | args->retval = result ? new FstClass(*result) : nullptr; 28 | } 29 | 30 | FstClass *Convert(const FstClass &fst, const string &new_type); 31 | 32 | } // namespace script 33 | } // namespace fst 34 | 35 | #endif // FST_SCRIPT_CONVERT_H_ 36 | -------------------------------------------------------------------------------- /src/script/randequivalent.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | bool RandEquivalent(const FstClass &fst1, const FstClass &fst2, int32 npath, 12 | float delta, time_t seed, 13 | const RandGenOptions &opts) { 14 | if (!internal::ArcTypesMatch(fst1, fst2, "RandEquivalent")) return false; 15 | RandEquivalentInnerArgs iargs(fst1, fst2, npath, delta, seed, opts); 16 | RandEquivalentArgs args(iargs); 17 | Apply>("RandEquivalent", fst1.ArcType(), &args); 18 | return args.retval; 19 | } 20 | 21 | REGISTER_FST_OPERATION(RandEquivalent, StdArc, RandEquivalentArgs); 22 | REGISTER_FST_OPERATION(RandEquivalent, LogArc, RandEquivalentArgs); 23 | REGISTER_FST_OPERATION(RandEquivalent, Log64Arc, RandEquivalentArgs); 24 | 25 | } // namespace script 26 | } // namespace fst 27 | -------------------------------------------------------------------------------- /src/bin/fstprint.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(acceptor, false, "Input in acceptor format?"); 7 | DEFINE_string(isymbols, "", "Input label symbol table"); 8 | DEFINE_string(osymbols, "", "Output label symbol table"); 9 | DEFINE_string(ssymbols, "", "State label symbol table"); 10 | DEFINE_bool(numeric, false, "Print numeric labels?"); 11 | DEFINE_string(save_isymbols, "", "Save input symbol table to file"); 12 | DEFINE_string(save_osymbols, "", "Save output symbol table to file"); 13 | DEFINE_bool(show_weight_one, false, 14 | "Print/draw arc weights and final weights equal to semiring One?"); 15 | DEFINE_bool(allow_negative_labels, false, 16 | "Allow negative labels (not recommended; may cause conflicts)?"); 17 | DEFINE_string(missing_symbol, "", 18 | "Symbol to print when lookup fails (default raises error)"); 19 | 20 | int fstprint_main(int argc, char **argv); 21 | 22 | int main(int argc, char **argv) { return fstprint_main(argc, argv); } 23 | -------------------------------------------------------------------------------- /src/include/fst/script/arcsort.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_ARCSORT_H_ 5 | #define FST_SCRIPT_ARCSORT_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | enum ArcSortType { 16 | ILABEL_SORT, 17 | OLABEL_SORT 18 | }; 19 | 20 | using ArcSortArgs = std::pair; 21 | 22 | template 23 | void ArcSort(ArcSortArgs *args) { 24 | MutableFst *fst = std::get<0>(*args)->GetMutableFst(); 25 | switch (std::get<1>(*args)) { 26 | case ILABEL_SORT: { 27 | const ILabelCompare icomp; 28 | ArcSort(fst, icomp); 29 | return; 30 | } 31 | case OLABEL_SORT: { 32 | const OLabelCompare ocomp; 33 | ArcSort(fst, ocomp); 34 | return; 35 | } 36 | } 37 | } 38 | 39 | void ArcSort(MutableFstClass *ofst, ArcSortType); 40 | 41 | } // namespace script 42 | } // namespace fst 43 | 44 | #endif // FST_SCRIPT_ARCSORT_H_ 45 | -------------------------------------------------------------------------------- /src/include/fst/script/equivalent.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_EQUIVALENT_H_ 5 | #define FST_SCRIPT_EQUIVALENT_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace fst { 14 | namespace script { 15 | 16 | using EquivalentInnerArgs = std::tuple; 18 | 19 | using EquivalentArgs = WithReturnValue; 20 | 21 | template 22 | void Equivalent(EquivalentArgs *args) { 23 | const Fst &fst1 = *(std::get<0>(args->args).GetFst()); 24 | const Fst &fst2 = *(std::get<1>(args->args).GetFst()); 25 | args->retval = Equivalent(fst1, fst2, std::get<2>(args->args)); 26 | } 27 | 28 | bool Equivalent(const FstClass &fst1, const FstClass &fst2, 29 | float delta = kDelta); 30 | 31 | } // namespace script 32 | } // namespace fst 33 | 34 | #endif // FST_SCRIPT_EQUIVALENT_H_ 35 | -------------------------------------------------------------------------------- /src/include/fst/script/isomorphic.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_ISOMORPHIC_H_ 5 | #define FST_SCRIPT_ISOMORPHIC_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace fst { 14 | namespace script { 15 | 16 | using IsomorphicInnerArgs = std::tuple; 18 | 19 | using IsomorphicArgs = WithReturnValue; 20 | 21 | template 22 | void Isomorphic(IsomorphicArgs *args) { 23 | const Fst &fst1 = *(std::get<0>(args->args).GetFst()); 24 | const Fst &fst2 = *(std::get<1>(args->args).GetFst()); 25 | args->retval = Isomorphic(fst1, fst2, std::get<2>(args->args)); 26 | } 27 | 28 | bool Isomorphic(const FstClass &fst1, const FstClass &fst2, 29 | float delta = kDelta); 30 | 31 | } // namespace script 32 | } // namespace fst 33 | 34 | #endif // FST_SCRIPT_ISOMORPHIC_H_ 35 | -------------------------------------------------------------------------------- /src/extensions/special/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include -I$(srcdir)/../../bin $(ICU_CPPFLAGS) 2 | 3 | if HAVE_BIN 4 | bin_PROGRAMS = fstspecial 5 | 6 | LDADD = ../../script/libfstscript.la \ 7 | ../../lib/libfst.la -lm $(DL_LIBS) 8 | 9 | fstspecial_SOURCES = fstspecial.cc phi-fst.cc rho-fst.cc sigma-fst.cc 10 | fstspecial_CPPFLAGS = $(AM_CPPFLAGS) 11 | endif 12 | 13 | libfstdir = @libfstdir@ 14 | libfst_LTLIBRARIES = phi-fst.la rho-fst.la sigma-fst.la 15 | 16 | lib_LTLIBRARIES = libfstspecial.la 17 | 18 | libfstspecial_la_SOURCES = phi-fst.cc rho-fst.cc sigma-fst.cc 19 | libfstspecial_la_LDFLAGS = -version-info 16:0:0 -lm $(DL_LIBS) 20 | libfstspecial_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 21 | 22 | phi_fst_la_SOURCES = phi-fst.cc 23 | phi_fst_la_LDFLAGS = -module 24 | phi_fst_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 25 | 26 | rho_fst_la_SOURCES = rho-fst.cc 27 | rho_fst_la_LDFLAGS = -module 28 | rho_fst_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 29 | 30 | sigma_fst_la_SOURCES = sigma-fst.cc 31 | sigma_fst_la_LDFLAGS = -module 32 | sigma_fst_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 33 | -------------------------------------------------------------------------------- /src/test/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../include $(ICU_CPPFLAGS) 2 | LDADD = ../lib/libfst.la -lm $(DL_LIBS) 3 | 4 | check_PROGRAMS = fst_test weight_test 5 | 6 | fst_test_SOURCES = fst_test.cc 7 | 8 | weight_test_SOURCES = weight_test.cc 9 | 10 | algo_test_SOURCES = algo_test.cc 11 | 12 | check_PROGRAMS += algo_test_log 13 | algo_test_log_SOURCES = $(algo_test_SOURCES) 14 | algo_test_log_CPPFLAGS = -DTEST_LOG $(AM_CPPFLAGS) 15 | 16 | check_PROGRAMS += algo_test_tropical 17 | algo_test_tropical_SOURCES = $(algo_test_SOURCES) 18 | algo_test_tropical_CPPFLAGS = -DTEST_TROPICAL $(AM_CPPFLAGS) 19 | 20 | check_PROGRAMS += algo_test_minmax 21 | algo_test_minmax_SOURCES = $(algo_test_SOURCES) 22 | algo_test_minmax_CPPFLAGS = -DTEST_MINMAX $(AM_CPPFLAGS) 23 | 24 | check_PROGRAMS += algo_test_lexicographic 25 | algo_test_lexicographic_SOURCES = $(algo_test_SOURCES) 26 | algo_test_lexicographic_CPPFLAGS = -DTEST_LEXICOGRAPHIC $(AM_CPPFLAGS) 27 | 28 | check_PROGRAMS += algo_test_power 29 | algo_test_power_SOURCES = $(algo_test_SOURCES) 30 | algo_test_power_CPPFLAGS = -DTEST_POWER $(AM_CPPFLAGS) 31 | 32 | TESTS = $(check_PROGRAMS) 33 | -------------------------------------------------------------------------------- /src/include/fst/script/minimize.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_MINIMIZE_H_ 5 | #define FST_SCRIPT_MINIMIZE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using MinimizeArgs = std::tuple; 17 | 18 | template 19 | void Minimize(MinimizeArgs *args) { 20 | MutableFst *ofst1 = std::get<0>(*args)->GetMutableFst(); 21 | MutableFst *ofst2 = (std::get<1>(*args) ? 22 | std::get<1>(*args)->GetMutableFst() : 23 | nullptr); 24 | Minimize(ofst1, ofst2, std::get<2>(*args), std::get<3>(*args)); 25 | } 26 | 27 | void Minimize(MutableFstClass *ofst1, MutableFstClass *ofst2 = nullptr, 28 | float delta = kShortestDelta, bool allow_nondet = false); 29 | 30 | } // namespace script 31 | } // namespace fst 32 | 33 | #endif // FST_SCRIPT_MINIMIZE_H_ 34 | -------------------------------------------------------------------------------- /src/extensions/linear/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | if HAVE_BIN 4 | bin_PROGRAMS = fstlinear fstloglinearapply 5 | 6 | LDADD = libfstlinearscript.la ../../script/libfstscript.la \ 7 | ../../lib/libfst.la -lm $(DL_LIBS) 8 | 9 | fstlinear_SOURCES = fstlinear.cc 10 | 11 | fstloglinearapply_SOURCES = fstloglinearapply.cc 12 | endif 13 | 14 | if HAVE_SCRIPT 15 | libfstlinearscript_la_SOURCES = linearscript.cc 16 | libfstlinearscript_la_LDFLAGS = -version-info 16:0:0 -lm $(DL_LIBS) 17 | libfstlinearscript_la_LIBADD = ../../script/libfstscript.la \ 18 | ../../lib/libfst.la -lm $(DL_LIBS) 19 | endif 20 | 21 | if HAVE_SCRIPT 22 | libfst_LTLIBRARIES = linear_tagger-fst.la \ 23 | linear_classifier-fst.la 24 | lib_LTLIBRARIES = libfstlinearscript.la 25 | else 26 | libfst_LTLIBRARIES = linear_tagger-fst.la linear_classifier-fst.la 27 | endif 28 | 29 | libfstdir = @libfstdir@ 30 | 31 | linear_tagger_fst_la_SOURCES = linear-tagger-fst.cc 32 | linear_tagger_fst_la_LDFLAGS = -module 33 | 34 | linear_classifier_fst_la_SOURCES = linear-classifier-fst.cc 35 | linear_classifier_fst_la_LDFLAGS = -module 36 | -------------------------------------------------------------------------------- /src/script/print.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fst { 12 | namespace script { 13 | 14 | void PrintFst(const FstClass &fst, std::ostream &ostrm, const string &dest, 15 | const SymbolTable *isyms, const SymbolTable *osyms, 16 | const SymbolTable *ssyms, bool accept, bool show_weight_one, 17 | const string &missing_sym) { 18 | const auto sep = FLAGS_fst_field_separator.substr(0, 1); 19 | FstPrinterArgs args(fst, isyms, osyms, ssyms, accept, show_weight_one, &ostrm, 20 | dest, sep, missing_sym); 21 | Apply>("PrintFst", fst.ArcType(), &args); 22 | } 23 | 24 | REGISTER_FST_OPERATION(PrintFst, StdArc, FstPrinterArgs); 25 | REGISTER_FST_OPERATION(PrintFst, LogArc, FstPrinterArgs); 26 | REGISTER_FST_OPERATION(PrintFst, Log64Arc, FstPrinterArgs); 27 | 28 | } // namespace script 29 | } // namespace fst 30 | -------------------------------------------------------------------------------- /src/include/fst/script/compose.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_COMPOSE_H_ 5 | #define FST_SCRIPT_COMPOSE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using ComposeArgs = std::tuple; 17 | 18 | template 19 | void Compose(ComposeArgs *args) { 20 | const Fst &ifst1 = *(std::get<0>(*args).GetFst()); 21 | const Fst &ifst2 = *(std::get<1>(*args).GetFst()); 22 | MutableFst *ofst = std::get<2>(*args)->GetMutableFst(); 23 | const auto &opts = std::get<3>(*args); 24 | Compose(ifst1, ifst2, ofst, opts); 25 | } 26 | 27 | void Compose(const FstClass &ifst1, const FstClass &ifst2, 28 | MutableFstClass *ofst, 29 | const ComposeOptions &opts = ComposeOptions()); 30 | 31 | } // namespace script 32 | } // namespace fst 33 | 34 | #endif // FST_SCRIPT_COMPOSE_H_ 35 | -------------------------------------------------------------------------------- /src/bin/fstsynchronize-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Synchronizes an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | int fstsynchronize_main(int argc, char **argv) { 15 | namespace s = fst::script; 16 | using fst::script::FstClass; 17 | using fst::script::VectorFstClass; 18 | 19 | string usage = "Synchronizes an FST.\n\n Usage: "; 20 | usage += argv[0]; 21 | usage += " [in.fst [out.fst]]\n"; 22 | 23 | std::set_new_handler(FailedNewHandler); 24 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 25 | if (argc > 3) { 26 | ShowUsage(); 27 | return 1; 28 | } 29 | 30 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 31 | const string out_name = argc > 2 ? argv[2] : ""; 32 | 33 | std::unique_ptr ifst(FstClass::Read(in_name)); 34 | if (!ifst) return 1; 35 | 36 | VectorFstClass ofst(ifst->ArcType()); 37 | 38 | s::Synchronize(*ifst, &ofst); 39 | 40 | return !ofst.Write(out_name); 41 | } 42 | -------------------------------------------------------------------------------- /src/extensions/mpdt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB HEADER_FILES ../../include/fst/extensions/mpdt/*.h) 2 | message(STATUS "${HEADER_FILES}") 3 | 4 | if(HAVE_SCRIPT) 5 | add_library(fstmpdtscript mpdtscript.cc ${HEADER_FILES}) 6 | target_link_libraries(fstmpdtscript fstscript fst) 7 | set_target_properties(fstmpdtscript PROPERTIES 8 | SOVERSION "${SOVERSION}" 9 | FOLDER mpdt 10 | ) 11 | install(TARGETS fstmpdtscript 12 | LIBRARY DESTINATION lib 13 | ARCHIVE DESTINATION lib 14 | RUNTIME DESTINATION lib 15 | ) 16 | endif(HAVE_SCRIPT) 17 | 18 | if(HAVE_BIN) 19 | function (add_executable2 _name) 20 | add_executable(${ARGV}) 21 | if (TARGET ${_name}) 22 | target_link_libraries(${_name} fstmpdtscript fstpdtscript fstscript fst ${CMAKE_DL_LIBS}) 23 | set_target_properties(${_name} PROPERTIES 24 | FOLDER mpdt/bin 25 | ) 26 | endif() 27 | install(TARGETS ${_name} RUNTIME DESTINATION bin) 28 | endfunction() 29 | add_executable2(mpdtcompose mpdtcompose.cc) 30 | add_executable2(mpdtexpand mpdtexpand.cc) 31 | add_executable2(mpdtinfo mpdtinfo.cc) 32 | add_executable2(mpdtreverse mpdtreverse.cc) 33 | endif(HAVE_BIN) 34 | 35 | -------------------------------------------------------------------------------- /src/include/fst/script/arc-class.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_ARC_CLASS_H_ 5 | #define FST_SCRIPT_ARC_CLASS_H_ 6 | 7 | #include 8 | 9 | namespace fst { 10 | namespace script { 11 | 12 | // A struct representing an arc while ignoring arc type. It is passed as an 13 | // argument to AddArc. 14 | 15 | struct ArcClass { 16 | template 17 | explicit ArcClass(const Arc &arc) 18 | : ilabel(arc.ilabel), olabel(arc.olabel), weight(arc.weight), 19 | nextstate(arc.nextstate) {} 20 | 21 | ArcClass(int64 ilabel, int64 olabel, const WeightClass &weight, 22 | int64 nextstate) 23 | : ilabel(ilabel), olabel(olabel), weight(weight), nextstate(nextstate) {} 24 | 25 | template 26 | Arc GetArc() const { 27 | return Arc(ilabel, olabel, *(weight.GetWeight()), 28 | nextstate); 29 | } 30 | 31 | int64 ilabel; 32 | int64 olabel; 33 | WeightClass weight; 34 | int64 nextstate; 35 | }; 36 | 37 | } // namespace script 38 | } // namespace fst 39 | 40 | #endif // FST_SCRIPT_ARC_CLASS_H_ 41 | -------------------------------------------------------------------------------- /src/bin/fstconnect-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Removes useless (inaccessible or non-coaccessible) states and arcs from an 5 | // FST. 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | int fstconnect_main(int argc, char **argv) { 16 | namespace s = fst::script; 17 | using fst::script::FstClass; 18 | using fst::script::MutableFstClass; 19 | 20 | string usage = "Removes useless states and arcs from an FST.\n\n Usage: "; 21 | usage += argv[0]; 22 | usage += " [in.fst [out.fst]]\n"; 23 | 24 | std::set_new_handler(FailedNewHandler); 25 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 26 | if (argc > 3) { 27 | ShowUsage(); 28 | return 1; 29 | } 30 | 31 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 32 | const string out_name = argc > 2 ? argv[2] : ""; 33 | 34 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 35 | if (!fst) return 1; 36 | 37 | s::Connect(fst.get()); 38 | 39 | return !fst->Write(out_name); 40 | } 41 | -------------------------------------------------------------------------------- /src/bin/fsttopsort-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Topologically sorts an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int fsttopsort_main(int argc, char **argv) { 16 | namespace s = fst::script; 17 | using fst::script::MutableFstClass; 18 | 19 | string usage = "Topologically sorts an FST.\n\n Usage: "; 20 | usage += argv[0]; 21 | usage += " [in.fst [out.fst]]\n"; 22 | 23 | std::set_new_handler(FailedNewHandler); 24 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 25 | if (argc > 3) { 26 | ShowUsage(); 27 | return 1; 28 | } 29 | 30 | const string in_name = argc > 1 && strcmp(argv[1], "-") != 0 ? argv[1] : ""; 31 | const string out_name = argc > 2 ? argv[2] : ""; 32 | 33 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 34 | if (!fst) return 1; 35 | 36 | bool acyclic = TopSort(fst.get()); 37 | 38 | if (!acyclic) LOG(WARNING) << argv[0] << ": Input FST is cyclic"; 39 | 40 | return !fst->Write(out_name); 41 | } 42 | -------------------------------------------------------------------------------- /src/extensions/compress/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB HEADER_FILES ../../include/fst/extensions/compress/*.h) 2 | message(STATUS "${HEADER_FILES}") 3 | 4 | add_library(fstcompressscript 5 | compress-script.cc 6 | ${HEADER_FILES} 7 | ) 8 | 9 | target_link_libraries(fstcompressscript 10 | fstscript 11 | fst 12 | ${ZLIBS} 13 | ) 14 | set_target_properties(fstcompressscript PROPERTIES 15 | SOVERSION "${SOVERSION}" 16 | ) 17 | install(TARGETS fstcompressscript 18 | LIBRARY DESTINATION lib 19 | ARCHIVE DESTINATION lib 20 | RUNTIME DESTINATION lib 21 | ) 22 | 23 | if(HAVE_BIN) 24 | add_executable(fstcompress 25 | fstcompress.cc) 26 | 27 | target_link_libraries(fstcompress 28 | fstcompressscript 29 | fstscript 30 | fst 31 | ${ZLIBS} 32 | ${CMAKE_DL_LIBS} 33 | ) 34 | 35 | add_executable(fstrandmod 36 | fstrandmod.cc 37 | ) 38 | 39 | target_link_libraries(fstrandmod 40 | fstcompressscript 41 | fstscript 42 | fst 43 | ${ZLIBS} 44 | ${CMAKE_DL_LIBS} 45 | ) 46 | 47 | install(TARGETS fstcompress fstrandmod 48 | LIBRARY DESTINATION bin 49 | ARCHIVE DESTINATION bin 50 | RUNTIME DESTINATION bin 51 | ) 52 | endif(HAVE_BIN) 53 | -------------------------------------------------------------------------------- /src/include/fst/script/intersect.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_INTERSECT_H_ 5 | #define FST_SCRIPT_INTERSECT_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace fst { 14 | namespace script { 15 | 16 | using IntersectArgs = std::tuple; 18 | 19 | template 20 | void Intersect(IntersectArgs *args) { 21 | const Fst &ifst1 = *(std::get<0>(*args).GetFst()); 22 | const Fst &ifst2 = *(std::get<1>(*args).GetFst()); 23 | MutableFst *ofst = std::get<2>(*args)->GetMutableFst(); 24 | const auto &opts = std::get<3>(*args); 25 | Intersect(ifst1, ifst2, ofst, opts); 26 | } 27 | 28 | void Intersect(const FstClass &ifst, const FstClass &ifst2, 29 | MutableFstClass *ofst, 30 | const ComposeOptions &opts = ComposeOptions()); 31 | 32 | } // namespace script 33 | } // namespace fst 34 | 35 | #endif // FST_SCRIPT_INTERSECT_H_ 36 | -------------------------------------------------------------------------------- /src/include/fst/script/concat.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_CONCAT_H_ 5 | #define FST_SCRIPT_CONCAT_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace fst { 13 | namespace script { 14 | 15 | using ConcatArgs1 = std::pair; 16 | 17 | template 18 | void Concat(ConcatArgs1 *args) { 19 | MutableFst *ofst = std::get<0>(*args)->GetMutableFst(); 20 | const Fst &ifst = *(std::get<1>(*args).GetFst()); 21 | Concat(ofst, ifst); 22 | } 23 | 24 | using ConcatArgs2 = std::pair; 25 | 26 | template 27 | void Concat(ConcatArgs2 *args) { 28 | const Fst &ifst = *(std::get<0>(*args).GetFst()); 29 | MutableFst *ofst = std::get<1>(*args)->GetMutableFst(); 30 | Concat(ifst, ofst); 31 | } 32 | 33 | void Concat(MutableFstClass *ofst, const FstClass &ifst); 34 | 35 | void Concat(const FstClass &ifst, MutableFstClass *ofst); 36 | 37 | } // namespace script 38 | } // namespace fst 39 | 40 | #endif // FST_SCRIPT_CONCAT_H_ 41 | -------------------------------------------------------------------------------- /src/script/replace.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Replace(const std::vector &pairs, MutableFstClass *ofst, 12 | const ReplaceOptions &opts) { 13 | if (!pairs.empty()) { 14 | for (auto it = pairs.begin(); it != pairs.end() - 1; ++it) { 15 | if (!internal::ArcTypesMatch(*it->second, *(it + 1)->second, "Replace")) { 16 | ofst->SetProperties(kError, kError); 17 | return; 18 | } 19 | } 20 | if (!internal::ArcTypesMatch(*pairs[0].second, *ofst, "Replace")) { 21 | ofst->SetProperties(kError, kError); 22 | return; 23 | } 24 | } 25 | ReplaceArgs args(pairs, ofst, opts); 26 | Apply>("Replace", ofst->ArcType(), &args); 27 | } 28 | 29 | REGISTER_FST_OPERATION(Replace, StdArc, ReplaceArgs); 30 | REGISTER_FST_OPERATION(Replace, LogArc, ReplaceArgs); 31 | REGISTER_FST_OPERATION(Replace, Log64Arc, ReplaceArgs); 32 | 33 | } // namespace script 34 | } // namespace fst 35 | -------------------------------------------------------------------------------- /src/include/fst/script/difference.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_DIFFERENCE_H_ 5 | #define FST_SCRIPT_DIFFERENCE_H_ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace fst { 14 | namespace script { 15 | 16 | using DifferenceArgs = std::tuple; 18 | 19 | template 20 | void Difference(DifferenceArgs *args) { 21 | const Fst &ifst1 = *(std::get<0>(*args).GetFst()); 22 | const Fst &ifst2 = *(std::get<1>(*args).GetFst()); 23 | MutableFst *ofst = std::get<2>(*args)->GetMutableFst(); 24 | const auto &opts = std::get<3>(*args); 25 | Difference(ifst1, ifst2, ofst, opts); 26 | } 27 | 28 | void Difference(const FstClass &ifst1, const FstClass &ifst2, 29 | MutableFstClass *ofst, 30 | const ComposeOptions &opts = ComposeOptions()); 31 | 32 | } // namespace script 33 | } // namespace fst 34 | 35 | #endif // FST_SCRIPT_DIFFERENCE_H_ 36 | -------------------------------------------------------------------------------- /src/bin/fstclosure-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Creates the Kleene closure of an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | DECLARE_bool(closure_plus); 16 | 17 | int fstclosure_main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | using fst::script::MutableFstClass; 20 | 21 | string usage = "Creates the Kleene closure of an FST.\n\n Usage: "; 22 | usage += argv[0]; 23 | usage += " [in.fst [out.fst]]\n"; 24 | 25 | std::set_new_handler(FailedNewHandler); 26 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 27 | if (argc > 3) { 28 | ShowUsage(); 29 | return 1; 30 | } 31 | 32 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 33 | const string out_name = argc > 2 ? argv[2] : ""; 34 | 35 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 36 | if (!fst) return 1; 37 | 38 | s::Closure(fst.get(), s::GetClosureType(FLAGS_closure_plus)); 39 | 40 | return !fst->Write(out_name); 41 | } 42 | -------------------------------------------------------------------------------- /src/extensions/far/script-impl.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Definitions and functions for invoking and using Far main functions that 5 | // support multiple and extensible arc types. 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace fst { 15 | namespace script { 16 | 17 | string LoadArcTypeFromFar(const string &far_fname) { 18 | FarHeader hdr; 19 | if (!hdr.Read(far_fname)) { 20 | LOG(ERROR) << "Error reading FAR: " << far_fname; 21 | return ""; 22 | } 23 | string atype = hdr.ArcType(); 24 | if (atype == "unknown") { 25 | LOG(ERROR) << "Empty FST archive: " << far_fname; 26 | return ""; 27 | } 28 | return atype; 29 | } 30 | 31 | string LoadArcTypeFromFst(const string &fst_fname) { 32 | FstHeader hdr; 33 | std::ifstream in(fst_fname, std::ios_base::in | std::ios_base::binary); 34 | if (!hdr.Read(in, fst_fname)) { 35 | LOG(ERROR) << "Error reading FST: " << fst_fname; 36 | return ""; 37 | } 38 | return hdr.ArcType(); 39 | } 40 | 41 | } // namespace script 42 | } // namespace fst 43 | -------------------------------------------------------------------------------- /src/include/fst/script/arg-packs.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // std::pair and std::tuple are used for the arguments of FstClass operations. 5 | // 6 | // If a function with a return value is required, use the WithReturnValue 7 | // template as follows: 8 | // 9 | // WithReturnValue> 10 | 11 | #ifndef FST_SCRIPT_ARG_PACKS_H_ 12 | #define FST_SCRIPT_ARG_PACKS_H_ 13 | 14 | #include 15 | 16 | namespace fst { 17 | namespace script { 18 | 19 | // Tack this on to an existing type to add a return value. The syntax for 20 | // accessing the args is then slightly more stilted, as you must do an extra 21 | // member access (since the args are stored as a member of this class). 22 | 23 | template 24 | struct WithReturnValue { 25 | // Avoid reference-to-reference if ArgTuple is a reference. 26 | using Args = typename std::remove_reference::type; 27 | 28 | Retval retval; 29 | const Args &args; 30 | 31 | explicit WithReturnValue(const Args &args) : args(args) {} 32 | }; 33 | 34 | } // namespace script 35 | } // namespace fst 36 | 37 | #endif // FST_SCRIPT_ARG_PACKS_H_ 38 | -------------------------------------------------------------------------------- /src/script/decode.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace fst { 10 | namespace script { 11 | 12 | void Decode(MutableFstClass *fst, const string &coder_fname) { 13 | DecodeArgs1 args(fst, coder_fname); 14 | Apply>("Decode", fst->ArcType(), &args); 15 | } 16 | 17 | void Decode(MutableFstClass *fst, const EncodeMapperClass &encoder) { 18 | if (!internal::ArcTypesMatch(*fst, encoder, "Decode")) { 19 | fst->SetProperties(kError, kError); 20 | return; 21 | } 22 | DecodeArgs2 args(fst, encoder); 23 | Apply>("Decode", fst->ArcType(), &args); 24 | } 25 | 26 | REGISTER_FST_OPERATION(Decode, StdArc, DecodeArgs1); 27 | REGISTER_FST_OPERATION(Decode, LogArc, DecodeArgs1); 28 | REGISTER_FST_OPERATION(Decode, Log64Arc, DecodeArgs1); 29 | 30 | REGISTER_FST_OPERATION(Decode, StdArc, DecodeArgs2); 31 | REGISTER_FST_OPERATION(Decode, LogArc, DecodeArgs2); 32 | REGISTER_FST_OPERATION(Decode, Log64Arc, DecodeArgs2); 33 | 34 | } // namespace script 35 | } // namespace fst 36 | -------------------------------------------------------------------------------- /src/bin/bin.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | {84657A19-CAF2-49E8-8DB3-A428C19F460D} 7 | Application 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {de80efec-9ed9-4631-bd96-8568c31ed26d} 19 | 20 | 21 | {111f46ed-da1f-469b-b912-ba2acc2ff8e6} 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/include/fst/script/reweight.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_REWEIGHT_H_ 5 | #define FST_SCRIPT_REWEIGHT_H_ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace fst { 16 | namespace script { 17 | 18 | using ReweightArgs = std::tuple &, ReweightType>; 20 | 21 | template 22 | void Reweight(ReweightArgs *args) { 23 | using Weight = typename Arc::Weight; 24 | MutableFst *fst = std::get<0>(*args)->GetMutableFst(); 25 | const std::vector &potentials = std::get<1>(*args); 26 | std::vector typed_potentials; 27 | internal::CopyWeights(potentials, &typed_potentials); 28 | Reweight(fst, typed_potentials, std::get<2>(*args)); 29 | } 30 | 31 | void Reweight(MutableFstClass *fst, const std::vector &potentials, 32 | ReweightType reweight_type); 33 | 34 | } // namespace script 35 | } // namespace fst 36 | 37 | #endif // FST_SCRIPT_REWEIGHT_H_ 38 | -------------------------------------------------------------------------------- /src/extensions/pdt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB HEADER_FILES ../../include/fst/extensions/pdt/*.h) 2 | message(STATUS "${HEADER_FILES}") 3 | 4 | if(HAVE_SCRIPT) 5 | add_library(fstpdtscript getters.cc pdtscript.cc ${HEADER_FILES}) 6 | target_link_libraries(fstpdtscript fstscript fst) 7 | set_target_properties(fstpdtscript PROPERTIES 8 | SOVERSION "${SOVERSION}" 9 | FOLDER pdt 10 | ) 11 | 12 | install(TARGETS fstpdtscript 13 | LIBRARY DESTINATION lib 14 | ARCHIVE DESTINATION lib 15 | RUNTIME DESTINATION lib 16 | ) 17 | endif(HAVE_SCRIPT) 18 | 19 | if(HAVE_BIN) 20 | function (add_executable2 _name) 21 | add_executable(${ARGV}) 22 | if (TARGET ${_name}) 23 | target_link_libraries(${_name} fstpdtscript fstscript fst ${CMAKE_DL_LIBS}) 24 | set_target_properties(${_name} PROPERTIES 25 | FOLDER pdt/bin 26 | ) 27 | endif() 28 | install(TARGETS ${_name} RUNTIME DESTINATION bin) 29 | endfunction() 30 | 31 | add_executable2(pdtcompose pdtcompose.cc) 32 | add_executable2(pdtexpand pdtexpand.cc) 33 | add_executable2(pdtinfo pdtinfo.cc) 34 | add_executable2(pdtreplace pdtreplace.cc) 35 | add_executable2(pdtreverse pdtreverse.cc) 36 | add_executable2(pdtshortestpath pdtshortestpath.cc) 37 | endif(HAVE_BIN) 38 | -------------------------------------------------------------------------------- /src/bin/fstreverse-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Reverses the paths in an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | DECLARE_bool(require_superinitial); 16 | 17 | int fstreverse_main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | using fst::script::FstClass; 20 | using fst::script::VectorFstClass; 21 | 22 | string usage = "Reverses the paths in an FST.\n\n Usage: "; 23 | usage += argv[0]; 24 | usage += " [in.fst [out.fst]]\n"; 25 | 26 | std::set_new_handler(FailedNewHandler); 27 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 28 | if (argc > 3) { 29 | ShowUsage(); 30 | return 1; 31 | } 32 | 33 | const string in_name = 34 | (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : ""; 35 | const string out_name = argc > 2 ? argv[2] : ""; 36 | 37 | std::unique_ptr ifst(FstClass::Read(in_name)); 38 | if (!ifst) return 1; 39 | 40 | VectorFstClass ofst(ifst->ArcType()); 41 | 42 | s::Reverse(*ifst, &ofst, FLAGS_require_superinitial); 43 | 44 | return !ofst.Write(out_name); 45 | } 46 | -------------------------------------------------------------------------------- /src/include/fst/extensions/pdt/reverse.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Expands a PDT to an FST. 5 | 6 | #ifndef FST_EXTENSIONS_PDT_REVERSE_H_ 7 | #define FST_EXTENSIONS_PDT_REVERSE_H_ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace fst { 16 | 17 | // Reverses a pushdown transducer (PDT) encoded as an FST. 18 | template 19 | void Reverse(const Fst &ifst, 20 | const std::vector< 21 | std::pair> &parens, 22 | MutableFst *ofst) { 23 | using Label = typename Arc::Label; 24 | // Reverses FST component. 25 | Reverse(ifst, ofst); 26 | // Exchanges open and close parenthesis pairs. 27 | std::vector> relabel_pairs; 28 | relabel_pairs.reserve(2 * parens.size()); 29 | for (const auto &pair : parens) { 30 | relabel_pairs.emplace_back(pair.first, pair.second); 31 | relabel_pairs.emplace_back(pair.second, pair.first); 32 | } 33 | Relabel(ofst, relabel_pairs, relabel_pairs); 34 | } 35 | 36 | } // namespace fst 37 | 38 | #endif // FST_EXTENSIONS_PDT_REVERSE_H_ 39 | -------------------------------------------------------------------------------- /src/bin/fstconvert-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Converts an FST to another type. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | DECLARE_string(fst_type); 15 | 16 | int fstconvert_main(int argc, char **argv) { 17 | namespace s = fst::script; 18 | using fst::script::FstClass; 19 | 20 | string usage = "Converts an FST to another type.\n\n Usage: "; 21 | usage += argv[0]; 22 | usage += " [in.fst [out.fst]]\n"; 23 | 24 | std::set_new_handler(FailedNewHandler); 25 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 26 | if (argc > 3) { 27 | ShowUsage(); 28 | return 1; 29 | } 30 | 31 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 32 | const string out_name = argc > 2 ? argv[2] : ""; 33 | 34 | std::unique_ptr ifst(FstClass::Read(in_name)); 35 | if (!ifst) return 1; 36 | 37 | if (ifst->FstType() != FLAGS_fst_type) { 38 | std::unique_ptr ofst(s::Convert(*ifst, FLAGS_fst_type)); 39 | if (!ofst) return 1; 40 | return !ofst->Write(out_name); 41 | } else { 42 | return !ifst->Write(out_name); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/bin/fstproject-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Projects a transduction onto its input or output language. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | DECLARE_bool(project_output); 16 | 17 | int fstproject_main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | using fst::script::MutableFstClass; 20 | 21 | string usage = 22 | "Projects a transduction onto its input" 23 | " or output language.\n\n Usage: "; 24 | usage += argv[0]; 25 | usage += " [in.fst [out.fst]]\n"; 26 | 27 | std::set_new_handler(FailedNewHandler); 28 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 29 | if (argc > 3) { 30 | ShowUsage(); 31 | return 1; 32 | } 33 | 34 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 35 | const string out_name = argc > 2 ? argv[2] : ""; 36 | 37 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 38 | if (!fst) return 1; 39 | 40 | s::Project(fst.get(), s::GetProjectType(FLAGS_project_output)); 41 | 42 | return !fst->Write(out_name); 43 | } 44 | -------------------------------------------------------------------------------- /src/bin/fstepsnormalize-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Epsilon-normalizes an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | DECLARE_bool(eps_norm_output); 16 | 17 | int fstepsnormalize_main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | using fst::script::FstClass; 20 | using fst::script::VectorFstClass; 21 | 22 | string usage = "Epsilon normalizes an FST.\n\n Usage: "; 23 | usage += argv[0]; 24 | usage += " [in.fst [out.fst]]\n"; 25 | 26 | std::set_new_handler(FailedNewHandler); 27 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 28 | if (argc > 3) { 29 | ShowUsage(); 30 | return 1; 31 | } 32 | 33 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 34 | const string out_name = argc > 2 ? argv[2] : ""; 35 | 36 | std::unique_ptr ifst(FstClass::Read(in_name)); 37 | if (!ifst) return 1; 38 | 39 | VectorFstClass ofst(ifst->ArcType()); 40 | 41 | s::EpsNormalize(*ifst, &ofst, s::GetEpsNormalizeType(FLAGS_eps_norm_output)); 42 | 43 | return !ofst.Write(out_name); 44 | } 45 | -------------------------------------------------------------------------------- /src/script/encode.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace fst { 10 | namespace script { 11 | 12 | void Encode(MutableFstClass *fst, uint32 flags, bool reuse_encoder, 13 | const string &coder_fname) { 14 | EncodeArgs1 args(fst, flags, reuse_encoder, coder_fname); 15 | Apply>("Encode", fst->ArcType(), &args); 16 | } 17 | 18 | void Encode(MutableFstClass *fst, EncodeMapperClass *encoder) { 19 | if (!internal::ArcTypesMatch(*fst, *encoder, "Encode")) { 20 | fst->SetProperties(kError, kError); 21 | return; 22 | } 23 | EncodeArgs2 args(fst, encoder); 24 | Apply>("Encode", fst->ArcType(), &args); 25 | } 26 | 27 | REGISTER_FST_OPERATION(Encode, StdArc, EncodeArgs1); 28 | REGISTER_FST_OPERATION(Encode, LogArc, EncodeArgs1); 29 | REGISTER_FST_OPERATION(Encode, Log64Arc, EncodeArgs1); 30 | 31 | REGISTER_FST_OPERATION(Encode, StdArc, EncodeArgs2); 32 | REGISTER_FST_OPERATION(Encode, LogArc, EncodeArgs2); 33 | REGISTER_FST_OPERATION(Encode, Log64Arc, EncodeArgs2); 34 | 35 | } // namespace script 36 | } // namespace fst 37 | -------------------------------------------------------------------------------- /src/script/push.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Push(MutableFstClass *fst, ReweightType rew_type, float delta, 12 | bool remove_total_weight) { 13 | PushArgs1 args(fst, rew_type, delta, remove_total_weight); 14 | Apply>("Push", fst->ArcType(), &args); 15 | } 16 | 17 | void Push(const FstClass &ifst, MutableFstClass *ofst, uint32 flags, 18 | ReweightType rew_type, float delta) { 19 | if (!internal::ArcTypesMatch(ifst, *ofst, "Push")) { 20 | ofst->SetProperties(kError, kError); 21 | return; 22 | } 23 | PushArgs2 args(ifst, ofst, flags, rew_type, delta); 24 | Apply>("Push", ifst.ArcType(), &args); 25 | } 26 | 27 | REGISTER_FST_OPERATION(Push, StdArc, PushArgs1); 28 | REGISTER_FST_OPERATION(Push, LogArc, PushArgs1); 29 | REGISTER_FST_OPERATION(Push, Log64Arc, PushArgs1); 30 | 31 | REGISTER_FST_OPERATION(Push, StdArc, PushArgs2); 32 | REGISTER_FST_OPERATION(Push, LogArc, PushArgs2); 33 | REGISTER_FST_OPERATION(Push, Log64Arc, PushArgs2); 34 | 35 | } // namespace script 36 | } // namespace fst 37 | -------------------------------------------------------------------------------- /src/extensions/far/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(srcdir)/../../include $(ICU_CPPFLAGS) 2 | 3 | if HAVE_SCRIPT 4 | lib_LTLIBRARIES = libfstfar.la libfstfarscript.la 5 | else 6 | lib_LTLIBRARIES = libfstfar.la 7 | endif 8 | 9 | libfstfar_la_SOURCES = sttable.cc stlist.cc 10 | libfstfar_la_LDFLAGS = -version-info 16:0:0 11 | libfstfar_la_LIBADD = ../../lib/libfst.la -lm $(DL_LIBS) 12 | 13 | if HAVE_SCRIPT 14 | libfstfarscript_la_SOURCES = far-class.cc farscript.cc getters.cc script-impl.cc \ 15 | strings.cc 16 | libfstfarscript_la_LDFLAGS = -version-info 16:0:0 17 | libfstfarscript_la_LIBADD = \ 18 | libfstfar.la ../../script/libfstscript.la \ 19 | ../../lib/libfst.la -lm $(DL_LIBS) 20 | endif 21 | 22 | if HAVE_BIN 23 | bin_PROGRAMS = farcompilestrings farcreate farequal farextract farinfo \ 24 | farisomorphic farprintstrings 25 | 26 | LDADD = libfstfarscript.la ../../script/libfstscript.la \ 27 | ../../lib/libfst.la -lm $(DL_LIBS) 28 | 29 | farcompilestrings_SOURCES = farcompilestrings.cc 30 | 31 | farcreate_SOURCES = farcreate.cc 32 | 33 | farequal_SOURCES = farequal.cc 34 | 35 | farextract_SOURCES = farextract.cc 36 | 37 | farinfo_SOURCES = farinfo.cc 38 | 39 | farisomorphic_SOURCES = farisomorphic.cc 40 | 41 | farprintstrings_SOURCES = farprintstrings.cc 42 | endif 43 | -------------------------------------------------------------------------------- /src/script/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB HEADER_FILES ../include/fst/script/*.h) 2 | message(STATUS "${HEADER_FILES}") 3 | 4 | add_library(fstscript 5 | arciterator-class.cc 6 | arcsort.cc 7 | closure.cc 8 | compile.cc 9 | compose.cc 10 | concat.cc 11 | connect.cc 12 | convert.cc 13 | decode.cc 14 | determinize.cc 15 | difference.cc 16 | disambiguate.cc 17 | draw.cc 18 | encode.cc 19 | encodemapper-class.cc 20 | epsnormalize.cc 21 | equal.cc 22 | equivalent.cc 23 | fst-class.cc 24 | getters.cc 25 | info.cc 26 | info-impl.cc 27 | intersect.cc 28 | invert.cc 29 | isomorphic.cc 30 | map.cc 31 | minimize.cc 32 | print.cc 33 | project.cc 34 | prune.cc 35 | push.cc 36 | randequivalent.cc 37 | randgen.cc 38 | relabel.cc 39 | replace.cc 40 | reverse.cc 41 | reweight.cc 42 | rmepsilon.cc 43 | shortest-distance.cc 44 | shortest-path.cc 45 | stateiterator-class.cc 46 | synchronize.cc 47 | text-io.cc 48 | topsort.cc 49 | union.cc 50 | weight-class.cc 51 | verify.cc 52 | ${HEADER_FILES} 53 | ) 54 | target_link_libraries(fstscript PRIVATE fst) 55 | 56 | set_target_properties(fstscript PROPERTIES 57 | SOVERSION "${SOVERSION}" 58 | ) 59 | install(TARGETS fstscript 60 | LIBRARY DESTINATION lib 61 | ARCHIVE DESTINATION lib 62 | RUNTIME DESTINATION lib) 63 | 64 | -------------------------------------------------------------------------------- /src/script/draw.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fst { 12 | namespace script { 13 | 14 | void DrawFst(const FstClass &fst, const SymbolTable *isyms, 15 | const SymbolTable *osyms, const SymbolTable *ssyms, bool accep, 16 | const string &title, float width, float height, bool portrait, 17 | bool vertical, float ranksep, float nodesep, int fontsize, 18 | int precision, const string &float_format, bool show_weight_one, 19 | std::ostream *ostrm, const string &dest) { 20 | FstDrawerArgs args(fst, isyms, osyms, ssyms, accep, title, width, height, 21 | portrait, vertical, ranksep, nodesep, fontsize, precision, 22 | float_format, show_weight_one, ostrm, dest); 23 | Apply>("DrawFst", fst.ArcType(), &args); 24 | } 25 | 26 | REGISTER_FST_OPERATION(DrawFst, StdArc, FstDrawerArgs); 27 | REGISTER_FST_OPERATION(DrawFst, LogArc, FstDrawerArgs); 28 | REGISTER_FST_OPERATION(DrawFst, Log64Arc, FstDrawerArgs); 29 | 30 | } // namespace script 31 | } // namespace fst 32 | -------------------------------------------------------------------------------- /src/script/concat.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | // 1 12 | void Concat(MutableFstClass *ofst, const FstClass &ifst) { 13 | if (!internal::ArcTypesMatch(*ofst, ifst, "Concat")) { 14 | ofst->SetProperties(kError, kError); 15 | return; 16 | } 17 | ConcatArgs1 args(ofst, ifst); 18 | Apply>("Concat", ofst->ArcType(), &args); 19 | } 20 | 21 | // 2 22 | void Concat(const FstClass &ifst, MutableFstClass *ofst) { 23 | if (!internal::ArcTypesMatch(ifst, *ofst, "Concat")) { 24 | ofst->SetProperties(kError, kError); 25 | return; 26 | } 27 | ConcatArgs2 args(ifst, ofst); 28 | Apply>("Concat", ofst->ArcType(), &args); 29 | } 30 | 31 | REGISTER_FST_OPERATION(Concat, StdArc, ConcatArgs1); 32 | REGISTER_FST_OPERATION(Concat, LogArc, ConcatArgs1); 33 | REGISTER_FST_OPERATION(Concat, Log64Arc, ConcatArgs1); 34 | 35 | REGISTER_FST_OPERATION(Concat, StdArc, ConcatArgs2); 36 | REGISTER_FST_OPERATION(Concat, LogArc, ConcatArgs2); 37 | REGISTER_FST_OPERATION(Concat, Log64Arc, ConcatArgs2); 38 | 39 | } // namespace script 40 | } // namespace fst 41 | -------------------------------------------------------------------------------- /src/bin/fstinfo-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Prints out various information about an FST such as number of states 5 | // and arcs and property values (see properties.h). 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | DECLARE_string(arc_filter); 16 | DECLARE_string(info_type); 17 | DECLARE_bool(pipe); 18 | DECLARE_bool(test_properties); 19 | DECLARE_bool(fst_verify); 20 | 21 | int fstinfo_main(int argc, char **argv) { 22 | namespace s = fst::script; 23 | using fst::script::FstClass; 24 | 25 | string usage = "Prints out information about an FST.\n\n Usage: "; 26 | usage += argv[0]; 27 | usage += " [in.fst]\n"; 28 | 29 | std::set_new_handler(FailedNewHandler); 30 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 31 | if (argc > 2) { 32 | ShowUsage(); 33 | return 1; 34 | } 35 | 36 | const string in_name = 37 | (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : ""; 38 | 39 | std::unique_ptr ifst(FstClass::Read(in_name)); 40 | if (!ifst) return 1; 41 | 42 | s::PrintFstInfo(*ifst, FLAGS_test_properties, FLAGS_arc_filter, 43 | FLAGS_info_type, FLAGS_fst_verify, FLAGS_pipe); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/extensions/special/rho-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | #include 7 | 8 | DEFINE_int64(rho_fst_rho_label, 0, 9 | "Label of transitions to be interpreted as rho ('rest') " 10 | "transitions"); 11 | DEFINE_string(rho_fst_rewrite_mode, "auto", 12 | "Rewrite both sides when matching? One of:" 13 | " \"auto\" (rewrite iff acceptor), \"always\", \"never\""); 14 | 15 | namespace fst { 16 | 17 | const char rho_fst_type[] = "rho"; 18 | const char input_rho_fst_type[] = "input_rho"; 19 | const char output_rho_fst_type[] = "output_rho"; 20 | 21 | static FstRegisterer RhoFst_StdArc_registerer; 22 | static FstRegisterer RhoFst_LogArc_registerer; 23 | static FstRegisterer RhoFst_Log64Arc_registerer; 24 | 25 | static FstRegisterer InputRhoFst_StdArc_registerer; 26 | static FstRegisterer InputRhoFst_LogArc_registerer; 27 | static FstRegisterer InputRhoFst_Log64Arc_registerer; 28 | 29 | static FstRegisterer OutputRhoFst_StdArc_registerer; 30 | static FstRegisterer OutputRhoFst_LogArc_registerer; 31 | static FstRegisterer OutputRhoFst_Log64Arc_registerer; 32 | 33 | } // namespace fst 34 | -------------------------------------------------------------------------------- /src/lib/fst-types.cc: -------------------------------------------------------------------------------- 1 | // Registration of common FST and arc types. 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace fst { 11 | 12 | REGISTER_FST(VectorFst, StdArc); 13 | REGISTER_FST(VectorFst, LogArc); 14 | REGISTER_FST(VectorFst, Log64Arc); 15 | 16 | REGISTER_FST(ConstFst, StdArc); 17 | REGISTER_FST(ConstFst, LogArc); 18 | REGISTER_FST(ConstFst, Log64Arc); 19 | 20 | REGISTER_FST(EditFst, StdArc); 21 | REGISTER_FST(EditFst, LogArc); 22 | REGISTER_FST(EditFst, Log64Arc); 23 | 24 | REGISTER_FST(CompactStringFst, StdArc); 25 | REGISTER_FST(CompactStringFst, LogArc); 26 | REGISTER_FST(CompactStringFst, Log64Arc); 27 | 28 | REGISTER_FST(CompactWeightedStringFst, StdArc); 29 | REGISTER_FST(CompactWeightedStringFst, LogArc); 30 | REGISTER_FST(CompactWeightedStringFst, Log64Arc); 31 | 32 | REGISTER_FST(CompactAcceptorFst, StdArc); 33 | REGISTER_FST(CompactAcceptorFst, LogArc); 34 | REGISTER_FST(CompactAcceptorFst, Log64Arc); 35 | 36 | REGISTER_FST(CompactUnweightedFst, StdArc); 37 | REGISTER_FST(CompactUnweightedFst, LogArc); 38 | REGISTER_FST(CompactUnweightedFst, Log64Arc); 39 | 40 | REGISTER_FST(CompactUnweightedAcceptorFst, StdArc); 41 | REGISTER_FST(CompactUnweightedAcceptorFst, LogArc); 42 | REGISTER_FST(CompactUnweightedAcceptorFst, Log64Arc); 43 | 44 | } // namespace fst 45 | -------------------------------------------------------------------------------- /src/extensions/linear/fstlinear.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | #include 7 | 8 | DEFINE_string(arc_type, "standard", "Output arc type"); 9 | 10 | DEFINE_string(epsilon_symbol, "", "Epsilon symbol"); 11 | DEFINE_string(unknown_symbol, "", "Unknown word symbol"); 12 | 13 | DEFINE_string(vocab, "", "Path to the vocabulary file"); 14 | DEFINE_string(out, "", "Path to the output binary"); 15 | 16 | DEFINE_string(save_isymbols, "", "Save input symbol table to file"); 17 | DEFINE_string(save_fsymbols, "", "Save feature symbol table to file"); 18 | DEFINE_string(save_osymbols, "", "Save output symbol table to file"); 19 | 20 | int main(int argc, char **argv) { 21 | // TODO(wuke): more detailed usage 22 | std::set_new_handler(FailedNewHandler); 23 | SET_FLAGS(argv[0], &argc, &argv, true); 24 | fst::script::ValidateDelimiter(); 25 | fst::script::ValidateEmptySymbol(); 26 | 27 | if (argc == 1) { 28 | ShowUsage(); 29 | return 1; 30 | } 31 | 32 | fst::script::LinearCompile(FLAGS_arc_type, FLAGS_epsilon_symbol, 33 | FLAGS_unknown_symbol, FLAGS_vocab, argv + 1, 34 | argc - 1, FLAGS_out, FLAGS_save_isymbols, 35 | FLAGS_save_fsymbols, FLAGS_save_osymbols); 36 | } 37 | -------------------------------------------------------------------------------- /src/extensions/far/farequal.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Tests if two Far files contains the same (key,fst) pairs. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | DEFINE_string(begin_key, "", 13 | "First key to extract (def: first key in archive)"); 14 | DEFINE_string(end_key, "", "Last key to extract (def: last key in archive)"); 15 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 16 | 17 | int main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | 20 | string usage = "Compares the FSTs in two FST archives for equality."; 21 | usage += "\n\n Usage:"; 22 | usage += argv[0]; 23 | usage += " in1.far in2.far"; 24 | 25 | std::set_new_handler(FailedNewHandler); 26 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 27 | s::ExpandArgs(argc, argv, &argc, &argv); 28 | if (argc != 3) { 29 | ShowUsage(); 30 | return 1; 31 | } 32 | 33 | const auto arc_type = s::LoadArcTypeFromFar(argv[1]); 34 | if (arc_type.empty()) return 1; 35 | 36 | bool result = s::FarEqual(argv[1], argv[2], arc_type, FLAGS_delta, 37 | FLAGS_begin_key, FLAGS_end_key); 38 | 39 | if (!result) VLOG(1) << "FARs are not equal."; 40 | 41 | return result ? 0 : 2; 42 | } 43 | -------------------------------------------------------------------------------- /src/script/info.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace fst { 11 | namespace script { 12 | 13 | void PrintFstInfo(const FstClass &fst, bool test_properties, 14 | const string &arc_filter, const string &info_type, bool pipe, 15 | bool verify) { 16 | InfoArgs args(fst, test_properties, arc_filter, info_type, pipe, verify); 17 | Apply>("PrintFstInfo", fst.ArcType(), &args); 18 | } 19 | 20 | void GetFstInfo(const FstClass &fst, bool test_properties, 21 | const string &arc_filter, const string &info_type, bool verify, 22 | FstInfo *result) { 23 | GetInfoArgs args(fst, test_properties, arc_filter, info_type, verify, result); 24 | Apply>("GetFstInfo", fst.ArcType(), &args); 25 | } 26 | 27 | REGISTER_FST_OPERATION(PrintFstInfo, StdArc, InfoArgs); 28 | REGISTER_FST_OPERATION(PrintFstInfo, LogArc, InfoArgs); 29 | REGISTER_FST_OPERATION(PrintFstInfo, Log64Arc, InfoArgs); 30 | 31 | REGISTER_FST_OPERATION(GetFstInfo, StdArc, GetInfoArgs); 32 | REGISTER_FST_OPERATION(GetFstInfo, LogArc, GetInfoArgs); 33 | REGISTER_FST_OPERATION(GetFstInfo, Log64Arc, GetInfoArgs); 34 | 35 | } // namespace script 36 | } // namespace fst 37 | -------------------------------------------------------------------------------- /src/bin/fstarcsort-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Sorts arcs of an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | DECLARE_string(sort_type); 17 | 18 | int fstarcsort_main(int argc, char **argv) { 19 | namespace s = fst::script; 20 | using fst::script::MutableFstClass; 21 | 22 | string usage = "Sorts arcs of an FST.\n\n Usage: "; 23 | usage += argv[0]; 24 | usage += " [in.fst [out.fst]]\n"; 25 | 26 | std::set_new_handler(FailedNewHandler); 27 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 28 | 29 | if (argc > 3) { 30 | ShowUsage(); 31 | return 1; 32 | } 33 | 34 | const string in_name = 35 | (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : ""; 36 | const string out_name = argc > 2 ? argv[2] : ""; 37 | 38 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 39 | if (!fst) return 1; 40 | 41 | s::ArcSortType sort_type; 42 | if (!s::GetArcSortType(FLAGS_sort_type, &sort_type)) { 43 | LOG(ERROR) << argv[0] << ": Unknown or unsupported sort type: " 44 | << FLAGS_sort_type; 45 | return 1; 46 | } 47 | 48 | s::ArcSort(fst.get(), sort_type); 49 | 50 | return !fst->Write(out_name); 51 | } 52 | -------------------------------------------------------------------------------- /src/extensions/special/sigma-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | #include 7 | 8 | DEFINE_int64(sigma_fst_sigma_label, 0, 9 | "Label of transitions to be interpreted as sigma ('any') " 10 | "transitions"); 11 | DEFINE_string(sigma_fst_rewrite_mode, "auto", 12 | "Rewrite both sides when matching? One of:" 13 | " \"auto\" (rewrite iff acceptor), \"always\", \"never\""); 14 | 15 | namespace fst { 16 | 17 | const char sigma_fst_type[] = "sigma"; 18 | const char input_sigma_fst_type[] = "input_sigma"; 19 | const char output_sigma_fst_type[] = "output_sigma"; 20 | 21 | static FstRegisterer SigmaFst_StdArc_registerer; 22 | static FstRegisterer SigmaFst_LogArc_registerer; 23 | static FstRegisterer SigmaFst_Log64Arc_registerer; 24 | 25 | static FstRegisterer InputSigmaFst_StdArc_registerer; 26 | static FstRegisterer InputSigmaFst_LogArc_registerer; 27 | static FstRegisterer InputSigmaFst_Log64Arc_registerer; 28 | 29 | static FstRegisterer OutputSigmaFst_StdArc_registerer; 30 | static FstRegisterer OutputSigmaFst_LogArc_registerer; 31 | static FstRegisterer OutputSigmaFst_Log64Arc_registerer; 32 | 33 | } // namespace fst 34 | -------------------------------------------------------------------------------- /src/bin/fstreweight-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Reweights an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | DECLARE_bool(to_final); 18 | 19 | int fstreweight_main(int argc, char **argv) { 20 | namespace s = fst::script; 21 | using fst::script::MutableFstClass; 22 | using fst::script::WeightClass; 23 | 24 | string usage = "Reweights an FST.\n\n Usage: "; 25 | usage += argv[0]; 26 | usage += " in.fst potential.txt [out.fst]\n"; 27 | 28 | std::set_new_handler(FailedNewHandler); 29 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 30 | if (argc < 3 || argc > 4) { 31 | ShowUsage(); 32 | return 1; 33 | } 34 | 35 | const string in_name = argv[1]; 36 | const string potentials_name = argv[2]; 37 | const string out_name = argc > 3 ? argv[3] : ""; 38 | 39 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 40 | if (!fst) return 1; 41 | 42 | std::vector potential; 43 | if (!s::ReadPotentials(fst->WeightType(), potentials_name, &potential)) { 44 | return 1; 45 | } 46 | 47 | s::Reweight(fst.get(), potential, s::GetReweightType(FLAGS_to_final)); 48 | 49 | return !fst->Write(out_name); 50 | } 51 | -------------------------------------------------------------------------------- /src/bin/fstconcat-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Concatenates two FSTs. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int fstconcat_main(int argc, char **argv) { 16 | namespace s = fst::script; 17 | using fst::script::FstClass; 18 | using fst::script::MutableFstClass; 19 | 20 | string usage = "Concatenates two FSTs.\n\n Usage: "; 21 | usage += argv[0]; 22 | usage += " in1.fst in2.fst [out.fst]\n"; 23 | 24 | std::set_new_handler(FailedNewHandler); 25 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 26 | if (argc < 3 || argc > 4) { 27 | ShowUsage(); 28 | return 1; 29 | } 30 | 31 | const string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1]; 32 | const string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2]; 33 | const string out_name = argc > 3 ? argv[3] : ""; 34 | 35 | if (in1_name.empty() && in2_name.empty()) { 36 | LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input"; 37 | return 1; 38 | } 39 | 40 | std::unique_ptr fst1(MutableFstClass::Read(in1_name, true)); 41 | if (!fst1) return 1; 42 | 43 | std::unique_ptr fst2(FstClass::Read(in2_name)); 44 | if (!fst2) return 1; 45 | 46 | s::Concat(fst1.get(), *fst2); 47 | 48 | return !fst1->Write(out_name); 49 | } 50 | -------------------------------------------------------------------------------- /src/bin/fstprune-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Prunes states and arcs of an FST w.r.t. the shortest path weight. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | DECLARE_double(delta); 15 | DECLARE_int64(nstate); 16 | DECLARE_string(weight); 17 | 18 | int fstprune_main(int argc, char **argv) { 19 | namespace s = fst::script; 20 | using fst::script::MutableFstClass; 21 | using fst::script::WeightClass; 22 | 23 | string usage = "Prunes states and arcs of an FST.\n\n Usage: "; 24 | usage += argv[0]; 25 | usage += " [in.fst [out.fst]]\n"; 26 | 27 | std::set_new_handler(FailedNewHandler); 28 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 29 | if (argc > 3) { 30 | ShowUsage(); 31 | return 1; 32 | } 33 | 34 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 35 | const string out_name = argc > 2 ? argv[2] : ""; 36 | 37 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 38 | if (!fst) return 1; 39 | 40 | const auto weight_threshold = 41 | FLAGS_weight.empty() ? WeightClass::Zero(fst->WeightType()) 42 | : WeightClass(fst->WeightType(), FLAGS_weight); 43 | 44 | s::Prune(fst.get(), weight_threshold, FLAGS_nstate, FLAGS_delta); 45 | 46 | return !fst->Write(out_name); 47 | } 48 | -------------------------------------------------------------------------------- /src/bin/fstunion-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Creates the union of two FSTs. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int fstunion_main(int argc, char **argv) { 16 | namespace s = fst::script; 17 | using fst::script::FstClass; 18 | using fst::script::MutableFstClass; 19 | 20 | string usage = "Creates the union of two FSTs.\n\n Usage: "; 21 | usage += argv[0]; 22 | usage += " in1.fst in2.fst [out.fst]\n"; 23 | 24 | std::set_new_handler(FailedNewHandler); 25 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 26 | if (argc < 3 || argc > 4) { 27 | ShowUsage(); 28 | return 1; 29 | } 30 | 31 | const string in1_name = strcmp(argv[1], "-") != 0 ? argv[1] : ""; 32 | const string in2_name = strcmp(argv[2], "-") != 0 ? argv[2] : ""; 33 | const string out_name = argc > 3 ? argv[3] : ""; 34 | 35 | if (in1_name == "" && in2_name == "") { 36 | LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input"; 37 | return 1; 38 | } 39 | 40 | std::unique_ptr fst1(MutableFstClass::Read(in1_name, true)); 41 | if (!fst1) return 1; 42 | 43 | std::unique_ptr fst2(FstClass::Read(in2_name)); 44 | if (!fst2) return 1; 45 | 46 | s::Union(fst1.get(), *fst2); 47 | 48 | return !fst1->Write(out_name); 49 | } 50 | -------------------------------------------------------------------------------- /src/lib/compat.cc: -------------------------------------------------------------------------------- 1 | // compat.cc 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // Author: riley@google.com (Michael Riley) 16 | // 17 | // \file 18 | // Google compatibility definitions. 19 | 20 | #include 21 | #include 22 | 23 | using namespace std; 24 | 25 | void FailedNewHandler() { 26 | cerr << "Memory allocation failed\n"; 27 | exit(1); 28 | } 29 | 30 | #ifdef _MSC_VER 31 | 32 | const char *basename(const char *path) { 33 | //the man page for the original basename states the function 34 | //can return a pointer to an internal static structure 35 | //so this might be ugly but still within the scope of acceptable behavior 36 | char basename[_MAX_FNAME]; 37 | char ext[_MAX_EXT]; 38 | static char full_path[_MAX_EXT + _MAX_FNAME]; 39 | 40 | _splitpath(path, NULL, NULL, basename, ext); 41 | _makepath(full_path, NULL, NULL, basename, ext); 42 | return full_path; 43 | } 44 | 45 | #endif // _MSC_VER 46 | -------------------------------------------------------------------------------- /src/include/fst/script/decode.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_SCRIPT_DECODE_H_ 5 | #define FST_SCRIPT_DECODE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace fst { 16 | namespace script { 17 | 18 | using DecodeArgs1 = std::pair; 19 | 20 | template 21 | void Decode(DecodeArgs1 *args) { 22 | MutableFst *fst = std::get<0>(*args)->GetMutableFst(); 23 | std::unique_ptr> decoder( 24 | EncodeMapper::Read(std::get<1>(*args), DECODE)); 25 | if (!decoder) { 26 | fst->SetProperties(kError, kError); 27 | return; 28 | } 29 | Decode(fst, *decoder); 30 | } 31 | 32 | using DecodeArgs2 = std::pair; 33 | 34 | template 35 | void Decode(DecodeArgs2 *args) { 36 | MutableFst *fst = std::get<0>(*args)->GetMutableFst(); 37 | const EncodeMapper &encoder = 38 | *(std::get<1>(*args).GetEncodeMapper()); 39 | Decode(fst, encoder); 40 | } 41 | 42 | void Decode(MutableFstClass *fst, const string &coder_fname); 43 | 44 | void Decode(MutableFstClass *fst, const EncodeMapperClass &encoder); 45 | 46 | } // namespace script 47 | } // namespace fst 48 | 49 | #endif // FST_SCRIPT_DECODE_H_ 50 | -------------------------------------------------------------------------------- /src/bin/fstequal-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Two FSTS are equal iff their exit status is zero. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | DECLARE_double(delta); 16 | 17 | int fstequal_main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | using fst::script::FstClass; 20 | 21 | string usage = "Two FSTs are equal iff the exit status is zero.\n\n Usage: "; 22 | usage += argv[0]; 23 | usage += " in1.fst in2.fst\n"; 24 | 25 | std::set_new_handler(FailedNewHandler); 26 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 27 | if (argc != 3) { 28 | ShowUsage(); 29 | return 1; 30 | } 31 | 32 | const string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1]; 33 | const string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2]; 34 | 35 | if (in1_name.empty() && in2_name.empty()) { 36 | LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input"; 37 | return 1; 38 | } 39 | 40 | std::unique_ptr ifst1(FstClass::Read(in1_name)); 41 | if (!ifst1) return 1; 42 | 43 | std::unique_ptr ifst2(FstClass::Read(in2_name)); 44 | if (!ifst2) return 1; 45 | 46 | bool result = s::Equal(*ifst1, *ifst2, FLAGS_delta); 47 | if (!result) VLOG(1) << "FSTs are not equal."; 48 | 49 | return result ? 0 : 2; 50 | } 51 | -------------------------------------------------------------------------------- /src/extensions/far/farisomorphic.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Tests if two Far files contains isomorphic (key,fst) pairs. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | DEFINE_string(begin_key, "", 13 | "First key to extract (def: first key in archive)"); 14 | DEFINE_string(end_key, "", "Last key to extract (def: last key in archive)"); 15 | DEFINE_double(delta, fst::kDelta, "Comparison/quantization delta"); 16 | 17 | int main(int argc, char **argv) { 18 | namespace s = fst::script; 19 | 20 | string usage = "Compares the FSTs in two FST archives for isomorphism."; 21 | usage += "\n\n Usage:"; 22 | usage += argv[0]; 23 | usage += " in1.far in2.far\n"; 24 | usage += " Flags: begin_key end_key"; 25 | 26 | std::set_new_handler(FailedNewHandler); 27 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 28 | s::ExpandArgs(argc, argv, &argc, &argv); 29 | 30 | if (argc != 3) { 31 | ShowUsage(); 32 | return 1; 33 | } 34 | 35 | const auto arc_type = s::LoadArcTypeFromFar(argv[1]); 36 | if (arc_type.empty()) return 1; 37 | 38 | bool result = s::FarIsomorphic(argv[1], argv[2], arc_type, 39 | FLAGS_delta, FLAGS_begin_key, FLAGS_end_key); 40 | 41 | if (!result) VLOG(1) << "FARs are not isomorphic."; 42 | 43 | return result ? 0 : 2; 44 | } 45 | -------------------------------------------------------------------------------- /src/extensions/special/phi-fst.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | DEFINE_int64(phi_fst_phi_label, 0, 8 | "Label of transitions to be interpreted as phi ('failure') " 9 | "transitions"); 10 | DEFINE_bool(phi_fst_phi_loop, true, 11 | "When true, a phi self loop consumes a symbol"); 12 | DEFINE_string(phi_fst_rewrite_mode, "auto", 13 | "Rewrite both sides when matching? One of:" 14 | " \"auto\" (rewrite iff acceptor), \"always\", \"never\""); 15 | 16 | namespace fst { 17 | 18 | const char phi_fst_type[] = "phi"; 19 | const char input_phi_fst_type[] = "input_phi"; 20 | const char output_phi_fst_type[] = "output_phi"; 21 | 22 | static FstRegisterer PhiFst_StdArc_registerer; 23 | static FstRegisterer PhiFst_LogArc_registerer; 24 | static FstRegisterer PhiFst_Log64Arc_registerer; 25 | 26 | static FstRegisterer InputPhiFst_StdArc_registerer; 27 | static FstRegisterer InputPhiFst_LogArc_registerer; 28 | static FstRegisterer InputPhiFst_Log64Arc_registerer; 29 | 30 | static FstRegisterer OutputPhiFst_StdArc_registerer; 31 | static FstRegisterer OutputPhiFst_LogArc_registerer; 32 | static FstRegisterer OutputPhiFst_Log64Arc_registerer; 33 | 34 | } // namespace fst 35 | -------------------------------------------------------------------------------- /src/include/fst/types.h: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | // 13 | // See www.openfst.org for extensive documentation on this weighted 14 | // finite-state transducer library. 15 | // 16 | // Various type definitions (mostly for Google compatibility). 17 | 18 | #include // For std::ptrdiff_t. 19 | #include // for ssize_t. 20 | #include // for ?int*_t. 21 | 22 | #ifndef FST_LIB_TYPES_H_ 23 | #define FST_LIB_TYPES_H_ 24 | 25 | using int8 = int8_t; 26 | using int16 = int16_t; 27 | using int32 = int32_t; 28 | using int64 = int64_t; 29 | 30 | using uint8 = uint8_t; 31 | using uint16 = uint16_t; 32 | using uint32 = uint32_t; 33 | using uint64 = uint64_t; 34 | 35 | #ifdef _MSC_VER 36 | // Not really Windows-specific: they should have used ptrdiff_t in the first 37 | // place. But on Windows there has never been ssize_t. 38 | using ssize_t = std::ptrdiff_t; 39 | #endif // _MSC_VER 40 | 41 | #endif // FST_LIB_TYPES_H_ 42 | -------------------------------------------------------------------------------- /src/script/shortest-distance.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void ShortestDistance(const FstClass &fst, std::vector *distance, 12 | const ShortestDistanceOptions &opts) { 13 | ShortestDistanceArgs1 args(fst, distance, opts); 14 | Apply>("ShortestDistance", fst.ArcType(), 15 | &args); 16 | } 17 | 18 | void ShortestDistance(const FstClass &ifst, std::vector *distance, 19 | bool reverse, double delta) { 20 | ShortestDistanceArgs2 args(ifst, distance, reverse, delta); 21 | Apply>("ShortestDistance", ifst.ArcType(), 22 | &args); 23 | } 24 | 25 | REGISTER_FST_OPERATION(ShortestDistance, StdArc, ShortestDistanceArgs1); 26 | REGISTER_FST_OPERATION(ShortestDistance, LogArc, ShortestDistanceArgs1); 27 | REGISTER_FST_OPERATION(ShortestDistance, Log64Arc, ShortestDistanceArgs1); 28 | 29 | REGISTER_FST_OPERATION(ShortestDistance, StdArc, ShortestDistanceArgs2); 30 | REGISTER_FST_OPERATION(ShortestDistance, LogArc, ShortestDistanceArgs2); 31 | REGISTER_FST_OPERATION(ShortestDistance, Log64Arc, ShortestDistanceArgs2); 32 | 33 | } // namespace script 34 | } // namespace fst 35 | -------------------------------------------------------------------------------- /src/extensions/compress/compress-script.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Definitions of 'scriptable' versions of compression operations, that is, 5 | // those that can be called with FstClass-type arguments. 6 | // 7 | // See comments in nlp/fst/script/script-impl.h for how the registration 8 | // mechanism allows these to work with various arc types. 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | namespace fst { 16 | namespace script { 17 | 18 | void Compress(const FstClass &fst, const string &filename, const bool gzip) { 19 | CompressArgs args(fst, filename, gzip); 20 | Apply>("Compress", fst.ArcType(), &args); 21 | } 22 | 23 | void Decompress(const string &filename, MutableFstClass *fst, const bool gzip) { 24 | DecompressArgs args(filename, fst, gzip); 25 | Apply>("Decompress", fst->ArcType(), &args); 26 | } 27 | 28 | // Register operations for common arc types. 29 | 30 | REGISTER_FST_OPERATION(Compress, StdArc, CompressArgs); 31 | REGISTER_FST_OPERATION(Compress, LogArc, CompressArgs); 32 | REGISTER_FST_OPERATION(Compress, Log64Arc, CompressArgs); 33 | 34 | REGISTER_FST_OPERATION(Decompress, StdArc, DecompressArgs); 35 | REGISTER_FST_OPERATION(Decompress, LogArc, DecompressArgs); 36 | REGISTER_FST_OPERATION(Decompress, Log64Arc, DecompressArgs); 37 | 38 | } // namespace script 39 | } // namespace fst 40 | -------------------------------------------------------------------------------- /src/extensions/pdt/pdtinfo.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Prints out various information about a PDT such as number of states, arcs, 5 | // and parentheses. 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | DEFINE_string(pdt_parentheses, "", "PDT parenthesis label pairs"); 20 | 21 | int main(int argc, char **argv) { 22 | namespace s = fst::script; 23 | using fst::ReadLabelPairs; 24 | using fst::script::FstClass; 25 | 26 | string usage = "Prints out information about a PDT.\n\n Usage: "; 27 | usage += argv[0]; 28 | usage += " in.pdt\n"; 29 | 30 | std::set_new_handler(FailedNewHandler); 31 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 32 | if (argc > 2) { 33 | ShowUsage(); 34 | return 1; 35 | } 36 | 37 | const string in_name = 38 | (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : ""; 39 | 40 | std::unique_ptr ifst(FstClass::Read(in_name)); 41 | if (!ifst) return 1; 42 | 43 | if (FLAGS_pdt_parentheses.empty()) { 44 | LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; 45 | return 1; 46 | } 47 | 48 | std::vector parens; 49 | if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; 50 | 51 | s::PrintPdtInfo(*ifst, parens); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/include/fst/extensions/ngram/nthbit.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #ifndef FST_EXTENSIONS_NGRAM_NTHBIT_H_ 5 | #define FST_EXTENSIONS_NGRAM_NTHBIT_H_ 6 | 7 | #include 8 | #include 9 | 10 | #ifdef __BMI2__ 11 | // PDEP requires BMI2. 12 | 13 | // Returns the position (0-63) of the r-th 1 bit in v. 14 | // 1 <= r <= CountOnes(v) <= 64. Therefore, v must not be 0. 15 | inline uint32 nth_bit(uint64 v, uint32 r) { 16 | // PDEP example from https://stackoverflow.com/a/27453505 17 | return __builtin_ctzll(_pdep_u64(uint64{1} << (r - 1), v)); 18 | } 19 | 20 | #else // !defined(__BMI2__) 21 | 22 | extern const uint32 nth_bit_bit_offset[]; 23 | 24 | // Returns the position (0-63) of the r-th 1 bit in v. 25 | // 1 <= r <= CountOnes(v) <= 64. Therefore, v must not be 0. 26 | inline uint32 nth_bit(uint64 v, uint32 r) { 27 | uint32 shift = 0; 28 | uint32 c = __builtin_popcount(v & 0xffffffff); 29 | uint32 mask = -(r > c); 30 | r -= c & mask; 31 | shift += (32 & mask); 32 | 33 | c = __builtin_popcount((v >> shift) & 0xffff); 34 | mask = -(r > c); 35 | r -= c & mask; 36 | shift += (16 & mask); 37 | 38 | c = __builtin_popcount((v >> shift) & 0xff); 39 | mask = -(r > c); 40 | r -= c & mask; 41 | shift += (8 & mask); 42 | 43 | return shift + 44 | ((nth_bit_bit_offset[(v >> shift) & 0xff] >> ((r - 1) << 2)) & 0xf); 45 | } 46 | 47 | #endif // !defined(__BMI2__) 48 | 49 | #endif // FST_EXTENSIONS_NGRAM_NTHBIT_H_ 50 | -------------------------------------------------------------------------------- /src/extensions/far/farinfo.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Prints some basic information about the FSTs in an FST archive. 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | DEFINE_string(begin_key, "", 14 | "First key to extract (default: first key in archive)"); 15 | DEFINE_string(end_key, "", 16 | "Last key to extract (default: last key in archive)"); 17 | 18 | DEFINE_bool(list_fsts, false, "Display FST information for each key"); 19 | 20 | int main(int argc, char **argv) { 21 | namespace s = fst::script; 22 | 23 | string usage = "Prints some basic information about the FSTs in an FST "; 24 | usage += "archive.\n\n Usage:"; 25 | usage += argv[0]; 26 | usage += " [in1.far in2.far...]\n"; 27 | usage += " Flags: begin_key end_key list_fsts"; 28 | 29 | std::set_new_handler(FailedNewHandler); 30 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 31 | s::ExpandArgs(argc, argv, &argc, &argv); 32 | 33 | std::vector in_fnames; 34 | for (int i = 1; i < argc; ++i) in_fnames.push_back(argv[i]); 35 | if (in_fnames.empty()) in_fnames.push_back(""); 36 | 37 | const auto arc_type = s::LoadArcTypeFromFar(in_fnames[0]); 38 | if (arc_type.empty()) return 1; 39 | 40 | s::FarInfo(in_fnames, arc_type, FLAGS_begin_key, FLAGS_end_key, 41 | FLAGS_list_fsts); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/include/fst/extensions/far/create.h: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Creates a finite-state archive from component FSTs. 5 | 6 | #ifndef FST_EXTENSIONS_FAR_CREATE_H_ 7 | #define FST_EXTENSIONS_FAR_CREATE_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace fst { 16 | 17 | template 18 | void FarCreate(const std::vector &in_fnames, const string &out_fname, 19 | const int32 generate_keys, const FarType &far_type, 20 | const string &key_prefix, const string &key_suffix) { 21 | std::unique_ptr> far_writer( 22 | FarWriter::Create(out_fname, far_type)); 23 | if (!far_writer) return; 24 | for (size_t i = 0; i < in_fnames.size(); ++i) { 25 | std::unique_ptr> ifst(Fst::Read(in_fnames[i])); 26 | if (!ifst) return; 27 | string key; 28 | if (generate_keys > 0) { 29 | std::ostringstream keybuf; 30 | keybuf.width(generate_keys); 31 | keybuf.fill('0'); 32 | keybuf << i + 1; 33 | key = keybuf.str(); 34 | } else { 35 | auto *filename = new char[in_fnames[i].size() + 1]; 36 | strcpy(filename, in_fnames[i].c_str()); 37 | key = basename(filename); 38 | delete[] filename; 39 | } 40 | far_writer->Add(key_prefix + key + key_suffix, *ifst); 41 | } 42 | } 43 | 44 | } // namespace fst 45 | 46 | #endif // FST_EXTENSIONS_FAR_CREATE_H_ 47 | -------------------------------------------------------------------------------- /src/bin/fstdraw.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | 6 | DEFINE_bool(acceptor, false, "Input in acceptor format"); 7 | DEFINE_string(isymbols, "", "Input label symbol table"); 8 | DEFINE_string(osymbols, "", "Output label symbol table"); 9 | DEFINE_string(ssymbols, "", "State label symbol table"); 10 | DEFINE_bool(numeric, false, "Print numeric labels"); 11 | DEFINE_int32(precision, 5, "Set precision (number of char/float)"); 12 | DEFINE_string(float_format, "g", 13 | "Floating-point format, one of: \"e\", \"f\", or \"g\""); 14 | DEFINE_bool(show_weight_one, false, 15 | "Print/draw arc weights and final weights equal to Weight::One()"); 16 | DEFINE_string(title, "", "Set figure title"); 17 | DEFINE_bool(portrait, false, "Portrait mode (def: landscape)"); 18 | DEFINE_bool(vertical, false, "Draw bottom-to-top instead of left-to-right"); 19 | DEFINE_int32(fontsize, 14, "Set fontsize"); 20 | DEFINE_double(height, 11, "Set height"); 21 | DEFINE_double(width, 8.5, "Set width"); 22 | DEFINE_double(nodesep, 0.25, 23 | "Set minimum separation between nodes (see dot documentation)"); 24 | DEFINE_double(ranksep, 0.40, 25 | "Set minimum separation between ranks (see dot documentation)"); 26 | DEFINE_bool(allow_negative_labels, false, 27 | "Allow negative labels (not recommended; may cause conflicts)"); 28 | 29 | int fstdraw_main(int argc, char **argv); 30 | 31 | int main(int argc, char **argv) { return fstdraw_main(argc, argv); } 32 | -------------------------------------------------------------------------------- /src/extensions/linear/fstloglinearapply.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | DEFINE_bool(normalize, true, "Normalize to get posterior"); 13 | 14 | int main(int argc, char **argv) { 15 | string usage = 16 | "Applies an FST to another FST, treating the second as a log-linear " 17 | "model.\n\n " 18 | "Usage: "; 19 | usage += argv[0]; 20 | usage += " in.fst linear.fst [out.fst]\n"; 21 | 22 | std::set_new_handler(FailedNewHandler); 23 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 24 | if (argc < 3 || argc > 4) { 25 | ShowUsage(); 26 | return 1; 27 | } 28 | 29 | string in_name = strcmp(argv[1], "-") != 0 ? argv[1] : ""; 30 | string linear_name = (argc > 2 && (strcmp(argv[2], "-") != 0)) ? argv[2] : ""; 31 | string out_name = argc > 3 ? argv[3] : ""; 32 | 33 | if (in_name.empty() && linear_name.empty()) { 34 | LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input."; 35 | return 1; 36 | } 37 | 38 | fst::StdFst *ifst1 = fst::StdFst::Read(in_name); 39 | if (!ifst1) return 1; 40 | 41 | fst::StdFst *ifst2 = fst::StdFst::Read(linear_name); 42 | if (!ifst2) return 1; 43 | 44 | fst::StdVectorFst ofst; 45 | 46 | LogLinearApply(*ifst1, *ifst2, &ofst, FLAGS_normalize); 47 | 48 | ofst.Write(out_name); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/script/prune.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Prune(const FstClass &ifst, MutableFstClass *ofst, 12 | const WeightClass &weight_threshold, 13 | int64 state_threshold, float delta) { 14 | if (!internal::ArcTypesMatch(ifst, *ofst, "Prune") || 15 | !ofst->WeightTypesMatch(weight_threshold, "Prune")) { 16 | ofst->SetProperties(kError, kError); 17 | return; 18 | } 19 | PruneArgs1 args(ifst, ofst, weight_threshold, state_threshold, delta); 20 | Apply>("Prune", ifst.ArcType(), &args); 21 | } 22 | 23 | void Prune(MutableFstClass *fst, const WeightClass &weight_threshold, 24 | int64 state_threshold, float delta) { 25 | if (!fst->WeightTypesMatch(weight_threshold, "Prune")) { 26 | fst->SetProperties(kError, kError); 27 | return; 28 | } 29 | PruneArgs2 args(fst, weight_threshold, state_threshold, delta); 30 | Apply>("Prune", fst->ArcType(), &args); 31 | } 32 | 33 | REGISTER_FST_OPERATION(Prune, StdArc, PruneArgs1); 34 | REGISTER_FST_OPERATION(Prune, LogArc, PruneArgs1); 35 | REGISTER_FST_OPERATION(Prune, Log64Arc, PruneArgs1); 36 | 37 | REGISTER_FST_OPERATION(Prune, StdArc, PruneArgs2); 38 | REGISTER_FST_OPERATION(Prune, LogArc, PruneArgs2); 39 | REGISTER_FST_OPERATION(Prune, Log64Arc, PruneArgs2); 40 | 41 | } // namespace script 42 | } // namespace fst 43 | -------------------------------------------------------------------------------- /src/script/relabel.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace fst { 9 | namespace script { 10 | 11 | void Relabel(MutableFstClass *ofst, 12 | const SymbolTable *old_isyms, const SymbolTable *relabel_isyms, 13 | const string &unknown_isymbol, bool attach_new_isyms, 14 | const SymbolTable *old_osyms, const SymbolTable *relabel_osyms, 15 | const string &unknown_osymbol, bool attach_new_osyms) { 16 | RelabelArgs1 args(ofst, old_isyms, relabel_isyms, unknown_isymbol, 17 | attach_new_isyms, old_osyms, relabel_osyms, 18 | unknown_osymbol, attach_new_osyms); 19 | Apply>("Relabel", ofst->ArcType(), &args); 20 | } 21 | 22 | void Relabel(MutableFstClass *ofst, const std::vector &ipairs, 23 | const std::vector &opairs) { 24 | RelabelArgs2 args(ofst, ipairs, opairs); 25 | Apply>("Relabel", ofst->ArcType(), &args); 26 | } 27 | 28 | REGISTER_FST_OPERATION(Relabel, StdArc, RelabelArgs1); 29 | REGISTER_FST_OPERATION(Relabel, LogArc, RelabelArgs1); 30 | REGISTER_FST_OPERATION(Relabel, Log64Arc, RelabelArgs1); 31 | 32 | REGISTER_FST_OPERATION(Relabel, StdArc, RelabelArgs2); 33 | REGISTER_FST_OPERATION(Relabel, LogArc, RelabelArgs2); 34 | REGISTER_FST_OPERATION(Relabel, Log64Arc, RelabelArgs2); 35 | 36 | } // namespace script 37 | } // namespace fst 38 | -------------------------------------------------------------------------------- /src/script/arciterator-class.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | 4 | #include 5 | #include 6 | 7 | namespace fst { 8 | namespace script { 9 | 10 | ArcIteratorClass::ArcIteratorClass(const FstClass &fst, int64 s) 11 | : impl_(nullptr) { 12 | InitArcIteratorClassArgs args(fst, s, this); 13 | Apply>("InitArcIteratorClass", 14 | fst.ArcType(), &args); 15 | } 16 | 17 | MutableArcIteratorClass::MutableArcIteratorClass(MutableFstClass *fst, 18 | int64 s) : impl_(nullptr) { 19 | InitMutableArcIteratorClassArgs args(fst, s, this); 20 | Apply>( 21 | "InitMutableArcIteratorClass", fst->ArcType(), &args); 22 | } 23 | 24 | REGISTER_FST_OPERATION(InitArcIteratorClass, StdArc, InitArcIteratorClassArgs); 25 | REGISTER_FST_OPERATION(InitArcIteratorClass, LogArc, InitArcIteratorClassArgs); 26 | REGISTER_FST_OPERATION(InitArcIteratorClass, Log64Arc, 27 | InitArcIteratorClassArgs); 28 | 29 | REGISTER_FST_OPERATION(InitMutableArcIteratorClass, StdArc, 30 | InitMutableArcIteratorClassArgs); 31 | REGISTER_FST_OPERATION(InitMutableArcIteratorClass, LogArc, 32 | InitMutableArcIteratorClassArgs); 33 | REGISTER_FST_OPERATION(InitMutableArcIteratorClass, Log64Arc, 34 | InitMutableArcIteratorClassArgs); 35 | 36 | } // namespace script 37 | } // namespace fst 38 | -------------------------------------------------------------------------------- /src/extensions/pdt/pdtreverse.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Reverses a PDT. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | DEFINE_string(pdt_parentheses, "", "PDT parenthesis label pairs"); 19 | 20 | int main(int argc, char **argv) { 21 | namespace s = fst::script; 22 | using fst::ReadLabelPairs; 23 | using fst::script::FstClass; 24 | using fst::script::VectorFstClass; 25 | 26 | string usage = "Reverse a PDT.\n\n Usage: "; 27 | usage += argv[0]; 28 | usage += " in.pdt [out.fst]\n"; 29 | 30 | std::set_new_handler(FailedNewHandler); 31 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 32 | if (argc > 3) { 33 | ShowUsage(); 34 | return 1; 35 | } 36 | 37 | const string in_name = 38 | (argc > 1 && (strcmp(argv[1], "-") != 0)) ? argv[1] : ""; 39 | const string out_name = argc > 2 ? argv[2] : ""; 40 | 41 | std::unique_ptr ifst(FstClass::Read(in_name)); 42 | if (!ifst) return 1; 43 | 44 | if (FLAGS_pdt_parentheses.empty()) { 45 | LOG(ERROR) << argv[0] << ": No PDT parenthesis label pairs provided"; 46 | return 1; 47 | } 48 | 49 | std::vector parens; 50 | if (!ReadLabelPairs(FLAGS_pdt_parentheses, &parens, false)) return 1; 51 | 52 | VectorFstClass ofst(ifst->ArcType()); 53 | 54 | s::PdtReverse(*ifst, parens, &ofst); 55 | 56 | ofst.Write(out_name); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /src/bin/fstencode-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Encode transducer labels and/or weights. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | DECLARE_bool(encode_labels); 17 | DECLARE_bool(encode_weights); 18 | DECLARE_bool(encode_reuse); 19 | DECLARE_bool(decode); 20 | 21 | int fstencode_main(int argc, char **argv) { 22 | namespace s = fst::script; 23 | using fst::script::FstClass; 24 | using fst::script::MutableFstClass; 25 | 26 | string usage = "Encodes transducer labels and/or weights.\n\n Usage: "; 27 | usage += argv[0]; 28 | usage += " in.fst codex [out.fst]\n"; 29 | 30 | std::set_new_handler(FailedNewHandler); 31 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 32 | if (argc < 3 || argc > 4) { 33 | ShowUsage(); 34 | return 1; 35 | } 36 | 37 | const string in_name = (strcmp(argv[1], "-") != 0) ? argv[1] : ""; 38 | const string codex_name = argv[2]; 39 | const string out_name = argc > 3 ? argv[3] : ""; 40 | 41 | std::unique_ptr fst(MutableFstClass::Read(in_name, true)); 42 | if (!fst) return 1; 43 | 44 | if (FLAGS_decode) { 45 | s::Decode(fst.get(), codex_name); 46 | return !fst->Write(out_name); 47 | } else { 48 | const auto flags = 49 | s::GetEncodeFlags(FLAGS_encode_labels, FLAGS_encode_weights); 50 | s::Encode(fst.get(), flags, FLAGS_encode_reuse, codex_name); 51 | return !fst->Write(out_name); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/bin/fstisomorphic-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Two FSTS are isomorphic (equal up to state and arc re-ordering) iff their 5 | // exit status is zero. FSTs should be deterministic when viewed as unweighted 6 | // automata. 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | DECLARE_double(delta); 18 | 19 | int fstisomorphic_main(int argc, char **argv) { 20 | namespace s = fst::script; 21 | using fst::script::FstClass; 22 | 23 | string usage = 24 | "Two FSTs are isomorphic iff the exit status is zero.\n\n Usage: "; 25 | usage += argv[0]; 26 | usage += " in1.fst in2.fst\n"; 27 | 28 | std::set_new_handler(FailedNewHandler); 29 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 30 | if (argc != 3) { 31 | ShowUsage(); 32 | return 1; 33 | } 34 | 35 | const string in1_name = strcmp(argv[1], "-") == 0 ? "" : argv[1]; 36 | const string in2_name = strcmp(argv[2], "-") == 0 ? "" : argv[2]; 37 | 38 | if (in1_name.empty() && in2_name.empty()) { 39 | LOG(ERROR) << argv[0] << ": Can't take both inputs from standard input"; 40 | return 1; 41 | } 42 | 43 | std::unique_ptr ifst1(FstClass::Read(in1_name)); 44 | if (!ifst1) return 1; 45 | 46 | std::unique_ptr ifst2(FstClass::Read(in2_name)); 47 | if (!ifst2) return 1; 48 | 49 | bool result = s::Isomorphic(*ifst1, *ifst2, FLAGS_delta); 50 | if (!result) VLOG(1) << "FSTs are not isomorphic"; 51 | 52 | return result ? 0 : 2; 53 | } 54 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | project(openfst) 3 | include(CTest) 4 | find_package(ICU COMPONENTS data i18n io test tu uc) 5 | if (ICU_FOUND) 6 | include_directories(${ICU_INCLUDE_DIRS}) 7 | set(LIBS ${LIBS} ${ICU_LIBRARIES}) 8 | endif (ICU_FOUND) 9 | 10 | find_package(ZLIB) 11 | if (ZLIB_FOUND) 12 | include_directories(${ZLIB_INCLUDE_DIRECTORIES}) 13 | set(ZLIBS ${ZLIB_LIBRARIES}) 14 | endif (ZLIB_FOUND) 15 | 16 | set(CMAKE_MACOSX_RPATH 1) 17 | set(CMAKE_CXX_STANDARD 11) 18 | 19 | if (WIN32) 20 | add_definitions(/bigobj) 21 | #set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1) 22 | #this must be disabled unless the previous option (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS) is enabled 23 | option(BUILD_SHARED_LIBS "Build shared libraries" OFF) 24 | else() 25 | option(BUILD_SHARED_LIBS "Build shared libraries" ON) 26 | endif (WIN32) 27 | 28 | set(SOVERSION "16") 29 | OPTION(BUILD_USE_SOLUTION_FOLDERS "Enable grouping of projects in VS" ON) 30 | SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ${BUILD_USE_SOLUTION_FOLDERS}) 31 | 32 | 33 | option(HAVE_BIN "Build the fst binaries" ON) 34 | option(HAVE_SCRIPT "Build the fstscript" ON) 35 | option(HAVE_COMPACT "Build compact" ON) 36 | option(HAVE_COMPRESS "Build compress" OFF) 37 | option(HAVE_CONST "Build const" ON) 38 | option(HAVE_FAR "Build far" ON) 39 | option(HAVE_GRM "Build grm" ON) 40 | option(HAVE_PDT "Build pdt" ON) 41 | option(HAVE_MPDT "Build mpdt" ON) 42 | option(HAVE_LINEAR "Build linear" ON) 43 | option(HAVE_LOOKAHEAD "Build lookahead" ON) 44 | option(HAVE_NGRAM "Build ngram" ON) 45 | option(HAVE_PYTHON "Build python" OFF) 46 | option(HAVE_SPECIAL "Build special" ON) 47 | 48 | add_subdirectory(src) 49 | 50 | -------------------------------------------------------------------------------- /src/bin/fstdisambiguate-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Disambiguates an FST. 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | DECLARE_double(delta); 15 | DECLARE_int64(nstate); 16 | DECLARE_string(weight); 17 | DECLARE_int64(subsequential_label); 18 | 19 | int fstdisambiguate_main(int argc, char **argv) { 20 | namespace s = fst::script; 21 | using fst::script::FstClass; 22 | using fst::script::VectorFstClass; 23 | using fst::script::WeightClass; 24 | 25 | string usage = "Disambiguates an FST.\n\n Usage: "; 26 | usage += argv[0]; 27 | usage += " [in.fst [out.fst]]\n"; 28 | 29 | std::set_new_handler(FailedNewHandler); 30 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 31 | if (argc > 3) { 32 | ShowUsage(); 33 | return 1; 34 | } 35 | 36 | const string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 37 | const string out_name = argc > 2 ? argv[2] : ""; 38 | 39 | std::unique_ptr ifst(FstClass::Read(in_name)); 40 | if (!ifst) return 1; 41 | 42 | VectorFstClass ofst(ifst->ArcType()); 43 | 44 | const auto weight_threshold = 45 | FLAGS_weight.empty() ? WeightClass::Zero(ifst->WeightType()) 46 | : WeightClass(ifst->WeightType(), FLAGS_weight); 47 | 48 | const s::DisambiguateOptions opts(FLAGS_delta, weight_threshold, FLAGS_nstate, 49 | FLAGS_subsequential_label); 50 | 51 | s::Disambiguate(*ifst, &ofst, opts); 52 | 53 | return !ofst.Write(out_name); 54 | } 55 | -------------------------------------------------------------------------------- /src/bin/fstpush-main.cc: -------------------------------------------------------------------------------- 1 | // See www.openfst.org for extensive documentation on this weighted 2 | // finite-state transducer library. 3 | // 4 | // Pushes weights and/or output labels in an FST toward the initial or final 5 | // states. 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | DECLARE_double(delta); 17 | DECLARE_bool(push_weights); 18 | DECLARE_bool(push_labels); 19 | DECLARE_bool(remove_total_weight); 20 | DECLARE_bool(remove_common_affix); 21 | DECLARE_bool(to_final); 22 | 23 | int fstpush_main(int argc, char **argv) { 24 | namespace s = fst::script; 25 | using fst::script::FstClass; 26 | using fst::script::VectorFstClass; 27 | 28 | string usage = "Pushes weights and/or olabels in an FST.\n\n Usage: "; 29 | usage += argv[0]; 30 | usage += " [in.fst [out.fst]]\n"; 31 | 32 | std::set_new_handler(FailedNewHandler); 33 | SET_FLAGS(usage.c_str(), &argc, &argv, true); 34 | if (argc > 3) { 35 | ShowUsage(); 36 | return 1; 37 | } 38 | 39 | string in_name = (argc > 1 && strcmp(argv[1], "-") != 0) ? argv[1] : ""; 40 | string out_name = argc > 2 ? argv[2] : ""; 41 | 42 | std::unique_ptr ifst(FstClass::Read(in_name)); 43 | if (!ifst) return 1; 44 | 45 | const auto flags = 46 | s::GetPushFlags(FLAGS_push_weights, FLAGS_push_labels, 47 | FLAGS_remove_total_weight, FLAGS_remove_common_affix); 48 | 49 | VectorFstClass ofst(ifst->ArcType()); 50 | 51 | s::Push(*ifst, &ofst, flags, s::GetReweightType(FLAGS_to_final), 52 | FLAGS_delta); 53 | 54 | return !ofst.Write(out_name); 55 | } 56 | --------------------------------------------------------------------------------