diff options
author | Lane Schwartz <dowobeha@gmail.com> | 2013-02-22 21:24:35 +0400 |
---|---|---|
committer | Lane Schwartz <dowobeha@gmail.com> | 2013-02-23 01:28:48 +0400 |
commit | 04f107fbb02442638928c190dd3fa2f13225d570 (patch) | |
tree | 577dec3cc61465632d5a7ee081ae000209dda239 /moses-cmd | |
parent | e7563111de02c5e39ff297e58641b612ff02fb4b (diff) |
Add flag to output search graph in Kenneth's hypergraph format.
Diffstat (limited to 'moses-cmd')
-rw-r--r-- | moses-cmd/IOWrapper.cpp | 9 | ||||
-rw-r--r-- | moses-cmd/IOWrapper.h | 1 | ||||
-rw-r--r-- | moses-cmd/Main.cpp | 24 |
3 files changed, 31 insertions, 3 deletions
diff --git a/moses-cmd/IOWrapper.cpp b/moses-cmd/IOWrapper.cpp index 451c53ae0..7c27476d1 100644 --- a/moses-cmd/IOWrapper.cpp +++ b/moses-cmd/IOWrapper.cpp @@ -198,6 +198,15 @@ InputType*IOWrapper::GetInput(InputType* inputType) return file; } + ofstream* IOWrapper::GetOutputSearchGraphHypergraphStream(size_t sentenceNumber) { + const StaticData &staticData = StaticData::Instance(); + stringstream fileName; + fileName << staticData.GetParam("output-search-graph-hypergraph")[0] << "/" << sentenceNumber; + std::ofstream *file = new std::ofstream; + file->open(fileName.str().c_str()); + return file; + } + /*** * print surface factor only for the given phrase */ diff --git a/moses-cmd/IOWrapper.h b/moses-cmd/IOWrapper.h index 1fdc1c6e4..044e71491 100644 --- a/moses-cmd/IOWrapper.h +++ b/moses-cmd/IOWrapper.h @@ -118,6 +118,7 @@ public: } std::ofstream *GetOutputSearchGraphSLFStream(size_t sentenceNumber); + std::ofstream *GetOutputSearchGraphHypergraphStream(size_t sentenceNumber); std::ostream &GetDetailedTranslationReportingStream() { assert (m_detailedTranslationReportingStream); diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index 16754b2fb..afadddabf 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -84,7 +84,8 @@ public: OutputCollector* detailedTranslationCollector, OutputCollector* alignmentInfoCollector, OutputCollector* unknownsCollector, - std::ofstream* searchGraphSLFStream) : + std::ofstream* searchGraphSLFStream, + std::ofstream* searchGraphHypergraphStream) : m_source(source), m_lineNumber(lineNumber), m_outputCollector(outputCollector), m_nbestCollector(nbestCollector), m_latticeSamplesCollector(latticeSamplesCollector), @@ -92,7 +93,8 @@ public: m_detailedTranslationCollector(detailedTranslationCollector), m_alignmentInfoCollector(alignmentInfoCollector), m_unknownsCollector(unknownsCollector), - m_searchGraphSLFStream(searchGraphSLFStream) {} + m_searchGraphSLFStream(searchGraphSLFStream), + m_searchGraphHypergraphStream(searchGraphHypergraphStream) {} /** Translate one sentence * gets called by main function implemented at end of this source file */ @@ -158,6 +160,19 @@ public: } } + // Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder + if (m_searchGraphHypergraphStream) { + if (m_searchGraphHypergraphStream->is_open() && m_searchGraphHypergraphStream->good()) { + ostringstream out; + fix(out,PRECISION); + manager.OutputSearchGraphAsHypergraph(m_lineNumber, out); + *m_searchGraphHypergraphStream << out.str(); + m_searchGraphHypergraphStream -> flush(); + } else { + TRACE_ERR("Cannot output hypergraph for line " << m_lineNumber << " because the output file is not open or not ready for writing" << std::endl); + } + } + // apply decision rule and output best translation(s) if (m_outputCollector) { ostringstream out; @@ -334,6 +349,7 @@ private: OutputCollector* m_alignmentInfoCollector; OutputCollector* m_unknownsCollector; std::ofstream *m_searchGraphSLFStream; + std::ofstream *m_searchGraphHypergraphStream; std::ofstream *m_alignmentStream; @@ -558,7 +574,9 @@ int main(int argc, char** argv) alignmentInfoCollector.get(), unknownsCollector.get(), staticData.GetOutputSearchGraphSLF() ? - ioWrapper->GetOutputSearchGraphSLFStream(lineCount) : NULL); + ioWrapper->GetOutputSearchGraphSLFStream(lineCount) : NULL, + staticData.GetOutputSearchGraphHypergraph() ? + ioWrapper->GetOutputSearchGraphHypergraphStream(lineCount) : NULL); // execute task #ifdef WITH_THREADS pool.Submit(task); |