mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
TranslationTaskChart --> TranslationTask
This commit is contained in:
parent
4403bd5b3c
commit
d507af5b1d
@ -916,16 +916,6 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationTask.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>TranslationTaskChart.cpp</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationTaskChart.cpp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>TranslationTaskChart.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/TranslationTaskChart.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>TreeInput.cpp</name>
|
||||
<type>1</type>
|
||||
|
@ -59,7 +59,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "moses/ChartHypothesis.h"
|
||||
#include "moses/FF/StatefulFeatureFunction.h"
|
||||
#include "moses/FF/StatelessFeatureFunction.h"
|
||||
#include "moses/TranslationTaskChart.h"
|
||||
#include "moses/TranslationTask.h"
|
||||
|
||||
#include "util/usage.hh"
|
||||
#include "util/exception.hh"
|
||||
@ -131,7 +131,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
FeatureFunction::CallChangeSource(source);
|
||||
|
||||
TranslationTaskChart *task = new TranslationTaskChart(source, *ioWrapper, hypergraphOutput);
|
||||
TranslationTask *task = new TranslationTask(source, *ioWrapper, hypergraphOutput);
|
||||
source = NULL; // task will delete source
|
||||
#ifdef WITH_THREADS
|
||||
pool.Submit(task); // pool will delete task
|
||||
|
@ -7,8 +7,11 @@
|
||||
#include "moses/Util.h"
|
||||
#include "moses/InputType.h"
|
||||
#include "moses/OutputCollector.h"
|
||||
#include "moses/Incremental.h"
|
||||
#include "mbr.h"
|
||||
|
||||
#include "util/exception.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
@ -16,18 +19,44 @@ namespace Moses
|
||||
|
||||
TranslationTask::TranslationTask(InputType* source, Moses::IOWrapper &ioWrapper,
|
||||
bool outputSearchGraphSLF,
|
||||
boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput) :
|
||||
m_source(source),
|
||||
m_ioWrapper(ioWrapper),
|
||||
m_outputSearchGraphSLF(outputSearchGraphSLF),
|
||||
m_hypergraphOutput(hypergraphOutput)
|
||||
boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput)
|
||||
: m_source(source)
|
||||
, m_ioWrapper(ioWrapper)
|
||||
, m_outputSearchGraphSLF(outputSearchGraphSLF)
|
||||
, m_hypergraphOutput(hypergraphOutput)
|
||||
, m_pbOrChart(1)
|
||||
{}
|
||||
|
||||
TranslationTask::TranslationTask(InputType *source, IOWrapper &ioWrapper,
|
||||
boost::shared_ptr<HypergraphOutput<ChartManager> > hypergraphOutputChart)
|
||||
: m_source(source)
|
||||
, m_ioWrapper(ioWrapper)
|
||||
, m_hypergraphOutputChart(hypergraphOutputChart)
|
||||
, m_pbOrChart(2)
|
||||
{}
|
||||
|
||||
TranslationTask::~TranslationTask() {
|
||||
delete m_source;
|
||||
}
|
||||
|
||||
void TranslationTask::Run() {
|
||||
void TranslationTask::Run()
|
||||
{
|
||||
switch (m_pbOrChart)
|
||||
{
|
||||
case 1:
|
||||
RunPb();
|
||||
break;
|
||||
case 2:
|
||||
RunChart();
|
||||
break;
|
||||
default:
|
||||
UTIL_THROW(util::Exception, "Unknown value: " << m_pbOrChart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TranslationTask::RunPb()
|
||||
{
|
||||
// shorthand for "global data"
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
|
||||
@ -285,4 +314,102 @@ void TranslationTask::Run() {
|
||||
}
|
||||
|
||||
|
||||
void TranslationTask::RunChart()
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const size_t translationId = m_source->GetTranslationId();
|
||||
|
||||
VERBOSE(2,"\nTRANSLATING(" << translationId << "): " << *m_source);
|
||||
|
||||
if (staticData.GetSearchAlgorithm() == ChartIncremental) {
|
||||
Incremental::Manager manager(*m_source);
|
||||
const std::vector<search::Applied> &nbest = manager.ProcessSentence();
|
||||
if (!nbest.empty()) {
|
||||
m_ioWrapper.OutputBestHypo(nbest[0], translationId);
|
||||
if (staticData.IsDetailedTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTranslationReport(&nbest[0], sentence, translationId);
|
||||
}
|
||||
if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTreeFragmentsTranslationReport(&nbest[0], sentence, translationId);
|
||||
}
|
||||
} else {
|
||||
m_ioWrapper.OutputBestNone(translationId);
|
||||
}
|
||||
if (staticData.GetNBestSize() > 0)
|
||||
m_ioWrapper.OutputNBestList(nbest, translationId);
|
||||
return;
|
||||
}
|
||||
|
||||
ChartManager manager(*m_source);
|
||||
manager.ProcessSentence();
|
||||
|
||||
UTIL_THROW_IF2(staticData.UseMBR(), "Cannot use MBR");
|
||||
|
||||
// Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder
|
||||
if (m_hypergraphOutputChart.get()) {
|
||||
m_hypergraphOutputChart->Write(manager);
|
||||
}
|
||||
|
||||
|
||||
// 1-best
|
||||
const ChartHypothesis *bestHypo = manager.GetBestHypothesis();
|
||||
m_ioWrapper.OutputBestHypo(bestHypo, translationId);
|
||||
IFVERBOSE(2) {
|
||||
PrintUserTime("Best Hypothesis Generation Time:");
|
||||
}
|
||||
|
||||
if (!staticData.GetAlignmentOutputFile().empty()) {
|
||||
m_ioWrapper.OutputAlignment(translationId, bestHypo);
|
||||
}
|
||||
|
||||
if (staticData.IsDetailedTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTranslationReport(bestHypo, sentence, translationId);
|
||||
}
|
||||
if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTreeFragmentsTranslationReport(bestHypo, sentence, translationId);
|
||||
}
|
||||
if (!staticData.GetOutputUnknownsFile().empty()) {
|
||||
m_ioWrapper.OutputUnknowns(manager.GetParser().GetUnknownSources(),
|
||||
translationId);
|
||||
}
|
||||
|
||||
//DIMw
|
||||
if (staticData.IsDetailedAllTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
size_t nBestSize = staticData.GetNBestSize();
|
||||
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
|
||||
manager.CalcNBest(nBestSize, nBestList, staticData.GetDistinctNBest());
|
||||
m_ioWrapper.OutputDetailedAllTranslationReport(nBestList, manager, sentence, translationId);
|
||||
}
|
||||
|
||||
// n-best
|
||||
size_t nBestSize = staticData.GetNBestSize();
|
||||
if (nBestSize > 0) {
|
||||
VERBOSE(2,"WRITING " << nBestSize << " TRANSLATION ALTERNATIVES TO " << staticData.GetNBestFilePath() << endl);
|
||||
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
|
||||
manager.CalcNBest(nBestSize, nBestList,staticData.GetDistinctNBest());
|
||||
m_ioWrapper.OutputNBestList(nBestList, translationId);
|
||||
IFVERBOSE(2) {
|
||||
PrintUserTime("N-Best Hypotheses Generation Time:");
|
||||
}
|
||||
}
|
||||
|
||||
if (staticData.GetOutputSearchGraph()) {
|
||||
std::ostringstream out;
|
||||
manager.OutputSearchGraphMoses( out);
|
||||
OutputCollector *oc = m_ioWrapper.GetSearchGraphOutputCollector();
|
||||
UTIL_THROW_IF2(oc == NULL, "File for search graph output not specified");
|
||||
oc->Write(translationId, out.str());
|
||||
}
|
||||
|
||||
IFVERBOSE(2) {
|
||||
PrintUserTime("Sentence Decoding Time:");
|
||||
}
|
||||
manager.CalcDecoderStatistics();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "moses/ThreadPool.h"
|
||||
#include "moses/Manager.h"
|
||||
#include "moses/HypergraphOutput.h"
|
||||
#include "moses/Manager.h"
|
||||
#include "moses/ChartManager.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -26,6 +28,9 @@ public:
|
||||
bool outputSearchGraphSLF,
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > hypergraphOutput);
|
||||
|
||||
TranslationTask(Moses::InputType *source, IOWrapper &ioWrapper,
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > hypergraphOutputChart);
|
||||
|
||||
~TranslationTask();
|
||||
|
||||
/** Translate one sentence
|
||||
@ -34,12 +39,16 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
int m_pbOrChart; // 1=pb. 2=chart
|
||||
Moses::InputType* m_source;
|
||||
Moses::IOWrapper &m_ioWrapper;
|
||||
|
||||
bool m_outputSearchGraphSLF;
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > m_hypergraphOutput;
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > m_hypergraphOutputChart;
|
||||
|
||||
void RunPb();
|
||||
void RunChart();
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,124 +0,0 @@
|
||||
#include "TranslationTaskChart.h"
|
||||
#include "moses/Sentence.h"
|
||||
#include "moses/StaticData.h"
|
||||
#include "moses/Incremental.h"
|
||||
#include "moses/IOWrapper.h"
|
||||
#include "moses/OutputCollector.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Moses;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
TranslationTaskChart::TranslationTaskChart(InputType *source, IOWrapper &ioWrapper,
|
||||
boost::shared_ptr<HypergraphOutput<ChartManager> > hypergraphOutput)
|
||||
: m_source(source)
|
||||
, m_ioWrapper(ioWrapper)
|
||||
, m_hypergraphOutput(hypergraphOutput)
|
||||
{}
|
||||
|
||||
TranslationTaskChart::~TranslationTaskChart() {
|
||||
delete m_source;
|
||||
}
|
||||
|
||||
void TranslationTaskChart::Run() {
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const size_t translationId = m_source->GetTranslationId();
|
||||
|
||||
VERBOSE(2,"\nTRANSLATING(" << translationId << "): " << *m_source);
|
||||
|
||||
if (staticData.GetSearchAlgorithm() == ChartIncremental) {
|
||||
Incremental::Manager manager(*m_source);
|
||||
const std::vector<search::Applied> &nbest = manager.ProcessSentence();
|
||||
if (!nbest.empty()) {
|
||||
m_ioWrapper.OutputBestHypo(nbest[0], translationId);
|
||||
if (staticData.IsDetailedTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTranslationReport(&nbest[0], sentence, translationId);
|
||||
}
|
||||
if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTreeFragmentsTranslationReport(&nbest[0], sentence, translationId);
|
||||
}
|
||||
} else {
|
||||
m_ioWrapper.OutputBestNone(translationId);
|
||||
}
|
||||
if (staticData.GetNBestSize() > 0)
|
||||
m_ioWrapper.OutputNBestList(nbest, translationId);
|
||||
return;
|
||||
}
|
||||
|
||||
ChartManager manager(*m_source);
|
||||
manager.ProcessSentence();
|
||||
|
||||
UTIL_THROW_IF2(staticData.UseMBR(), "Cannot use MBR");
|
||||
|
||||
// Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder
|
||||
if (m_hypergraphOutput.get()) {
|
||||
m_hypergraphOutput->Write(manager);
|
||||
}
|
||||
|
||||
|
||||
// 1-best
|
||||
const ChartHypothesis *bestHypo = manager.GetBestHypothesis();
|
||||
m_ioWrapper.OutputBestHypo(bestHypo, translationId);
|
||||
IFVERBOSE(2) {
|
||||
PrintUserTime("Best Hypothesis Generation Time:");
|
||||
}
|
||||
|
||||
if (!staticData.GetAlignmentOutputFile().empty()) {
|
||||
m_ioWrapper.OutputAlignment(translationId, bestHypo);
|
||||
}
|
||||
|
||||
if (staticData.IsDetailedTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTranslationReport(bestHypo, sentence, translationId);
|
||||
}
|
||||
if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
m_ioWrapper.OutputDetailedTreeFragmentsTranslationReport(bestHypo, sentence, translationId);
|
||||
}
|
||||
if (!staticData.GetOutputUnknownsFile().empty()) {
|
||||
m_ioWrapper.OutputUnknowns(manager.GetParser().GetUnknownSources(),
|
||||
translationId);
|
||||
}
|
||||
|
||||
//DIMw
|
||||
if (staticData.IsDetailedAllTranslationReportingEnabled()) {
|
||||
const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source);
|
||||
size_t nBestSize = staticData.GetNBestSize();
|
||||
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
|
||||
manager.CalcNBest(nBestSize, nBestList, staticData.GetDistinctNBest());
|
||||
m_ioWrapper.OutputDetailedAllTranslationReport(nBestList, manager, sentence, translationId);
|
||||
}
|
||||
|
||||
// n-best
|
||||
size_t nBestSize = staticData.GetNBestSize();
|
||||
if (nBestSize > 0) {
|
||||
VERBOSE(2,"WRITING " << nBestSize << " TRANSLATION ALTERNATIVES TO " << staticData.GetNBestFilePath() << endl);
|
||||
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
|
||||
manager.CalcNBest(nBestSize, nBestList,staticData.GetDistinctNBest());
|
||||
m_ioWrapper.OutputNBestList(nBestList, translationId);
|
||||
IFVERBOSE(2) {
|
||||
PrintUserTime("N-Best Hypotheses Generation Time:");
|
||||
}
|
||||
}
|
||||
|
||||
if (staticData.GetOutputSearchGraph()) {
|
||||
std::ostringstream out;
|
||||
manager.OutputSearchGraphMoses( out);
|
||||
OutputCollector *oc = m_ioWrapper.GetSearchGraphOutputCollector();
|
||||
UTIL_THROW_IF2(oc == NULL, "File for search graph output not specified");
|
||||
oc->Write(translationId, out.str());
|
||||
}
|
||||
|
||||
IFVERBOSE(2) {
|
||||
PrintUserTime("Sentence Decoding Time:");
|
||||
}
|
||||
manager.CalcDecoderStatistics();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/smart_ptr/shared_ptr.hpp>
|
||||
#include "moses/ThreadPool.h"
|
||||
#include "moses/ChartManager.h"
|
||||
#include "moses/HypergraphOutput.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
class InputType;
|
||||
class OutputCollector;
|
||||
class IOWrapper;
|
||||
|
||||
/**
|
||||
* Translates a sentence.
|
||||
**/
|
||||
class TranslationTaskChart : public Moses::Task
|
||||
{
|
||||
public:
|
||||
TranslationTaskChart(Moses::InputType *source, IOWrapper &ioWrapper,
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > hypergraphOutput);
|
||||
|
||||
~TranslationTaskChart();
|
||||
|
||||
void Run();
|
||||
|
||||
private:
|
||||
// Non-copyable: copy constructor and assignment operator not implemented.
|
||||
TranslationTaskChart(const TranslationTaskChart &);
|
||||
TranslationTaskChart &operator=(const TranslationTaskChart &);
|
||||
|
||||
Moses::InputType *m_source;
|
||||
IOWrapper &m_ioWrapper;
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > m_hypergraphOutput;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user