consistent constructor for all managers

This commit is contained in:
Hieu Hoang 2015-01-03 00:10:15 +05:30
parent 1ff52ebb0e
commit 0552a79b1e
7 changed files with 29 additions and 23 deletions

View File

@ -301,7 +301,7 @@ public:
inputFactorOrder = staticData.GetInputFactorOrder();
stringstream in(source + "\n");
sentence.Read(in,inputFactorOrder);
Manager manager(sentence, staticData.GetSearchAlgorithm());
Manager manager(sentence);
manager.Decode();
const Hypothesis* hypo = manager.GetBestHypothesis();

View File

@ -143,7 +143,7 @@ vector< vector<const Word*> > MosesDecoder::runDecoder(const std::string& source
string filename)
{
// run the decoder
m_manager = new Moses::Manager(*m_sentence, search);
m_manager = new Moses::Manager(*m_sentence);
m_manager->Decode();
TrellisPathList nBestList;
m_manager->CalcNBest(nBestSize, nBestList, distinct);

View File

@ -181,7 +181,7 @@ int main(int argc, char* argv[])
++lineCount;
source->SetTranslationId(lineCount);
Manager manager(*source, staticData.GetSearchAlgorithm());
Manager manager(*source);
manager.Decode();
TrellisPathList nBestList;
manager.CalcNBest(nBestSize, nBestList,true);

View File

@ -59,13 +59,16 @@ using namespace std;
namespace Moses
{
Manager::Manager(InputType const& source, SearchAlgorithm searchAlgorithm)
Manager::Manager(InputType const& source)
:BaseManager(source)
,m_transOptColl(source.CreateTranslationOptionCollection())
,m_search(Search::CreateSearch(*this, source, searchAlgorithm, *m_transOptColl))
,interrupted_flag(0)
,m_hypoId(0)
{
const StaticData &staticData = StaticData::Instance();
SearchAlgorithm searchAlgorithm = staticData.GetSearchAlgorithm();
m_search = Search::CreateSearch(*this, source, searchAlgorithm, *m_transOptColl);
StaticData::Instance().InitializeForInput(m_source);
}

View File

@ -151,7 +151,7 @@ protected:
void OutputAlignment(std::ostringstream &out, const TrellisPath &path) const;
public:
Manager(InputType const& source, SearchAlgorithm searchAlgorithm);
Manager(InputType const& source);
~Manager();
const TranslationOptionCollection* getSntTranslationOptions();

View File

@ -41,7 +41,7 @@ MockHypothesisGuard::MockHypothesisGuard(
m_wp("WordPenalty"),
m_uwp("UnknownWordPenalty"),
m_dist("Distortion"),
m_manager(m_sentence,Normal)
m_manager(m_sentence)
{
BOOST_CHECK_EQUAL(alignments.size(), targetSegments.size());

View File

@ -50,6 +50,7 @@ void TranslationTask::RunPb()
{
// shorthand for "global data"
const StaticData &staticData = StaticData::Instance();
const size_t translationId = m_source->GetTranslationId();
// input sentence
Sentence sentence;
@ -60,7 +61,7 @@ void TranslationTask::RunPb()
// report thread number
#if defined(WITH_THREADS) && defined(BOOST_HAS_PTHREADS)
TRACE_ERR("Translating line " << m_source->GetTranslationId() << " in thread id " << pthread_self() << endl);
TRACE_ERR("Translating line " << translationId << " in thread id " << pthread_self() << endl);
#endif
@ -69,50 +70,52 @@ void TranslationTask::RunPb()
// we still need to apply the decision rule (MAP, MBR, ...)
Timer initTime;
initTime.start();
Manager manager(*m_source,staticData.GetSearchAlgorithm());
VERBOSE(1, "Line " << m_source->GetTranslationId() << ": Initialize search took " << initTime << " seconds total" << endl);
manager.Decode();
Manager *manager = new Manager(*m_source);
VERBOSE(1, "Line " << translationId << ": Initialize search took " << initTime << " seconds total" << endl);
manager->Decode();
// we are done with search, let's look what we got
Timer additionalReportingTime;
additionalReportingTime.start();
manager.OutputBest(m_ioWrapper.GetSingleBestOutputCollector());
manager->OutputBest(m_ioWrapper.GetSingleBestOutputCollector());
// output word graph
manager.OutputWordGraph(m_ioWrapper.GetWordGraphCollector());
manager->OutputWordGraph(m_ioWrapper.GetWordGraphCollector());
// output search graph
manager.OutputSearchGraph(m_ioWrapper.GetSearchGraphOutputCollector());
manager->OutputSearchGraph(m_ioWrapper.GetSearchGraphOutputCollector());
manager.OutputSearchGraphSLF();
manager->OutputSearchGraphSLF();
// Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder
manager.OutputSearchGraphHypergraph();
manager->OutputSearchGraphHypergraph();
additionalReportingTime.stop();
additionalReportingTime.start();
// output n-best list
manager.OutputNBest(m_ioWrapper.GetNBestOutputCollector());
manager->OutputNBest(m_ioWrapper.GetNBestOutputCollector());
//lattice samples
manager.OutputLatticeSamples(m_ioWrapper.GetLatticeSamplesCollector());
manager->OutputLatticeSamples(m_ioWrapper.GetLatticeSamplesCollector());
// detailed translation reporting
manager.OutputDetailedTranslationReport(m_ioWrapper.GetDetailedTranslationCollector());
manager->OutputDetailedTranslationReport(m_ioWrapper.GetDetailedTranslationCollector());
//list of unknown words
manager.OutputUnknowns(m_ioWrapper.GetUnknownsCollector());
manager->OutputUnknowns(m_ioWrapper.GetUnknownsCollector());
// report additional statistics
manager.CalcDecoderStatistics();
VERBOSE(1, "Line " << m_source->GetTranslationId() << ": Additional reporting took " << additionalReportingTime << " seconds total" << endl);
VERBOSE(1, "Line " << m_source->GetTranslationId() << ": Translation took " << translationTime << " seconds total" << endl);
manager->CalcDecoderStatistics();
VERBOSE(1, "Line " << translationId << ": Additional reporting took " << additionalReportingTime << " seconds total" << endl);
VERBOSE(1, "Line " << translationId << ": Translation took " << translationTime << " seconds total" << endl);
IFVERBOSE(2) {
PrintUserTime("Sentence Decoding Time:");
}
delete manager;
}