From 6a77fd0ce3f5d3d52a20c1be808f1f7a0ffcb63b Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Fri, 5 Dec 2014 19:40:51 +0000 Subject: [PATCH] add OutputSearchGraphSLF() to API framework --- moses-cmd/Main.cpp | 1 - moses/BaseManager.h | 1 + moses/ChartManager.h | 2 ++ moses/Incremental.h | 3 ++- moses/Manager.cpp | 30 ++++++++++++++++++++++++++++++ moses/Manager.h | 1 + moses/Syntax/S2T/Manager.h | 2 ++ moses/TranslationTask.cpp | 24 +----------------------- moses/TranslationTask.h | 2 -- 9 files changed, 39 insertions(+), 27 deletions(-) diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index f224f2d8d..1c57cb33d 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -175,7 +175,6 @@ int main(int argc, char** argv) else { // pb task = new TranslationTask(source, *ioWrapper, - staticData.GetOutputSearchGraphSLF(), hypergraphOutput); } diff --git a/moses/BaseManager.h b/moses/BaseManager.h index 70316274d..27a9ee39f 100644 --- a/moses/BaseManager.h +++ b/moses/BaseManager.h @@ -55,6 +55,7 @@ public: virtual void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const = 0; virtual void OutputWordGraph(OutputCollector *collector) const = 0; virtual void OutputSearchGraph(OutputCollector *collector) const = 0; + virtual void OutputSearchGraphSLF() const = 0; }; diff --git a/moses/ChartManager.h b/moses/ChartManager.h index 814be1e60..b2ee3d0a9 100644 --- a/moses/ChartManager.h +++ b/moses/ChartManager.h @@ -161,6 +161,8 @@ public: void OutputWordGraph(OutputCollector *collector) const {} void OutputSearchGraph(OutputCollector *collector) const; + void OutputSearchGraphSLF() const + {} }; diff --git a/moses/Incremental.h b/moses/Incremental.h index ea4b3feda..c856f6a93 100644 --- a/moses/Incremental.h +++ b/moses/Incremental.h @@ -52,7 +52,8 @@ public: {} void OutputSearchGraph(OutputCollector *collector) const {} - + void OutputSearchGraphSLF() const + {} private: diff --git a/moses/Manager.cpp b/moses/Manager.cpp index 0b5f70dc4..e04c58c66 100644 --- a/moses/Manager.cpp +++ b/moses/Manager.cpp @@ -1780,4 +1780,34 @@ void Manager::OutputSearchGraph(OutputCollector *collector) const } +void Manager::OutputSearchGraphSLF() const +{ + const StaticData &staticData = StaticData::Instance(); + long translationId = m_source.GetTranslationId(); + + // Output search graph in HTK standard lattice format (SLF) + bool slf = staticData.GetOutputSearchGraphSLF(); + if (slf) { + stringstream fileName; + + string dir; + staticData.GetParameter().SetParameter(dir, "output-search-graph-slf", ""); + + fileName << dir << "/" << translationId << ".slf"; + ofstream *file = new ofstream; + file->open(fileName.str().c_str()); + if (file->is_open() && file->good()) { + ostringstream out; + FixPrecision(out,PRECISION); + OutputSearchGraphAsSLF(translationId, out); + *file << out.str(); + file -> flush(); + } else { + TRACE_ERR("Cannot output HTK standard lattice for line " << translationId << " because the output file is not open or not ready for writing" << endl); + } + delete file; + } + } + +} // namespace diff --git a/moses/Manager.h b/moses/Manager.h index ef32c4a9a..25fbed12d 100644 --- a/moses/Manager.h +++ b/moses/Manager.h @@ -198,6 +198,7 @@ public: {} void OutputWordGraph(OutputCollector *collector) const; void OutputSearchGraph(OutputCollector *collector) const; + void OutputSearchGraphSLF() const; }; diff --git a/moses/Syntax/S2T/Manager.h b/moses/Syntax/S2T/Manager.h index 817b8cdb9..71d2081e1 100644 --- a/moses/Syntax/S2T/Manager.h +++ b/moses/Syntax/S2T/Manager.h @@ -56,6 +56,8 @@ class Manager : public BaseManager {} void OutputSearchGraph(OutputCollector *collector) const {} + void OutputSearchGraphSLF() const + {} private: void FindOovs(const PChart &, std::set &, std::size_t); diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index e72811377..d0f03ed4d 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -21,11 +21,9 @@ namespace Moses { TranslationTask::TranslationTask(InputType* source, Moses::IOWrapper &ioWrapper, - bool outputSearchGraphSLF, boost::shared_ptr > hypergraphOutput) : m_source(source) , m_ioWrapper(ioWrapper) -, m_outputSearchGraphSLF(outputSearchGraphSLF) , m_hypergraphOutput(hypergraphOutput) , m_pbOrChart(1) {} @@ -95,27 +93,7 @@ void TranslationTask::RunPb() // output search graph manager.OutputSearchGraph(m_ioWrapper.GetSearchGraphOutputCollector()); - // Output search graph in HTK standard lattice format (SLF) - if (m_outputSearchGraphSLF) { - stringstream fileName; - - string dir; - staticData.GetParameter().SetParameter(dir, "output-search-graph-slf", ""); - - fileName << dir << "/" << m_source->GetTranslationId() << ".slf"; - ofstream *file = new ofstream; - file->open(fileName.str().c_str()); - if (file->is_open() && file->good()) { - ostringstream out; - FixPrecision(out,PRECISION); - manager.OutputSearchGraphAsSLF(m_source->GetTranslationId(), out); - *file << out.str(); - file -> flush(); - } else { - TRACE_ERR("Cannot output HTK standard lattice for line " << m_source->GetTranslationId() << " because the output file is not open or not ready for writing" << endl); - } - delete file; - } + manager.OutputSearchGraphSLF(); // Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder if (m_hypergraphOutput.get()) { diff --git a/moses/TranslationTask.h b/moses/TranslationTask.h index fa280a804..a169f84dd 100644 --- a/moses/TranslationTask.h +++ b/moses/TranslationTask.h @@ -27,7 +27,6 @@ class TranslationTask : public Moses::Task public: TranslationTask(Moses::InputType* source, Moses::IOWrapper &ioWrapper, - bool outputSearchGraphSLF, boost::shared_ptr > hypergraphOutput); TranslationTask(Moses::InputType *source, IOWrapper &ioWrapper, @@ -45,7 +44,6 @@ private: Moses::InputType* m_source; Moses::IOWrapper &m_ioWrapper; - bool m_outputSearchGraphSLF; boost::shared_ptr > m_hypergraphOutput; boost::shared_ptr > m_hypergraphOutputChart;