diff --git a/moses/TargetPhraseCollection.h b/moses/TargetPhraseCollection.h index 4207bccef..696eed398 100644 --- a/moses/TargetPhraseCollection.h +++ b/moses/TargetPhraseCollection.h @@ -36,6 +36,7 @@ class TargetPhraseCollection protected: friend std::ostream& operator<<(std::ostream &, const TargetPhraseCollection &); + // TODO boost::ptr_vector std::vector m_collection; public: @@ -57,7 +58,7 @@ public: } ~TargetPhraseCollection() { - RemoveAllInColl(m_collection); + Clear(); } const std::vector &GetCollection() const { @@ -83,6 +84,10 @@ public: void Prune(bool adhereTableLimit, size_t tableLimit); void Sort(bool adhereTableLimit, size_t tableLimit); + void Clear() { + RemoveAllInColl(m_collection); + } + }; } diff --git a/moses/TranslationModel/PhraseDictionaryMemory.cpp b/moses/TranslationModel/PhraseDictionaryMemory.cpp index 4a1a86813..2caaa5aa9 100644 --- a/moses/TranslationModel/PhraseDictionaryMemory.cpp +++ b/moses/TranslationModel/PhraseDictionaryMemory.cpp @@ -70,14 +70,7 @@ const TargetPhraseCollection *PhraseDictionaryMemory::GetTargetPhraseCollection( return NULL; } - const TargetPhraseCollection *coll = currNode->GetTargetPhraseCollection(); - /* - if (coll) { - cerr << "source=" << source << endl - << *coll << endl; - } - */ - return coll; + return currNode->GetTargetPhraseCollection(); } PhraseDictionaryNodeMemory &PhraseDictionaryMemory::GetOrCreateNode(const Phrase &source diff --git a/moses/TranslationModel/PhraseDictionaryNodeMemory.cpp b/moses/TranslationModel/PhraseDictionaryNodeMemory.cpp index 389c74394..9bca9ee45 100644 --- a/moses/TranslationModel/PhraseDictionaryNodeMemory.cpp +++ b/moses/TranslationModel/PhraseDictionaryNodeMemory.cpp @@ -38,14 +38,6 @@ PhraseDictionaryNodeMemory::~PhraseDictionaryNodeMemory() const PhraseDictionaryNodeMemory *node = iter->second; delete node; } - delete m_targetPhraseCollection; -} - -TargetPhraseCollection &PhraseDictionaryNodeMemory::GetOrCreateTargetPhraseCollection() -{ - if (m_targetPhraseCollection == NULL) - m_targetPhraseCollection = new TargetPhraseCollection(); - return *m_targetPhraseCollection; } void PhraseDictionaryNodeMemory::Prune(size_t tableLimit) @@ -59,8 +51,7 @@ void PhraseDictionaryNodeMemory::Prune(size_t tableLimit) } // prune TargetPhraseCollection in this node - if (m_targetPhraseCollection != NULL) - m_targetPhraseCollection->Prune(true, tableLimit); + m_targetPhraseCollection.Prune(true, tableLimit); } void PhraseDictionaryNodeMemory::Sort(size_t tableLimit) @@ -74,9 +65,7 @@ void PhraseDictionaryNodeMemory::Sort(size_t tableLimit) } // prune TargetPhraseCollection in this node - if (m_targetPhraseCollection != NULL) { - m_targetPhraseCollection->Sort(true, tableLimit); - } + m_targetPhraseCollection.Sort(true, tableLimit); } PhraseDictionaryNodeMemory *PhraseDictionaryNodeMemory::GetOrCreateChild(const Word &sourceTerm) @@ -138,8 +127,7 @@ void PhraseDictionaryNodeMemory::Clear() { m_sourceTermMap.clear(); m_nonTermMap.clear(); - delete m_targetPhraseCollection; - + m_targetPhraseCollection.Clear(); } std::ostream& operator<<(std::ostream &out, const PhraseDictionaryNodeMemory &node) diff --git a/moses/TranslationModel/PhraseDictionaryNodeMemory.h b/moses/TranslationModel/PhraseDictionaryNodeMemory.h index 17c477b41..0cdae42d7 100644 --- a/moses/TranslationModel/PhraseDictionaryNodeMemory.h +++ b/moses/TranslationModel/PhraseDictionaryNodeMemory.h @@ -120,14 +120,12 @@ private: friend class std::map; friend class std::map; -protected: TerminalMap m_sourceTermMap; NonTerminalMap m_nonTermMap; - TargetPhraseCollection *m_targetPhraseCollection; + TargetPhraseCollection m_targetPhraseCollection; + + PhraseDictionaryNodeMemory() {} - PhraseDictionaryNodeMemory() - :m_targetPhraseCollection(NULL) { - } public: ~PhraseDictionaryNodeMemory(); @@ -143,9 +141,11 @@ public: const PhraseDictionaryNodeMemory *GetChild(const Word &sourceNonTerm, const Word &targetNonTerm) const; const TargetPhraseCollection *GetTargetPhraseCollection() const { + return &m_targetPhraseCollection; + } + TargetPhraseCollection &GetOrCreateTargetPhraseCollection() { return m_targetPhraseCollection; } - TargetPhraseCollection &GetOrCreateTargetPhraseCollection(); const NonTerminalMap & GetNonTerminalMap() const { return m_nonTermMap;