From 4964c45489359dd5ad4894bdadf7996b400e556d Mon Sep 17 00:00:00 2001 From: hieuhoang1972 Date: Wed, 27 Feb 2008 12:43:04 +0000 Subject: output wordgraph for german git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1573 1f5c12ca-751b-0410-a591-d2e778427230 --- moses/src/Manager.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'moses/src/Manager.cpp') diff --git a/moses/src/Manager.cpp b/moses/src/Manager.cpp index acf5bbe20..692b6ba3f 100755 --- a/moses/src/Manager.cpp +++ b/moses/src/Manager.cpp @@ -479,3 +479,56 @@ void Manager::CalcDecoderStatistics() const } } } + +void Manager::GetWordGraph() const +{ + const StaticData &staticData = StaticData::Instance(); + string fileName = staticData.GetParam("output-word-graph")[0]; + bool outputNBest = Scan(staticData.GetParam("output-word-graph")[1]); + + std::ofstream wordGraphFile; + wordGraphFile.open(fileName.c_str()); + + size_t stackNo = 1; + std::vector < HypothesisStack >::const_iterator iterStack; + for (iterStack = ++m_hypoStackColl.begin() ; iterStack != m_hypoStackColl.end() ; ++iterStack) + { + cerr << endl << stackNo++ << endl; + const HypothesisStack &stack = *iterStack; + HypothesisStack::const_iterator iterHypo; + for (iterHypo = stack.begin() ; iterHypo != stack.end() ; ++iterHypo) + { + const Hypothesis *hypo = *iterHypo; + const Hypothesis *prevHypo = hypo->GetPrevHypo(); + const Phrase *sourcePhrase = hypo->GetSourcePhrase(); + const Phrase &targetPhrase = hypo->GetCurrTargetPhrase(); + + + wordGraphFile << prevHypo->GetId() << " -> " << hypo->GetId() << ": " + << *sourcePhrase << " " + << targetPhrase << " " + << hypo->GetTranslationOption().GetScoreBreakdown() << endl; + + if (outputNBest) + { + const ArcList *arcList = hypo->GetArcList(); + if (arcList != NULL) + { + ArcList::const_iterator iterArcList; + for (iterArcList = arcList->begin() ; iterArcList != arcList->end() ; ++iterArcList) + { + const Hypothesis *loserHypo = *iterArcList; + const Hypothesis *prevHypo = loserHypo->GetPrevHypo(); + + wordGraphFile << prevHypo->GetId() << " -> " << loserHypo->GetId() << ": " + << *sourcePhrase << " " + << targetPhrase << " " + << loserHypo->GetTranslationOption().GetScoreBreakdown() << endl; + } + } + } //if (outputNBest) + } //for (iterHypo + } // for (iterStack + + wordGraphFile.close(); +} \ No newline at end of file -- cgit v1.2.3