diff --git a/moses/DecodeStepTranslation.cpp b/moses/DecodeStepTranslation.cpp index 2bfc3f549..286c0a543 100644 --- a/moses/DecodeStepTranslation.cpp +++ b/moses/DecodeStepTranslation.cpp @@ -143,8 +143,7 @@ void DecodeStepTranslation::ProcessInitialTranslationLegacy( const size_t tableLimit = phraseDictionary->GetTableLimit(); const WordsRange wordsRange(startPos, endPos); - std::pair > retPair = phraseDictionary->GetTargetPhraseCollectionLegacy(source,wordsRange); - const TargetPhraseCollection *phraseColl = retPair.first; + const TargetPhraseCollectionWithSourcePhrase *phraseColl = phraseDictionary->GetTargetPhraseCollectionLegacy(source,wordsRange); if (phraseColl != NULL) { IFVERBOSE(3) { @@ -216,9 +215,8 @@ void DecodeStepTranslation::ProcessLegacy(const TranslationOption &inputPartialT const size_t currSize = inPhrase.GetSize(); const size_t tableLimit = phraseDictionary->GetTableLimit(); - std::pair > - retPair = phraseDictionary->GetTargetPhraseCollectionLegacy(toc->GetSource(),sourceWordsRange); - const TargetPhraseCollection *phraseColl = retPair.first; + const TargetPhraseCollectionWithSourcePhrase *phraseColl + = phraseDictionary->GetTargetPhraseCollectionLegacy(toc->GetSource(),sourceWordsRange); if (phraseColl != NULL) { diff --git a/moses/PDTAimp.h b/moses/PDTAimp.h index d0a21825a..e53f114ec 100644 --- a/moses/PDTAimp.h +++ b/moses/PDTAimp.h @@ -57,10 +57,10 @@ public: std::vector m_input,m_output; PhraseDictionaryTree *m_dict; const InputFeature *m_inputFeature; - typedef std::vector vTPC; + typedef std::vector vTPC; mutable vTPC m_tgtColls; - typedef std::map MapSrc2Tgt; + typedef std::map MapSrc2Tgt; mutable MapSrc2Tgt m_cache; PhraseDictionaryTreeAdaptor *m_obj; int useCache; @@ -125,7 +125,7 @@ public: uniqSrcPhr.clear(); } - TargetPhraseCollection const* + TargetPhraseCollectionWithSourcePhrase const* GetTargetPhraseCollection(Phrase const &src) const { CHECK(m_dict); @@ -133,7 +133,7 @@ public: std::pair piter; if(useCache) { - piter=m_cache.insert(std::make_pair(src,static_cast(0))); + piter=m_cache.insert(std::make_pair(src,static_cast(0))); if(!piter.second) return piter.first->second; } else if (m_cache.size()) { MapSrc2Tgt::const_iterator i=m_cache.find(src); @@ -194,7 +194,7 @@ public: sourcePhrases.push_back(src); } - TargetPhraseCollection *rv; + TargetPhraseCollectionWithSourcePhrase *rv; rv=PruneTargetCandidates(tCands,costs, sourcePhrases); if(rv->IsEmpty()) { delete rv; @@ -308,12 +308,12 @@ public: targetPhrase.Evaluate(*srcPtr, m_obj->GetFeaturesToApply()); } - TargetPhraseCollection* PruneTargetCandidates + TargetPhraseCollectionWithSourcePhrase* PruneTargetCandidates (const std::vector & tCands, std::vector >& costs, const std::vector &sourcePhrases) const { // convert into TargetPhraseCollection - TargetPhraseCollection *rv=new TargetPhraseCollection; + TargetPhraseCollectionWithSourcePhrase *rv=new TargetPhraseCollectionWithSourcePhrase; // set limit to tableLimit or actual size, whatever is smaller @@ -543,7 +543,7 @@ public: //std::cerr << i->first.first << "-" << i->first.second << ": " << targetPhrase << std::endl; } - TargetPhraseCollection *rv=PruneTargetCandidates(tCands, costs, sourcePhrases); + TargetPhraseCollectionWithSourcePhrase *rv=PruneTargetCandidates(tCands, costs, sourcePhrases); if(rv->IsEmpty()) delete rv; diff --git a/moses/TargetPhraseCollection.h b/moses/TargetPhraseCollection.h index ef855a653..5717faf91 100644 --- a/moses/TargetPhraseCollection.h +++ b/moses/TargetPhraseCollection.h @@ -93,6 +93,24 @@ public: }; + +// LEGACY +// DO NOT USE. NOT LEGACY CODE +class TargetPhraseCollectionWithSourcePhrase : public TargetPhraseCollection +{ +protected: + //friend std::ostream& operator<<(std::ostream &, const TargetPhraseCollectionWithSourcePhrase &); + + // TODO boost::ptr_vector + std::vector m_sourcePhrases; + +public: + const std::vector &GetSourcePhrases() const { + return m_sourcePhrases; + } + +}; + } #endif diff --git a/moses/TranslationModel/PhraseDictionary.cpp b/moses/TranslationModel/PhraseDictionary.cpp index 2335daa73..f36d29f19 100644 --- a/moses/TranslationModel/PhraseDictionary.cpp +++ b/moses/TranslationModel/PhraseDictionary.cpp @@ -44,7 +44,7 @@ const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollection(const } -std::pair > PhraseDictionary:: +const TargetPhraseCollectionWithSourcePhrase* PhraseDictionary:: GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const& range) const { UTIL_THROW(util::Exception, "Legacy method not implemented"); diff --git a/moses/TranslationModel/PhraseDictionary.h b/moses/TranslationModel/PhraseDictionary.h index 7f7208a32..0acfaff87 100644 --- a/moses/TranslationModel/PhraseDictionary.h +++ b/moses/TranslationModel/PhraseDictionary.h @@ -72,8 +72,6 @@ public: // See class PhraseDictionaryMemory or PhraseDictionaryOnDisk for details //! find list of translations that can translates src. Only for phrase input virtual const TargetPhraseCollection *GetTargetPhraseCollection(const Phrase& src) const; - //! find list of translations that can translates a portion of src. Used by confusion network decoding - virtual std::pair > GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const& range) const; virtual void GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const; @@ -100,6 +98,10 @@ public: void SetParameter(const std::string& key, const std::string& value); + // LEGACY + //! find list of translations that can translates a portion of src. Used by confusion network decoding + virtual const TargetPhraseCollectionWithSourcePhrase* GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const& range) const; + protected: size_t m_tableLimit; std::string m_filePath; diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp index 37cff54f4..44bbb30ef 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.cpp @@ -103,19 +103,15 @@ const PDTAimp& PhraseDictionaryTreeAdaptor::GetImplementation() const } // legacy -std::pair > +const TargetPhraseCollectionWithSourcePhrase* PhraseDictionaryTreeAdaptor::GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const &range) const { if(GetImplementation().m_rangeCache.empty()) { - const TargetPhraseCollection *tpColl = GetImplementation().GetTargetPhraseCollection(src.GetSubString(range)); - std::vector sourPhrases; - std::pair > ret(tpColl, sourPhrases); - return ret; + const TargetPhraseCollectionWithSourcePhrase *tpColl = GetImplementation().GetTargetPhraseCollection(src.GetSubString(range)); + return tpColl; } else { - const TargetPhraseCollection *tpColl = GetImplementation().m_rangeCache[range.GetStartPos()][range.GetEndPos()]; - std::vector sourPhrases; - std::pair > ret(tpColl, sourPhrases); - return ret; + const TargetPhraseCollectionWithSourcePhrase *tpColl = GetImplementation().m_rangeCache[range.GetStartPos()][range.GetEndPos()]; + return tpColl; } } diff --git a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h index d2d3056af..0b52640a2 100644 --- a/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h +++ b/moses/TranslationModel/PhraseDictionaryTreeAdaptor.h @@ -73,7 +73,7 @@ public: } // legacy - std::pair > GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const & srcRange) const; + const TargetPhraseCollectionWithSourcePhrase *GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const & srcRange) const; };