diff options
author | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-12-13 14:52:47 +0300 |
---|---|---|
committer | Nicola Bertoldi <bertoldi@fbk.eu> | 2014-12-13 14:52:47 +0300 |
commit | e4eb201c52be74fee74399a6f35fcbe8eb85d834 (patch) | |
tree | 7792ef96d63262f6e28f1857741e1162c7dccbc4 /moses/ChartHypothesis.cpp | |
parent | cea2d9d8bb34a81660974cae20d66aefec4e0468 (diff) | |
parent | a0b6b6a341e74b47bbef4652ad7fd928cf91e17c (diff) |
merged master into dynamic-models and solved conflicts
Diffstat (limited to 'moses/ChartHypothesis.cpp')
-rw-r--r-- | moses/ChartHypothesis.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/moses/ChartHypothesis.cpp b/moses/ChartHypothesis.cpp index 83d95aee9..5227d91d2 100644 --- a/moses/ChartHypothesis.cpp +++ b/moses/ChartHypothesis.cpp @@ -149,6 +149,40 @@ Phrase ChartHypothesis::GetOutputPhrase() const return outPhrase; } +void ChartHypothesis::GetOutputPhrase(int leftRightMost, int numWords, Phrase &outPhrase) const +{ + const TargetPhrase &tp = GetCurrTargetPhrase(); + + int targetSize = tp.GetSize(); + for (int i = 0; i < targetSize; ++i) { + int pos; + if (leftRightMost == 1) { + pos = i; + } + else if (leftRightMost == 2) { + pos = targetSize - i - 1; + } + else { + abort(); + } + + const Word &word = tp.GetWord(pos); + + if (word.IsNonTerminal()) { + // non-term. fill out with prev hypo + size_t nonTermInd = tp.GetAlignNonTerm().GetNonTermIndexMap()[pos]; + const ChartHypothesis *prevHypo = m_prevHypos[nonTermInd]; + prevHypo->GetOutputPhrase(outPhrase); + } else { + outPhrase.AddWord(word); + } + + if (outPhrase.GetSize() >= numWords) { + return; + } + } +} + /** check, if two hypothesis can be recombined. this is actually a sorting function that allows us to keep an ordered list of hypotheses. This makes recombination @@ -178,7 +212,7 @@ int ChartHypothesis::RecombineCompare(const ChartHypothesis &compare) const /** calculate total score * @todo this should be in ScoreBreakdown */ -void ChartHypothesis::Evaluate() +void ChartHypothesis::EvaluateWhenApplied() { const StaticData &staticData = StaticData::Instance(); // total scores from prev hypos @@ -200,7 +234,7 @@ void ChartHypothesis::Evaluate() StatelessFeatureFunction::GetStatelessFeatureFunctions(); for (unsigned i = 0; i < sfs.size(); ++i) { if (! staticData.IsFeatureFunctionIgnored( *sfs[i] )) { - sfs[i]->EvaluateChart(*this,&m_scoreBreakdown); + sfs[i]->EvaluateWhenApplied(*this,&m_scoreBreakdown); } } @@ -208,7 +242,7 @@ void ChartHypothesis::Evaluate() StatefulFeatureFunction::GetStatefulFeatureFunctions(); for (unsigned i = 0; i < ffs.size(); ++i) { if (! staticData.IsFeatureFunctionIgnored( *ffs[i] )) { - m_ffStates[i] = ffs[i]->EvaluateChart(*this,i,&m_scoreBreakdown); + m_ffStates[i] = ffs[i]->EvaluateWhenApplied(*this,i,&m_scoreBreakdown); } } @@ -259,7 +293,7 @@ void ChartHypothesis::CleanupArcList() */ const StaticData &staticData = StaticData::Instance(); size_t nBestSize = staticData.GetNBestSize(); - bool distinctNBest = staticData.GetDistinctNBest() || staticData.UseMBR() || staticData.GetOutputSearchGraph(); + bool distinctNBest = staticData.GetDistinctNBest() || staticData.UseMBR() || staticData.GetOutputSearchGraph() || staticData.GetOutputSearchGraphHypergraph(); if (!distinctNBest && m_arcList->size() > nBestSize) { // prune arc list only if there too many arcs |