void PhraseDictionaryMemory:: GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const { InputPathList::const_iterator iter; for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) { InputPath &node = **iter; const Phrase &phrase = node.GetPhrase(); const InputPath *prevPath = node.GetPrevPath(); const PhraseDictionaryNodeMemory *prevPtNode = NULL; if (prevPath) { prevPtNode = static_cast<const PhraseDictionaryNodeMemory*>(prevPath->GetPtNode(*this)); } else { // Starting subphrase. assert(phrase.GetSize() == 1); prevPtNode = &GetRootNode(); } if (prevPtNode) { Word lastWord = phrase.GetWord(phrase.GetSize() - 1); lastWord.OnlyTheseFactors(m_inputFactors); const PhraseDictionaryNodeMemory *ptNode = prevPtNode->GetChild(lastWord); if (ptNode) { const TargetPhraseCollection &targetPhrases = ptNode->GetTargetPhraseCollection(); node.SetTargetPhrases(*this, &targetPhrases, ptNode); } else { node.SetTargetPhrases(*this, NULL, NULL); } } } }
void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const { InputPathList::const_iterator iter; for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) { InputPath &inputPath = **iter; GetTargetPhraseCollectionBatch(inputPath); } }
void PhraseDictionary::GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const { InputPathList::const_iterator iter; for (iter = phraseDictionaryQueue.begin(); iter != phraseDictionaryQueue.end(); ++iter) { InputPath &node = **iter; const Phrase &phrase = node.GetPhrase(); const TargetPhraseCollection *targetPhrases = this->GetTargetPhraseCollectionLEGACY(phrase); node.SetTargetPhrases(*this, targetPhrases, NULL); } }
void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const { OnDiskPt::OnDiskWrapper &wrapper = const_cast<OnDiskPt::OnDiskWrapper&>(GetImplementation()); InputPathList::const_iterator iter; for (iter = phraseDictionaryQueue.begin(); iter != phraseDictionaryQueue.end(); ++iter) { InputPath &node = **iter; const Phrase &phrase = node.GetPhrase(); const InputPath *prevNode = node.GetPrevNode(); const OnDiskPt::PhraseNode *prevPtNode = NULL; if (prevNode) { prevPtNode = static_cast<const OnDiskPt::PhraseNode*>(prevNode->GetPtNode(*this)); } else { // Starting subphrase. assert(phrase.GetSize() == 1); prevPtNode = &wrapper.GetRootSourceNode(); } if (prevPtNode) { Word lastWord = phrase.GetWord(phrase.GetSize() - 1); lastWord.OnlyTheseFactors(m_inputFactors); OnDiskPt::Word *lastWordOnDisk = wrapper.ConvertFromMoses(m_input, lastWord); if (lastWordOnDisk == NULL) { // OOV according to this phrase table. Not possible to extend node.SetTargetPhrases(*this, NULL, NULL); } else { const OnDiskPt::PhraseNode *ptNode = prevPtNode->GetChild(*lastWordOnDisk, wrapper); if (ptNode) { vector<float> weightT = StaticData::Instance().GetWeights(this); OnDiskPt::Vocab &vocab = wrapper.GetVocab(); const OnDiskPt::TargetPhraseCollection *targetPhrasesOnDisk = ptNode->GetTargetPhraseCollection(m_tableLimit, wrapper); TargetPhraseCollection *targetPhrases = targetPhrasesOnDisk->ConvertToMoses(m_input, m_output, *this, weightT, vocab, false); node.SetTargetPhrases(*this, targetPhrases, ptNode); delete targetPhrasesOnDisk; } else { node.SetTargetPhrases(*this, NULL, NULL); } delete lastWordOnDisk; } } } }
void SkeletonPT::GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const { InputPathList::const_iterator iter; for (iter = phraseDictionaryQueue.begin(); iter != phraseDictionaryQueue.end(); ++iter) { InputPath &inputPath = **iter; TargetPhrase *tp = CreateTargetPhrase(inputPath.GetPhrase()); TargetPhraseCollection *tpColl = new TargetPhraseCollection(); tpColl->Add(tp); m_allTPColl.push_back(tpColl); inputPath.SetTargetPhrases(*this, tpColl, NULL); } }
void PhraseDictionaryOnDisk::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const { InputPathList::const_iterator iter; for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) { InputPath &inputPath = **iter; GetTargetPhraseCollectionBatch(inputPath); } // delete nodes that's been saved for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) { InputPath &inputPath = **iter; const OnDiskPt::PhraseNode *ptNode = static_cast<const OnDiskPt::PhraseNode*>(inputPath.GetPtNode(*this)); delete ptNode; } }
void PhraseDictionaryTransliteration::GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const { InputPathList::const_iterator iter; for (iter = inputPathQueue.begin(); iter != inputPathQueue.end(); ++iter) { InputPath &inputPath = **iter; if (!SatisfyBackoff(inputPath)) { continue; } const Phrase &sourcePhrase = inputPath.GetPhrase(); if (sourcePhrase.GetSize() != 1) { // only translit single words. A limitation of the translit script continue; } GetTargetPhraseCollection(inputPath); } }
//Find top n translations of source, and send them to output static void outputTopN(const StringPiece& sourcePhraseString, PhraseDictionary* phraseTable, const std::vector<FactorType> &input, ostream& out) { //get list of target phrases Phrase sourcePhrase; sourcePhrase.CreateFromString(Input,input,sourcePhraseString,NULL); InputPath inputPath(sourcePhrase, NonTerminalSet(), WordsRange(0,sourcePhrase.GetSize()-1),NULL,NULL); InputPathList inputPaths; inputPaths.push_back(&inputPath); phraseTable->GetTargetPhraseCollectionBatch(inputPaths); const TargetPhraseCollection* targetPhrases = inputPath.GetTargetPhrases(*phraseTable); //print phrases const std::vector<FactorType>& output = StaticData::Instance().GetOutputFactorOrder(); if (targetPhrases) { //if (targetPhrases->GetSize() > 10) cerr << "src " << sourcePhrase << " tgt count " << targetPhrases->GetSize() << endl; for (TargetPhraseCollection::const_iterator i = targetPhrases->begin(); i != targetPhrases->end(); ++i) { const TargetPhrase* targetPhrase = *i; out << sourcePhrase.GetStringRep(input); out << " ||| "; out << targetPhrase->GetStringRep(output); out << " ||| "; const ScoreComponentCollection scores = targetPhrase->GetScoreBreakdown(); vector<float> phraseScores = scores.GetScoresForProducer(phraseTable); for (size_t j = 0; j < phraseScores.size(); ++j) { out << exp(phraseScores[j]) << " "; } out << "||| "; const AlignmentInfo& align = targetPhrase->GetAlignTerm(); for (AlignmentInfo::const_iterator j = align.begin(); j != align.end(); ++j) { out << j->first << "-" << j->second << " "; } out << endl; } } }