init moses2

This commit is contained in:
Hieu Hoang 2015-10-24 02:14:52 +01:00
parent 60a588ff29
commit a71cfeb3db
6 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,7 @@ int main()
string line;
while (getline(cin, line)) {
Phrase *input = Phrase::CreateFromString(line);
Phrase *input = Phrase::CreateFromString(NULL, line);
Manager mgr(staticData, *input);

View File

@ -12,11 +12,11 @@
using namespace std;
Phrase *Phrase::CreateFromString(const std::string &str)
Phrase *Phrase::CreateFromString(util::Pool *pool, const std::string &str)
{
vector<string> toks = Moses::Tokenize(str);
size_t size = toks.size();
Phrase *ret = new Phrase(size);
Phrase *ret = new Phrase(pool, size);
ret->CreateFromString(toks);
return ret;
@ -29,10 +29,15 @@ void Phrase::CreateFromString(const std::vector<std::string> &toks)
}
}
Phrase::Phrase(size_t size)
Phrase::Phrase(util::Pool *pool, size_t size)
:m_size(size)
{
m_words = new Word[size];
if (pool) {
m_words = new (pool->Allocate<Word>()) Word[size];
}
else {
m_words = new Word[size];
}
}

View File

@ -10,6 +10,7 @@
#include <cstddef>
#include <string>
#include "Word.h"
#include "util/pool.hh"
class PhraseBase
{
@ -23,8 +24,9 @@ class SubPhrase;
class Phrase : public PhraseBase
{
public:
static Phrase *CreateFromString(const std::string &str);
Phrase(size_t size);
static Phrase *CreateFromString(util::Pool *pool, const std::string &str);
Phrase(util::Pool *pool, size_t size);
virtual ~Phrase();
const Word& operator[](size_t pos) const {

View File

@ -35,7 +35,7 @@ void PhraseTable::Load(StaticData &staticData)
Moses::TokenizeMultiCharSeparator(toks, line, "|||");
assert(toks.size() >= 3);
Phrase *source = Phrase::CreateFromString(toks[0]);
Phrase *source = Phrase::CreateFromString(&staticData.GetPool(), toks[0]);
TargetPhrase *target = TargetPhrase::CreateFromString(&staticData.GetPool(), staticData, toks[1]);
target->GetScores().CreateFromString(toks[2], *this, staticData);
}

View File

@ -32,7 +32,7 @@ TargetPhrase *TargetPhrase::CreateFromString(util::Pool *pool, StaticData &stati
}
TargetPhrase::TargetPhrase(util::Pool *pool, StaticData &staticData, size_t size)
:Phrase(size)
:Phrase(pool, size)
{
if (pool) {
m_scores = new (pool->Allocate<Scores>()) Scores(staticData.GetNumScores());

View File

@ -26,8 +26,8 @@ class Pool {
}
template<typename T>
void *Allocate() {
void *ret = Allocate(sizeof(T));
void *Allocate(size_t num = 1) {
void *ret = Allocate(sizeof(T) * num);
return ret;
}