/** * Create xml-based translation options for the specific input span */ void TranslationOptionCollectionText::CreateXmlOptionsForRange(size_t startPos, size_t endPos) { Sentence const& source=dynamic_cast<Sentence const&>(m_source); InputPath &inputPath = GetInputPath(startPos,endPos); vector <TranslationOption*> xmlOptions; source.GetXmlTranslationOptions(xmlOptions,startPos,endPos); //get vector of TranslationOptions from Sentence for(size_t i=0; i<xmlOptions.size(); i++) { TranslationOption *transOpt = xmlOptions[i]; transOpt->SetInputPath(inputPath); Add(transOpt); } };
void TranslationOptionCollectionLattice::CreateTranslationOptions() { GetTargetPhraseCollectionBatch(); VERBOSE(2,"Translation Option Collection\n " << *this << endl); const vector <DecodeGraph*> &decodeGraphs = StaticData::Instance().GetDecodeGraphs(); UTIL_THROW_IF2(decodeGraphs.size() != 1, "Multiple decoder graphs not supported yet"); const DecodeGraph &decodeGraph = *decodeGraphs[0]; UTIL_THROW_IF2(decodeGraph.GetSize() != 1, "Factored decomposition not supported yet"); const DecodeStep &decodeStep = **decodeGraph.begin(); const PhraseDictionary &phraseDictionary = *decodeStep.GetPhraseDictionaryFeature(); for (size_t i = 0; i < m_inputPathQueue.size(); ++i) { const InputPath &path = *m_inputPathQueue[i]; const TargetPhraseCollection *tpColl = path.GetTargetPhrases(phraseDictionary); const WordsRange &range = path.GetWordsRange(); if (tpColl) { TargetPhraseCollection::const_iterator iter; for (iter = tpColl->begin(); iter != tpColl->end(); ++iter) { const TargetPhrase &tp = **iter; TranslationOption *transOpt = new TranslationOption(range, tp); transOpt->SetInputPath(path); transOpt->Evaluate(m_source); Add(transOpt); } } else if (path.GetPhrase().GetSize() == 1) { // unknown word processing ProcessOneUnknownWord(path, path.GetWordsRange().GetEndPos(), 1, path.GetInputScore()); } } // Prune Prune(); Sort(); // future score matrix CalcFutureScore(); // Cached lex reodering costs CacheLexReordering(); }
void DecodeStepGeneration::Process(const TranslationOption &inputPartialTranslOpt , const DecodeStep &decodeStep , PartialTranslOptColl &outputPartialTranslOptColl , TranslationOptionCollection * /* toc */ , bool /*adhereTableLimit*/) const { if (inputPartialTranslOpt.GetTargetPhrase().GetSize() == 0) { // word deletion TranslationOption *newTransOpt = new TranslationOption(inputPartialTranslOpt); outputPartialTranslOptColl.Add(newTransOpt); return; } // normal generation step const GenerationDictionary* generationDictionary = decodeStep.GetGenerationDictionaryFeature(); const Phrase &targetPhrase = inputPartialTranslOpt.GetTargetPhrase(); const InputPath &inputPath = inputPartialTranslOpt.GetInputPath(); size_t targetLength = targetPhrase.GetSize(); // generation list for each word in phrase vector< WordList > wordListVector(targetLength); // create generation list int wordListVectorPos = 0; for (size_t currPos = 0 ; currPos < targetLength ; currPos++) { // going thorugh all words // generatable factors for this word to be put in wordList WordList &wordList = wordListVector[wordListVectorPos]; const Word &word = targetPhrase.GetWord(currPos); // consult dictionary for possible generations for this word const OutputWordCollection *wordColl = generationDictionary->FindWord(word); if (wordColl == NULL) { // word not found in generation dictionary //toc->ProcessUnknownWord(sourceWordsRange.GetStartPos(), factorCollection); return; // can't be part of a phrase, special handling } else { // sort(*wordColl, CompareWordCollScore); OutputWordCollection::const_iterator iterWordColl; for (iterWordColl = wordColl->begin() ; iterWordColl != wordColl->end(); ++iterWordColl) { const Word &outputWord = (*iterWordColl).first; const ScoreComponentCollection& score = (*iterWordColl).second; // enter into word list generated factor(s) and its(their) score(s) wordList.push_back(WordPair(outputWord, score)); } wordListVectorPos++; // done, next word } } // use generation list (wordList) // set up iterators (total number of expansions) size_t numIteration = 1; vector< WordListIterator > wordListIterVector(targetLength); vector< const Word* > mergeWords(targetLength); for (size_t currPos = 0 ; currPos < targetLength ; currPos++) { wordListIterVector[currPos] = wordListVector[currPos].begin(); numIteration *= wordListVector[currPos].size(); } // go thru each possible factor for each word & create hypothesis for (size_t currIter = 0 ; currIter < numIteration ; currIter++) { ScoreComponentCollection generationScore; // total score for this string of words // create vector of words with new factors for last phrase for (size_t currPos = 0 ; currPos < targetLength ; currPos++) { const WordPair &wordPair = *wordListIterVector[currPos]; mergeWords[currPos] = &(wordPair.first); generationScore.PlusEquals(wordPair.second); } // merge with existing trans opt Phrase genPhrase( mergeWords); if (IsFilteringStep()) { if (!inputPartialTranslOpt.IsCompatible(genPhrase, m_conflictFactors)) continue; } const TargetPhrase &inPhrase = inputPartialTranslOpt.GetTargetPhrase(); TargetPhrase outPhrase(inPhrase); outPhrase.GetScoreBreakdown().PlusEquals(generationScore); outPhrase.MergeFactors(genPhrase, m_newOutputFactors); outPhrase.Evaluate(inputPath.GetPhrase(), m_featuresToApply); const WordsRange &sourceWordsRange = inputPartialTranslOpt.GetSourceWordsRange(); TranslationOption *newTransOpt = new TranslationOption(sourceWordsRange, outPhrase); assert(newTransOpt); newTransOpt->SetInputPath(inputPath); outputPartialTranslOptColl.Add(newTransOpt); // increment iterators IncrementIterators(wordListIterVector, wordListVector); } }