15 #ifndef TASK_HIFST_REPLACEFSTBYARC_HPP 16 #define TASK_HIFST_REPLACEFSTBYARC_HPP 33 fst::VectorFst<Arc> *
operator()(
typename Arc::Label
const& hieroindex)
const {
34 fst::VectorFst<Arc>* outfst =
new fst::VectorFst<Arc>;
36 outfst->SetStart ( 0 );
38 outfst->SetFinal ( 1, Arc::Weight::One() );
40 outfst->AddArc ( 0, Arc (
NORULE, hieroindex, Arc::Weight::One() , 1 ) );
42 outfst->AddArc ( 0, Arc ( hieroindex, hieroindex, Arc::Weight::One() , 1 ) );
53 template<
class Arc = fst::LexStdArc>
55 typedef typename Arc::Label Label;
56 typedef typename Arc::Weight Weight;
62 const std::size_t minns_;
67 std::size_t min_numstates = 2 )
68 : minns_ ( min_numstates )
78 inline fst::VectorFst<Arc> *
operator() ( fst::VectorFst<Arc>
const&
fst,
79 Label
const& hieroindex )
const {
80 if ( fst.NumStates() <= minns_ )
return NULL;
81 return gtf_(hieroindex);
94 template<
class Arc = fst::LexStdArc>
96 typedef typename Arc::Label Label;
97 typedef typename Arc::Weight Weight;
103 unordered_set<std::string> replacefstbyarc_;
104 unordered_set<std::string> replacefstbyarcexceptions_;
107 std::size_t
const minns_;
118 unordered_set<std::string>
const& replacefstbyarc,
120 std::size_t min_numstates = std::numeric_limits<std::size_t>::max()
123 , replacefstbyarc_ ( replacefstbyarc )
124 , minns_ ( min_numstates )
129 unordered_set<std::string>
const& replacefstbyarc,
130 unordered_set<std::string>
const& replacefstbyarcexceptions,
132 std::size_t min_numstates = std::numeric_limits<std::size_t>::max()
135 , replacefstbyarc_ ( replacefstbyarc )
136 , replacefstbyarcexceptions_ ( replacefstbyarcexceptions )
137 , minns_ ( min_numstates )
150 Label
const& hieroindex )
const {
151 grammar_inversecategories_t::const_iterator itx = vcat_.find ( (
153 if ( !
USER_CHECK ( itx != vcat_.end(),
"Category not identified!" ) ) {
157 if (replacefstbyarcexceptions_.find (itx->second) !=
158 replacefstbyarcexceptions_.end() )
160 if ( replacefstbyarc_.find ( itx->second ) != replacefstbyarc_.end()
161 || fst.NumStates() >= minns_
163 return gtf_(hieroindex);
#define ZDISALLOW_COPY_AND_ASSIGN(TypeName)
ReplaceFstByArc(bool alignmode, std::size_t min_numstates=2)
Creates FST replacement or not depending on conditions.
unordered_map< uint, std::string > grammar_inversecategories_t
GenerateTrivialFst(bool alignmode)
fst::VectorFst< Arc > * operator()(typename Arc::Label const &hieroindex) const
#define USER_CHECK(exp, comment)
Tests whether exp is true. If not, comment is printed and program ends.
ManualReplaceFstByArc(grammar_inversecategories_t const &vcat, unordered_set< std::string > const &replacefstbyarc, unordered_set< std::string > const &replacefstbyarcexceptions, bool alignmode, std::size_t min_numstates=std::numeric_limits< std::size_t >::max())
ManualReplaceFstByArc(grammar_inversecategories_t const &vcat, unordered_set< std::string > const &replacefstbyarc, bool alignmode, std::size_t min_numstates=std::numeric_limits< std::size_t >::max())
Creates FST replacement or not depending on conditions including program options. ...