diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2013-09-22 18:15:00 +0400 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2013-09-22 18:15:00 +0400 |
commit | 5f8e8f7db9730dc27f774ec6bf72e0b14386e394 (patch) | |
tree | 46b4189499a511ea9fe52a24907b601c2f222eb0 /moses/ChartTranslationOptions.cpp | |
parent | 00b21b4f530458a2c86f3582ae15af3b081c50d7 (diff) |
placeholder for chart decoding
Diffstat (limited to 'moses/ChartTranslationOptions.cpp')
-rw-r--r-- | moses/ChartTranslationOptions.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/moses/ChartTranslationOptions.cpp b/moses/ChartTranslationOptions.cpp index 196becc01..bcfca72a5 100644 --- a/moses/ChartTranslationOptions.cpp +++ b/moses/ChartTranslationOptions.cpp @@ -70,6 +70,11 @@ float ChartTranslationOptions::CalcEstimateOfBestScore( void ChartTranslationOptions::Evaluate(const InputType &input, const InputPath &inputPath) { + SetInputPath(&inputPath); + if (StaticData::Instance().GetPlaceholderFactor() != NOT_FOUND) { + CreateSourceRuleFromInputPath(); + } + CollType::iterator iter; for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { ChartTranslationOption &transOpt = **iter; @@ -79,4 +84,58 @@ void ChartTranslationOptions::Evaluate(const InputType &input, const InputPath & } +void ChartTranslationOptions::SetInputPath(const InputPath *inputPath) +{ + CollType::iterator iter; + for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { + ChartTranslationOption &transOpt = **iter; + transOpt.SetInputPath(inputPath); + } +} + +void ChartTranslationOptions::CreateSourceRuleFromInputPath() +{ + if (m_collection.size() == 0) { + return; + } + + const InputPath *inputPath = m_collection.front()->GetInputPath(); + CHECK(inputPath); + std::vector<const Word*> &ruleSourceFromInputPath = inputPath->AddRuleSourceFromInputPath(); + + size_t chartCellIndex = 0; + const ChartCellLabel *chartCellLabel = (chartCellIndex < m_stackVec.size()) ? m_stackVec[chartCellIndex] : NULL; + + size_t ind = 0; + for (size_t sourcePos = m_wordsRange->GetStartPos(); sourcePos <= m_wordsRange->GetEndPos(); ++sourcePos, ++ind) { + if (chartCellLabel) { + if (sourcePos == chartCellLabel->GetCoverage().GetEndPos()) { + // end of child range. push an empty word to denote non-term + ruleSourceFromInputPath.push_back(NULL); + ++chartCellIndex; + chartCellLabel = (chartCellIndex < m_stackVec.size()) ? m_stackVec[chartCellIndex] : NULL; + } + else if (sourcePos >= chartCellLabel->GetCoverage().GetStartPos()) { + // in the range of child hypo. do nothing + } + else { + // not yet reached child range. add word + ruleSourceFromInputPath.push_back(&inputPath->GetPhrase().GetWord(ind)); + } + } + else { + // no child in sight. add word + ruleSourceFromInputPath.push_back(&inputPath->GetPhrase().GetWord(ind)); + } + } + + // save it to each trans opt + CollType::iterator iter; + for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { + ChartTranslationOption &transOpt = **iter; + transOpt.SetSourceRuleFromInputPath(&ruleSourceFromInputPath); + } + +} + } |