diff --git a/moses-chart-cmd/IOWrapper.cpp b/moses-chart-cmd/IOWrapper.cpp index 3f2a19de9..09e06fcf6 100644 --- a/moses-chart-cmd/IOWrapper.cpp +++ b/moses-chart-cmd/IOWrapper.cpp @@ -243,13 +243,9 @@ void OutputInput(std::ostream& os, const ChartHypothesis* hypo) } */ -namespace { - -typedef std::vector > ApplicationContext; - // Given a hypothesis and sentence, reconstructs the 'application context' -- // the source RHS symbols of the SCFG rule that was applied, plus their spans. -void ReconstructApplicationContext(const ChartHypothesis &hypo, +void IOWrapper::ReconstructApplicationContext(const ChartHypothesis &hypo, const Sentence &sentence, ApplicationContext &context) { @@ -280,7 +276,7 @@ void ReconstructApplicationContext(const ChartHypothesis &hypo, // output format is a bit odd (reverse order and double spacing between symbols) // but there are scripts and tools that expect the output of -T to look like // that. -void WriteApplicationContext(std::ostream &out, +void IOWrapper::WriteApplicationContext(std::ostream &out, const ApplicationContext &context) { assert(!context.empty()); @@ -294,12 +290,8 @@ void WriteApplicationContext(std::ostream &out, } } -} // anonymous namespace - -void OutputTranslationOptions(std::ostream &out, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) +void IOWrapper::OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) { - static ApplicationContext applicationContext; - // recursive if (hypo != NULL) { ReconstructApplicationContext(*hypo, sentence, applicationContext); @@ -317,7 +309,7 @@ void OutputTranslationOptions(std::ostream &out, const ChartHypothesis *hypo, co std::vector::const_iterator iter; for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { const ChartHypothesis *prevHypo = *iter; - OutputTranslationOptions(out, prevHypo, sentence, translationId); + OutputTranslationOptions(out, applicationContext, prevHypo, sentence, translationId); } } @@ -330,7 +322,9 @@ void IOWrapper::OutputDetailedTranslationReport( return; } std::ostringstream out; - OutputTranslationOptions(out, hypo, sentence, translationId); + ApplicationContext applicationContext; + + OutputTranslationOptions(out, applicationContext, hypo, sentence, translationId); CHECK(m_detailOutputCollector); m_detailOutputCollector->Write(translationId, out.str()); } diff --git a/moses-chart-cmd/IOWrapper.h b/moses-chart-cmd/IOWrapper.h index 1e495793d..9aed9294f 100644 --- a/moses-chart-cmd/IOWrapper.h +++ b/moses-chart-cmd/IOWrapper.h @@ -61,6 +61,7 @@ namespace MosesChartCmd class IOWrapper { protected: + typedef std::vector > ApplicationContext; long m_translationId; @@ -82,6 +83,12 @@ protected: size_t OutputAlignmentNBest(Alignments &retAlign, const Moses::ChartTrellisNode &node, size_t startTarget); size_t OutputAlignment(Alignments &retAlign, const Moses::ChartHypothesis *hypo, size_t startTarget); void OutputAlignment(std::vector< std::set > &retAlignmentsS2T, const Moses::AlignmentInfo &ai); + void OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId); + void ReconstructApplicationContext(const Moses::ChartHypothesis &hypo, + const Moses::Sentence &sentence, + ApplicationContext &context); + void WriteApplicationContext(std::ostream &out, + const ApplicationContext &context); public: IOWrapper(const std::vector &inputFactorOrder