mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-19 07:07:24 +03:00
init moses2
This commit is contained in:
parent
60a588ff29
commit
a71cfeb3db
@ -14,7 +14,7 @@ int main()
|
|||||||
|
|
||||||
string line;
|
string line;
|
||||||
while (getline(cin, line)) {
|
while (getline(cin, line)) {
|
||||||
Phrase *input = Phrase::CreateFromString(line);
|
Phrase *input = Phrase::CreateFromString(NULL, line);
|
||||||
|
|
||||||
Manager mgr(staticData, *input);
|
Manager mgr(staticData, *input);
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
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);
|
vector<string> toks = Moses::Tokenize(str);
|
||||||
size_t size = toks.size();
|
size_t size = toks.size();
|
||||||
Phrase *ret = new Phrase(size);
|
Phrase *ret = new Phrase(pool, size);
|
||||||
ret->CreateFromString(toks);
|
ret->CreateFromString(toks);
|
||||||
|
|
||||||
return ret;
|
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_size(size)
|
||||||
{
|
{
|
||||||
m_words = new Word[size];
|
if (pool) {
|
||||||
|
m_words = new (pool->Allocate<Word>()) Word[size];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_words = new Word[size];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Word.h"
|
#include "Word.h"
|
||||||
|
#include "util/pool.hh"
|
||||||
|
|
||||||
class PhraseBase
|
class PhraseBase
|
||||||
{
|
{
|
||||||
@ -23,8 +24,9 @@ class SubPhrase;
|
|||||||
class Phrase : public PhraseBase
|
class Phrase : public PhraseBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Phrase *CreateFromString(const std::string &str);
|
static Phrase *CreateFromString(util::Pool *pool, const std::string &str);
|
||||||
Phrase(size_t size);
|
|
||||||
|
Phrase(util::Pool *pool, size_t size);
|
||||||
virtual ~Phrase();
|
virtual ~Phrase();
|
||||||
|
|
||||||
const Word& operator[](size_t pos) const {
|
const Word& operator[](size_t pos) const {
|
||||||
|
@ -35,7 +35,7 @@ void PhraseTable::Load(StaticData &staticData)
|
|||||||
Moses::TokenizeMultiCharSeparator(toks, line, "|||");
|
Moses::TokenizeMultiCharSeparator(toks, line, "|||");
|
||||||
assert(toks.size() >= 3);
|
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]);
|
TargetPhrase *target = TargetPhrase::CreateFromString(&staticData.GetPool(), staticData, toks[1]);
|
||||||
target->GetScores().CreateFromString(toks[2], *this, staticData);
|
target->GetScores().CreateFromString(toks[2], *this, staticData);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ TargetPhrase *TargetPhrase::CreateFromString(util::Pool *pool, StaticData &stati
|
|||||||
}
|
}
|
||||||
|
|
||||||
TargetPhrase::TargetPhrase(util::Pool *pool, StaticData &staticData, size_t size)
|
TargetPhrase::TargetPhrase(util::Pool *pool, StaticData &staticData, size_t size)
|
||||||
:Phrase(size)
|
:Phrase(pool, size)
|
||||||
{
|
{
|
||||||
if (pool) {
|
if (pool) {
|
||||||
m_scores = new (pool->Allocate<Scores>()) Scores(staticData.GetNumScores());
|
m_scores = new (pool->Allocate<Scores>()) Scores(staticData.GetNumScores());
|
||||||
|
@ -26,8 +26,8 @@ class Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void *Allocate() {
|
void *Allocate(size_t num = 1) {
|
||||||
void *ret = Allocate(sizeof(T));
|
void *ret = Allocate(sizeof(T) * num);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user