// initialise the RuleCube by creating the top-left corner item RuleCube::RuleCube(const ChartTranslationOptions &transOpt, const ChartCellCollection &allChartCells, ChartManager &manager) : m_transOpt(transOpt) { RuleCubeItem *item = new RuleCubeItem(transOpt, allChartCells); m_covered.insert(item); if (StaticData::Instance().GetCubePruningLazyScoring()) { item->EstimateScore(); } else { item->CreateHypothesis(transOpt, manager); } m_queue.push(item); }
void RuleCube::CreateNeighbor(const RuleCubeItem &item, int dimensionIndex, ChartManager &manager) { RuleCubeItem *newItem = new RuleCubeItem(item, dimensionIndex); std::pair<ItemSet::iterator, bool> result = m_covered.insert(newItem); if (!result.second) { delete newItem; // already seen it } else { if (StaticData::Instance().GetCubePruningLazyScoring()) { newItem->EstimateScore(); } else { newItem->CreateHypothesis(m_transOpt, manager); } m_queue.push(newItem); } }
// create new RuleCube for neighboring principle rules void RuleCube::CreateNeighbors(const RuleCubeItem &item, ChartManager &manager) { // create neighbor along translation dimension const TranslationDimension &translationDimension = item.GetTranslationDimension(); if (translationDimension.HasMoreTranslations()) { CreateNeighbor(item, -1, manager); } // create neighbors along all hypothesis dimensions for (size_t i = 0; i < item.GetHypothesisDimensions().size(); ++i) { const HypothesisDimension &dimension = item.GetHypothesisDimensions()[i]; if (dimension.HasMoreHypo()) { CreateNeighbor(item, i, manager); } } }
ChartHypothesis *RuleCubeQueue::Pop() { // pop the most promising rule cube RuleCube *cube = m_queue.top(); m_queue.pop(); // pop the most promising item from the cube and get the corresponding // hypothesis RuleCubeItem *item = cube->Pop(m_manager); if (m_manager.options()->cube.lazy_scoring) { item->CreateHypothesis(cube->GetTranslationOption(), m_manager); } ChartHypothesis *hypo = item->ReleaseHypothesis(); // if the cube contains more items then push it back onto the queue if (!cube->IsEmpty()) { m_queue.push(cube); } else { delete cube; } return hypo; }