mosesdecoder/contrib/other-builds/moses2/Manager.cpp
2015-10-29 15:29:14 +00:00

63 lines
1.5 KiB
C++

/*
* Manager.cpp
*
* Created on: 23 Oct 2015
* Author: hieu
*/
#include "Manager.h"
#include "PhraseTable.h"
#include "System.h"
#include "SearchNormal.h"
using namespace std;
Manager::Manager(System &system, const std::string &inputStr)
:m_pool(&system.GetManagerPool())
,m_system(system)
,m_initRange(NOT_FOUND, NOT_FOUND)
,m_initPhrase(system.GetManagerPool(), system, 0)
{
Moses::FactorCollection &vocab = system.GetVocab();
m_input = Phrase::CreateFromString(GetPool(), vocab, inputStr);
m_inputPaths.Init(*m_input, system);
const std::vector<const PhraseTable*> &pts = system.GetFeatureFunctions().GetPhraseTables();
for (size_t i = 0; i < pts.size(); ++i) {
const PhraseTable &pt = *pts[i];
//cerr << "Looking up from " << pt.GetName() << endl;
pt.Lookup(*this, m_inputPaths);
}
m_stacks.resize(m_input->GetSize() + 1);
m_bitmaps = new Moses::Bitmaps(m_input->GetSize(), vector<bool>(0));
m_search = new SearchNormal(*this, m_stacks);
}
Manager::~Manager() {
delete m_bitmaps;
delete m_search;
GetPool().Reset();
}
const Hypothesis *Manager::GetBestHypothesis() const
{
return m_search->GetBestHypothesis();
}
void Manager::Decode()
{
const Moses::Bitmap &initBitmap = m_bitmaps->GetInitialBitmap();
Hypothesis *initHypo = new (GetPool().Allocate<Hypothesis>()) Hypothesis(*this, m_initPhrase, m_initRange, initBitmap);
initHypo->EmptyHypothesisState(*m_input);
StackAdd stackAdded = m_stacks[0].Add(initHypo);
assert(stackAdded.added);
for (size_t i = 0; i < m_stacks.size(); ++i) {
m_search->Decode(i);
}
}