Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Sennrich <rico.sennrich@gmx.ch>2014-12-01 14:05:17 +0300
committerRico Sennrich <rico.sennrich@gmx.ch>2014-12-01 14:05:17 +0300
commit56921cae3b1f0a807b137152573db6a27cc2369f (patch)
tree52f460325e725bab3c02f247d247a1d9dcb47fe4
parent46e7aebce49d4f769c41e144472dd6c6c7881b62 (diff)
small simplification of recursive CYK+
(following Chris Dyer's suggestion and Phil's refactoring in S2T decoder)
-rw-r--r--moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemory.cpp19
-rw-r--r--moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp19
2 files changed, 8 insertions, 30 deletions
diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemory.cpp b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemory.cpp
index ac6522ef5..f229a0f4b 100644
--- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemory.cpp
+++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemory.cpp
@@ -70,24 +70,13 @@ void ChartRuleLookupManagerMemory::GetChartRuleCollection(
const PhraseDictionaryNodeMemory &rootNode = m_ruleTable.GetRootNode();
- // size-1 terminal rules
+ // all rules starting with terminal
if (startPos == absEndPos) {
- const Word &sourceWord = GetSourceAt(absEndPos).GetLabel();
- const PhraseDictionaryNodeMemory *child = rootNode.GetChild(sourceWord);
-
- // if we found a new rule -> directly add it to the out collection
- if (child != NULL) {
- const TargetPhraseCollection &tpc = child->GetTargetPhraseCollection();
- outColl.Add(tpc, m_stackVec, range);
- }
+ GetTerminalExtension(&rootNode, startPos);
}
// all rules starting with nonterminal
else if (absEndPos > startPos) {
GetNonTerminalExtension(&rootNode, startPos);
- // all (non-unary) rules starting with terminal
- if (absEndPos == startPos+1) {
- GetTerminalExtension(&rootNode, absEndPos-1);
- }
}
// copy temporarily stored rules to out collection
@@ -177,8 +166,8 @@ void ChartRuleLookupManagerMemory::AddAndExtend(
size_t endPos) {
const TargetPhraseCollection &tpc = node->GetTargetPhraseCollection();
- // add target phrase collection (except if rule is empty or unary)
- if (!tpc.IsEmpty() && endPos != m_unaryPos) {
+ // add target phrase collection (except if rule is empty or a unary non-terminal rule)
+ if (!tpc.IsEmpty() && (m_stackVec.empty() || endPos != m_unaryPos)) {
m_completedRules[endPos].Add(tpc, m_stackVec, m_stackScores, *m_outColl);
}
diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp
index 784d31deb..23d357f10 100644
--- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp
+++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp
@@ -70,24 +70,13 @@ void ChartRuleLookupManagerMemoryPerSentence::GetChartRuleCollection(
const PhraseDictionaryNodeMemory &rootNode = m_ruleTable.GetRootNode(GetParser().GetTranslationId());
- // size-1 terminal rules
+ // all rules starting with terminal
if (startPos == absEndPos) {
- const Word &sourceWord = GetSourceAt(absEndPos).GetLabel();
- const PhraseDictionaryNodeMemory *child = rootNode.GetChild(sourceWord);
-
- // if we found a new rule -> directly add it to the out collection
- if (child != NULL) {
- const TargetPhraseCollection &tpc = child->GetTargetPhraseCollection();
- outColl.Add(tpc, m_stackVec, range);
- }
+ GetTerminalExtension(&rootNode, startPos);
}
// all rules starting with nonterminal
else if (absEndPos > startPos) {
GetNonTerminalExtension(&rootNode, startPos);
- // all (non-unary) rules starting with terminal
- if (absEndPos == startPos+1) {
- GetTerminalExtension(&rootNode, absEndPos-1);
- }
}
// copy temporarily stored rules to out collection
@@ -177,8 +166,8 @@ void ChartRuleLookupManagerMemoryPerSentence::AddAndExtend(
size_t endPos) {
const TargetPhraseCollection &tpc = node->GetTargetPhraseCollection();
- // add target phrase collection (except if rule is empty or unary)
- if (!tpc.IsEmpty() && endPos != m_unaryPos) {
+ // add target phrase collection (except if rule is empty or a unary non-terminal rule)
+ if (!tpc.IsEmpty() && (m_stackVec.empty() || endPos != m_unaryPos)) {
m_completedRules[endPos].Add(tpc, m_stackVec, m_stackScores, *m_outColl);
}