2010-05-27 12:37:25 +04:00
|
|
|
// $Id: MainMT.cpp 3045 2010-04-05 13:07:29Z hieuhoang1972 $
|
2006-07-04 22:04:38 +04:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
2010-05-27 12:37:25 +04:00
|
|
|
Copyright (C) 2009 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-07-04 22:04:38 +04:00
|
|
|
***********************************************************************/
|
|
|
|
|
2010-05-27 12:37:25 +04:00
|
|
|
/**
|
|
|
|
* Moses main, for single-threaded and multi-threaded.
|
|
|
|
**/
|
2012-01-13 19:20:42 +04:00
|
|
|
#include <exception>
|
2010-05-27 12:37:25 +04:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2006-07-04 22:04:38 +04:00
|
|
|
|
2012-10-05 20:49:52 +04:00
|
|
|
#include "util/usage.hh"
|
|
|
|
|
2006-07-04 22:04:38 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
// Include Visual Leak Detector
|
2011-07-24 03:52:34 +04:00
|
|
|
//#include <vld.h>
|
2006-07-04 22:04:38 +04:00
|
|
|
#endif
|
|
|
|
|
2014-09-29 20:58:20 +04:00
|
|
|
#include "moses/IOWrapper.h"
|
2012-11-13 00:21:32 +04:00
|
|
|
#include "moses/Hypothesis.h"
|
|
|
|
#include "moses/Manager.h"
|
|
|
|
#include "moses/StaticData.h"
|
2014-09-30 15:25:36 +04:00
|
|
|
#include "moses/TypeDef.h"
|
2012-11-13 00:21:32 +04:00
|
|
|
#include "moses/Util.h"
|
|
|
|
#include "moses/Timer.h"
|
2013-10-03 14:05:53 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionary.h"
|
|
|
|
#include "moses/FF/StatefulFeatureFunction.h"
|
|
|
|
#include "moses/FF/StatelessFeatureFunction.h"
|
2014-09-30 15:59:31 +04:00
|
|
|
#include "moses/TranslationTask.h"
|
2014-09-30 15:25:36 +04:00
|
|
|
|
2008-09-24 20:48:23 +04:00
|
|
|
#ifdef HAVE_PROTOBUF
|
|
|
|
#include "hypergraph.pb.h"
|
2006-07-04 22:04:38 +04:00
|
|
|
#endif
|
|
|
|
|
2014-11-20 20:38:02 +03:00
|
|
|
#ifdef PT_UG
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include "moses/TranslationModel/UG/mmsapt.h"
|
|
|
|
#include "moses/TranslationModel/UG/generic/program_options/ug_splice_arglist.h"
|
|
|
|
#endif
|
|
|
|
|
2006-07-04 22:04:38 +04:00
|
|
|
using namespace std;
|
2008-10-09 03:51:26 +04:00
|
|
|
using namespace Moses;
|
2006-08-08 01:18:13 +04:00
|
|
|
|
2014-10-09 15:52:06 +04:00
|
|
|
namespace Moses
|
2012-07-02 20:05:11 +04:00
|
|
|
{
|
2010-05-27 12:37:25 +04:00
|
|
|
|
2013-02-23 01:20:03 +04:00
|
|
|
void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream)
|
|
|
|
{
|
|
|
|
outputSearchGraphStream.setf(std::ios::fixed);
|
|
|
|
outputSearchGraphStream.precision(6);
|
2014-08-06 14:38:51 +04:00
|
|
|
StaticData::Instance().GetAllWeights().Save(outputSearchGraphStream);
|
2013-02-23 01:20:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-02 20:05:11 +04:00
|
|
|
} //namespace
|
|
|
|
|
2011-03-02 22:02:07 +03:00
|
|
|
/** main function of the command line version of the decoder **/
|
2011-02-24 15:39:29 +03:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2012-01-13 19:20:42 +04:00
|
|
|
try {
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2010-05-27 12:37:25 +04:00
|
|
|
#ifdef HAVE_PROTOBUF
|
2012-01-13 19:20:42 +04:00
|
|
|
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
2010-05-27 12:37:25 +04:00
|
|
|
#endif
|
2015-01-14 14:07:42 +03:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// echo command line, if verbose
|
|
|
|
IFVERBOSE(1) {
|
|
|
|
TRACE_ERR("command: ");
|
|
|
|
for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" ");
|
|
|
|
TRACE_ERR(endl);
|
2010-05-27 12:37:25 +04:00
|
|
|
}
|
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// set number of significant decimals in output
|
2014-12-02 22:09:10 +03:00
|
|
|
FixPrecision(cout);
|
|
|
|
FixPrecision(cerr);
|
2008-10-30 22:44:54 +03:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// load all the settings into the Parameter class
|
|
|
|
// (stores them as strings, or array of strings)
|
2013-03-15 16:30:39 +04:00
|
|
|
Parameter params;
|
|
|
|
if (!params.LoadParam(argc,argv)) {
|
2012-01-13 19:20:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2011-02-24 15:39:29 +03:00
|
|
|
|
2011-08-30 16:25:50 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// initialize all "global" variables, which are stored in StaticData
|
|
|
|
// note: this also loads models such as the language model, etc.
|
2013-03-15 16:30:39 +04:00
|
|
|
if (!StaticData::LoadDataStatic(¶ms, argv[0])) {
|
2012-01-13 19:20:42 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2007-01-22 19:21:28 +03:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// setting "-show-weights" -> just dump out weights and exit
|
2013-03-15 16:30:39 +04:00
|
|
|
if (params.isParamSpecified("show-weights")) {
|
2012-01-13 19:20:42 +04:00
|
|
|
ShowWeights();
|
|
|
|
exit(0);
|
|
|
|
}
|
2011-08-18 01:13:21 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// shorthand for accessing information in StaticData
|
|
|
|
const StaticData& staticData = StaticData::Instance();
|
2011-03-02 22:02:07 +03:00
|
|
|
|
2011-09-23 02:29:56 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
//initialise random numbers
|
|
|
|
srand(time(NULL));
|
2011-10-04 19:46:24 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// set up read/writing class
|
2014-12-01 18:26:47 +03:00
|
|
|
IFVERBOSE(1) {
|
2015-01-14 14:07:42 +03:00
|
|
|
PrintUserTime("Created input-output object");
|
2014-12-01 18:26:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
IOWrapper* ioWrapper = new IOWrapper();
|
|
|
|
if (ioWrapper == NULL) {
|
2012-01-13 19:20:42 +04:00
|
|
|
cerr << "Error; Failed to create IO object" << endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2011-02-24 15:39:29 +03:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// check on weights
|
2012-05-25 00:11:35 +04:00
|
|
|
const ScoreComponentCollection& weights = staticData.GetAllWeights();
|
2012-01-13 19:20:42 +04:00
|
|
|
IFVERBOSE(2) {
|
2012-05-25 00:11:35 +04:00
|
|
|
TRACE_ERR("The global weight vector looks like this: ");
|
|
|
|
TRACE_ERR(weights);
|
2012-01-13 19:20:42 +04:00
|
|
|
TRACE_ERR("\n");
|
2010-05-27 12:37:25 +04:00
|
|
|
}
|
2014-10-10 18:09:56 +04:00
|
|
|
|
2011-09-23 02:29:56 +04:00
|
|
|
#ifdef WITH_THREADS
|
2012-01-13 19:20:42 +04:00
|
|
|
ThreadPool pool(staticData.ThreadCount());
|
2011-09-23 02:29:56 +04:00
|
|
|
#endif
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// main loop over set of input sentences
|
|
|
|
InputType* source = NULL;
|
2013-02-14 00:52:40 +04:00
|
|
|
size_t lineCount = staticData.GetStartTranslationId();
|
2014-10-13 15:46:58 +04:00
|
|
|
while(ioWrapper->ReadInput(staticData.GetInputType(),source)) {
|
2014-10-07 22:16:30 +04:00
|
|
|
source->SetTranslationId(lineCount);
|
2012-01-13 19:20:42 +04:00
|
|
|
IFVERBOSE(1) {
|
|
|
|
ResetUserTime();
|
|
|
|
}
|
2014-08-02 01:41:24 +04:00
|
|
|
|
|
|
|
FeatureFunction::CallChangeSource(source);
|
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// set up task of translating one sentence
|
2015-01-04 13:02:44 +03:00
|
|
|
TranslationTask* task = new TranslationTask(source, *ioWrapper);
|
2014-10-10 18:09:56 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
// execute task
|
2010-05-27 12:37:25 +04:00
|
|
|
#ifdef WITH_THREADS
|
2014-11-20 14:21:50 +03:00
|
|
|
#ifdef PT_UG
|
|
|
|
bool spe = params.isParamSpecified("spe-src");
|
|
|
|
if (spe) {
|
2015-01-14 14:07:42 +03:00
|
|
|
// simulated post-editing: always run single-threaded!
|
2014-11-20 14:21:50 +03:00
|
|
|
task->Run();
|
|
|
|
delete task;
|
|
|
|
string src,trg,aln;
|
2014-11-20 20:38:02 +03:00
|
|
|
UTIL_THROW_IF2(!getline(*ioWrapper->spe_src,src), "[" << HERE << "] "
|
2014-11-20 14:21:50 +03:00
|
|
|
<< "missing update data for simulated post-editing.");
|
2014-11-20 20:38:02 +03:00
|
|
|
UTIL_THROW_IF2(!getline(*ioWrapper->spe_trg,trg), "[" << HERE << "] "
|
2015-01-14 14:07:42 +03:00
|
|
|
<< "missing update data for simulated post-editing.");
|
2014-11-20 20:38:02 +03:00
|
|
|
UTIL_THROW_IF2(!getline(*ioWrapper->spe_aln,aln), "[" << HERE << "] "
|
2015-01-14 14:07:42 +03:00
|
|
|
<< "missing update data for simulated post-editing.");
|
|
|
|
BOOST_FOREACH (PhraseDictionary* pd, PhraseDictionary::GetColl()) {
|
|
|
|
Mmsapt* sapt = dynamic_cast<Mmsapt*>(pd);
|
|
|
|
if (sapt) sapt->add(src,trg,aln);
|
|
|
|
VERBOSE(1,"[" << HERE << " added src] " << src << endl);
|
|
|
|
VERBOSE(1,"[" << HERE << " added trg] " << trg << endl);
|
|
|
|
VERBOSE(1,"[" << HERE << " added aln] " << aln << endl);
|
|
|
|
}
|
|
|
|
} else
|
2014-11-20 14:21:50 +03:00
|
|
|
#endif
|
2015-01-14 14:07:42 +03:00
|
|
|
pool.Submit(task);
|
2010-05-27 12:37:25 +04:00
|
|
|
#else
|
2012-01-13 19:20:42 +04:00
|
|
|
task->Run();
|
2012-03-30 23:25:42 +04:00
|
|
|
delete task;
|
2010-05-27 12:37:25 +04:00
|
|
|
#endif
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
source = NULL; //make sure it doesn't get deleted
|
|
|
|
++lineCount;
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
// we are done, finishing up
|
2010-05-27 12:37:25 +04:00
|
|
|
#ifdef WITH_THREADS
|
2012-01-13 19:20:42 +04:00
|
|
|
pool.Stop(true); //flush remaining jobs
|
2010-05-27 12:37:25 +04:00
|
|
|
#endif
|
|
|
|
|
2013-03-15 20:11:15 +04:00
|
|
|
delete ioWrapper;
|
2014-01-01 00:15:43 +04:00
|
|
|
FeatureFunction::Destroy();
|
2013-03-15 20:11:15 +04:00
|
|
|
|
2012-01-13 19:20:42 +04:00
|
|
|
} catch (const std::exception &e) {
|
|
|
|
std::cerr << "Exception: " << e.what() << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-10-05 20:49:52 +04:00
|
|
|
IFVERBOSE(1) util::PrintUsage(std::cerr);
|
|
|
|
|
2010-05-27 12:37:25 +04:00
|
|
|
#ifndef EXIT_RETURN
|
2011-02-24 15:39:29 +03:00
|
|
|
//This avoids that destructors are called (it can take a long time)
|
|
|
|
exit(EXIT_SUCCESS);
|
2010-05-27 12:37:25 +04:00
|
|
|
#else
|
2011-02-24 15:39:29 +03:00
|
|
|
return EXIT_SUCCESS;
|
2010-05-27 12:37:25 +04:00
|
|
|
#endif
|
2006-07-04 22:04:38 +04:00
|
|
|
}
|