bool PhraseDictionaryTransliteration::SatisfyBackoff(const InputPath &inputPath) const { const Phrase &sourcePhrase = inputPath.GetPhrase(); assert(m_container); const DecodeGraph *decodeGraph = m_container->GetContainer(); size_t backoff = decodeGraph->GetBackoff(); if (backoff == 0) { // ie. don't backoff. Collect ALL translations return true; } if (sourcePhrase.GetSize() > backoff) { // source phrase too big return false; } // lookup translation only if no other translations InputPath::TargetPhrases::const_iterator iter; for (iter = inputPath.GetTargetPhrases().begin(); iter != inputPath.GetTargetPhrases().end(); ++iter) { const std::pair<const TargetPhraseCollection*, const void*> &temp = iter->second; const TargetPhraseCollection *tpCollPrev = temp.first; if (tpCollPrev && tpCollPrev->GetSize()) { // already have translation from another pt. Don't create translations return false; } } return true; }
void TranslationOptionCollection::CreateTranslationOptionsForRange( const DecodeGraph &decodeGraph , size_t startPos , size_t endPos , bool adhereTableLimit , size_t graphInd , InputPath &inputPath) { if ((StaticData::Instance().GetXmlInputType() != XmlExclusive) || !HasXmlOptionsOverlappingRange(startPos,endPos)) { // partial trans opt stored in here PartialTranslOptColl* oldPtoc = new PartialTranslOptColl; size_t totalEarlyPruned = 0; // initial translation step list <const DecodeStep* >::const_iterator iterStep = decodeGraph.begin(); const DecodeStep &decodeStep = **iterStep; const PhraseDictionary &phraseDictionary = *decodeStep.GetPhraseDictionaryFeature(); const TargetPhraseCollection *targetPhrases = inputPath.GetTargetPhrases(phraseDictionary); static_cast<const DecodeStepTranslation&>(decodeStep).ProcessInitialTranslation (m_source, *oldPtoc , startPos, endPos, adhereTableLimit , inputPath, targetPhrases); SetInputScore(inputPath, *oldPtoc); // do rest of decode steps int indexStep = 0; for (++iterStep ; iterStep != decodeGraph.end() ; ++iterStep) { const DecodeStep *decodeStep = *iterStep; PartialTranslOptColl* newPtoc = new PartialTranslOptColl; // go thru each intermediate trans opt just created const vector<TranslationOption*>& partTransOptList = oldPtoc->GetList(); vector<TranslationOption*>::const_iterator iterPartialTranslOpt; for (iterPartialTranslOpt = partTransOptList.begin() ; iterPartialTranslOpt != partTransOptList.end() ; ++iterPartialTranslOpt) { TranslationOption &inputPartialTranslOpt = **iterPartialTranslOpt; if (const DecodeStepTranslation *translateStep = dynamic_cast<const DecodeStepTranslation*>(decodeStep) ) { const PhraseDictionary &phraseDictionary = *translateStep->GetPhraseDictionaryFeature(); const TargetPhraseCollection *targetPhrases = inputPath.GetTargetPhrases(phraseDictionary); translateStep->Process(inputPartialTranslOpt , *decodeStep , *newPtoc , this , adhereTableLimit , targetPhrases); } else { const DecodeStepGeneration *genStep = dynamic_cast<const DecodeStepGeneration*>(decodeStep); assert(genStep); genStep->Process(inputPartialTranslOpt , *decodeStep , *newPtoc , this , adhereTableLimit); } } // last but 1 partial trans not required anymore totalEarlyPruned += newPtoc->GetPrunedCount(); delete oldPtoc; oldPtoc = newPtoc; indexStep++; } // for (++iterStep // add to fully formed translation option list PartialTranslOptColl &lastPartialTranslOptColl = *oldPtoc; const vector<TranslationOption*>& partTransOptList = lastPartialTranslOptColl.GetList(); vector<TranslationOption*>::const_iterator iterColl; for (iterColl = partTransOptList.begin() ; iterColl != partTransOptList.end() ; ++iterColl) { TranslationOption *transOpt = *iterColl; if (StaticData::Instance().GetXmlInputType() != XmlConstraint || !ViolatesXmlOptionsConstraint(startPos,endPos,transOpt)) { Add(transOpt); } } lastPartialTranslOptColl.DetachAll(); totalEarlyPruned += oldPtoc->GetPrunedCount(); delete oldPtoc; // TRACE_ERR( "Early translation options pruned: " << totalEarlyPruned << endl); } // if ((StaticData::Instance().GetXmlInputType() != XmlExclusive) || !HasXmlOptionsOverlappingRange(startPos,endPos)) if (graphInd == 0 && StaticData::Instance().GetXmlInputType() != XmlPassThrough && HasXmlOptionsOverlappingRange(startPos,endPos)) { CreateXmlOptionsForRange(startPos, endPos); } }