Cambridge SMT System
hifst.task.hifst.gtest.cpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, AdriĆ  de Gispert, William Byrne
14 
21 #include <openfst.h>
22 #include <googletesting.h>
23 
24 #ifndef GMAINTEST
25 #include "main.custom_assert.hpp"
26 #include "main.logger.hpp"
27 #endif
28 
29 #include "params.hpp"
30 #include "wordmapper.hpp"
31 
32 #include "addresshandler.hpp"
33 #include "taskinterface.hpp"
34 
35 #include "tropical-sparse-tuple-weight.h"
36 #include "tropical-sparse-tuple-weight-decls.h"
38 
42 
43 #include "fstio.hpp"
44 #include "fstutils.hpp"
45 #include "fstutils.mapper.hpp"
46 #include "fstutils.multiunion.hpp"
47 
48 //KenLM
49 #include "lm/model.hh"
51 
52 #include "defs.grammar.hpp"
53 #include "defs.ssgrammar.hpp"
54 #include "defs.cykparser.hpp"
55 
56 #include "data.stats.hpp"
57 #include "data.grammar.hpp"
58 #include "data.lm.hpp"
59 
61 #include "data.ssgrammar.hpp"
62 #include "data.cykparser.hpp"
63 
64 #include "task.grammar.hpp"
65 #include "task.ssgrammar.hpp"
66 #include "task.cykparser.hpp"
67 #include "task.loadlm.hpp"
68 #include "task.hifst.hpp"
69 #include "data-main.hifst.hpp"
70 
71 namespace bfs = boost::filesystem;
72 namespace uf = ucam::fsttools;
73 namespace uh = ucam::hifst;
74 
78 class HifstTest : public testing::Test {
79  protected: // You should make the members protected s.t. they can be
80  // accessed from sub-classes.
81 
82  // virtual void SetUp() will be called before each test is run. You
83  // should define it if you need to initialize the variables.
84  // Otherwise, this can be skipped.
85  virtual void SetUp() {
87  using namespace HifstConstants;
88  v_[kGrammarLoad] = std::string ( "" );
89  v_[kGrammarStorepatterns] = std::string ( "" );
90  v_[kGrammarStorentorder] = std::string ( "" );
91  v_[kGrammarFeatureweights] = std::string ( "1" );
92  v_[kSsgrammarStore] = std::string ( "" );
93  v_[kSsgrammarAddoovsEnable] = std::string ("no");
94  v_[kSsgrammarAddoovsSourcedeletions] = std::string ("no");
95  v_[kCykparserHrmaxheight] = unsigned ( 10 );
96  v_[kCykparserHmax] = std::string ( "X,10" );
97  v_[kCykparserHmin] = std::string ( "X,0" );
98  v_[kCykparserNtexceptionsmaxspan] = std::string ( "S" );
99  v_[kHifstLatticeStore] = std::string ( "" );
100  v_[kHifstLocalpruneEnable] = std::string ("no");
101  v_[kHifstLocalpruneConditions] = std::string ( "" );
102  v_[kHifstLocalpruneLmLoad] = std::string ("");
103  v_[kHifstLocalpruneLmFeatureweights] = unsigned (1);
104  v_[kHifstLocalpruneLmWordpenalty] = unsigned (0);
105  v_[kHifstLocalpruneNumstates] = unsigned ( 1000 );
106  v_[kHifstPrune] = float ( 1.0 );
107  v_[kHifstUsepdt] = std::string ("no");
108  v_[kHifstRtnopt] = std::string ("yes");
109  v_[kHifstWritertn] = std::string ( "" );
110  v_[kHifstAlilatsmode] = std::string ("no");
111  v_[kHifstAlilatsmodeLinks] = std::string ("rules");
112  v_[kHifstOptimizecells] = std::string ("yes");
113  v_[kReferencefilterLoad] = std::string ("");
114  const uu::RegistryPO rg ( v_ );
115  //We need to generate some rules. It is easy to do so with GrammarTask, so we do it. We need to keep these tasks during all the lifespan of the tests, though.
117  std::stringstream ss;
118  ss << "X 3 3 0" << endl << "S S_X S_X 0" << endl;
119  ss << "X 4 4 0" << endl << "X 5 5 0" << endl << "X 1 1 0" << endl << "X 2 2 0"
120  << endl;
121  ss << "X 3_4 3_4 0" << endl << "X 3_X_5 3_X_5 0" << endl << "S X X 0" << endl;
122  gt_->load ( ss );
124  for ( unsigned k = 0; k < 9; ++k ) {
125  LINFO ( "RULE #" << k << ":" << d_.grammar->getRule ( k ) << ", real_idx=" <<
126  d_.grammar->getIdx ( k ) );
127  }
128  // Now we prepare manually some instance-patterns
129  d_.sidx = 0;
130  d_.sentence = "1 3 4 5 2";
131  d_.hpinstances["1"].push_back ( pair<unsigned, unsigned> ( 0, 0 ) );
132  d_.hpinstances["3"].push_back ( pair<unsigned, unsigned> ( 1, 0 ) );
133  d_.hpinstances["4"].push_back ( pair<unsigned, unsigned> ( 2, 0 ) );
134  d_.hpinstances["5"].push_back ( pair<unsigned, unsigned> ( 3, 0 ) );
135  d_.hpinstances["2"].push_back ( pair<unsigned, unsigned> ( 4, 0 ) );
136  d_.hpinstances["3_4"].push_back ( pair<unsigned, unsigned> ( 1, 1 ) );
137  d_.hpinstances["3_X_5"].push_back ( pair<unsigned, unsigned> ( 1, 2 ) );
138  d_.hpinstances["X_X"].push_back ( pair<unsigned, unsigned> ( 0, 1 ) );
139  d_.hpinstances["X"].push_back ( pair<unsigned, unsigned> ( 0, 0 ) );
140  // Prepare sentence-specific grammar.
142  ssgt_->run ( d_ );
143  // Run cyk parse
145  cyk_->run ( d_ );
146  LINFO ( "Setup finished!" );
147  }
148 
149  // virtual void TearDown() will be called after each test is run.
150  // You should define it if there is cleanup work to do. Otherwise,
151  // you don't have to provide it.
152  //
153  virtual void TearDown() {
154  LINFO ( "Teardown..." );
155  delete gt_;
156  delete ssgt_;
157  delete cyk_;
158  }
159 
160  // Declares the variables your tests want to use.
162  unordered_map<std::string, boost::any> v_;
163 
167 };
168 
173 TEST_F ( HifstTest, basic_translation ) {
174  using namespace HifstConstants;
175  v_[kHifstReplacefstbyarcNonterminals] = std::string ( "" );
176  v_[kHifstReplacefstbyarcNumstates] = unsigned (
177  std::numeric_limits<unsigned>::max() );
178  v_[kHifstReplacefstbyarcExceptions] = std::string ( "" );
179  const uu::RegistryPO rg ( v_ );
180  LINFO ( "Number of inst:" << d_.hpinstances.size() );
181  EXPECT_TRUE ( d_.cykdata != NULL );
182  //Finally, build translation
183  uh::HiFSTTask<uh::HifstTaskData<> > hifst ( rg );
184  hifst.run ( d_ );
185  //Test output.
186  EXPECT_TRUE ( d_.fsts[kHifstLatticeStore] != NULL );
187  std::stringstream ss;
188  fst::printstrings ( *static_cast<fst::VectorFst<fst::LexStdArc> *>
189  (d_.fsts[kHifstLatticeStore]), &ss );
190  EXPECT_EQ ( ss.str(),
191  "1 3 4 5 2 || 1 3 4 5 2 || 0,0\n" );
192 };
193 
198 TEST_F ( HifstTest, basic_translation2 ) {
199  using namespace HifstConstants;
200  v_[kHifstReplacefstbyarcNumstates] = unsigned (
201  std::numeric_limits<unsigned>::max() );
202  v_[kHifstReplacefstbyarcNonterminals] = std::string ( "X" );
203  v_[kHifstReplacefstbyarcExceptions] = std::string ( "S" );
204  const uu::RegistryPO rg ( v_ );
205  LINFO ( "Number of inst:" << d_.hpinstances.size() );
206  EXPECT_TRUE ( d_.cykdata != NULL );
207  //Finally, build translation
208  uh::HiFSTTask<uh::HifstTaskData<> > hifst ( rg );
209  hifst.run ( d_ );
210  //Test output.
211  EXPECT_TRUE ( d_.fsts[kHifstLatticeStore] != NULL );
212  std::stringstream ss;
213  fst::printstrings ( * static_cast<fst::VectorFst<fst::LexStdArc> *>
214  (d_.fsts[kHifstLatticeStore]), &ss );
215  EXPECT_EQ ( ss.str(),
216  "1 3 4 5 2 || 1 3 4 5 2 || 0,0\n1 3 4 5 2 || 1 3 4 5 2 || 0,0\n1 3 4 5 2 || 1 3 4 5 2 || 0,0\n" );
217 };
218 
223 TEST_F ( HifstTest, basic_translation3 ) {
224  using namespace HifstConstants;
225  {
226  uu::oszfstream o ( "mylm" );
227  o << endl;
228  o << "\\data\\" << endl;
229  o << "ngram 1=5" << endl;
230  o << "ngram 2=2" << endl;
231  o << "ngram 3=1" << endl;
232  o << endl;
233  o << "\\1-grams:" << endl;
234  o << "-1\t3\t0" << endl;
235  o << "-10\t4\t0" << endl;
236  o << "-100\t5\t0" << endl;
237  o << "-1000\t</s>\t0" << endl;
238  o << "0\t<s>\t0" << endl;
239  o << endl;
240  o << "\\2-grams:" << endl;
241  o << "-10000\t3 4\t0" << endl;
242  o << "-100000\t4 </s>\t0" << endl;
243  o << endl;
244  o << "\\3-grams:" << endl;
245  o << "-1000000\t3 4 </s>" << endl;
246  o << endl;
247  o << "\\end\\" << endl;
248  o.close();
249  }
250  v_[kLmFeatureweights] = std::string ( "1.0" );
251  v_[kLmLoad] = std::string ( "mylm" );
252  v_[kLmWordmap] = std::string ("");
253  v_[kHifstReplacefstbyarcNumstates] = unsigned (
254  std::numeric_limits<unsigned>::max() );
255  v_[kHifstReplacefstbyarcNonterminals] = std::string ( "X" );
256  v_[kHifstReplacefstbyarcExceptions] = std::string ( "S" );
257  const uu::RegistryPO rg ( v_ );
258  LINFO ( "Number of inst:" << d_.hpinstances.size() );
259  EXPECT_TRUE ( d_.cykdata != NULL );
260  //Finally, build translation
262  uh::HiFSTTask<uh::HifstTaskData<> > hifst ( rg );
263  loadlm.run ( d_ );
264  hifst.run ( d_ );
265  //Test output.
266  EXPECT_TRUE ( d_.fsts[kHifstLatticeStore] != NULL );
267  std::stringstream ss;
268  fst::printstrings ( * static_cast<fst::VectorFst<fst::LexStdArc> *>
269  (d_.fsts[kHifstLatticeStore]), &ss );
270  //Hypothesis <s> 3 4 5 </s> yields -11101
271  //log2ln -11101=25560.99711732690113819501, apparently rounded somewhere to 25561.
272  EXPECT_EQ ( ss.str(),
273  "1 3 4 5 2 || 1 3 4 5 2 || 25561,0\n1 3 4 5 2 || 1 3 4 5 2 || 25561,0\n1 3 4 5 2 || 1 3 4 5 2 || 25561,0\n" );
274  bfs::remove ( bfs::path ( "mylm" ) );
275 };
276 
282 TEST_F ( HifstTest, alignment ) {
283  using namespace HifstConstants;
284  unordered_map<std::string, boost::any> v = v_;
285  v[kHifstReplacefstbyarcNonterminals] = std::string ( "" );
286  v[kHifstReplacefstbyarcNumstates] = unsigned (
287  std::numeric_limits<unsigned>::max() );
288  v[kHifstReplacefstbyarcExceptions] = std::string ( "S" );
289  v[kHifstAlilatsmode] = std::string ("yes");
290  const uu::RegistryPO rg ( v );
291  LINFO ( "Number of inst:" << d_.hpinstances.size() );
292  EXPECT_TRUE ( d_.cykdata != NULL );
293  //Finally, build translation
294  uh::HiFSTTask<uh::HifstTaskData<> > hifst ( rg );
295  hifst.run ( d_ );
296  //Test output.
297  EXPECT_TRUE ( d_.fsts[kHifstLatticeStore] != NULL );
298  /*
299  std::stringstream ss;
300  printstrings ( * static_cast<fst::VectorFst<fst::LexStdArc> *>(d_.fsts[kHifstLatticeStore]), &ss );
301 
302  EXPECT_EQ ( ss.str(),
303  "5 9 1 2 3 2 4 2 6 2 || 1 3 4 5 2 || 0,0\n5 9 7 2 4 2 6 2 || 1 3 4 5 2 || 0,0\n5 9 3 8 2 6 2 || 1 3 4 5 2 || 0,0\n");
304  //"5 9 7 2 4 2 6 2 || 1 3 4 5 2 || 0,0\n5 9 3 8 2 6 2 || 1 3 4 5 2 || 0,0\n5 9 1 2 3 2 4 2 6 2 || 1 3 4 5 2 || 0,0\n" );
305  // FstWrite(*d_.fsts[kHifstLatticeStore],"jajaja.fst");
306  */
307  fst::VectorFst<fst::LexStdArc> *a = new fst::VectorFst<fst::LexStdArc>;
308  fst::VectorFst<fst::LexStdArc> *b = new fst::VectorFst<fst::LexStdArc>;
309  fst::VectorFst<fst::LexStdArc> *c = new fst::VectorFst<fst::LexStdArc>;
310  fst::string2fst<fst::LexStdArc> ("5 9 1 2 3 2 4 2 6 2", a);
311  fst::string2fst<fst::LexStdArc> ("5 9 7 2 4 2 6 2", b);
312  fst::string2fst<fst::LexStdArc> ("5 9 3 8 2 6 2", c);
314  mur.Add (a);
315  mur.Add (b);
316  mur.Add (c);
317  fst::VectorFst<fst::LexStdArc> *j = mur();
318  fst::Determinize (fst::RmEpsilonFst<fst::LexStdArc> (*j), j);
319  fst::Minimize (j);
320  fst::RmEpsilon (j);
321  fst::Project (static_cast<fst::VectorFst<fst::LexStdArc> *>
322  (d_.fsts[kHifstLatticeStore]), fst::PROJECT_INPUT);
323  fst::Determinize (fst::RmEpsilonFst<fst::LexStdArc>
324  (*static_cast<fst::VectorFst<fst::LexStdArc> *>
326  static_cast<fst::VectorFst<fst::LexStdArc> *>
328  fst::Minimize (static_cast<fst::VectorFst<fst::LexStdArc> *>
330  fst::RmEpsilon (static_cast<fst::VectorFst<fst::LexStdArc> *>
332  EXPECT_EQ (Equivalent (*static_cast<fst::VectorFst<fst::LexStdArc> *>
333  (d_.fsts[kHifstLatticeStore]), *j), true);
334  delete j;
335 };
336 
337 TEST ( HifstTest2, localconditions ) {
338 
339  using uh::conditions;
349  // Trigger pruning weight=9 if you are at or over cell (S,x,21) and your expanded cell lattice has +10000 states.
350  lpc.add ( conditions ( 1, 20, 10000, 9.0f ) );
351  // Trigger pruning weight=8.5 if you are at or over cell (X,x,11) and your expanded cell lattice has +1000 states.
352  lpc.add ( conditions ( 2, 10, 1000, 8.5f ) );
353  // Trigger pruning weight=10.5 if you are at or over cell (V,x,6) and your expanded cell lattice has +50 states.
354  lpc.add ( conditions ( 3, 5, 50, 10.5f ) );
355  // Trigger pruning weight=3.5 if you are at or over cell (V,x,6) and your expanded cell lattice has +500 states.
356  lpc.add (conditions (3, 5 , 500 , 3.5f ) );
357  float w = 0;
359  EXPECT_EQ ( lpc ( 4, 20, 10000, w ), false );
360  EXPECT_EQ ( lpc ( 1, 18, 10000, w ), false );
362  EXPECT_EQ ( lpc ( 1, 19, 10000, w ), false );
363  EXPECT_EQ ( lpc ( 1, 20, 10000, w ), true );
364  EXPECT_EQ ( w, 9.0 );
365  EXPECT_EQ ( lpc ( 2, 10, 1000, w ), true );
366  EXPECT_EQ ( w, 8.5 );
367  EXPECT_EQ ( lpc ( 3, 5, 50, w ), true );
368  EXPECT_EQ ( w, 10.5 );
369  EXPECT_EQ ( lpc ( 3, 5, 499, w ), true );
370  EXPECT_EQ ( w, 10.5 );
371  EXPECT_EQ ( lpc ( 3, 5, 500, w ), true );
372  EXPECT_EQ ( w, 3.5 );
373  EXPECT_EQ ( lpc ( 3, 6, 500, w ), true );
374  EXPECT_EQ ( w, 3.5 );
375  EXPECT_EQ ( lpc ( 3, 6, 300, w ), true );
376  EXPECT_EQ ( w, 10.5 );
377  //Only 49 states
378  EXPECT_EQ ( lpc ( 3, 5, 49, w ), false );
379  //Below span=5
380  EXPECT_EQ ( lpc ( 3, 1, 490, w ), false );
381  //Unexpected entries
382  EXPECT_EQ ( lpc ( 0, 0, 0, w ), false );
383  EXPECT_EQ ( lpc ( std::numeric_limits<unsigned>::max(),
384  std::numeric_limits<unsigned>::max(), 0, w ), false );
385  EXPECT_EQ ( lpc ( -1, -2, 0, w ), false );
387  //Given no conditions loaded, everything should be false!
388  EXPECT_EQ ( lpc2 ( 3, 5, 49, w ), false );
389 };
390 
392 TEST ( HifstTest2, expandednumstatesrtn ) {
394  fst::VectorFst<fst::StdArc> a, b;
395  a.AddState();
396  a.AddState();
397  a.AddState();
398  a.SetStart ( 0 );
399  a.SetFinal ( 2, fst::StdArc::Weight::One() );
400  a.AddArc ( 0, fst::StdArc ( APBASETAG + 1 * APCCTAG + 1 * APXTAG + 1 * APYTAG,
401  APBASETAG + 1, 0, 1 ) );
402  a.AddArc ( 1, fst::StdArc ( APBASETAG + 1 * APCCTAG + 1 * APXTAG + 1 * APYTAG,
403  APBASETAG + 1, 0, 2 ) );
404  b.AddState();
405  b.AddState();
406  b.SetStart ( 0 );
407  b.SetFinal ( 1, fst::StdArc::Weight::One() );
408  b.AddArc ( 0, fst::StdArc ( 1, 1, 0, 1 ) );
409  test.update ( 1, 1, 1, &b );
410  test.update ( 1, 0, 1, &a );
411  EXPECT_EQ ( test ( 1, 0, 1 ), 3 );
412 }
413 
414 TEST ( HifstTest2, replacefstbyarc ) {
415  uh::ReplaceFstByArc<fst::StdArc> x ( true, 4 );
416  fst::VectorFst<fst::StdArc> a;
417  for ( unsigned k = 0; k < 4; ++k ) a.AddState();
418  fst::VectorFst<fst::StdArc> *aux = x ( a, 1 );
419  ASSERT_TRUE ( aux == NULL );
420  a.AddState();
421  aux = x ( a, 1 );
422  ASSERT_TRUE ( aux != NULL );
423  EXPECT_EQ ( aux->NumStates(), 2 );
424  ASSERT_EQ ( aux->NumArcs ( 0 ), 1 );
425  delete aux;
426 }
427 
428 TEST ( HifstTest2, manualreplacefstbyarc ) {
430  vcat[1] = "S";
431  vcat[2] = "X";
432  unordered_set<std::string> replacefstbyarc;
433  replacefstbyarc.insert ( "X" );
434  unordered_set<std::string> replacefstbyarcexceptions;
435  replacefstbyarcexceptions.insert ("S");
436  fst::VectorFst<fst::StdArc> a;
437  for ( unsigned k = 0; k < 2; ++k ) a.AddState();
438  {
439  uh::ManualReplaceFstByArc<fst::StdArc> x ( vcat, replacefstbyarc, true );
440  fst::StdArc::Label label1 = APBASETAG + 1 * APCCTAG + 1;
441  fst::VectorFst<fst::StdArc> *aux = x ( a, label1 );
442  ASSERT_TRUE ( aux == NULL );
443  fst::StdArc::Label label2 = APBASETAG + 2 * APCCTAG + 1;
444  aux = x ( a, label2 );
445  ASSERT_TRUE ( aux != NULL );
446  EXPECT_EQ ( aux->NumStates(), 2 );
447  delete aux;
448  }
450  {
451  uh::ManualReplaceFstByArc<fst::StdArc> x ( vcat, replacefstbyarc, true, 0);
452  fst::StdArc::Label label1 = APBASETAG + 1 * APCCTAG + 1;
453  fst::VectorFst<fst::StdArc> *aux = x ( a, label1 );
454  ASSERT_TRUE ( aux != NULL );
455  EXPECT_EQ ( aux->NumStates(), 2 );
456  delete aux;
457  fst::StdArc::Label label2 = APBASETAG + 2 * APCCTAG + 1;
458  aux = x ( a, label2 );
459  ASSERT_TRUE ( aux != NULL );
460  EXPECT_EQ ( aux->NumStates(), 2 );
461  delete aux;
462  }
464  {
465  uh::ManualReplaceFstByArc<fst::StdArc> x ( vcat, replacefstbyarc,
466  replacefstbyarcexceptions, true, 0);
467  fst::StdArc::Label label1 = APBASETAG + 1 * APCCTAG + 1;
468  fst::VectorFst<fst::StdArc> *aux = x ( a, label1 );
469  ASSERT_TRUE ( aux == NULL );
470  fst::StdArc::Label label2 = APBASETAG + 2 * APCCTAG + 1;
471  aux = x ( a, label2 );
472  ASSERT_TRUE ( aux != NULL );
473  EXPECT_EQ ( aux->NumStates(), 2 );
474  delete aux;
475  }
476 }
477 
478 TEST ( HifstTest2, optimize ) {
480  //FSA
481  fst::VectorFst<fst::StdArc> a ;
482  a.AddState();
483  a.AddState();
484  a.AddState();
485  a.AddState();
486  a.SetStart ( 0 );
487  a.SetFinal ( 1, fst::StdArc::Weight::One() );
488  a.SetFinal ( 3, fst::StdArc::Weight::One() );
489  a.AddArc ( 0, fst::StdArc ( 1 , 1 , 0, 1 ) );
490  a.AddArc ( 0, fst::StdArc ( 1 , 1 , 0, 2 ) );
491  a.AddArc ( 2, fst::StdArc ( 0 , 0 , 0, 3 ) );
492  fst::VectorFst<fst::StdArc> d (a);
493  fst::RmEpsilon (&d); //If above numstatethreshold
494  //If under numstatethreshold
495  fst::VectorFst<fst::StdArc> e (a);
496  fst::Determinize (fst::RmEpsilonFst<fst::StdArc> (e), &e);
497  fst::Minimize (&e);
498  fst::VectorFst<fst::StdArc> b (a);
499  om (&b, 3);
500  EXPECT_EQ ( d.NumStates(), b.NumStates() );
501  b = a;
502  om (&b, 4);
503  EXPECT_TRUE ( Equivalent (e, b) );
504  //Fst. Now we cannot use Equivalent easily.
505  fst::VectorFst<fst::StdArc> c;
506  c.AddState();
507  c.AddState();
508  c.AddState();
509  c.AddState();
510  c.SetStart ( 0 );
511  c.SetFinal ( 1, fst::StdArc::Weight::One() );
512  c.SetFinal ( 3, fst::StdArc::Weight::One() );
513  c.AddArc ( 0, fst::StdArc ( 1 , 2 , 0, 1 ) );
514  c.AddArc ( 0, fst::StdArc ( 1 , 2 , 0, 2 ) );
515  c.AddArc ( 2, fst::StdArc ( 0 , 0 , 0, 3 ) );
517  om1 (&c, 4);
518  EXPECT_EQ (c.NumStates(), 2);
519 }
520 
521 #ifndef GMAINTEST
522 
523 int main ( int argc, char **argv ) {
524  ::testing::InitGoogleTest ( &argc, argv );
525  return RUN_ALL_TESTS();
526 }
527 #endif
Wrapper stream class that writes to pipes, text files or gzipped files.
Definition: szfstream.hpp:200
Handles simple wildcard expansion for strings.
unordered_map< std::string, boost::any > v_
Unit testing: google testing common header.
struct containing the elements that trigger local pruning.
Convenience functors/functions for lexicographic<tropical,tropical> semiring.
Contains convenience functions to write and read fsts.
bool run(Data &d)
Runs the parsing algorithm.
Creates FST replacement or not depending on conditions.
Relative to Stats across the pipeline.
Data object for hifst or related tools.
const std::string kHifstLatticeStore
#define APBASETAG
const std::string kHifstLocalpruneLmFeatureweights
const std::string kCykparserHrmaxheight
Implements cyk+ parser.
const std::string kHifstWritertn
const std::string kHifstPrune
#define LINFO(msg)
Contains structures and classes for GrammarData.
const std::string kCykparserNtexceptionsmaxspan
unordered_map< uint, std::string > grammar_inversecategories_t
Convenience functions for tropical sparse vector weight.
const std::string kGrammarFeatureweights
void Add(Fst< Arc > const *fst)
Adds an fst to the list.
bool run(Data &d)
run method, given a grammar and instantiated patterns, creates and returns the hashes ...
const std::string kHifstUsepdt
Core of Hifst. Implements the lattice-building procedure for a cyk-parsed sentence.
Definition: task.hifst.hpp:50
This class creates the Union of an arbitrarily large number of fsts. This implementation uses one RTN...
const std::string kHifstReplacefstbyarcNonterminals
TEST(HifstTest2, localconditions)
Interfaces with basic methods for iteration.
const std::string kHifstAlilatsmode
Implementations of multiple fst unions.
int main(int argc, char **argv)
Language model loader task, loads a language model wrapping it in a class to provide.
Describes class GrammarTask.
Contains structures and classes for hifst task (target lattice building)
const std::string kHifstLocalpruneLmLoad
const std::size_t getIdx(std::size_t idx) const
Gets the real position (line) in the (potentially unsorted) file.
Task class that loads a grammar into memory.
const std::string kHifstLocalpruneNumstates
Implementation of a language model task.
uh::GrammarTask< uh::HifstTaskData<> > * gt_
void printstrings(const fst::VectorFst< Arc > &pcostslat, std::ostream *hyps, unsigned s=0)
Trivial function that outputs all the hypothesis in the lattice with its cost.
Definition: fstutils.hpp:253
const std::string kHifstOptimizecells
#define APXTAG
bool run(Data &d)
Method inherited from TaskInterface. Loads the language model and stores in lm data structure...
Contains implementation of ApplyLanguageModelOnTheFly.
uh::CYKParserTask< uh::HifstTaskData<> > * cyk_
const std::string kHifstAlilatsmodeLinks
const std::string kHifstLocalpruneLmWordpenalty
std::string const kLmFeatureweights
virtual void SetUp()
Contains structures and classes for GrammarData.
uh::HifstTaskData d_
Static variables for logger. Include only once from main file.
Utilites to extract vocabulary, pseudo-determinize lattices and build substring transducers.
const std::string kCykparserHmin
Headers for standalone shared library.
Implementation of a language model data structure using kenlm.
const std::string kHifstLocalpruneConditions
const std::string kSsgrammarAddoovsSourcedeletions
void add(const conditions &c)
Add condition.
const std::string kSsgrammarAddoovsEnable
Convenience functions to parse parameters from a string.
const std::string getRule(std::size_t idx) const
Gets a rule indexed by idx. Rule format: LHS RHSSource RHSTarget weight.
convenience class that takes care of local pruning conditions. Conditions are indexed by 1000*cc+y...
void load(const std::string &file)
Loads rules from a grammar file.
This class uses instantiated patterns to analyze the grammar and deliver two hashes providing candida...
Contains implementation for sentence-specific grammar task.
const GrammarData * grammar
Contains translation grammar.
void update(uint cc, uint x, uint y, fst::VectorFst< Arc > *myfst)
Estimates (expanded) number of states of rtn_[cc][x][y] Traverses arcs and and add number of states o...
bool run(Data &d)
Runs the lattice building procedure.
Definition: task.hifst.hpp:224
Contains definitions for cykparser data and task.
hifst test class for google test fixtures
Contains definitions for cykparser data and task.
Contains cyk parser implementation.
Generalized weight mapper functor.
unordered_map< std::string, std::vector< pair< uint, uint > > > hpinstances
uh::SentenceSpecificGrammarTask< uh::HifstTaskData<> > * ssgt_
Contains definitions for sentence-specific grammar data and task.
const std::string kHifstRtnopt
GrammarData * getGrammarData()
Returns GrammarData.
const std::string kSsgrammarStore
Convenience functors that allow transparent handling for weights within hifst.
const std::string kGrammarStorepatterns
unordered_map< std::string, void * > fsts
Pointers to lattices (e.g. translation lattice, lmbr, etc) , and related, accessed by unique keys...
#define APYTAG
virtual void TearDown()
std::string const kLmWordmap
class WordMapper
Contains sentence-specific grammar data.
Utility class that, given an RTN with root at (cc,x,y), estimates the number of states of an expanded...
std::string const kLmLoad
const std::string kHifstReplacefstbyarcNumstates
#define APCCTAG
const std::string kGrammarStorentorder
Multiepsilon composition.
const std::string kReferencefilterLoad
TEST_F(HifstTest, basic_translation)
Basic test for HifstTask.
const std::string kHifstReplacefstbyarcExceptions
const std::string kCykparserHmax
Unit testing: google testing common header.
CYKdata * cykdata
cyk data structures
const std::string kGrammarLoad
Creates FST replacement or not depending on conditions including program options. ...
const std::string kHifstLocalpruneEnable
Static variable for custom_assert. Include only once from main file.
void close()
Closes the file.
Definition: szfstream.hpp:323