diff --git a/moses/src/CYKPlusParser/ChartRuleLookupManagerMemory.cpp b/moses/src/CYKPlusParser/ChartRuleLookupManagerMemory.cpp index 904d536e1..13362c08b 100644 --- a/moses/src/CYKPlusParser/ChartRuleLookupManagerMemory.cpp +++ b/moses/src/CYKPlusParser/ChartRuleLookupManagerMemory.cpp @@ -76,7 +76,7 @@ void ChartRuleLookupManagerMemory::GetChartRuleCollection( DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()]; const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList(); - const ChartCellLabel &sourceWordLabel = GetCellCollection().Get(WordsRange(absEndPos, absEndPos)).GetSourceWordLabel(); + const ChartCellLabel &sourceWordLabel = GetSourceAt(absEndPos); // loop through the rules // (note that expandableDottedRuleList can be expanded as the loop runs @@ -185,8 +185,7 @@ void ChartRuleLookupManagerMemory::ExtendPartialRuleApplication( GetSentence().GetLabelSet(startPos, endPos); // target non-terminal labels for the remainder - const ChartCellLabelSet &targetNonTerms = - GetCellCollection().Get(WordsRange(startPos, endPos)).GetTargetLabelSet(); + const ChartCellLabelSet &targetNonTerms = GetTargetLabelSet(startPos, endPos); // note where it was found in the prefix tree of the rule dictionary const PhraseDictionaryNodeSCFG &node = prevDottedRule.GetLastNode(); diff --git a/moses/src/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp b/moses/src/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp index e504a24d7..3dc19c4ca 100644 --- a/moses/src/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp +++ b/moses/src/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.cpp @@ -76,8 +76,6 @@ void ChartRuleLookupManagerMemoryPerSentence::GetChartRuleCollection( DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()]; const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList(); - const ChartCellLabel &sourceWordLabel = GetCellCollection().Get(WordsRange(absEndPos, absEndPos)).GetSourceWordLabel(); - // loop through the rules // (note that expandableDottedRuleList can be expanded as the loop runs // through calls to ExtendPartialRuleApplication()) @@ -95,6 +93,7 @@ void ChartRuleLookupManagerMemoryPerSentence::GetChartRuleCollection( // look up in rule dictionary, if the current rule can be extended // with the source word in the last position + const ChartCellLabel &sourceWordLabel = GetSourceAt(absEndPos); const Word &sourceWord = sourceWordLabel.GetLabel(); const PhraseDictionaryNodeSCFG *node = prevDottedRule.GetLastNode().GetChild(sourceWord); @@ -185,8 +184,7 @@ void ChartRuleLookupManagerMemoryPerSentence::ExtendPartialRuleApplication( GetSentence().GetLabelSet(startPos, endPos); // target non-terminal labels for the remainder - const ChartCellLabelSet &targetNonTerms = - GetCellCollection().Get(WordsRange(startPos, endPos)).GetTargetLabelSet(); + const ChartCellLabelSet &targetNonTerms = GetTargetLabelSet(startPos, endPos); // note where it was found in the prefix tree of the rule dictionary const PhraseDictionaryNodeSCFG &node = prevDottedRule.GetLastNode(); diff --git a/moses/src/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp b/moses/src/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp index 08db10472..a3b3906cd 100644 --- a/moses/src/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp +++ b/moses/src/CYKPlusParser/ChartRuleLookupManagerOnDisk.cpp @@ -95,7 +95,7 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( const DottedRuleStackOnDisk::SavedNodeColl &savedNodeColl = expandableDottedRuleList.GetSavedNodeColl(); //cerr << "savedNodeColl=" << savedNodeColl.size() << " "; - const ChartCellLabel &sourceWordLabel = GetCellCollection().Get(WordsRange(absEndPos, absEndPos)).GetSourceWordLabel(); + const ChartCellLabel &sourceWordLabel = GetSourceAt(absEndPos); for (size_t ind = 0; ind < (savedNodeColl.size()) ; ++ind) { const SavedNodeOnDisk &savedNode = *savedNodeColl[ind]; @@ -142,7 +142,7 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( // get target nonterminals in this span from chart const ChartCellLabelSet &chartNonTermSet = - GetCellCollection().Get(WordsRange(startPos, endPos)).GetTargetLabelSet(); + GetTargetLabelSet(startPos, endPos); //const Word &defaultSourceNonTerm = staticData.GetInputDefaultNonTerminal() // ,&defaultTargetNonTerm = staticData.GetOutputDefaultNonTerminal(); diff --git a/moses/src/ChartManager.cpp b/moses/src/ChartManager.cpp index d9a157f34..cd2b9c6a4 100644 --- a/moses/src/ChartManager.cpp +++ b/moses/src/ChartManager.cpp @@ -385,9 +385,6 @@ void ChartManager::ProcessOneUnknownWord(const Word &sourceWord, const WordsRang const UnknownWordPenaltyProducer *unknownWordPenaltyProducer = m_system->GetUnknownWordPenaltyProducer(); vector wordPenaltyScore(1, -0.434294482); // TODO what is this number? - const ChartCell &chartCell = m_hypoStackColl.Get(range); - const ChartCellLabel &sourceWordLabel = chartCell.GetSourceWordLabel(); - size_t isDigit = 0; if (staticData.GetDropUnknown()) { const Factor *f = sourceWord[0]; // TODO hack. shouldn't know which factor is surface diff --git a/moses/src/ChartRuleLookupManager.h b/moses/src/ChartRuleLookupManager.h index 2c17aea19..2fa7305ef 100644 --- a/moses/src/ChartRuleLookupManager.h +++ b/moses/src/ChartRuleLookupManager.h @@ -51,9 +51,12 @@ public: return m_sentence; } - //! all the chart cells - const ChartCellCollection &GetCellCollection() const { - return m_cellCollection; + const ChartCellLabelSet &GetTargetLabelSet(size_t begin, size_t end) const { + return m_cellCollection.Get(WordsRange(begin, end)).GetTargetLabelSet(); + } + + const ChartCellLabel &GetSourceAt(size_t at) const { + return m_cellCollection.Get(WordsRange(at, at)).GetSourceWordLabel(); } /** abstract function. Return a vector of translation options for given a range in the input sentence diff --git a/moses/src/Scope3Parser/Parser.cpp b/moses/src/Scope3Parser/Parser.cpp index 54ab77236..681a96aa5 100644 --- a/moses/src/Scope3Parser/Parser.cpp +++ b/moses/src/Scope3Parser/Parser.cpp @@ -61,7 +61,7 @@ void Scope3Parser::GetChartRuleCollection( } else { // Rule has at least one non-terminal. varSpanNode.CalculateRanges(start, end, m_ranges); m_latticeBuilder.Build(start, end, ruleNode, varSpanNode, m_ranges, - this->GetCellCollection(), m_lattice, + *this, m_lattice, m_quickCheckTable); StackLatticeSearcher searcher(m_lattice, m_ranges); UTrieNode::LabelMap::const_iterator p = labelMap.begin(); diff --git a/moses/src/Scope3Parser/StackLatticeBuilder.cpp b/moses/src/Scope3Parser/StackLatticeBuilder.cpp index 4a41922d0..711b08a23 100644 --- a/moses/src/Scope3Parser/StackLatticeBuilder.cpp +++ b/moses/src/Scope3Parser/StackLatticeBuilder.cpp @@ -19,8 +19,7 @@ #include "StackLatticeBuilder.h" -#include "ChartCell.h" -#include "ChartCellCollection.h" +#include "ChartRuleLookupManager.h" #include "RuleTable/UTrieNode.h" #include "Scope3Parser/StackLattice.h" #include "Scope3Parser/VarSpanNode.h" @@ -34,7 +33,7 @@ void StackLatticeBuilder::Build( const UTrieNode &ruleNode, const VarSpanNode &varSpanNode, const std::vector &ranges, - const ChartCellCollection &chartCellColl, + const ChartRuleLookupManager &manager, StackLattice &lattice, std::vector > &checkTable) { @@ -75,14 +74,12 @@ void StackLatticeBuilder::Build( StackVec &stackVec = lattice[offset][index][span]; stackVec.clear(); stackVec.reserve(labelVec.size()); - const WordsRange range(start+offset, start+offset+span-1); - const ChartCell &chartCell = chartCellColl.Get(range); std::vector::iterator q = checkTable[index].begin(); for (std::vector::const_iterator p = labelVec.begin(); p != labelVec.end(); ++p) { const Word &label = *p; - const ChartCellLabel *stack = chartCell.GetTargetLabelSet().Find(label); - stackVec.push_back(chartCell.GetTargetLabelSet().Find(label)); + const ChartCellLabel *stack = manager.GetTargetLabelSet(start+offset, start+offset+span-1).Find(label); + stackVec.push_back(stack); *q++ = *q || static_cast(stack); } } diff --git a/moses/src/Scope3Parser/StackLatticeBuilder.h b/moses/src/Scope3Parser/StackLatticeBuilder.h index f17051dc2..5a8a988ba 100644 --- a/moses/src/Scope3Parser/StackLatticeBuilder.h +++ b/moses/src/Scope3Parser/StackLatticeBuilder.h @@ -37,7 +37,7 @@ class StackLatticeBuilder void Build(int, int, const UTrieNode &, const VarSpanNode &, const std::vector &, - const ChartCellCollection &, StackLattice &, + const ChartRuleLookupManager &, StackLattice &, std::vector > &); };