15 #ifndef TASK_DISAMBIG_FLOWER_HPP 16 #define TASK_DISAMBIG_FLOWER_HPP 30 void SetGsf ( fst::VectorFst<Arc> *grmfst,
const float gsf ) {
31 if ( gsf == 1.0f )
return;
33 fst::Map<Arc> ( grmfst,
38 void SetGsf ( fst::VectorFst<TupleArc32> *grmfst,
const float gsf ) {
39 LERROR(
"Sorry, TupleArc32 not supported!");
45 template <
class Arc >
47 fst::VectorFst<Arc>& flowerlattice ) {
49 typedef typename Arc::Weight Weight;
50 flowerlattice.AddState();
51 flowerlattice.SetStart ( 0 );
52 flowerlattice.SetFinal ( 0, Weight::One() );
54 while ( umf.
getline ( line ) ) {
56 std::vector<std::string> aux;
57 boost::algorithm::split ( aux, line, boost::algorithm::is_any_of (
" " ) );
58 USER_CHECK ( aux.size() % 2,
"Wrong unimap input file format" );
59 if ( aux[0] ==
"<unk>" )
continue;
60 if ( aux[0] ==
"<s>" ) aux[0] =
"1";
61 if ( aux[1] ==
"<s>" ) aux[1] =
"1";
62 if ( aux[0] ==
"</s>" ) aux[0] =
"2";
63 if ( aux[1] ==
"</s>" ) aux[1] =
"2";
64 for (
unsigned k = 1; k < aux.size(); k += 2 ) {
65 float w = -std::log ( toNumber<float> ( aux[k + 1] ) ) ;
66 if (w != std::numeric_limits<float>::infinity() )
67 flowerlattice.AddArc ( 0, Arc ( toNumber<unsigned> ( aux[0] ),
68 toNumber<unsigned> ( aux[k] ), mw ( w ), 0 ) );
70 LWARN (
"Skipping 0 probability at line:" << line);
73 flowerlattice.AddArc ( 0, Arc (
RHO,
RHO, Weight::One(), 0 ) );
74 flowerlattice.AddArc ( 0, Arc (
OOV,
OOV, Weight::One(), 0 ) );
75 ArcSort ( &flowerlattice, fst::ILabelCompare<Arc>() );
81 inline void tagOOVs ( fst::VectorFst<Arc> *myfst,
82 unordered_set<std::string>& vcb ) {
84 typedef typename Arc::StateId StateId;
85 for ( fst::StateIterator< fst::VectorFst<Arc> > si ( *myfst ); !si.Done();
87 StateId state_id = si.Value();
88 for ( fst::MutableArcIterator< fst::MutableFst<Arc> > ai ( myfst, si.Value() );
89 !ai.Done(); ai.Next() ) {
91 if ( vcb.find ( ucam::util::toString<unsigned> ( arc.olabel ) ) == vcb.end() ) {
92 arc.ilabel = arc.olabel;
94 arc.weight = mw ( 0 );
105 typedef typename Arc::StateId StateId;
106 for ( fst::StateIterator< fst::VectorFst<Arc> > si ( *myfst ); !si.Done();
108 StateId state_id = si.Value();
109 for ( fst::MutableArcIterator< fst::MutableFst<Arc> > ai ( myfst, si.Value() );
110 !ai.Done(); ai.Next() ) {
111 Arc arc = ai.Value();
112 if ( arc.olabel ==
OOV ) {
113 arc.olabel = arc.ilabel;
123 #endif // FSTDISAMBIG_HPP virtual iszfstream & getline(std::string &line)
Read a line.
templated Mapper that modifies weights over an FST, passing through the other values of the arc...
Function object that applies to every single weight a scaling factor.
Templated functor that creates a weight given a float.
#define USER_CHECK(exp, comment)
Tests whether exp is true. If not, comment is printed and program ends.
T toNumber(const std::string &x)
Converts a string to an arbitrary number Converts strings to a number. Quits execution if conversion ...
Wrapper stream class that reads pipes, text files or gzipped files.