diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2014-10-03 18:30:06 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2014-10-03 18:30:06 +0400 |
commit | 65bd64ca6ab7b3e5ad54e3fc981173fc9fd0744c (patch) | |
tree | 6a3676edc15b75104cdd27555bb78bcb171a0a3e | |
parent | 62fe00b1a5775dbba1f961e41511dd99b4f946cb (diff) |
move lattice sample collector from Main to IOWrapper
-rw-r--r-- | moses-cmd/Main.cpp | 24 | ||||
-rw-r--r-- | moses/IOWrapper.cpp | 18 | ||||
-rw-r--r-- | moses/IOWrapper.h | 1 |
3 files changed, 19 insertions, 24 deletions
diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index ca251882f..398a3a824 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -134,30 +134,6 @@ int main(int argc, char** argv) hypergraphOutput.reset(new HypergraphOutput<Manager>(PRECISION)); } - - // initialize output streams - // note: we can't just write to STDOUT or files - // because multithreading may return sentences in shuffled order - auto_ptr<OutputCollector> latticeSamplesCollector; //for lattice samples - auto_ptr<ofstream> latticeSamplesOut; - bool output1best = true; - - size_t latticeSamplesSize = staticData.GetLatticeSamplesSize(); - string latticeSamplesFile = staticData.GetLatticeSamplesFilePath(); - if (latticeSamplesSize) { - if (latticeSamplesFile == "-" || latticeSamplesFile == "/dev/stdout") { - latticeSamplesCollector.reset(new OutputCollector()); - output1best = false; - } else { - latticeSamplesOut.reset(new ofstream(latticeSamplesFile.c_str())); - if (!latticeSamplesOut->good()) { - TRACE_ERR("ERROR: Failed to open " << latticeSamplesFile << " for lattice samples" << endl); - exit(1); - } - latticeSamplesCollector.reset(new OutputCollector(latticeSamplesOut.get())); - } - } - #ifdef WITH_THREADS ThreadPool pool(staticData.ThreadCount()); #endif diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index 79d3e4248..a4d28bc1d 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -73,6 +73,7 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder ,m_detailedTranslationReportingStream(NULL) ,m_unknownsStream(NULL) ,m_alignmentInfoStream(NULL) + ,m_latticeSamplesStream(NULL) ,m_singleBestOutputCollector(NULL) ,m_nBestOutputCollector(NULL) @@ -162,6 +163,22 @@ IOWrapper::IOWrapper(const std::vector<FactorType> &inputFactorOrder m_wordGraphCollector = new OutputCollector(m_outputWordGraphStream); } + size_t latticeSamplesSize = staticData.GetLatticeSamplesSize(); + string latticeSamplesFile = staticData.GetLatticeSamplesFilePath(); + if (latticeSamplesSize) { + if (latticeSamplesFile == "-" || latticeSamplesFile == "/dev/stdout") { + m_latticeSamplesCollector = new OutputCollector(); + m_surpressSingleBestOutput = true; + } else { + m_latticeSamplesStream = new ofstream(latticeSamplesFile.c_str()); + if (!m_latticeSamplesStream->good()) { + TRACE_ERR("ERROR: Failed to open " << latticeSamplesFile << " for lattice samples" << endl); + exit(1); + } + m_latticeSamplesCollector = new OutputCollector(m_latticeSamplesStream); + } + } + if (!m_surpressSingleBestOutput) { m_singleBestOutputCollector = new Moses::OutputCollector(&std::cout); } @@ -182,6 +199,7 @@ IOWrapper::~IOWrapper() delete m_unknownsStream; delete m_outputSearchGraphStream; delete m_outputWordGraphStream; + delete m_latticeSamplesStream; delete m_singleBestOutputCollector; delete m_nBestOutputCollector; diff --git a/moses/IOWrapper.h b/moses/IOWrapper.h index 1c962a7c6..b76adf8bd 100644 --- a/moses/IOWrapper.h +++ b/moses/IOWrapper.h @@ -81,6 +81,7 @@ protected: std::ofstream *m_alignmentInfoStream; std::ostream *m_unknownsStream; std::ostream *m_outputSearchGraphStream; + std::ofstream *m_latticeSamplesStream; bool m_surpressSingleBestOutput; |