diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-10-02 17:57:04 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-10-02 17:57:04 +0400 |
commit | b907fb7492f8cc22937ef65aa5ac5e4de8a18800 (patch) | |
tree | a90cccb8326ac6e6984a96c82d1fa7cefd011c10 | |
parent | f8b762a6ec0030f79b4fee44c00692407dd9bfef (diff) |
merge TranslationTask and IOWrapper. Move m_wordGraphCollector into IOWrapper
-rw-r--r-- | moses-cmd/Main.cpp | 7 | ||||
-rw-r--r-- | moses/IOWrapper.cpp | 22 | ||||
-rw-r--r-- | moses/IOWrapper.h | 17 | ||||
-rw-r--r-- | moses/TranslationTask.cpp | 6 | ||||
-rw-r--r-- | moses/TranslationTask.h | 2 |
5 files changed, 23 insertions, 31 deletions
diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index db94c1de5..f78c71acd 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -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 diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index 911d39e2f..e0392eb5d 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -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; diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index a396875cf..db8deaa3e 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -75,9 +75,9 @@ protected: std::string m_inputFilePath; Moses::InputFileStream *m_inputFile; std::istream *m_inputStream; - std::ostream *m_nBestStream - ,*m_outputWordGraphStream; - std::ostream *m_detailedTranslationReportingStream; + std::ostream *m_nBestStream; + std::ostream *m_outputWordGraphStream; + std::ostream *m_detailedTranslationReportingStream; std::ofstream *m_alignmentInfoStream; std::ostream *m_unknownsStream; std::ostream *m_outputSearchGraphStream; @@ -89,7 +89,8 @@ protected: Moses::OutputCollector *m_unknownsCollector; Moses::OutputCollector *m_alignmentInfoCollector; Moses::OutputCollector *m_searchGraphOutputCollector; - Moses::OutputCollector *m_detailedTranslationCollector; + 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); diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index bbcbd151b..2044429e2 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -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 diff --git a/moses/TranslationTask.h b/moses/TranslationTask.h index 40aa0c7ff..df0db549c 100644 --- a/moses/TranslationTask.h +++ b/moses/TranslationTask.h @@ -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; |