set set<ptr> rather than set<object>

This commit is contained in:
Hieu Hoang 2014-02-27 14:59:23 +00:00
parent 715af8bcad
commit efee9f8f95
5 changed files with 19 additions and 25 deletions

View File

@ -11,18 +11,6 @@
using namespace std;
ConsistentPhrase::ConsistentPhrase(const ConsistentPhrase &copy)
:corners(copy.corners)
{
for (size_t i = 0; i < copy.m_nonTerms.size(); ++i) {
const NonTerm &oldNonTerm = copy.m_nonTerms[i];
m_nonTerms.push_back(NonTerm (*this,
oldNonTerm.GetLabel(Moses::Input),
oldNonTerm.GetLabel(Moses::Output)));
}
}
ConsistentPhrase::ConsistentPhrase(
int sourceStart, int sourceEnd,
int targetStart, int targetEnd)

View File

@ -20,7 +20,7 @@ public:
std::vector<int> corners;
ConsistentPhrase(const ConsistentPhrase &copy);
ConsistentPhrase(const ConsistentPhrase &copy); // do not implement
ConsistentPhrase(int sourceStart, int sourceEnd,
int targetStart, int targetEnd);

View File

@ -8,6 +8,7 @@
#include <cassert>
#include "ConsistentPhrases.h"
#include "NonTerm.h"
#include "moses/Util.h"
using namespace std;
@ -16,7 +17,14 @@ ConsistentPhrases::ConsistentPhrases()
}
ConsistentPhrases::~ConsistentPhrases() {
// TODO Auto-generated destructor stub
for (int start = 0; start < m_coll.size(); ++start) {
std::vector<Coll> &allSourceStart = m_coll[start];
for (int size = 0; size < allSourceStart.size(); ++size) {
Coll &coll = allSourceStart[size];
Moses::RemoveAllInColl(coll);
}
}
}
void ConsistentPhrases::Initialize(size_t size)
@ -33,16 +41,14 @@ void ConsistentPhrases::Add(int sourceStart, int sourceEnd,
int targetStart, int targetEnd)
{
Coll &coll = m_coll[sourceStart][sourceEnd - sourceStart];
ConsistentPhrase cp(sourceStart,
sourceEnd,
targetStart,
targetEnd);
cp.AddNonTerms("[X]", "[X]");
ConsistentPhrase *cp = new ConsistentPhrase(sourceStart,
sourceEnd,
targetStart,
targetEnd);
cp->AddNonTerms("[X]", "[X]");
pair<Coll::iterator, bool> inserted = coll.insert(cp);
assert(inserted.second);
const ConsistentPhrase &cpNew = *inserted.first;
}
@ -64,7 +70,7 @@ std::string ConsistentPhrases::Debug() const
Coll::const_iterator iter;
for (iter = coll.begin(); iter != coll.end(); ++iter) {
const ConsistentPhrase &consistentPhrase = *iter;
const ConsistentPhrase &consistentPhrase = **iter;
out << consistentPhrase.Debug() << endl;
}
}

View File

@ -15,7 +15,7 @@ class Word;
class ConsistentPhrases {
public:
typedef std::set<ConsistentPhrase> Coll;
typedef std::set<ConsistentPhrase*> Coll;
ConsistentPhrases();
virtual ~ConsistentPhrases();

View File

@ -63,7 +63,7 @@ void Rules::Extend(const Parameter &params)
ConsistentPhrases::Coll::const_iterator iter;
for (iter = cps.begin(); iter != cps.end(); ++iter) {
const ConsistentPhrase &cp = *iter;
const ConsistentPhrase &cp = **iter;
CreateRules(cp, params);
}
}
@ -95,7 +95,7 @@ void Rules::Extend(const Rule &rule, const ConsistentPhrases::Coll &cps, const P
{
ConsistentPhrases::Coll::const_iterator iter;
for (iter = cps.begin(); iter != cps.end(); ++iter) {
const ConsistentPhrase &cp = *iter;
const ConsistentPhrase &cp = **iter;
Extend(rule, cp, params);
}
}