diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-03-04 22:19:28 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-03-04 22:19:28 +0400 |
commit | 35bffae402c6e3427cc94560138db00adfe9eb11 (patch) | |
tree | 83e00993cc8f75478524036f3db2262b5d9e3b38 /moses-cmd | |
parent | cc2ec9bc3e0b480a109716ba1acfa4d1a0eb97d1 (diff) | |
parent | ec69acf3d4a2a0561ae4bed147e12562fd449280 (diff) |
Merge github.com:moses-smt/mosesdecoder into weight-new
Diffstat (limited to 'moses-cmd')
-rw-r--r-- | moses-cmd/IOWrapper.cpp | 18 | ||||
-rw-r--r-- | moses-cmd/IOWrapper.h | 2 | ||||
-rw-r--r-- | moses-cmd/Main.cpp | 52 |
3 files changed, 26 insertions, 46 deletions
diff --git a/moses-cmd/IOWrapper.cpp b/moses-cmd/IOWrapper.cpp index 2b4e41bf4..5597c68bf 100644 --- a/moses-cmd/IOWrapper.cpp +++ b/moses-cmd/IOWrapper.cpp @@ -189,24 +189,6 @@ InputType*IOWrapper::GetInput(InputType* inputType) } } - ofstream* IOWrapper::GetOutputSearchGraphSLFStream(size_t sentenceNumber) { - const StaticData &staticData = StaticData::Instance(); - stringstream fileName; - fileName << staticData.GetParam("output-search-graph-slf")[0] << "/" << sentenceNumber << ".slf"; - std::ofstream *file = new std::ofstream; - file->open(fileName.str().c_str()); - 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; - } - ofstream* IOWrapper::GetOutputSearchGraphHypergraphWeightsStream() { const StaticData &staticData = StaticData::Instance(); stringstream fileName; diff --git a/moses-cmd/IOWrapper.h b/moses-cmd/IOWrapper.h index 8b58f589c..b50b33ea6 100644 --- a/moses-cmd/IOWrapper.h +++ b/moses-cmd/IOWrapper.h @@ -124,8 +124,6 @@ public: return *m_outputSearchGraphStream; } - std::ofstream *GetOutputSearchGraphSLFStream(size_t sentenceNumber); - std::ofstream *GetOutputSearchGraphHypergraphStream(size_t sentenceNumber); std::ofstream *GetOutputSearchGraphHypergraphWeightsStream(); std::ostream &GetDetailedTranslationReportingStream() { diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index 4b7393501..85205e50d 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -84,8 +84,8 @@ public: OutputCollector* detailedTranslationCollector, OutputCollector* alignmentInfoCollector, OutputCollector* unknownsCollector, - std::ofstream* searchGraphSLFStream, - std::ofstream* searchGraphHypergraphStream) : + bool outputSearchGraphSLF, + bool outputSearchGraphHypergraph) : m_source(source), m_lineNumber(lineNumber), m_outputCollector(outputCollector), m_nbestCollector(nbestCollector), m_latticeSamplesCollector(latticeSamplesCollector), @@ -93,8 +93,8 @@ public: m_detailedTranslationCollector(detailedTranslationCollector), m_alignmentInfoCollector(alignmentInfoCollector), m_unknownsCollector(unknownsCollector), - m_searchGraphSLFStream(searchGraphSLFStream), - m_searchGraphHypergraphStream(searchGraphHypergraphStream) {} + m_outputSearchGraphSLF(outputSearchGraphSLF), + m_outputSearchGraphHypergraph(outputSearchGraphHypergraph) {} /** Translate one sentence * gets called by main function implemented at end of this source file */ @@ -148,29 +148,39 @@ public: } // Output search graph in HTK standard lattice format (SLF) - if (m_searchGraphSLFStream) { - if (m_searchGraphSLFStream->is_open() && m_searchGraphSLFStream->good()) { + if (m_outputSearchGraphSLF) { + stringstream fileName; + fileName << staticData.GetParam("output-search-graph-slf")[0] << "/" << m_lineNumber << ".slf"; + std::ofstream *file = new std::ofstream; + file->open(fileName.str().c_str()); + if (file->is_open() && file->good()) { ostringstream out; fix(out,PRECISION); manager.OutputSearchGraphAsSLF(m_lineNumber, out); - *m_searchGraphSLFStream << out.str(); - m_searchGraphSLFStream -> flush(); + *file << out.str(); + file -> flush(); } else { TRACE_ERR("Cannot output HTK standard lattice for line " << m_lineNumber << " because the output file is not open or not ready for writing" << std::endl); } } // Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder - if (m_searchGraphHypergraphStream) { - if (m_searchGraphHypergraphStream->is_open() && m_searchGraphHypergraphStream->good()) { + if (m_outputSearchGraphHypergraph) { + stringstream fileName; + fileName << staticData.GetParam("output-search-graph-hypergraph")[0] << "/" << m_lineNumber; + std::ofstream *file = new std::ofstream; + file->open(fileName.str().c_str()); + if (file->is_open() && file->good()) { ostringstream out; fix(out,PRECISION); manager.OutputSearchGraphAsHypergraph(m_lineNumber, out); - *m_searchGraphHypergraphStream << out.str(); - m_searchGraphHypergraphStream -> flush(); + *file << out.str(); + file -> 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); } + file -> close(); + delete file; } // apply decision rule and output best translation(s) @@ -327,15 +337,7 @@ public: } ~TranslationTask() { - - if (m_searchGraphSLFStream) { - m_searchGraphSLFStream->close(); - } - - delete m_searchGraphSLFStream; - delete m_searchGraphHypergraphStream; delete m_source; - } private: @@ -349,8 +351,8 @@ private: OutputCollector* m_detailedTranslationCollector; OutputCollector* m_alignmentInfoCollector; OutputCollector* m_unknownsCollector; - std::ofstream *m_searchGraphSLFStream; - std::ofstream *m_searchGraphHypergraphStream; + bool m_outputSearchGraphSLF; + bool m_outputSearchGraphHypergraph; std::ofstream *m_alignmentStream; @@ -632,10 +634,8 @@ int main(int argc, char** argv) detailedTranslationCollector.get(), alignmentInfoCollector.get(), unknownsCollector.get(), - staticData.GetOutputSearchGraphSLF() ? - ioWrapper->GetOutputSearchGraphSLFStream(lineCount) : NULL, - staticData.GetOutputSearchGraphHypergraph() ? - ioWrapper->GetOutputSearchGraphHypergraphStream(lineCount) : NULL); + staticData.GetOutputSearchGraphSLF(), + staticData.GetOutputSearchGraphHypergraph()); // execute task #ifdef WITH_THREADS pool.Submit(task); |