mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 22:14:57 +03:00
init moses2
This commit is contained in:
parent
f9de39ca4c
commit
fb233b50e0
@ -9,8 +9,9 @@
|
|||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "StaticData.h"
|
#include "StaticData.h"
|
||||||
|
|
||||||
Hypothesis::Hypothesis(const Manager &mgr)
|
Hypothesis::Hypothesis(const Manager &mgr, const Moses::WordsBitmap &bitmap)
|
||||||
:m_mgr(mgr)
|
:m_mgr(mgr)
|
||||||
|
,m_bitmap(bitmap)
|
||||||
{
|
{
|
||||||
util::Pool &pool = mgr.GetPool();
|
util::Pool &pool = mgr.GetPool();
|
||||||
size_t numStatefulFFs = mgr.GetStaticData().GetStatefulFeatureFunctions().size();
|
size_t numStatefulFFs = mgr.GetStaticData().GetStatefulFeatureFunctions().size();
|
||||||
|
@ -10,12 +10,13 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include "moses/FF/FFState.h"
|
#include "moses/FF/FFState.h"
|
||||||
|
#include "moses/WordsBitmap.h"
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
class Hypothesis {
|
class Hypothesis {
|
||||||
public:
|
public:
|
||||||
Hypothesis(const Manager &mgr);
|
Hypothesis(const Manager &mgr, const Moses::WordsBitmap &bitmap);
|
||||||
virtual ~Hypothesis();
|
virtual ~Hypothesis();
|
||||||
|
|
||||||
size_t hash() const;
|
size_t hash() const;
|
||||||
@ -23,6 +24,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Manager &m_mgr;
|
const Manager &m_mgr;
|
||||||
|
const Moses::WordsBitmap &m_bitmap;
|
||||||
|
|
||||||
Moses::FFState **m_ffStates;
|
Moses::FFState **m_ffStates;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#include "Manager.h"
|
#include "Manager.h"
|
||||||
#include "PhraseTable.h"
|
#include "PhraseTable.h"
|
||||||
#include "StaticData.h"
|
#include "StaticData.h"
|
||||||
|
#include "SearchNormal.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
Manager::Manager(const StaticData &staticData, const std::string &inputStr)
|
Manager::Manager(const StaticData &staticData, const std::string &inputStr)
|
||||||
:m_staticData(staticData)
|
:m_staticData(staticData)
|
||||||
@ -22,14 +25,22 @@ Manager::Manager(const StaticData &staticData, const std::string &inputStr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_stacks.resize(m_input->GetSize());
|
m_stacks.resize(m_input->GetSize());
|
||||||
|
m_bitmaps = new Moses::Bitmaps(m_input->GetSize(), vector<bool>(0));
|
||||||
|
m_search = new SearchNormal(*this, m_stacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::Decode()
|
void Manager::Decode()
|
||||||
{
|
{
|
||||||
|
const Moses::WordsBitmap &initBitmap = m_bitmaps->GetInitialBitmap();
|
||||||
|
Hypothesis *iniHypo = new (GetPool().Allocate<Hypothesis>()) Hypothesis(*this, initBitmap);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < m_stacks.size(); ++i) {
|
||||||
|
m_search->Decode(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager::~Manager() {
|
Manager::~Manager() {
|
||||||
// TODO Auto-generated destructor stub
|
delete m_bitmaps;
|
||||||
|
delete m_search;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,12 +9,15 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include "InputPaths.h"
|
#include "InputPaths.h"
|
||||||
#include "Stack.h"
|
#include "Stack.h"
|
||||||
|
#include "moses/Bitmaps.h"
|
||||||
#include "util/pool.hh"
|
#include "util/pool.hh"
|
||||||
|
|
||||||
class StaticData;
|
class StaticData;
|
||||||
class Phrase;
|
class Phrase;
|
||||||
|
class SearchNormal;
|
||||||
|
|
||||||
class Manager {
|
class Manager {
|
||||||
public:
|
public:
|
||||||
@ -24,16 +27,22 @@ public:
|
|||||||
const StaticData &GetStaticData() const
|
const StaticData &GetStaticData() const
|
||||||
{ return m_staticData; }
|
{ return m_staticData; }
|
||||||
|
|
||||||
|
const Moses::Bitmaps &GetBitmaps() const
|
||||||
|
{ return *m_bitmaps; }
|
||||||
|
|
||||||
util::Pool &GetPool() const
|
util::Pool &GetPool() const
|
||||||
{ return m_pool; }
|
{ return m_pool; }
|
||||||
|
|
||||||
void Decode();
|
void Decode();
|
||||||
protected:
|
protected:
|
||||||
|
mutable util::Pool m_pool;
|
||||||
|
|
||||||
const StaticData &m_staticData;
|
const StaticData &m_staticData;
|
||||||
Phrase *m_input;
|
Phrase *m_input;
|
||||||
InputPaths m_inputPaths;
|
InputPaths m_inputPaths;
|
||||||
mutable util::Pool m_pool;
|
Moses::Bitmaps *m_bitmaps;
|
||||||
|
|
||||||
std::vector<Stack> m_stacks;
|
std::vector<Stack> m_stacks;
|
||||||
|
SearchNormal *m_search;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
39
contrib/other-builds/moses2/SearchNormal.cpp
Normal file
39
contrib/other-builds/moses2/SearchNormal.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* SearchNormal.cpp
|
||||||
|
*
|
||||||
|
* Created on: 25 Oct 2015
|
||||||
|
* Author: hieu
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SearchNormal.h"
|
||||||
|
#include "Stack.h"
|
||||||
|
|
||||||
|
SearchNormal::SearchNormal(const Manager &mgr, std::vector<Stack> &stacks)
|
||||||
|
:m_mgr(mgr)
|
||||||
|
,m_stacks(stacks)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchNormal::~SearchNormal() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchNormal::Decode(size_t stackInd)
|
||||||
|
{
|
||||||
|
Stack &stack = m_stacks[stackInd];
|
||||||
|
|
||||||
|
Stack::const_iterator iter;
|
||||||
|
for (iter = stack.begin(); iter != stack.end(); ++iter) {
|
||||||
|
const Hypothesis &hypo = **iter;
|
||||||
|
Extend(hypo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchNormal::Extend(const Hypothesis &hypo)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
30
contrib/other-builds/moses2/SearchNormal.h
Normal file
30
contrib/other-builds/moses2/SearchNormal.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* SearchNormal.h
|
||||||
|
*
|
||||||
|
* Created on: 25 Oct 2015
|
||||||
|
* Author: hieu
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SEARCHNORMAL_H_
|
||||||
|
#define SEARCHNORMAL_H_
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Manager;
|
||||||
|
class Stack;
|
||||||
|
class Hypothesis;
|
||||||
|
|
||||||
|
class SearchNormal {
|
||||||
|
public:
|
||||||
|
SearchNormal(const Manager &mgr, std::vector<Stack> &stacks);
|
||||||
|
virtual ~SearchNormal();
|
||||||
|
|
||||||
|
void Decode(size_t stackInd);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const Manager &m_mgr;
|
||||||
|
std::vector<Stack> &m_stacks;
|
||||||
|
|
||||||
|
void Extend(const Hypothesis &hypo);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SEARCHNORMAL_H_ */
|
@ -18,6 +18,7 @@ Stack::~Stack() {
|
|||||||
|
|
||||||
bool Stack::AddPrune(Hypothesis *hypo)
|
bool Stack::AddPrune(Hypothesis *hypo)
|
||||||
{
|
{
|
||||||
std::pair<iterator, bool> ret = m_hypos.insert(hypo);
|
std::pair<iterator, bool> ret = m_hypos.insert(hypo);
|
||||||
|
return ret.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ g++ -I../../.. -I../../../boost/include -L../../../lib -lmoses -lz -o moses2 \
|
|||||||
Phrase.cpp \
|
Phrase.cpp \
|
||||||
PhraseTable.cpp \
|
PhraseTable.cpp \
|
||||||
Scores.cpp \
|
Scores.cpp \
|
||||||
|
SearchNormal.cpp \
|
||||||
Stack.cpp \
|
Stack.cpp \
|
||||||
StatefulFeatureFunction.cpp \
|
StatefulFeatureFunction.cpp \
|
||||||
StatelessFeatureFunction.cpp \
|
StatelessFeatureFunction.cpp \
|
||||||
|
@ -26,9 +26,9 @@ class Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void *Allocate(size_t num = 1) {
|
T *Allocate(size_t num = 1) {
|
||||||
void *ret = Allocate(sizeof(T) * num);
|
void *ret = Allocate(sizeof(T) * num);
|
||||||
return ret;
|
return (T*) ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeAll();
|
void FreeAll();
|
||||||
|
Loading…
Reference in New Issue
Block a user