32 #include "tropical-sparse-tuple-weight.h" 33 #include "tropical-sparse-tuple-weight-decls.h" 45 using boost::any_cast;
46 namespace bfs = boost::filesystem;
55 typedef fst::LexicographicArc< fst::StdArc::Weight, fst::StdArc::Weight>
Arc;
56 typedef fst::LexicographicWeight<fst::StdArc::Weight, fst::StdArc::Weight>
59 std::vector < fst::VectorFst<Arc> *>
filters;
60 unordered_set<std::string>
tvcb;
61 unordered_map<std::string, fst::VectorFst<Arc> *>
fsts;
65 TEST ( HifstReferenceFilter, basic_test ) {
67 typedef fst::LexicographicArc< fst::StdArc::Weight, fst::StdArc::Weight>
Arc;
68 typedef fst::LexicographicWeight<fst::StdArc::Weight, fst::StdArc::Weight>
70 fst::VectorFst<Arc> aux;
76 aux.SetFinal ( 2, Arc::Weight::One() );
77 aux.AddArc ( 0, Arc ( 10, 10, mw ( 0 ), 1 ) );
78 aux.AddArc ( 1, Arc ( 100, 100, mw ( 0 ), 2 ) );
81 unordered_map<std::string, boost::any> v;
86 std::numeric_limits<float>::max() );
88 std::numeric_limits<unsigned>::max() );
97 EXPECT_EQ ( rft.
getWeight(), std::numeric_limits<float>::max() );
98 EXPECT_EQ ( rft.
getShortestPath(), std::numeric_limits<unsigned>::max() );
103 ASSERT_EQ ( d.
tvcb.size(), 2 );
104 EXPECT_TRUE ( d.
tvcb.find (
"10" ) != d.
tvcb.end() );
105 EXPECT_TRUE ( d.
tvcb.find (
"100" ) != d.
tvcb.end() );
106 ASSERT_EQ ( d.
filters.size(), 1 );
107 EXPECT_EQ ( d.
filters[0]->NumStates(), 3 );
108 std::stringstream ss;
110 LDEBUG(
"ss=" << ss.str());
111 EXPECT_TRUE ( ss.str() ==
"0\t1\t10\t10\n0\t2\t100\t100\n0\n1\t2\t100\t100\n1\n2\n" 112 || ss.str() ==
"0\t1\t10\t0,0\n0\t2\t100\t0,0\n0\t0,0\n1\t2\t100\t0,0\n1\t0,0\n2\t0,0\n" );
113 bfs::remove ( bfs::path (
"expecto.fst" ) );
117 TEST ( HifstReferenceFilter, empty ) {
119 unordered_map<std::string, boost::any> v;
124 std::numeric_limits<float>::max() );
126 std::numeric_limits<unsigned>::max() );
134 EXPECT_EQ ( rft.
getBuilt(), false );
135 ASSERT_EQ ( d.
filters.size(), 0 );
142 int main (
int argc,
char **argv ) {
143 ::testing::InitGoogleTest ( &argc, argv );
144 return RUN_ALL_TESTS();
std::string const kHifstSemiring
Handles simple wildcard expansion for strings.
bool run(Data &d)
Runs... Load substring lattice and add pointer in data object.
Unit testing: google testing common header.
Convenience functors/functions for lexicographic<tropical,tropical> semiring.
Contains convenience functions to write and read fsts.
Public class with variables required by TextTask to compile and run.
const std::string kReferencefilterSubstring
fst::LexicographicArc< fst::StdArc::Weight, fst::StdArc::Weight > Arc
Convenience functions for tropical sparse vector weight.
Generates a substring version of a reference translation lattice and associated vocabulary. This substring fst is typically used to guide translation towards a particular search space. The associated vocabulary can be used e.g. to restrict parsing algorithms.
Interfaces with basic methods for iteration.
unordered_map< std::string, fst::VectorFst< Arc > * > fsts
const std::string getTranslationLatticeFile()
fst::LexicographicWeight< fst::StdArc::Weight, fst::StdArc::Weight > Weight
const std::string kReferencefilterLoadSemiring
const std::string kReferencefilterPrunereferenceweight
unordered_set< std::string > tvcb
test-specific classes and functions
Static variables for logger. Include only once from main file.
void FstWrite(const Fst< Arc > &fst, const std::string &filename, const std::string &txtname="txt")
Templated method that writes an fst either in binary or text format.
Utilites to extract vocabulary, pseudo-determinize lattices and build substring transducers.
Templated functor that creates a weight given a float.
Headers for standalone shared library.
void PrintFst(const Fst< Arc > &fst, std::ostream *os)
Templated method that writes an fst in openfst text format to a stream.
int main(int argc, char **argv)
bool getDisableSubString(void)
unsigned getShortestPath(void)
Generalized weight mapper functor.
Convenience functors that allow transparent handling for weights within hifst.
const std::string kReferencefilterWrite
const std::string kReferencefilterPrunereferenceshortestpath
std::vector< fst::VectorFst< Arc > * > filters
Describes class ReferenceFilterTask (builds unweighted substring fst for lattice alignment ) ...
const std::string kReferencefilterLoad
Unit testing: google testing common header.
const unordered_set< std::string > & getVocabulary()
Static variable for custom_assert. Include only once from main file.