mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 21:42:19 +03:00
merge TranslationTask and IOWrapper. Move m_wordGraphCollector into IOWrapper
This commit is contained in:
parent
f8b762a6ec
commit
b907fb7492
@ -173,12 +173,6 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
// initialize stream for word graph (aka: output lattice)
|
||||
auto_ptr<OutputCollector> wordGraphCollector;
|
||||
if (staticData.GetOutputWordGraph()) {
|
||||
wordGraphCollector.reset(new OutputCollector(&(ioWrapper->GetOutputWordGraphStream())));
|
||||
}
|
||||
|
||||
#ifdef WITH_THREADS
|
||||
ThreadPool pool(staticData.ThreadCount());
|
||||
#endif
|
||||
@ -197,7 +191,6 @@ int main(int argc, char** argv)
|
||||
TranslationTask* task =
|
||||
new TranslationTask(lineCount,source, *ioWrapper,
|
||||
latticeSamplesCollector.get(),
|
||||
wordGraphCollector.get(),
|
||||
staticData.GetOutputSearchGraphSLF(),
|
||||
hypergraphOutput);
|
||||
// execute task
|
||||
|
@ -71,6 +71,7 @@ IOWrapper::IOWrapper(
|
||||
,m_outputWordGraphStream(NULL)
|
||||
,m_outputSearchGraphStream(NULL)
|
||||
,m_detailedTranslationReportingStream(NULL)
|
||||
,m_wordGraphCollector(NULL)
|
||||
{
|
||||
Initialization(inputFactorOrder, outputFactorOrder
|
||||
, inputFactorUsed
|
||||
@ -102,6 +103,7 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder
|
||||
,m_alignmentInfoCollector(NULL)
|
||||
,m_searchGraphOutputCollector(NULL)
|
||||
,m_detailedTranslationCollector(NULL)
|
||||
,m_wordGraphCollector(NULL)
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
|
||||
@ -157,6 +159,15 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder
|
||||
m_detailedTranslationCollector = new Moses::OutputCollector(m_detailedTranslationReportingStream);
|
||||
}
|
||||
|
||||
// wordgraph output
|
||||
if (staticData.GetOutputWordGraph()) {
|
||||
string fileName = staticData.GetParam("output-word-graph")[0];
|
||||
std::ofstream *file = new std::ofstream;
|
||||
m_outputWordGraphStream = file;
|
||||
file->open(fileName.c_str());
|
||||
m_wordGraphCollector = new OutputCollector(m_outputWordGraphStream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IOWrapper::~IOWrapper()
|
||||
@ -179,7 +190,7 @@ IOWrapper::~IOWrapper()
|
||||
delete m_alignmentInfoCollector;
|
||||
delete m_searchGraphOutputCollector;
|
||||
delete m_detailedTranslationCollector;
|
||||
|
||||
delete m_wordGraphCollector;
|
||||
}
|
||||
|
||||
void IOWrapper::Initialization(const std::vector<FactorType> &/*inputFactorOrder*/
|
||||
@ -204,15 +215,6 @@ void IOWrapper::Initialization(const std::vector<FactorType> &/*inputFactorOrder
|
||||
}
|
||||
}
|
||||
|
||||
// wordgraph output
|
||||
if (staticData.GetOutputWordGraph()) {
|
||||
string fileName = staticData.GetParam("output-word-graph")[0];
|
||||
std::ofstream *file = new std::ofstream;
|
||||
m_outputWordGraphStream = file;
|
||||
file->open(fileName.c_str());
|
||||
}
|
||||
|
||||
|
||||
// search graph output
|
||||
if (staticData.GetOutputSearchGraph()) {
|
||||
string fileName;
|
||||
|
@ -75,8 +75,8 @@ protected:
|
||||
std::string m_inputFilePath;
|
||||
Moses::InputFileStream *m_inputFile;
|
||||
std::istream *m_inputStream;
|
||||
std::ostream *m_nBestStream
|
||||
,*m_outputWordGraphStream;
|
||||
std::ostream *m_nBestStream;
|
||||
std::ostream *m_outputWordGraphStream;
|
||||
std::ostream *m_detailedTranslationReportingStream;
|
||||
std::ofstream *m_alignmentInfoStream;
|
||||
std::ostream *m_unknownsStream;
|
||||
@ -90,6 +90,7 @@ protected:
|
||||
Moses::OutputCollector *m_alignmentInfoCollector;
|
||||
Moses::OutputCollector *m_searchGraphOutputCollector;
|
||||
Moses::OutputCollector *m_detailedTranslationCollector;
|
||||
Moses::OutputCollector *m_wordGraphCollector;
|
||||
|
||||
void Initialization(const std::vector<Moses::FactorType> &inputFactorOrder
|
||||
, const std::vector<Moses::FactorType> &outputFactorOrder
|
||||
@ -123,10 +124,6 @@ public:
|
||||
m_translationId = 0;
|
||||
}
|
||||
|
||||
std::ostream &GetOutputWordGraphStream() {
|
||||
return *m_outputWordGraphStream;
|
||||
}
|
||||
|
||||
Moses::OutputCollector *GetSingleBestOutputCollector() {
|
||||
return m_singleBestOutputCollector;
|
||||
}
|
||||
@ -151,6 +148,10 @@ public:
|
||||
return m_detailedTranslationCollector;
|
||||
}
|
||||
|
||||
Moses::OutputCollector *GetWordGraphCollector() {
|
||||
return m_wordGraphCollector;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IOWrapper *GetIOWrapper(const Moses::StaticData &staticData);
|
||||
|
@ -17,13 +17,11 @@ namespace MosesCmd
|
||||
|
||||
TranslationTask::TranslationTask(size_t lineNumber, InputType* source, MosesCmd::IOWrapper &ioWrapper,
|
||||
OutputCollector* latticeSamplesCollector,
|
||||
OutputCollector* wordGraphCollector,
|
||||
bool outputSearchGraphSLF,
|
||||
boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput) :
|
||||
m_source(source), m_lineNumber(lineNumber),
|
||||
m_ioWrapper(ioWrapper),
|
||||
m_latticeSamplesCollector(latticeSamplesCollector),
|
||||
m_wordGraphCollector(wordGraphCollector),
|
||||
m_outputSearchGraphSLF(outputSearchGraphSLF),
|
||||
m_hypergraphOutput(hypergraphOutput)
|
||||
{}
|
||||
@ -63,11 +61,11 @@ void TranslationTask::Run() {
|
||||
additionalReportingTime.start();
|
||||
|
||||
// output word graph
|
||||
if (m_wordGraphCollector) {
|
||||
if (m_ioWrapper.GetWordGraphCollector()) {
|
||||
ostringstream out;
|
||||
fix(out,PRECISION);
|
||||
manager.GetWordGraph(m_lineNumber, out);
|
||||
m_wordGraphCollector->Write(m_lineNumber, out.str());
|
||||
m_ioWrapper.GetWordGraphCollector()->Write(m_lineNumber, out.str());
|
||||
}
|
||||
|
||||
// output search graph
|
||||
|
@ -28,7 +28,6 @@ public:
|
||||
|
||||
TranslationTask(size_t lineNumber, Moses::InputType* source, MosesCmd::IOWrapper &ioWrapper,
|
||||
Moses::OutputCollector* latticeSamplesCollector,
|
||||
Moses::OutputCollector* wordGraphCollector,
|
||||
bool outputSearchGraphSLF,
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > hypergraphOutput);
|
||||
|
||||
@ -45,7 +44,6 @@ private:
|
||||
MosesCmd::IOWrapper &m_ioWrapper;
|
||||
|
||||
Moses::OutputCollector* m_latticeSamplesCollector;
|
||||
Moses::OutputCollector* m_wordGraphCollector;
|
||||
bool m_outputSearchGraphSLF;
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > m_hypergraphOutput;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user