get ready to delete source phrase from TargetPhrase class

This commit is contained in:
Hieu Hoang 2013-08-07 14:35:40 +01:00
parent 441acf15e6
commit b3a860fd4f
3 changed files with 20 additions and 2 deletions

View File

@ -313,7 +313,7 @@ public:
std::vector<std::pair<float,size_t> >& costs,
const std::vector<Phrase> &sourcePhrases) const {
// convert into TargetPhraseCollection
CHECK(tCands.size() == sourcePhrases.size());
CHECK(tCands.size() == sourcePhrases.size());
TargetPhraseCollectionWithSourcePhrase *rv=new TargetPhraseCollectionWithSourcePhrase;
@ -330,7 +330,10 @@ public:
// add n top phrases to the return list
for(std::vector<std::pair<float,size_t> >::iterator
it = costs.begin(); it != nth; ++it) {
rv->Add(new TargetPhrase(tCands[it->second]));
size_t ind = it->second;
TargetPhrase *targetPhrase = new TargetPhrase(tCands[ind]);
const Phrase &sourcePhrase = sourcePhrases[ind];
rv->Add(targetPhrase, sourcePhrase);
}

View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <algorithm>
#include "TargetPhraseCollection.h"
#include "util/exception.hh"
using namespace std;
@ -84,6 +85,18 @@ std::ostream& operator<<(std::ostream &out, const TargetPhraseCollection &obj)
return out;
}
void TargetPhraseCollectionWithSourcePhrase::Add(TargetPhrase *targetPhrase)
{
UTIL_THROW(util::Exception, "Must use method Add(TargetPhrase*, const Phrase&)");
}
void TargetPhraseCollectionWithSourcePhrase::Add(TargetPhrase *targetPhrase, const Phrase &sourcePhrase)
{
m_collection.push_back(targetPhrase);
m_sourcePhrases.push_back(sourcePhrase);
}
} // namespace

View File

@ -109,6 +109,8 @@ public:
return m_sourcePhrases;
}
void Add(TargetPhrase *targetPhrase);
void Add(TargetPhrase *targetPhrase, const Phrase &sourcePhrase);
};
}