15 #ifndef MAIN_RUN_LMBR_HPP 16 #define MAIN_RUN_LMBR_HPP 32 template <
class Data = LmbrTaskData >
52 bool run ( Data& d ) {
53 using ucam::fsttools::ReadFstInit;
58 boost::scoped_ptr < ITask > mytask ( ReadFstInit<Data> ( rg_
62 ( ReadFstInit<Data> ( rg_
68 unordered_map<std::string, boost::shared_ptr<oszfstream > > onebestfiles;
77 d.lmbronebest = &lmbronebest;
78 mytask->chainrun ( d );
80 for (
unsigned j = 0; j < d.lmbronebest->alpha.size(); ++j) {
81 std::string filename = onebestfilename (d.lmbronebest->alpha[j]);
83 toString<float> (d.lmbronebest->wps[j] ) );
85 toString<unsigned> (d.lmbronebest->idx ) );
86 if (onebestfiles.find (filename) == onebestfiles.end() )
87 onebestfiles[filename] = boost::shared_ptr<oszfstream> (
new oszfstream (
89 *onebestfiles[filename] << d.lmbronebest->alpha[j]
90 <<
" " << d.lmbronebest->wps[j]
91 <<
" " << d.lmbronebest->idx
92 <<
":" << d.lmbronebest->hyp[j] << endl;
113 template <
class Data = LmbrTaskData >
124 unsigned threadcount_;
132 bool run ( Data& original_data ) {
133 using ucam::fsttools::ReadFstInit;
138 std::vector < boost::shared_ptr< lmbrtunedata > > lmbronebest;
148 TaskInterface<Data> *mytask (ReadFstInit <Data > ( rg_ ,
153 ( ReadFstInit<Data> ( rg_
162 LINFO (
"Processing sentence " << d->sidx);
163 lmbronebest.push_back ( boost::shared_ptr< lmbrtunedata >
165 d->lmbronebest = lmbronebest[lmbronebest.size() - 1].get();
166 tp ( TaskFunctor<Data> ( mytask, d ) );
171 unordered_map<std::string, boost::shared_ptr<oszfstream > > onebestfiles;
174 FORCELINFO (
"Writing to file(s) one best hypotheses");
175 for (
unsigned k = 0; k < lmbronebest.size(); ++k) {
176 for (
unsigned j = 0; j < lmbronebest[k]->alpha.size(); ++j) {
177 std::string filename = onebestfilename (lmbronebest[k]->alpha[j]);
179 toString<float> (lmbronebest[k]->wps[j] ) );
181 toString<unsigned> (lmbronebest[k]->idx ) );
182 if (onebestfiles.find (filename) == onebestfiles.end() )
183 onebestfiles[filename] = boost::shared_ptr<oszfstream> (
new oszfstream (
185 *onebestfiles[filename] << lmbronebest[k]->alpha[j]
186 <<
" " << lmbronebest[k]->wps[j]
187 <<
" " << lmbronebest[k]->idx
188 <<
":" << lmbronebest[k]->hyp[j] << endl;
Wrapper stream class that writes to pipes, text files or gzipped files.
const std::string kLmbrLoadHypothesesspace
bool run(Data &original_data)
original_data is being ignored in this case.
class that expands a wildcard into its actual value. This is useful e.g. for filenames ranging severa...
std::string toString(const T &x, uint pr=2)
Converts an arbitrary type to string Converts to string integers, floats, doubles Quits execution if ...
const std::string kLmbrLexstdarc
T get(const std::string &key) const
Returns parsed value associated to key.
boost::scoped_ptr< NumberRangeInterface< unsigned > > IntRangePtr
Trivial implementation of a threadpool based on boost::asio methods When initiated, creates a threadpool of n threads (n <= number of cpus). Jobs should be submitted with the templated operator(). When the object is deleted it will wait for all threads to finish.
const std::string kLmbrWritedecoder
SingleThreadedLmbrTask(const ucam::util::RegistryPO &rg)
Constructor.
Templated (hybrid) Interface for Task classes.
Full single-threaded Alignment lattices to Sparse lattices.
Simple functor that accepts an interface and pointer to the data object in which it will have to run ...
std::string const kHifstSemiringLexStdArc
const std::string kLmbrLoadEvidencespace
std::string const kHifstSemiringStdArc
const std::string kNThreads
MultiThreadedLmbrTask(const ucam::util::RegistryPO &rg)
bool exists(const std::string &key) const
Determines whether a program option (key) has been defined by the user.
void find_and_replace(std::string &haystack, const std::string &needle, const std::string &replace)
const std::string kRangeOne
bool run(Data &d)
Reads evidence space and hypotheses space (FSTs) and applies lmbr.
const std::string kLmbrWriteonebest