void ChartRuleLookupManagerCYKPlus::AddCompletedRule( const DottedRule &dottedRule, const TargetPhraseCollection &tpc, const WordsRange &range, ChartParserCallback &outColl) { // Determine the rule's rank. size_t rank = 0; const DottedRule *node = &dottedRule; while (!node->IsRoot()) { if (node->IsNonTerminal()) { ++rank; } node = node->GetPrev(); } // Fill m_stackVec with a stack pointer for each non-terminal. m_stackVec.resize(rank); node = &dottedRule; while (rank > 0) { if (node->IsNonTerminal()) { m_stackVec[--rank] = &node->GetChartCellLabel(); } node = node->GetPrev(); } // Add the (TargetPhraseCollection, StackVec) pair to the collection. outColl.Add(tpc, m_stackVec, range); }
void ChartRuleLookupManagerMemoryPerSentence::GetChartRuleCollection( const InputPath &inputPath, size_t lastPos, ChartParserCallback &outColl) { const Range &range = inputPath.GetWordsRange(); size_t startPos = range.GetStartPos(); size_t absEndPos = range.GetEndPos(); m_lastPos = lastPos; m_stackVec.clear(); m_stackScores.clear(); m_outColl = &outColl; m_unaryPos = absEndPos-1; // rules ending in this position are unary and should not be added to collection // create/update data structure to quickly look up all chart cells that match start position and label. UpdateCompressedMatrix(startPos, absEndPos, lastPos); const PhraseDictionaryNodeMemory &rootNode = m_ruleTable.GetRootNode(GetParser().GetTranslationId()); // all rules starting with terminal if (startPos == absEndPos) { GetTerminalExtension(&rootNode, startPos); } // all rules starting with nonterminal else if (absEndPos > startPos) { GetNonTerminalExtension(&rootNode, startPos); } // copy temporarily stored rules to out collection CompletedRuleCollection & rules = m_completedRules[absEndPos]; for (vector<CompletedRule*>::const_iterator iter = rules.begin(); iter != rules.end(); ++iter) { outColl.Add((*iter)->GetTPC(), (*iter)->GetStackVector(), range); } rules.Clear(); }