OpenFstInterop.hpp

Go to the documentation of this file.
00001 #ifndef OPENFST_INTEROP_HPP
00002 #define OPENFST_INTEROP_HPP
00003 
00004 #include <fst/fstlib.h>
00005 
00006 #include "opennwa/Nwa.hpp"
00007 
00008 namespace opennwa {
00009 
00010     /// Structure for holding Wali keys. (Introduced to increase type
00011     /// safety between Wali and OpenFST keys, to decrease the chance
00012     /// of me making a mistake.)
00013     struct WaliKey {
00014       Key key;
00015 
00016       explicit WaliKey(Key k) : key(k) {}
00017       bool operator== (WaliKey rhs) const { return key == rhs.key; }
00018       bool operator<  (WaliKey rhs) const { return key <  rhs.key; }
00019     };
00020 
00021     /// Structure for holding OpenFST keys. (Introduced to increase type
00022     /// safety between Wali and OpenFST keys, to decrease the chance
00023     /// of me making a mistake.)
00024     struct FstKey {
00025       fst::StdArc::StateId key;
00026 
00027       explicit FstKey(Key k) : key(k) {}
00028       bool operator== (FstKey rhs) const { return key == rhs.key; }
00029       bool operator<  (FstKey rhs) const { return key <  rhs.key; }
00030     };
00031 
00032 
00033     /// Maps a known OpenFST key to the corresponding Wali key.
00034     ///
00035     typedef std::map<FstKey, WaliKey> fst_to_wali_key_map;
00036     /// Maps a known Wali key to the corresponding OpenFST key.
00037     ///
00038     typedef std::map<WaliKey, FstKey> wali_to_fst_key_map;
00039     /// Holds bidirectional mappings between Wali and OpenFST keys, to
00040     /// allow bidirectional lookup.
00041     typedef std::pair<fst_to_wali_key_map, wali_to_fst_key_map> fst_wali_key_maps;
00042 
00043 
00044     /// Given an NWA 'nwa' with no call or return transitions,
00045     /// converts 'nwa' to an OpenFST acceptor. If 'fst_wali_key_maps'
00046     /// is non-null, stores the mapping between Wali and OpenFST keys
00047     /// (state IDs) at that location.
00048     fst::StdVectorFst
00049     internal_only_nwa_to_fst(NwaRefPtr nwa, fst_wali_key_maps * maps = NULL);
00050 
00051 
00052     /// Converts an OpenFST acceptor to an NWA. 'maps' could specify
00053     /// the mapping to use for the conversion, but the code is broken
00054     /// right now; instead, it is just an output parameter.
00055     /// 'node_prefix' is prepended to the OpenFST key of FST states,
00056     /// and provdies a way to make, say, state 1 of two different FSTs
00057     /// produce different Wali states.
00058     NwaRefPtr
00059     fst_to_nwa(fst::StdExpandedFst const & fst, fst_wali_key_maps & maps, std::string node_prefix = "");
00060 
00061     /// Given an NWA 'internal_nwa' without call or return
00062     /// transitions, treat the NWA as a standard FA and minimize
00063     /// it. (It does this by converting it to an OpenFST acceptor,
00064     /// minimizing that, then converting it back.)
00065     NwaRefPtr
00066     minimize_internal_nwa(NwaRefPtr internal_nwa, std::string node_prefix = "");
00067 
00068     /// Given an NWA 'internal_nwa' without call or return transitions, treat
00069     /// the NWA as a standard FA and determinize it using OpenFST.  (It does
00070     /// this by converting it to an OpenFST acceptor, minimizing that, then
00071     /// converting it back.)
00072     NwaRefPtr
00073     determinize_internal_nwa(NwaRefPtr internal_nwa, std::string node_prefix = "");
00074 
00075 }
00076 
00077 
00078 // Yo, Emacs!
00079 // Local Variables:
00080 //   c-file-style: "ellemtel"
00081 //   c-basic-offset: 2
00082 // End:
00083 
00084 #endif