mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
get ready to delete source phrase from TargetPhrase class
This commit is contained in:
parent
71073868a8
commit
5eef91c0ea
@ -143,8 +143,7 @@ void DecodeStepTranslation::ProcessInitialTranslationLegacy(
|
||||
const size_t tableLimit = phraseDictionary->GetTableLimit();
|
||||
|
||||
const WordsRange wordsRange(startPos, endPos);
|
||||
std::pair<const TargetPhraseCollection*, std::vector<Phrase> > 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<const TargetPhraseCollection*, std::vector<Phrase> >
|
||||
retPair = phraseDictionary->GetTargetPhraseCollectionLegacy(toc->GetSource(),sourceWordsRange);
|
||||
const TargetPhraseCollection *phraseColl = retPair.first;
|
||||
const TargetPhraseCollectionWithSourcePhrase *phraseColl
|
||||
= phraseDictionary->GetTargetPhraseCollectionLegacy(toc->GetSource(),sourceWordsRange);
|
||||
|
||||
|
||||
if (phraseColl != NULL) {
|
||||
|
@ -57,10 +57,10 @@ public:
|
||||
std::vector<FactorType> m_input,m_output;
|
||||
PhraseDictionaryTree *m_dict;
|
||||
const InputFeature *m_inputFeature;
|
||||
typedef std::vector<TargetPhraseCollection const*> vTPC;
|
||||
typedef std::vector<TargetPhraseCollectionWithSourcePhrase const*> vTPC;
|
||||
mutable vTPC m_tgtColls;
|
||||
|
||||
typedef std::map<Phrase,TargetPhraseCollection const*> MapSrc2Tgt;
|
||||
typedef std::map<Phrase,TargetPhraseCollectionWithSourcePhrase const*> 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<MapSrc2Tgt::iterator,bool> piter;
|
||||
if(useCache) {
|
||||
piter=m_cache.insert(std::make_pair(src,static_cast<TargetPhraseCollection const*>(0)));
|
||||
piter=m_cache.insert(std::make_pair(src,static_cast<TargetPhraseCollectionWithSourcePhrase const*>(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<TargetPhrase> & tCands,
|
||||
std::vector<std::pair<float,size_t> >& costs,
|
||||
const std::vector<Phrase> &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;
|
||||
|
@ -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<Phrase> m_sourcePhrases;
|
||||
|
||||
public:
|
||||
const std::vector<Phrase> &GetSourcePhrases() const {
|
||||
return m_sourcePhrases;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -44,7 +44,7 @@ const TargetPhraseCollection *PhraseDictionary::GetTargetPhraseCollection(const
|
||||
}
|
||||
|
||||
|
||||
std::pair<const TargetPhraseCollection*, std::vector<Phrase> > PhraseDictionary::
|
||||
const TargetPhraseCollectionWithSourcePhrase* PhraseDictionary::
|
||||
GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const& range) const
|
||||
{
|
||||
UTIL_THROW(util::Exception, "Legacy method not implemented");
|
||||
|
@ -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<const TargetPhraseCollection*, std::vector<Phrase> > 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;
|
||||
|
@ -103,19 +103,15 @@ const PDTAimp& PhraseDictionaryTreeAdaptor::GetImplementation() const
|
||||
}
|
||||
|
||||
// legacy
|
||||
std::pair<const TargetPhraseCollection*, std::vector<Phrase> >
|
||||
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<Phrase> sourPhrases;
|
||||
std::pair<const TargetPhraseCollection*, std::vector<Phrase> > 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<Phrase> sourPhrases;
|
||||
std::pair<const TargetPhraseCollection*, std::vector<Phrase> > ret(tpColl, sourPhrases);
|
||||
return ret;
|
||||
const TargetPhraseCollectionWithSourcePhrase *tpColl = GetImplementation().m_rangeCache[range.GetStartPos()][range.GetEndPos()];
|
||||
return tpColl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
}
|
||||
|
||||
// legacy
|
||||
std::pair<const TargetPhraseCollection*, std::vector<Phrase> > GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const & srcRange) const;
|
||||
const TargetPhraseCollectionWithSourcePhrase *GetTargetPhraseCollectionLegacy(InputType const& src,WordsRange const & srcRange) const;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user