Cambridge SMT System
tunewp.main.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 
15 #include <main.tunewp.hpp>
16 #include <main.custom_assert.hpp>
17 #include <main.logger.hpp>
18 
19 template <class Arc>
20 class TuneWpMain {
21  private:
22 
23  const ucam::util::RegistryPO& rg_;
25  public:
27  rg_ (rg) {
28  };
29  void operator () () {
31  using fst::VectorFstRead;
32  using fst::FstWrite;
34  PatternAddress<unsigned> pi (rg_.get<std::string> (HifstConstants::kInput ) );
35  PatternAddress<unsigned> po (rg_.get<std::string> (HifstConstants::kOutput ) );
36  ucam::util::NumberRange<float> wp ( rg_.get<std::string>
38  //Insert epsilons
39  unordered_set<typename Arc::Label> epsilons =
40  rg_.getSetNumber<typename Arc::Label> (HifstConstants::kEpsilonLabels);
41  unsigned shp = rg_.get<unsigned> (HifstConstants::kNbest);
44  !ir->done();
45  ir->next() ) {
46  fst::VectorFst<Arc> *mfst = VectorFstRead<Arc> (pi (ir->get() ) );
47  for ( wp.start(); !wp.done(); wp.next() ) {
48  fst::Map<Arc, WordPenaltyMapper<Arc> > (mfst,
49  WordPenaltyMapper<Arc> (mw_ (wp.get() ), epsilons) );
50  if (shp < std::numeric_limits<unsigned>::max() ) {
51  fst::VectorFst<Arc> aux;
52  fst::ShortestPath<Arc> (*mfst, &aux, shp);
53  *mfst = aux;
54  }
55  std::string auxs = po (ir->get() );
56  ucam::util::find_and_replace (auxs, "%%wp%%",
57  ucam::util::toString<float> (wp() ) );
58  FstWrite<Arc> (*mfst, auxs);
59  }
60  }
61  };
62 
63 };
64 
65 int main (int argc, const char* argv[] ) {
66  ucam::util::initLogger ( argc, argv );
67  FORCELINFO ( argv[0] << " starts!" );
68  ucam::util::RegistryPO rg ( argc, argv );
69  FORCELINFO ( rg.dump ( "CONFIG parameters:\n=====================",
70  "=====================" ) ) ;
71  if (rg.get<std::string> (HifstConstants::kHifstSemiring.c_str() ) ==
73  TuneWpMain<fst::StdArc> twp (rg);
74  twp();
75  } else if (rg.get<std::string> (HifstConstants::kHifstSemiring.c_str() ) ==
78  twp();
79  } else {
80  LERROR ("Unknown type");
81  }
82  FORCELINFO ( argv[0] << " ends!" );
83 }
84 
std::string const kHifstSemiring
int main(int argc, const char *argv[])
Definition: tunewp.main.cpp:65
class that expands a wildcard into its actual value. This is useful e.g. for filenames ranging severa...
std::string const kEpsilonLabels
VectorFst< Arc > * VectorFstRead(const std::string &filename)
Templated method that reads VectorFst.
Definition: fstio.hpp:78
templated Mapper that inserts a word penalty over an FST, skipping user defined epsilon arcs...
void operator()()
Definition: tunewp.main.cpp:29
NumberType get(void)
Returns range value at position k_.
Definition: range.hpp:119
Included headers for all the binary should be defined here. This file should be included only once...
unordered_set< NumberT > getSetNumber(const std::string &key) const
Templated method that returns a set of numbers taking "," as the separator character.
Definition: registrypo.hpp:294
TuneWpMain(ucam::util::RegistryPO const &rg)
Definition: tunewp.main.cpp:26
T get(const std::string &key) const
Returns parsed value associated to key.
Definition: registrypo.hpp:194
void initLogger(int argc, const char *argv[])
Inits logger, parses param options checking for –logger.verbose.
std::string const kInput
#define FORCELINFO(msg)
boost::scoped_ptr< NumberRangeInterface< unsigned > > IntRangePtr
Definition: range.hpp:214
#define IntRangeFactory
Definition: range.hpp:213
std::string const kNbest
std::string const kOutput
void start(void)
Empty implementation.
Definition: range.hpp:107
void next(void)
Increment index.
Definition: range.hpp:111
std::string const kHifstSemiringLexStdArc
std::string const kHifstSemiringStdArc
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.
Definition: fstio.hpp:111
Templated functor that creates a weight given a float.
std::string const kWordPenalty
std::string dump(const std::string &decorator_start="", const std::string &decorator_end="")
Dumps all configuration parameters into a string with a reasonably pretty format. ...
Definition: registrypo.hpp:108
bool done(void)
Checks if reached the last element.
Definition: range.hpp:115
#define LERROR(msg)
void find_and_replace(std::string &haystack, const std::string &needle, const std::string &replace)
const std::string kRangeOne
Definition: range.hpp:26
Static variable for custom_assert. Include only once from main file.