Home | History | Annotate | Download | only in fst

Lines Matching refs:FST

0 // fst.h
19 // Finite-State Transducer (FST) - abstract base class definition,
31 #include <fst/compat.h>
32 #include <fst/types.h>
34 #include <fst/arc.h>
35 #include <fst/properties.h>
36 #include <fst/register.h>
40 #include <fst/symbol-table.h>
41 #include <fst/util.h>
46 namespace fst {
62 const FstHeader *header; // Pointer to Fst header. If non-zero, use
99 // Fst HEADER CLASS
101 // This is the recommended Fst file header representation.
140 uint64 properties_; // FST property bits
155 // Fst INTERFACE CLASS DEFINITION
158 // A generic FST, templated on the arc definition, with
162 class Fst {
168 virtual ~Fst() {}
187 virtual const string& Type() const = 0; // Fst type name
189 // Get a copy of this Fst. The copying behaves as follows:
192 // and is on an otherwise unaccessed Fst.
196 // separate threads. For some Fst types, 'Copy(true)' should only be
197 // called on an Fst that has not otherwise been accessed. Its behavior
203 virtual Fst<A> *Copy(bool safe = false) const = 0;
205 // Read an Fst from an input stream; returns NULL on error
206 static Fst<A> *Read(istream &strm, const FstReadOptions &opts) {
220 LOG(ERROR) << "Fst::Read: Unknown FST type \"" << hdr.FstType()
228 // Read an Fst from a file; return NULL on error
230 static Fst<A> *Read(const string &filename) {
234 LOG(ERROR) << "Fst::Read: Can't open file: " << filename;
243 // Write an Fst to an output stream; return false on error
245 LOG(ERROR) << "Fst::Write: No write stream method for " << Type()
246 << " Fst type";
250 // Write an Fst to a file; return false on error
253 LOG(ERROR) << "Fst::Write: No write filename method for " << Type()
254 << " Fst type";
281 LOG(ERROR) << "Fst::Write: Can't open file: " << filename;
298 // Fst method.
331 // Generic state iterator, templated on the FST definition
334 // for (StateIterator<StdFst> siter(fst);
343 typedef F FST;
347 explicit StateIterator(const F &fst) : s_(0) {
348 fst.InitStateIterator(&data_);
397 // Fst method.
441 // Generic arc iterator, templated on the FST definition
444 // for (ArcIterator<StdFst> aiter(fst, s));
453 typedef F FST;
457 ArcIterator(const F &fst, StateId s) : i_(0) {
458 fst.InitArcIterator(s, &data_);
529 MatcherBase<A> *Fst<A>::InitMatcher(MatchType match_type) const {
535 // FST ACCESSORS - Useful functions in high-performance cases.
542 typename F::Arc::Weight Final(const F &fst, typename F::Arc::StateId s) {
543 return fst.F::Final(s);
547 ssize_t NumArcs(const F &fst, typename F::Arc::StateId s) {
548 return fst.F::NumArcs(s);
552 ssize_t NumInputEpsilons(const F &fst, typename F::Arc::StateId s) {
553 return fst.F::NumInputEpsilons(s);
557 ssize_t NumOutputEpsilons(const F &fst, typename F::Arc::StateId s) {
558 return fst.F::NumOutputEpsilons(s);
562 // Fst<A> case - abstract methods.
564 typename A::Weight Final(const Fst<A> &fst, typename A::StateId s) {
565 return fst.Final(s);
569 ssize_t NumArcs(const Fst<A> &fst, typename A::StateId s) {
570 return fst.NumArcs(s);
574 ssize_t NumInputEpsilons(const Fst<A> &fst, typename A::StateId s) {
575 return fst.NumInputEpsilons(s);
579 ssize_t NumOutputEpsilons(const Fst<A> &fst, typename A::StateId s) {
580 return fst.NumOutputEpsilons(s);
586 typedef Fst<StdArc> StdFst;
597 // Fst IMPLEMENTATION BASE
599 // This is the recommended Fst implementation base class. It will
639 // Allows (only) setting error bit on const FST impls
676 // Read-in header and symbols from input stream, initialize Fst, and
711 // type is the Fst type being written.
712 // This method is used in the cross-type serialization methods Fst::WriteFst.
713 static void WriteFstHeader(const Fst<A> &fst, ostream &strm,
723 if (fst.InputSymbols() && opts.write_isymbols)
725 if (fst.OutputSymbols() && opts.write_osymbols)
732 if (fst.InputSymbols() && opts.write_isymbols) {
733 fst.InputSymbols()->Write(strm);
735 if (fst.OutputSymbols() && opts.write_osymbols) {
736 fst.OutputSymbols()->Write(strm);
745 static bool UpdateFstHeader(const Fst<A> &fst, ostream &strm,
751 LOG(ERROR) << "Fst::UpdateFstHeader: write failed: " << opts.source;
754 WriteFstHeader(fst, strm, opts, version, type, properties, hdr);
756 LOG(ERROR) << "Fst::UpdateFstHeader: write failed: " << opts.source;
761 LOG(ERROR) << "Fst::UpdateFstHeader: write failed: " << opts.source;
771 string type_; // Unique name of Fst class
796 LOG(ERROR) << "FstImpl::ReadHeader: Fst not of type \"" << type_
807 << " Fst version: " << opts.source;
829 uint64 TestProperties(const Fst<Arc> &fst, uint64 mask, uint64 *known);
832 // This is a helper class template useful for attaching an Fst interface to
834 template < class I, class F = Fst<typename I::Arc> >
882 ImplToFst(const ImplToFst<I, F> &fst) {
883 impl_ = fst.impl_;
889 ImplToFst(const ImplToFst<I, F> &fst, bool safe) {
891 impl_ = new I(*(fst.impl_));
893 impl_ = fst.impl_;
900 // Change Fst implementation pointer. If 'own_impl' is true,
913 ImplToFst<I, F> &operator=(const ImplToFst<I, F> &fst);
915 ImplToFst<I, F> &operator=(const Fst<Arc> &fst) {
927 // methods). Must be a friend of the Fst classes involved (currently
933 // Fst Serialization
935 void FstToString(const Fst<A> &fst, string *result) {
937 fst.Write(ostrm, FstWriteOptions("FstToString"));
942 Fst<A> *StringToFst(const string &s) {
944 return Fst<A>::Read(istrm, FstReadOptions("StringToFst"));
947 } // namespace fst