mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
StaticData -> System
This commit is contained in:
parent
67f6ff1802
commit
9cfc682b15
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "Hypothesis.h"
|
#include "Hypothesis.h"
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
|
|
||||||
Hypothesis::Hypothesis(Manager &mgr, const Moses::Bitmap &bitmap, const Moses::Range &range)
|
Hypothesis::Hypothesis(Manager &mgr, const Moses::Bitmap &bitmap, const Moses::Range &range)
|
||||||
:m_mgr(mgr)
|
:m_mgr(mgr)
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "InputPaths.h"
|
#include "InputPaths.h"
|
||||||
#include "Phrase.h"
|
#include "Phrase.h"
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "moses/Range.h"
|
#include "moses/Range.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void InputPaths::Init(const Phrase &input, const StaticData &staticData)
|
void InputPaths::Init(const Phrase &input, const System &system)
|
||||||
{
|
{
|
||||||
size_t numPt = staticData.GetPhraseTables().size();
|
size_t numPt = system.GetPhraseTables().size();
|
||||||
size_t size = input.GetSize();
|
size_t size = input.GetSize();
|
||||||
for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
|
for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
|
||||||
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
|
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
#include "InputPath.h"
|
#include "InputPath.h"
|
||||||
|
|
||||||
class Phrase;
|
class Phrase;
|
||||||
class StaticData;
|
class System;
|
||||||
|
|
||||||
class InputPaths {
|
class InputPaths {
|
||||||
typedef std::vector<InputPath> Coll;
|
typedef std::vector<InputPath> Coll;
|
||||||
public:
|
public:
|
||||||
InputPaths() {}
|
InputPaths() {}
|
||||||
void Init(const Phrase &input, const StaticData &staticData);
|
void Init(const Phrase &input, const System &system);
|
||||||
virtual ~InputPaths();
|
virtual ~InputPaths();
|
||||||
|
|
||||||
//! iterators
|
//! iterators
|
||||||
|
@ -19,7 +19,7 @@ import path ;
|
|||||||
Stack.cpp
|
Stack.cpp
|
||||||
StatefulFeatureFunction.cpp
|
StatefulFeatureFunction.cpp
|
||||||
StatelessFeatureFunction.cpp
|
StatelessFeatureFunction.cpp
|
||||||
StaticData.cpp
|
System.cpp
|
||||||
TargetPhrase.cpp
|
TargetPhrase.cpp
|
||||||
TargetPhrases.cpp
|
TargetPhrases.cpp
|
||||||
Vocab.cpp
|
Vocab.cpp
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "Phrase.h"
|
#include "Phrase.h"
|
||||||
#include "moses/InputFileStream.h"
|
#include "moses/InputFileStream.h"
|
||||||
@ -10,12 +10,12 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
cerr << "Starting..." << endl;
|
cerr << "Starting..." << endl;
|
||||||
|
|
||||||
StaticData staticData;
|
System system;
|
||||||
|
|
||||||
string line;
|
string line;
|
||||||
while (getline(cin, line)) {
|
while (getline(cin, line)) {
|
||||||
|
|
||||||
Manager mgr(staticData, line);
|
Manager mgr(system, line);
|
||||||
mgr.Decode();
|
mgr.Decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,19 +7,19 @@
|
|||||||
|
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "PhraseTable.h"
|
#include "PhraseTable.h"
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "SearchNormal.h"
|
#include "SearchNormal.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Manager::Manager(const StaticData &staticData, const std::string &inputStr)
|
Manager::Manager(const System &system, const std::string &inputStr)
|
||||||
:m_staticData(staticData)
|
:m_staticData(system)
|
||||||
,m_initRange(NOT_FOUND, NOT_FOUND)
|
,m_initRange(NOT_FOUND, NOT_FOUND)
|
||||||
{
|
{
|
||||||
m_input = Phrase::CreateFromString(m_pool, inputStr);
|
m_input = Phrase::CreateFromString(m_pool, inputStr);
|
||||||
m_inputPaths.Init(*m_input, staticData);
|
m_inputPaths.Init(*m_input, system);
|
||||||
|
|
||||||
const std::vector<const PhraseTable*> &pts = staticData.GetPhraseTables();
|
const std::vector<const PhraseTable*> &pts = system.GetPhraseTables();
|
||||||
for (size_t i = 0; i < pts.size(); ++i) {
|
for (size_t i = 0; i < pts.size(); ++i) {
|
||||||
const PhraseTable &pt = *pts[i];
|
const PhraseTable &pt = *pts[i];
|
||||||
pt.Lookups(m_inputPaths);
|
pt.Lookups(m_inputPaths);
|
||||||
|
@ -15,19 +15,19 @@
|
|||||||
#include "moses/Bitmaps.h"
|
#include "moses/Bitmaps.h"
|
||||||
#include "util/pool.hh"
|
#include "util/pool.hh"
|
||||||
|
|
||||||
class StaticData;
|
class System;
|
||||||
class Phrase;
|
class Phrase;
|
||||||
class SearchNormal;
|
class SearchNormal;
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
public:
|
public:
|
||||||
Manager(const StaticData &staticData, const std::string &inputStr);
|
Manager(const System &system, const std::string &inputStr);
|
||||||
virtual ~Manager();
|
virtual ~Manager();
|
||||||
|
|
||||||
util::Pool &GetPool()
|
util::Pool &GetPool()
|
||||||
{ return m_pool; }
|
{ return m_pool; }
|
||||||
|
|
||||||
const StaticData &GetStaticData() const
|
const System &GetStaticData() const
|
||||||
{ return m_staticData; }
|
{ return m_staticData; }
|
||||||
|
|
||||||
Moses::Bitmaps &GetBitmaps()
|
Moses::Bitmaps &GetBitmaps()
|
||||||
@ -40,7 +40,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
util::Pool m_pool;
|
util::Pool m_pool;
|
||||||
|
|
||||||
const StaticData &m_staticData;
|
const System &m_staticData;
|
||||||
Phrase *m_input;
|
Phrase *m_input;
|
||||||
InputPaths m_inputPaths;
|
InputPaths m_inputPaths;
|
||||||
Moses::Bitmaps *m_bitmaps;
|
Moses::Bitmaps *m_bitmaps;
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#include "PhraseTable.h"
|
#include "PhraseTable.h"
|
||||||
#include "Phrase.h"
|
#include "Phrase.h"
|
||||||
#include "TargetPhrase.h"
|
#include "TargetPhrase.h"
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "Scores.h"
|
#include "Scores.h"
|
||||||
#include "InputPaths.h"
|
#include "InputPaths.h"
|
||||||
#include "moses/InputFileStream.h"
|
#include "moses/InputFileStream.h"
|
||||||
@ -75,7 +75,7 @@ PhraseTable::~PhraseTable() {
|
|||||||
// TODO Auto-generated destructor stub
|
// TODO Auto-generated destructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhraseTable::Load(StaticData &staticData)
|
void PhraseTable::Load(System &system)
|
||||||
{
|
{
|
||||||
m_path = "/Users/hieu/workspace/experiment/issues/sample-models/phrase-model/phrase-table";
|
m_path = "/Users/hieu/workspace/experiment/issues/sample-models/phrase-model/phrase-table";
|
||||||
|
|
||||||
@ -89,8 +89,8 @@ void PhraseTable::Load(StaticData &staticData)
|
|||||||
assert(toks.size() >= 3);
|
assert(toks.size() >= 3);
|
||||||
|
|
||||||
Phrase *source = Phrase::CreateFromString(tmpPool, toks[0]);
|
Phrase *source = Phrase::CreateFromString(tmpPool, toks[0]);
|
||||||
TargetPhrase *target = TargetPhrase::CreateFromString(staticData.GetPool(), staticData, toks[1]);
|
TargetPhrase *target = TargetPhrase::CreateFromString(system.GetPool(), system, toks[1]);
|
||||||
target->GetScores().CreateFromString(toks[2], *this, staticData);
|
target->GetScores().CreateFromString(toks[2], *this, system);
|
||||||
m_root.AddRule(*source, target);
|
m_root.AddRule(*source, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "StatelessFeatureFunction.h"
|
#include "StatelessFeatureFunction.h"
|
||||||
#include "moses/Util.h"
|
#include "moses/Util.h"
|
||||||
|
|
||||||
class StaticData;
|
class System;
|
||||||
class InputPaths;
|
class InputPaths;
|
||||||
|
|
||||||
class Node
|
class Node
|
||||||
@ -38,7 +38,7 @@ class PhraseTable : public StatelessFeatureFunction
|
|||||||
public:
|
public:
|
||||||
PhraseTable(size_t startInd);
|
PhraseTable(size_t startInd);
|
||||||
virtual ~PhraseTable();
|
virtual ~PhraseTable();
|
||||||
void Load(StaticData &staticData);
|
void Load(System &system);
|
||||||
void Lookups(InputPaths &inputPaths) const;
|
void Lookups(InputPaths &inputPaths) const;
|
||||||
|
|
||||||
void SetPtInd(size_t ind)
|
void SetPtInd(size_t ind)
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include "FeatureFunction.h"
|
#include "FeatureFunction.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Weights.h"
|
#include "Weights.h"
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "moses/Util.h"
|
#include "moses/Util.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -27,11 +27,11 @@ Scores::~Scores() {
|
|||||||
delete m_scores;
|
delete m_scores;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scores::PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction &featureFunction, const StaticData &staticData)
|
void Scores::PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction &featureFunction, const System &system)
|
||||||
{
|
{
|
||||||
assert(scores.size() == featureFunction.GetNumScores());
|
assert(scores.size() == featureFunction.GetNumScores());
|
||||||
|
|
||||||
const Weights &weights = staticData.GetWeights();
|
const Weights &weights = system.GetWeights();
|
||||||
|
|
||||||
size_t ffStartInd = featureFunction.GetStartInd();
|
size_t ffStartInd = featureFunction.GetStartInd();
|
||||||
for (size_t i = 0; i < scores.size(); ++i) {
|
for (size_t i = 0; i < scores.size(); ++i) {
|
||||||
@ -43,8 +43,8 @@ void Scores::PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scores::CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const StaticData &staticData)
|
void Scores::CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const System &system)
|
||||||
{
|
{
|
||||||
vector<SCORE> scores = Moses::Tokenize<SCORE>(str);
|
vector<SCORE> scores = Moses::Tokenize<SCORE>(str);
|
||||||
PlusEquals(scores, featureFunction, staticData);
|
PlusEquals(scores, featureFunction, system);
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,16 @@
|
|||||||
#include "util/pool.hh"
|
#include "util/pool.hh"
|
||||||
|
|
||||||
class FeatureFunction;
|
class FeatureFunction;
|
||||||
class StaticData;
|
class System;
|
||||||
|
|
||||||
class Scores {
|
class Scores {
|
||||||
public:
|
public:
|
||||||
Scores(util::Pool &pool, size_t numScores);
|
Scores(util::Pool &pool, size_t numScores);
|
||||||
virtual ~Scores();
|
virtual ~Scores();
|
||||||
|
|
||||||
void CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const StaticData &staticData);
|
void CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const System &system);
|
||||||
|
|
||||||
void PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction &featureFunction, const StaticData &staticData);
|
void PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction &featureFunction, const System &system);
|
||||||
protected:
|
protected:
|
||||||
SCORE *m_scores;
|
SCORE *m_scores;
|
||||||
SCORE m_total;
|
SCORE m_total;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* StaticData.cpp
|
* System.cpp
|
||||||
*
|
*
|
||||||
* Created on: 23 Oct 2015
|
* Created on: 23 Oct 2015
|
||||||
* Author: hieu
|
* Author: hieu
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "PhraseTable.h"
|
#include "PhraseTable.h"
|
||||||
#include "moses/Util.h"
|
#include "moses/Util.h"
|
||||||
|
|
||||||
StaticData::StaticData()
|
System::System()
|
||||||
:m_ffStartInd(0)
|
:m_ffStartInd(0)
|
||||||
{
|
{
|
||||||
PhraseTable *pt = new PhraseTable(m_ffStartInd);
|
PhraseTable *pt = new PhraseTable(m_ffStartInd);
|
||||||
@ -20,7 +20,7 @@ StaticData::StaticData()
|
|||||||
m_phraseTables.push_back(pt);
|
m_phraseTables.push_back(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticData::~StaticData() {
|
System::~System() {
|
||||||
Moses::RemoveAllInColl(m_featureFunctions);
|
Moses::RemoveAllInColl(m_featureFunctions);
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* StaticData.h
|
* System.h
|
||||||
*
|
*
|
||||||
* Created on: 23 Oct 2015
|
* Created on: 23 Oct 2015
|
||||||
* Author: hieu
|
* Author: hieu
|
||||||
@ -15,10 +15,10 @@ class FeatureFunction;
|
|||||||
class StatefulFeatureFunction;
|
class StatefulFeatureFunction;
|
||||||
class PhraseTable;
|
class PhraseTable;
|
||||||
|
|
||||||
class StaticData {
|
class System {
|
||||||
public:
|
public:
|
||||||
StaticData();
|
System();
|
||||||
virtual ~StaticData();
|
virtual ~System();
|
||||||
|
|
||||||
size_t GetNumScores() const
|
size_t GetNumScores() const
|
||||||
{ return 55; }
|
{ return 55; }
|
@ -9,25 +9,25 @@
|
|||||||
#include "TargetPhrase.h"
|
#include "TargetPhrase.h"
|
||||||
#include "Scores.h"
|
#include "Scores.h"
|
||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "StaticData.h"
|
#include "System.h"
|
||||||
#include "util/pool.hh"
|
#include "util/pool.hh"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
TargetPhrase *TargetPhrase::CreateFromString(util::Pool &pool, StaticData &staticData, const std::string &str)
|
TargetPhrase *TargetPhrase::CreateFromString(util::Pool &pool, System &system, 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();
|
||||||
TargetPhrase *ret = new (pool.Allocate<TargetPhrase>()) TargetPhrase(pool, staticData, size);
|
TargetPhrase *ret = new (pool.Allocate<TargetPhrase>()) TargetPhrase(pool, system, size);
|
||||||
ret->Phrase::CreateFromString(toks);
|
ret->Phrase::CreateFromString(toks);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPhrase::TargetPhrase(util::Pool &pool, StaticData &staticData, size_t size)
|
TargetPhrase::TargetPhrase(util::Pool &pool, System &system, size_t size)
|
||||||
:Phrase(pool, size)
|
:Phrase(pool, size)
|
||||||
{
|
{
|
||||||
m_scores = new (pool.Allocate<Scores>()) Scores(pool, staticData.GetNumScores());
|
m_scores = new (pool.Allocate<Scores>()) Scores(pool, system.GetNumScores());
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPhrase::~TargetPhrase() {
|
TargetPhrase::~TargetPhrase() {
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
class Scores;
|
class Scores;
|
||||||
class Manager;
|
class Manager;
|
||||||
class StaticData;
|
class System;
|
||||||
|
|
||||||
class TargetPhrase : public Phrase
|
class TargetPhrase : public Phrase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static TargetPhrase *CreateFromString(util::Pool &pool, StaticData &staticData, const std::string &str);
|
static TargetPhrase *CreateFromString(util::Pool &pool, System &system, const std::string &str);
|
||||||
TargetPhrase(util::Pool &pool, StaticData &staticData, size_t size);
|
TargetPhrase(util::Pool &pool, System &system, size_t size);
|
||||||
virtual ~TargetPhrase();
|
virtual ~TargetPhrase();
|
||||||
|
|
||||||
Scores &GetScores()
|
Scores &GetScores()
|
||||||
|
@ -13,7 +13,7 @@ g++ -I../../.. -I../../../boost/include -L../../../lib -lmoses -lz -o moses2 \
|
|||||||
Stack.cpp \
|
Stack.cpp \
|
||||||
StatefulFeatureFunction.cpp \
|
StatefulFeatureFunction.cpp \
|
||||||
StatelessFeatureFunction.cpp \
|
StatelessFeatureFunction.cpp \
|
||||||
StaticData.cpp \
|
System.cpp \
|
||||||
TargetPhrase.cpp \
|
TargetPhrase.cpp \
|
||||||
TargetPhrases.cpp \
|
TargetPhrases.cpp \
|
||||||
Vocab.cpp \
|
Vocab.cpp \
|
||||||
|
Loading…
Reference in New Issue
Block a user