diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-10-02 17:18:12 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-10-02 17:18:12 +0400 |
commit | f8b762a6ec0030f79b4fee44c00692407dd9bfef (patch) | |
tree | d2bb88c15c72b6f3b4fc6f76b4f53b1bdacbdacd | |
parent | c45967c9b4f10ab36157c33e048152eb9c74984b (diff) |
merge TranslationTask and IOWrapper. Move m_detailedTranslationCollector into IOWrapper
-rw-r--r-- | moses-cmd/Main.cpp | 7 | ||||
-rw-r--r-- | moses/IOWrapper.cpp | 18 | ||||
-rw-r--r-- | moses/IOWrapper.h | 13 | ||||
-rw-r--r-- | moses/IOWrapperChart.cpp | 14 | ||||
-rw-r--r-- | moses/IOWrapperChart.h | 2 | ||||
-rw-r--r-- | moses/TranslationTask.cpp | 6 | ||||
-rw-r--r-- | moses/TranslationTask.h | 3 |
7 files changed, 24 insertions, 39 deletions
diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index 4cb507610..db94c1de5 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -179,12 +179,6 @@ int main(int argc, char** argv) wordGraphCollector.reset(new OutputCollector(&(ioWrapper->GetOutputWordGraphStream()))); } - // initialize stram for details about the decoder run - auto_ptr<OutputCollector> detailedTranslationCollector; - if (staticData.IsDetailedTranslationReportingEnabled()) { - detailedTranslationCollector.reset(new OutputCollector(&(ioWrapper->GetDetailedTranslationReportingStream()))); - } - #ifdef WITH_THREADS ThreadPool pool(staticData.ThreadCount()); #endif @@ -204,7 +198,6 @@ int main(int argc, char** argv) new TranslationTask(lineCount,source, *ioWrapper, latticeSamplesCollector.get(), wordGraphCollector.get(), - detailedTranslationCollector.get(), staticData.GetOutputSearchGraphSLF(), hypergraphOutput); // execute task diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index 3186daad2..911d39e2f 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -101,6 +101,7 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder ,m_unknownsCollector(NULL) ,m_alignmentInfoCollector(NULL) ,m_searchGraphOutputCollector(NULL) + ,m_detailedTranslationCollector(NULL) { const StaticData &staticData = StaticData::Instance(); @@ -149,6 +150,13 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder m_searchGraphOutputCollector = new Moses::OutputCollector(m_outputSearchGraphStream); } + // detailed translation reporting + if (staticData.IsDetailedTranslationReportingEnabled()) { + const std::string &path = staticData.GetDetailedTranslationReportingFilePath(); + m_detailedTranslationReportingStream = new std::ofstream(path.c_str()); + m_detailedTranslationCollector = new Moses::OutputCollector(m_detailedTranslationReportingStream); + } + } IOWrapper::~IOWrapper() @@ -170,6 +178,7 @@ IOWrapper::~IOWrapper() delete m_nBestOutputCollector; delete m_alignmentInfoCollector; delete m_searchGraphOutputCollector; + delete m_detailedTranslationCollector; } @@ -216,15 +225,6 @@ void IOWrapper::Initialization(const std::vector<FactorType> &/*inputFactorOrder file->open(fileName.c_str()); } - // detailed translation reporting - if (staticData.IsDetailedTranslationReportingEnabled()) { - const std::string &path = staticData.GetDetailedTranslationReportingFilePath(); - m_detailedTranslationReportingStream = new std::ofstream(path.c_str()); - UTIL_THROW_IF(!m_detailedTranslationReportingStream->good(), - util::FileOpenException, - "File for output of detailed translation report could not be open"); - } - } InputType* diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index edaca9f8d..a396875cf 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -89,6 +89,7 @@ protected: Moses::OutputCollector *m_unknownsCollector; Moses::OutputCollector *m_alignmentInfoCollector; Moses::OutputCollector *m_searchGraphOutputCollector; + Moses::OutputCollector *m_detailedTranslationCollector; void Initialization(const std::vector<Moses::FactorType> &inputFactorOrder , const std::vector<Moses::FactorType> &outputFactorOrder @@ -125,14 +126,6 @@ public: std::ostream &GetOutputWordGraphStream() { return *m_outputWordGraphStream; } - std::ostream &GetOutputSearchGraphStream() { - return *m_outputSearchGraphStream; - } - - std::ostream &GetDetailedTranslationReportingStream() { - assert (m_detailedTranslationReportingStream); - return *m_detailedTranslationReportingStream; - } Moses::OutputCollector *GetSingleBestOutputCollector() { return m_singleBestOutputCollector; @@ -154,6 +147,10 @@ public: return m_searchGraphOutputCollector; } + Moses::OutputCollector *GetDetailedTranslationCollector() { + return m_detailedTranslationCollector; + } + }; IOWrapper *GetIOWrapper(const Moses::StaticData &staticData); diff --git a/moses/IOWrapperChart.cpp b/moses/IOWrapperChart.cpp index 144088c9e..31d298fdd 100644 --- a/moses/IOWrapperChart.cpp +++ b/moses/IOWrapperChart.cpp @@ -72,7 +72,7 @@ IOWrapperChart::IOWrapperChart(const std::vector<FactorType> &inputFactorOrder ,m_alignmentInfoStream(NULL) ,m_unknownsStream(NULL) ,m_inputFilePath(inputFilePath) - ,m_detailOutputCollector(NULL) + ,m_detailedTranslationCollector(NULL) ,m_detailTreeFragmentsOutputCollector(NULL) ,m_nBestOutputCollector(NULL) ,m_searchGraphOutputCollector(NULL) @@ -117,7 +117,7 @@ IOWrapperChart::IOWrapperChart(const std::vector<FactorType> &inputFactorOrder if (staticData.IsDetailedTranslationReportingEnabled()) { const std::string &path = staticData.GetDetailedTranslationReportingFilePath(); m_detailedTranslationReportingStream = new std::ofstream(path.c_str()); - m_detailOutputCollector = new Moses::OutputCollector(m_detailedTranslationReportingStream); + m_detailedTranslationCollector = new Moses::OutputCollector(m_detailedTranslationReportingStream); } if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) { @@ -153,7 +153,7 @@ IOWrapperChart::~IOWrapperChart() delete m_detailTreeFragmentsOutputCollector; delete m_alignmentInfoStream; delete m_unknownsStream; - delete m_detailOutputCollector; + delete m_detailedTranslationCollector; delete m_nBestOutputCollector; delete m_searchGraphOutputCollector; delete m_singleBestOutputCollector; @@ -468,9 +468,9 @@ void IOWrapperChart::OutputDetailedTranslationReport( ApplicationContext applicationContext; OutputTranslationOptions(out, applicationContext, hypo, sentence, translationId); - UTIL_THROW_IF2(m_detailOutputCollector == NULL, + UTIL_THROW_IF2(m_detailedTranslationCollector == NULL, "No ouput file for detailed reports specified"); - m_detailOutputCollector->Write(translationId, out.str()); + m_detailedTranslationCollector->Write(translationId, out.str()); } void IOWrapperChart::OutputDetailedTranslationReport( @@ -485,9 +485,9 @@ void IOWrapperChart::OutputDetailedTranslationReport( ApplicationContext applicationContext; OutputTranslationOptions(out, applicationContext, applied, sentence, translationId); - UTIL_THROW_IF2(m_detailOutputCollector == NULL, + UTIL_THROW_IF2(m_detailedTranslationCollector == NULL, "No ouput file for detailed reports specified"); - m_detailOutputCollector->Write(translationId, out.str()); + m_detailedTranslationCollector->Write(translationId, out.str()); } void IOWrapperChart::OutputDetailedTreeFragmentsTranslationReport( diff --git a/moses/IOWrapperChart.h b/moses/IOWrapperChart.h index 26f54a8c5..1194e43b3 100644 --- a/moses/IOWrapperChart.h +++ b/moses/IOWrapperChart.h @@ -76,7 +76,7 @@ protected: std::ostream *m_unknownsStream; std::string m_inputFilePath; std::istream *m_inputStream; - Moses::OutputCollector *m_detailOutputCollector; + Moses::OutputCollector *m_detailedTranslationCollector; Moses::OutputCollector *m_detailTreeFragmentsOutputCollector; //DIMw Moses::OutputCollector *m_detailAllOutputCollector; diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index 9b22ab344..bbcbd151b 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -18,14 +18,12 @@ namespace MosesCmd TranslationTask::TranslationTask(size_t lineNumber, InputType* source, MosesCmd::IOWrapper &ioWrapper, OutputCollector* latticeSamplesCollector, OutputCollector* wordGraphCollector, - OutputCollector* detailedTranslationCollector, bool outputSearchGraphSLF, boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput) : m_source(source), m_lineNumber(lineNumber), m_ioWrapper(ioWrapper), m_latticeSamplesCollector(latticeSamplesCollector), m_wordGraphCollector(wordGraphCollector), - m_detailedTranslationCollector(detailedTranslationCollector), m_outputSearchGraphSLF(outputSearchGraphSLF), m_hypergraphOutput(hypergraphOutput) {} @@ -264,11 +262,11 @@ void TranslationTask::Run() { } // detailed translation reporting - if (m_detailedTranslationCollector) { + if (m_ioWrapper.GetDetailedTranslationCollector()) { ostringstream out; fix(out,PRECISION); TranslationAnalysis::PrintTranslationAnalysis(out, manager.GetBestHypothesis()); - m_detailedTranslationCollector->Write(m_lineNumber,out.str()); + m_ioWrapper.GetDetailedTranslationCollector()->Write(m_lineNumber,out.str()); } //list of unknown words diff --git a/moses/TranslationTask.h b/moses/TranslationTask.h index db642705b..40aa0c7ff 100644 --- a/moses/TranslationTask.h +++ b/moses/TranslationTask.h @@ -29,7 +29,6 @@ public: TranslationTask(size_t lineNumber, Moses::InputType* source, MosesCmd::IOWrapper &ioWrapper, Moses::OutputCollector* latticeSamplesCollector, Moses::OutputCollector* wordGraphCollector, - Moses::OutputCollector* detailedTranslationCollector, bool outputSearchGraphSLF, boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > hypergraphOutput); @@ -47,10 +46,8 @@ private: Moses::OutputCollector* m_latticeSamplesCollector; Moses::OutputCollector* m_wordGraphCollector; - Moses::OutputCollector* m_detailedTranslationCollector; bool m_outputSearchGraphSLF; boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > m_hypergraphOutput; - std::ofstream *m_alignmentStream; }; |