diff options
author | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-10-18 23:27:58 +0300 |
---|---|---|
committer | Ulrich Germann <Ulrich.Germann@gmail.com> | 2015-10-18 23:27:58 +0300 |
commit | bdb0227ee9648ea96e8ee266d32581c63762b8b0 (patch) | |
tree | 5aff9707a743b3ec5f0e16cba70771b7299516f0 /moses/PDTAimp.cpp | |
parent | 7a85126a926c4ffdbd0a956b3b4cec07eea33ed2 (diff) |
Life cycle of TargetPhraseCollection is now managed via shared pointers.
Diffstat (limited to 'moses/PDTAimp.cpp')
-rw-r--r-- | moses/PDTAimp.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/moses/PDTAimp.cpp b/moses/PDTAimp.cpp index b8bafeb3e..ea40a2f4f 100644 --- a/moses/PDTAimp.cpp +++ b/moses/PDTAimp.cpp @@ -63,27 +63,29 @@ void PDTAimp::CleanUp() { assert(m_dict); m_dict->FreeMemory(); - for(size_t i=0; i<m_tgtColls.size(); ++i) delete m_tgtColls[i]; + // for(size_t i=0; i<m_tgtColls.size(); ++i) m_tgtColls[i].reset(); m_tgtColls.clear(); m_cache.clear(); m_rangeCache.clear(); uniqSrcPhr.clear(); } -TargetPhraseCollectionWithSourcePhrase const* +TargetPhraseCollectionWithSourcePhrase::shared_ptr PDTAimp::GetTargetPhraseCollection(Phrase const &src) const { assert(m_dict); - if(src.GetSize()==0) return 0; + + TargetPhraseCollectionWithSourcePhrase::shared_ptr ret; + if(src.GetSize()==0) return ret; std::pair<MapSrc2Tgt::iterator,bool> piter; if(useCache) { - piter=m_cache.insert(std::make_pair(src,static_cast<TargetPhraseCollectionWithSourcePhrase const*>(0))); + piter=m_cache.insert(std::make_pair(src, ret)); if(!piter.second) return piter.first->second; } else if (m_cache.size()) { MapSrc2Tgt::const_iterator i=m_cache.find(src); - return (i!=m_cache.end() ? i->second : 0); + return (i!=m_cache.end() ? i->second : ret); } std::vector<std::string> srcString(src.GetSize()); @@ -97,7 +99,7 @@ PDTAimp::GetTargetPhraseCollection(Phrase const &src) const std::vector<std::string> wacands; m_dict->GetTargetCandidates(srcString,cands,wacands); if(cands.empty()) { - return 0; + return ret; } //TODO: Multiple models broken here @@ -140,16 +142,14 @@ PDTAimp::GetTargetPhraseCollection(Phrase const &src) const sourcePhrases.push_back(src); } - TargetPhraseCollectionWithSourcePhrase *rv; - rv=PruneTargetCandidates(tCands,costs, sourcePhrases); - if(rv->IsEmpty()) { - delete rv; - return 0; + ret = PruneTargetCandidates(tCands,costs, sourcePhrases); + if(ret->IsEmpty()) { + ret.reset(); } else { - if(useCache) piter.first->second=rv; - m_tgtColls.push_back(rv); - return rv; + if(useCache) piter.first->second = ret; + m_tgtColls.push_back(ret); } + return ret; } @@ -352,7 +352,8 @@ void PDTAimp::CacheSource(ConfusionNet const& src) pathExplored[len]+=exploredPaths[len]; - m_rangeCache.resize(src.GetSize(),vTPC(src.GetSize(),0)); + // m_rangeCache.resize(src.GetSize(),vTPC(src.GetSize(),0)); + m_rangeCache.resize(src.GetSize(),vTPC(src.GetSize())); for(std::map<Range,E2Costs>::const_iterator i=cov2cand.begin(); i!=cov2cand.end(); ++i) { assert(i->first.first<m_rangeCache.size()); @@ -386,10 +387,11 @@ void PDTAimp::CacheSource(ConfusionNet const& src) //std::cerr << i->first.first << "-" << i->first.second << ": " << targetPhrase << std::endl; } - TargetPhraseCollectionWithSourcePhrase *rv=PruneTargetCandidates(tCands, costs, sourcePhrases); + TargetPhraseCollectionWithSourcePhrase::shared_ptr + rv = PruneTargetCandidates(tCands, costs, sourcePhrases); if(rv->IsEmpty()) - delete rv; + rv.reset(); else { m_rangeCache[i->first.first][i->first.second-1]=rv; m_tgtColls.push_back(rv); @@ -428,7 +430,8 @@ void PDTAimp::CreateTargetPhrase(TargetPhrase& targetPhrase, targetPhrase.EvaluateInIsolation(*srcPtr, m_obj->GetFeaturesToApply()); } -TargetPhraseCollectionWithSourcePhrase* PDTAimp::PruneTargetCandidates +TargetPhraseCollectionWithSourcePhrase::shared_ptr +PDTAimp::PruneTargetCandidates (const std::vector<TargetPhrase> & tCands, std::vector<std::pair<float,size_t> >& costs, const std::vector<Phrase> &sourcePhrases) const @@ -437,7 +440,8 @@ TargetPhraseCollectionWithSourcePhrase* PDTAimp::PruneTargetCandidates UTIL_THROW_IF2(tCands.size() != sourcePhrases.size(), "Number of target phrases must equal number of source phrases"); - TargetPhraseCollectionWithSourcePhrase *rv=new TargetPhraseCollectionWithSourcePhrase; + TargetPhraseCollectionWithSourcePhrase::shared_ptr rv; + rv.reset(new TargetPhraseCollectionWithSourcePhrase); // set limit to tableLimit or actual size, whatever is smaller |