Restrict access to ChartCell

This commit is contained in:
Kenneth Heafield 2012-10-02 13:27:02 +01:00
parent b7a280064e
commit 60f725f604
8 changed files with 18 additions and 24 deletions

View File

@ -76,7 +76,7 @@ void ChartRuleLookupManagerMemory::GetChartRuleCollection(
DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()]; DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()];
const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList(); const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList();
const ChartCellLabel &sourceWordLabel = GetCellCollection().Get(WordsRange(absEndPos, absEndPos)).GetSourceWordLabel(); const ChartCellLabel &sourceWordLabel = GetSourceAt(absEndPos);
// loop through the rules // loop through the rules
// (note that expandableDottedRuleList can be expanded as the loop runs // (note that expandableDottedRuleList can be expanded as the loop runs
@ -185,8 +185,7 @@ void ChartRuleLookupManagerMemory::ExtendPartialRuleApplication(
GetSentence().GetLabelSet(startPos, endPos); GetSentence().GetLabelSet(startPos, endPos);
// target non-terminal labels for the remainder // target non-terminal labels for the remainder
const ChartCellLabelSet &targetNonTerms = const ChartCellLabelSet &targetNonTerms = GetTargetLabelSet(startPos, endPos);
GetCellCollection().Get(WordsRange(startPos, endPos)).GetTargetLabelSet();
// note where it was found in the prefix tree of the rule dictionary // note where it was found in the prefix tree of the rule dictionary
const PhraseDictionaryNodeSCFG &node = prevDottedRule.GetLastNode(); const PhraseDictionaryNodeSCFG &node = prevDottedRule.GetLastNode();

View File

@ -76,8 +76,6 @@ void ChartRuleLookupManagerMemoryPerSentence::GetChartRuleCollection(
DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()]; DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()];
const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList(); const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList();
const ChartCellLabel &sourceWordLabel = GetCellCollection().Get(WordsRange(absEndPos, absEndPos)).GetSourceWordLabel();
// loop through the rules // loop through the rules
// (note that expandableDottedRuleList can be expanded as the loop runs // (note that expandableDottedRuleList can be expanded as the loop runs
// through calls to ExtendPartialRuleApplication()) // through calls to ExtendPartialRuleApplication())
@ -95,6 +93,7 @@ void ChartRuleLookupManagerMemoryPerSentence::GetChartRuleCollection(
// look up in rule dictionary, if the current rule can be extended // look up in rule dictionary, if the current rule can be extended
// with the source word in the last position // with the source word in the last position
const ChartCellLabel &sourceWordLabel = GetSourceAt(absEndPos);
const Word &sourceWord = sourceWordLabel.GetLabel(); const Word &sourceWord = sourceWordLabel.GetLabel();
const PhraseDictionaryNodeSCFG *node = prevDottedRule.GetLastNode().GetChild(sourceWord); const PhraseDictionaryNodeSCFG *node = prevDottedRule.GetLastNode().GetChild(sourceWord);
@ -185,8 +184,7 @@ void ChartRuleLookupManagerMemoryPerSentence::ExtendPartialRuleApplication(
GetSentence().GetLabelSet(startPos, endPos); GetSentence().GetLabelSet(startPos, endPos);
// target non-terminal labels for the remainder // target non-terminal labels for the remainder
const ChartCellLabelSet &targetNonTerms = const ChartCellLabelSet &targetNonTerms = GetTargetLabelSet(startPos, endPos);
GetCellCollection().Get(WordsRange(startPos, endPos)).GetTargetLabelSet();
// note where it was found in the prefix tree of the rule dictionary // note where it was found in the prefix tree of the rule dictionary
const PhraseDictionaryNodeSCFG &node = prevDottedRule.GetLastNode(); const PhraseDictionaryNodeSCFG &node = prevDottedRule.GetLastNode();

View File

@ -95,7 +95,7 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection(
const DottedRuleStackOnDisk::SavedNodeColl &savedNodeColl = expandableDottedRuleList.GetSavedNodeColl(); const DottedRuleStackOnDisk::SavedNodeColl &savedNodeColl = expandableDottedRuleList.GetSavedNodeColl();
//cerr << "savedNodeColl=" << savedNodeColl.size() << " "; //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) { for (size_t ind = 0; ind < (savedNodeColl.size()) ; ++ind) {
const SavedNodeOnDisk &savedNode = *savedNodeColl[ind]; const SavedNodeOnDisk &savedNode = *savedNodeColl[ind];
@ -142,7 +142,7 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection(
// get target nonterminals in this span from chart // get target nonterminals in this span from chart
const ChartCellLabelSet &chartNonTermSet = const ChartCellLabelSet &chartNonTermSet =
GetCellCollection().Get(WordsRange(startPos, endPos)).GetTargetLabelSet(); GetTargetLabelSet(startPos, endPos);
//const Word &defaultSourceNonTerm = staticData.GetInputDefaultNonTerminal() //const Word &defaultSourceNonTerm = staticData.GetInputDefaultNonTerminal()
// ,&defaultTargetNonTerm = staticData.GetOutputDefaultNonTerminal(); // ,&defaultTargetNonTerm = staticData.GetOutputDefaultNonTerminal();

View File

@ -385,9 +385,6 @@ void ChartManager::ProcessOneUnknownWord(const Word &sourceWord, const WordsRang
const UnknownWordPenaltyProducer *unknownWordPenaltyProducer = m_system->GetUnknownWordPenaltyProducer(); const UnknownWordPenaltyProducer *unknownWordPenaltyProducer = m_system->GetUnknownWordPenaltyProducer();
vector<float> wordPenaltyScore(1, -0.434294482); // TODO what is this number? vector<float> 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; size_t isDigit = 0;
if (staticData.GetDropUnknown()) { if (staticData.GetDropUnknown()) {
const Factor *f = sourceWord[0]; // TODO hack. shouldn't know which factor is surface const Factor *f = sourceWord[0]; // TODO hack. shouldn't know which factor is surface

View File

@ -51,9 +51,12 @@ public:
return m_sentence; return m_sentence;
} }
//! all the chart cells const ChartCellLabelSet &GetTargetLabelSet(size_t begin, size_t end) const {
const ChartCellCollection &GetCellCollection() const { return m_cellCollection.Get(WordsRange(begin, end)).GetTargetLabelSet();
return m_cellCollection; }
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 /** abstract function. Return a vector of translation options for given a range in the input sentence

View File

@ -61,7 +61,7 @@ void Scope3Parser::GetChartRuleCollection(
} else { // Rule has at least one non-terminal. } else { // Rule has at least one non-terminal.
varSpanNode.CalculateRanges(start, end, m_ranges); varSpanNode.CalculateRanges(start, end, m_ranges);
m_latticeBuilder.Build(start, end, ruleNode, varSpanNode, m_ranges, m_latticeBuilder.Build(start, end, ruleNode, varSpanNode, m_ranges,
this->GetCellCollection(), m_lattice, *this, m_lattice,
m_quickCheckTable); m_quickCheckTable);
StackLatticeSearcher<MatchCallback> searcher(m_lattice, m_ranges); StackLatticeSearcher<MatchCallback> searcher(m_lattice, m_ranges);
UTrieNode::LabelMap::const_iterator p = labelMap.begin(); UTrieNode::LabelMap::const_iterator p = labelMap.begin();

View File

@ -19,8 +19,7 @@
#include "StackLatticeBuilder.h" #include "StackLatticeBuilder.h"
#include "ChartCell.h" #include "ChartRuleLookupManager.h"
#include "ChartCellCollection.h"
#include "RuleTable/UTrieNode.h" #include "RuleTable/UTrieNode.h"
#include "Scope3Parser/StackLattice.h" #include "Scope3Parser/StackLattice.h"
#include "Scope3Parser/VarSpanNode.h" #include "Scope3Parser/VarSpanNode.h"
@ -34,7 +33,7 @@ void StackLatticeBuilder::Build(
const UTrieNode &ruleNode, const UTrieNode &ruleNode,
const VarSpanNode &varSpanNode, const VarSpanNode &varSpanNode,
const std::vector<VarSpanNode::NonTermRange> &ranges, const std::vector<VarSpanNode::NonTermRange> &ranges,
const ChartCellCollection &chartCellColl, const ChartRuleLookupManager &manager,
StackLattice &lattice, StackLattice &lattice,
std::vector<std::vector<bool> > &checkTable) std::vector<std::vector<bool> > &checkTable)
{ {
@ -75,14 +74,12 @@ void StackLatticeBuilder::Build(
StackVec &stackVec = lattice[offset][index][span]; StackVec &stackVec = lattice[offset][index][span];
stackVec.clear(); stackVec.clear();
stackVec.reserve(labelVec.size()); stackVec.reserve(labelVec.size());
const WordsRange range(start+offset, start+offset+span-1);
const ChartCell &chartCell = chartCellColl.Get(range);
std::vector<bool>::iterator q = checkTable[index].begin(); std::vector<bool>::iterator q = checkTable[index].begin();
for (std::vector<Word>::const_iterator p = labelVec.begin(); for (std::vector<Word>::const_iterator p = labelVec.begin();
p != labelVec.end(); ++p) { p != labelVec.end(); ++p) {
const Word &label = *p; const Word &label = *p;
const ChartCellLabel *stack = chartCell.GetTargetLabelSet().Find(label); const ChartCellLabel *stack = manager.GetTargetLabelSet(start+offset, start+offset+span-1).Find(label);
stackVec.push_back(chartCell.GetTargetLabelSet().Find(label)); stackVec.push_back(stack);
*q++ = *q || static_cast<bool>(stack); *q++ = *q || static_cast<bool>(stack);
} }
} }

View File

@ -37,7 +37,7 @@ class StackLatticeBuilder
void Build(int, int, const UTrieNode &, const VarSpanNode &, void Build(int, int, const UTrieNode &, const VarSpanNode &,
const std::vector<VarSpanNode::NonTermRange> &, const std::vector<VarSpanNode::NonTermRange> &,
const ChartCellCollection &, StackLattice &, const ChartRuleLookupManager &, StackLattice &,
std::vector<std::vector<bool> > &); std::vector<std::vector<bool> > &);
}; };