15 #ifndef MAIN_RUN_APPLYLM_HPP 16 #define MAIN_RUN_APPLYLM_HPP 37 , std::vector< std::vector<unsigned> > &srcw) {
39 LINFO(
"Creating source window...");
40 if (srcSize && !(srcSize % 2 )) {
41 LERROR(
"Only 0 or odd source sizes (1,3,...)");
45 using namespace boost::algorithm;
46 std::deque<std::string> words;
47 split(words, integerMappedSentence,is_any_of(
" "));
49 srcw.resize(words.size());
51 for (
unsigned k = 0; k < srcSize/2; ++k) {
52 words.push_front(
"1");
57 for (
unsigned k = 0; k < words.size() - srcSize + 1; ++k) {
58 srcw[k].push_back(toNumber<unsigned>(words[k]));
59 std::vector<unsigned> &aux = srcw[k];
60 for (
unsigned j = 1; j < srcSize; ++j) {
61 aux.push_back(toNumber<unsigned>(words[ k + j ]));
66 for (
unsigned k = 0; k < srcw.size(); ++k) {
67 std::stringstream ss; ss << srcw[k][0];
68 for (
unsigned j = 1; j < srcw[k].size(); ++j ){
69 ss <<
" " << srcw[k][j];
71 LDEBUG(
"*** ORIGINAL src words=" << ss.str());
76 template<
class ArcT,
template<
class>
class DataT >
80 typedef DataT<ArcT> Data;
86 return new ApplyLanguageModel
108 template <
template <
class>
class DataT
114 typedef DataT<ArcT> Data;
123 typedef boost::scoped_ptr<FastForwardRead> FastForwardReadPtr;
130 std::string srcFile_;
132 FastForwardReadPtr fastForwardRead_;
149 fastForwardRead_.reset(
new FastForwardRead
150 (
new iszfstream ( srcFile_) ));
153 <<
" needs to be defined");
170 bool run ( Data& original_data ) {
172 boost::scoped_ptr< LoadWordMap > tasks
175 (
new LoadLanguageModel ( rg_ ) )
177 ( addApplyLM<ArcT,DataT>(bilm_, rg_ ) )
180 (
new SpeedStats ( rg_ ) )
184 bool finished =
false;
192 finished = (*fastForwardRead_) ( d.sidx , &d.integerMappedSentence);
197 LINFO (
"Running sentence " << d.sidx );
198 tasks->chainrun ( d );
199 if (bilm_ && finished)
break;
210 template <
template <
class>
class DataT
216 typedef DataT<ArcT> Data;
227 typedef boost::scoped_ptr<FastForwardRead> FastForwardReadPtr;
234 std::string srcFile_;
236 FastForwardReadPtr fastForwardRead_;
240 unsigned threadcount_;
247 : threadcount_ ( rg.get<unsigned> (
HC::
kNThreads ) )
255 fastForwardRead_.reset(
new FastForwardRead
256 (
new iszfstream ( srcFile_) ));
259 <<
" needs to be defined");
265 inline bool operator() () {
280 bool run ( Data& original_data ) {
282 boost::scoped_ptr< LoadWordMap > mylm
284 mylm->appendTask (
new LoadLanguageModel ( rg_ ) );
285 mylm->chainrun ( original_data );
289 bool finished =
false;
291 ; !ir->done(); ir->next() ) {
294 ( addApplyLM<ArcT,DataT>(bilm_, rg_ ) )
297 (
new SpeedStats ( rg_ ) )
300 d->klm = original_data.klm;
303 finished = (*fastForwardRead_) ( d->sidx , &d->integerMappedSentence);
308 LINFO (
"Running sentence " << d->sidx );
310 if (bilm_ && finished)
break;
319 #endif //MAIN_RUN_APPLYLM_HPP Convenience class that reads "quickly" until a queried line.
void run(ucam::util::RegistryPO const &rg)
Stream wrapper for pipe/text/compressed files.
std::string const kUseBilingualModelSourceSentenceFile
std::string const kUseBilingualModel
std::string const kLatticeStore
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.
Templated (hybrid) Interface for Task classes.
Simple functor that accepts an interface and pointer to the data object in which it will have to run ...
TaskInterface & appendTask(TaskInterface *t)
Appends a task class. If there is no task, append here, otherwise delegate in next task...
std::string const kLatticeLoadDeleteLmCost
std::string const kTuneWrite
const std::string kNThreads
bool exists(const std::string &key) const
Determines whether a program option (key) has been defined by the user.
std::string const kLatticeLoad
T toNumber(const std::string &x)
Converts a string to an arbitrary number Converts strings to a number. Quits execution if conversion ...
std::string const kLmWordmap
std::string const kLmLoad
const std::string kRangeOne
Wrapper stream class that reads pipes, text files or gzipped files.
std::string const kUseBilingualModelSourceSize