From 2c6083c90e77c13e066396873ab049ff347e177f Mon Sep 17 00:00:00 2001 From: Matthias Huck Date: Fri, 13 Sep 2013 17:53:49 +0200 Subject: [PATCH] avoid code replication: OutputTranslationOption --- moses-chart-cmd/IOWrapper.cpp | 46 +++++++++++++++++------------------ moses-chart-cmd/IOWrapper.h | 1 + 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/moses-chart-cmd/IOWrapper.cpp b/moses-chart-cmd/IOWrapper.cpp index 69ec9ece4..c445539b4 100644 --- a/moses-chart-cmd/IOWrapper.cpp +++ b/moses-chart-cmd/IOWrapper.cpp @@ -298,21 +298,26 @@ void IOWrapper::WriteApplicationContext(std::ostream &out, } } +void IOWrapper::OutputTranslationOption(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) +{ + ReconstructApplicationContext(*hypo, sentence, applicationContext); + out << "Trans Opt " << translationId + << " " << hypo->GetCurrSourceRange() + << ": "; + WriteApplicationContext(out, applicationContext); + out << ": " << hypo->GetCurrTargetPhrase().GetTargetLHS() + << "->" << hypo->GetCurrTargetPhrase() + << " " << hypo->GetTotalScore() << hypo->GetScoreBreakdown(); +} + void IOWrapper::OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) { - // recursive if (hypo != NULL) { - ReconstructApplicationContext(*hypo, sentence, applicationContext); - out << "Trans Opt " << translationId - << " " << hypo->GetCurrSourceRange() - << ": "; - WriteApplicationContext(out, applicationContext); - out << ": " << hypo->GetCurrTargetPhrase().GetTargetLHS() - << "->" << hypo->GetCurrTargetPhrase() - << " " << hypo->GetTotalScore() << hypo->GetScoreBreakdown() - << endl; + OutputTranslationOption(out, applicationContext, hypo, sentence, translationId); + out << std::endl; } + // recursive const std::vector &prevHypos = hypo->GetPrevHypos(); std::vector::const_iterator iter; for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { @@ -323,32 +328,25 @@ void IOWrapper::OutputTranslationOptions(std::ostream &out, ApplicationContext & void IOWrapper::OutputTreeFragmentsTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) { - // recursive + if (hypo != NULL) { + OutputTranslationOption(out, applicationContext, hypo, sentence, translationId); + const std::string key = "Tree"; std::string value; - bool hasprop; + bool hasProperty; const TargetPhrase &currTarPhr = hypo->GetCurrTargetPhrase(); - currTarPhr.GetProperty(key, value, hasprop); - - ReconstructApplicationContext(*hypo, sentence, applicationContext); - out << "Trans Opt " << translationId - << " " << hypo->GetCurrSourceRange() - << ":"; - WriteApplicationContext(out, applicationContext); - out << ": " << hypo->GetCurrTargetPhrase().GetTargetLHS() - << "-> " << hypo->GetCurrTargetPhrase() - << " " << hypo->GetTotalScore() << hypo->GetScoreBreakdown(); + currTarPhr.GetProperty(key, value, hasProperty); out << " ||| "; - if (hasprop) + if (hasProperty) out << " " << value; else out << " " << "noTreeInfo"; - out << std::endl; } + // recursive const std::vector &prevHypos = hypo->GetPrevHypos(); std::vector::const_iterator iter; for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { diff --git a/moses-chart-cmd/IOWrapper.h b/moses-chart-cmd/IOWrapper.h index ec1aee9de..88ff3d33c 100644 --- a/moses-chart-cmd/IOWrapper.h +++ b/moses-chart-cmd/IOWrapper.h @@ -85,6 +85,7 @@ 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 OutputTranslationOption(std::ostream &out, ApplicationContext &applicationContext, const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId); void OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId); void OutputTreeFragmentsTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const Moses::ChartHypothesis *hypo, const Moses::Sentence &sentence, long translationId); void ReconstructApplicationContext(const Moses::ChartHypothesis &hypo,