diff options
author | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-12-06 03:12:01 +0300 |
---|---|---|
committer | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-12-06 03:12:01 +0300 |
commit | 69e5a1cc152de407513aa3889b2e665f32cb7507 (patch) | |
tree | 664a414f106a555966e2c9c6a8a36b1701e1f715 /moses/Hypothesis.cpp | |
parent | 889a33dcd68fb234824519681868355333b717be (diff) |
Code cleanup.
Diffstat (limited to 'moses/Hypothesis.cpp')
-rw-r--r-- | moses/Hypothesis.cpp | 68 |
1 files changed, 17 insertions, 51 deletions
diff --git a/moses/Hypothesis.cpp b/moses/Hypothesis.cpp index 16b56296a..ae622b182 100644 --- a/moses/Hypothesis.cpp +++ b/moses/Hypothesis.cpp @@ -332,57 +332,22 @@ GetTargetPhraseStringRep() const return GetTargetPhraseStringRep(allFactors); } -void -Hypothesis:: -OutputAlignment(std::ostream &out, WordAlignmentSort sortOrder) const -{ - std::vector<const Hypothesis *> edges; - const Hypothesis *currentHypo = this; - while (currentHypo) { - edges.push_back(currentHypo); - currentHypo = currentHypo->GetPrevHypo(); - } - - OutputAlignment(out, edges, sortOrder); - -} - -void -Hypothesis:: -OutputAlignment(ostream &out, - vector<const Hypothesis *> const& edges, - WordAlignmentSort waso) -{ - size_t targetOffset = 0; - - for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--) { - const Hypothesis &edge = *edges[currEdge]; - const TargetPhrase &tp = edge.GetCurrTargetPhrase(); - size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos(); - - OutputAlignment(out, tp.GetAlignTerm(), sourceOffset, targetOffset, waso); - - targetOffset += tp.GetSize(); - } - // Used by --print-alignment-info, so no endl -} - -void +size_t Hypothesis:: -OutputAlignment(ostream &out, const AlignmentInfo &ai, - size_t sourceOffset, size_t targetOffset, - WordAlignmentSort waso) +OutputAlignment(std::ostream &out, bool recursive=true) const { - typedef std::vector< const std::pair<size_t,size_t>* > AlignVec; - AlignVec alignments = ai.GetSortedAlignments(waso); - - AlignVec::const_iterator it; - for (it = alignments.begin(); it != alignments.end(); ++it) { - const std::pair<size_t,size_t> &alignment = **it; - out << alignment.first + sourceOffset << "-" - << alignment.second + targetOffset << " "; - } - + WordAlignmentSort const& waso = m_manager.options().output.WA_SortOrder; + TargetPhrase const& tp = GetCurrTargetPhrase(); + + // call with head recursion to output things in the right order + size_t trg_off = recursive && m_prevHypo ? m_prevHypo->OutputAlignment(out) : 0; + size_t src_off = GetCurrSourceWordsRange().GetStartPos(); + + typedef std::pair<size_t,size_t> const* entry; + std::vector<entry> alnvec = tp.GetAlignTerm().GetSortedAlignments(waso); + BOOST_FOREACH(entry e, alnvec) + out << e->first + src_off << "-" << e->second + trg_off << " "; + return trg_off + tp.GetSize(); } void @@ -489,8 +454,9 @@ OutputSurface(std::ostream &out, const Hypothesis &edge, out << "|" << sourceStart << "-" << sourceEnd; // enriched "-tt" if (options.ReportSegmentation == 2) { out << ",wa="; - const AlignmentInfo &ai = edge.GetCurrTargetPhrase().GetAlignTerm(); - Hypothesis::OutputAlignment(out, ai, 0, 0, options.WA_SortOrder); + edge.OutputAlignment(out, false); + // const AlignmentInfo &ai = edge.GetCurrTargetPhrase().GetAlignTerm(); + // Hypothesis::OutputAlignment(out, ai, 0, 0, options.WA_SortOrder); out << ",total="; out << edge.GetScore() - edge.GetPrevHypo()->GetScore(); out << ","; |