15 #ifndef TASK_SPWLATS_HPP 16 #define TASK_SPWLATS_HPP 33 template<
class Data,
class Arc>
37 const std::string alilatskey_;
39 const std::string sparseweightvectorlatticekey_;
41 const std::string lmkey_;
43 const std::string ruleflowerlatticekey_;
46 fst::VectorFst<TupleArc32> myfst_;
52 bool stripHifstEpsilons_;
58 const std::string& alilatskey =
60 const std::string& ruleflowerlatticekey =
62 const std::string& sparseweightvectorlatticekey =
65 ruleflowerlatticekey_ ( ruleflowerlatticekey )
66 , alilatskey_ ( alilatskey )
67 , sparseweightvectorlatticekey_ ( sparseweightvectorlatticekey )
68 , stripHifstEpsilons_ (rg.getBool (
70 , determinize_ (rg.getBool (
85 bool run ( Data& d ) {
86 myfst_.DeleteStates();
88 fst::VectorFst<Arc> *lattice =
static_cast<fst::VectorFst<Arc> *
> 89 ( d.fsts[alilatskey_] );
90 USER_CHECK ( lattice->NumStates(),
"Empty alignment lattice?" );
92 fst::VectorFst<TupleArc32> *lxr
93 = applyFlowerLattice (*lattice
94 , * (
static_cast<fst::VectorFst<TupleArc32> *
> 95 ( d.fsts[ruleflowerlatticekey_] ) ) );
96 LDBG_EXECUTE ( lattice->Write (
"fsts/aplats/aplats+flower.fst" ) );
97 if (stripHifstEpsilons_) {
98 LINFO (
"Remove hifst epsilons");
101 LINFO (
"Project, RmEpsilon, Determinize and Minimize" );
102 fst::Project ( lxr, fst::PROJECT_INPUT );
103 LDBG_EXECUTE ( lxr->Write (
"fsts/aplats/aplats+flower+p.fst.gz" ) );
104 fst::RmEpsilon<TupleArc32> ( lxr );
105 if ( determinize_ ) {
106 fst::Determinize<TupleArc32> ( *lxr, &myfst_ );
107 LDBG_EXECUTE ( myfst_.Write (
"fsts/aplats/aplats+flower+p+re+d.fst" ) );
109 fst::Minimize<TupleArc32> ( &myfst_ );
110 LDBG_EXECUTE ( myfst_.Write (
"fsts/aplats/aplats+flower+p+re+d+m.fst" ) );
114 d.fsts[sparseweightvectorlatticekey_] = &myfst_;
115 LINFO (
"Ready! Stored with key=" << sparseweightvectorlatticekey_ <<
"; NS=" <<
116 myfst_.NumStates() );
121 myfst_.DeleteStates();
128 fst::VectorFst<TupleArc32> * applyFlowerLattice (
const fst::VectorFst<Arc>
130 const fst::VectorFst<TupleArc32>& grammarflowerlattice ) {
131 LINFO (
"Removing Weights of Target Lattice" );
132 fst::VectorFst<Arc> prvfst ( hypfst );
133 fst::Map ( &prvfst, fst::RmWeightMapper<Arc>() );
134 fst::VectorFst<TupleArc32> *vwfst =
new fst::VectorFst<TupleArc32>;
135 LINFO (
"Mapping Arc Target Lattice to TupleArc32" );
137 fst::Map<Arc> ( prvfst, vwfst,
139 fst::VectorFst<TupleArc32> *output =
new fst::VectorFst<TupleArc32>;
140 LDBG_EXECUTE ( vwfst->Write (
"fsts/aplats/vw-beforecomposing.fst" ) );
141 LINFO (
"Compose (TupleArc32)" );
142 fst::Compose ( *vwfst, grammarflowerlattice, output );
154 #endif // TASK_ALATS2SPWLATS_HPP bool run(Data &d)
Implements virtual method from ucam::util::TaskInterface.
#define LDBG_EXECUTE(order)
const std::string kSparseweightvectorlatticeDeterminize
const std::string kSparseweightvectorlatticeLoadalilats
RelabelUtil & addIPL(typename Arc::Label labelfind, typename Arc::Label labelreplace)
fst::TropicalWeightTpl< F > Map(double)
Templated Functor to generate a sparse vector weight from any other representation.
const std::string kSparseweightvectorlatticeStripSpecialEpsilonLabels
~SparseWeightVectorLatticesTask()
Templated (hybrid) Interface for Task classes.
templated Mapper that modifies weights when copying from one FST to another, passing through the othe...
const std::string kRuleflowerlatticeStore
const std::string kSparseweightvectorlatticeStore
#define USER_CHECK(exp, comment)
Tests whether exp is true. If not, comment is printed and program ends.
SparseWeightVectorLatticesTask(const ucam::util::RegistryPO &rg, const std::string &alilatskey=HifstConstants::kSparseweightvectorlatticeLoadalilats, const std::string &ruleflowerlatticekey=HifstConstants::kRuleflowerlatticeStore, const std::string &sparseweightvectorlatticekey=HifstConstants::kSparseweightvectorlatticeStore)
Constructor with registry object and keys to access/write lattices in data object.
Creates lattices using tropical tuple weight semiring – each arc containing separate feature weight ...