2016-02-26 15:26:32 +03:00
|
|
|
/*
|
|
|
|
* Manager.cpp
|
|
|
|
*
|
|
|
|
* Created on: 23 Oct 2015
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
|
|
#include "Manager.h"
|
2016-03-03 16:04:27 +03:00
|
|
|
#include "InputPath.h"
|
2016-02-29 18:51:17 +03:00
|
|
|
#include "../Sentence.h"
|
2016-03-03 16:04:27 +03:00
|
|
|
#include "../System.h"
|
|
|
|
#include "../TranslationModel/PhraseTable.h"
|
2016-02-26 15:26:32 +03:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
namespace SCFG
|
|
|
|
{
|
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
Manager::Manager(System &sys, const TranslationTask &task,
|
|
|
|
const std::string &inputStr, long translationId) :
|
|
|
|
ManagerBase(sys, task, inputStr, translationId)
|
2016-02-26 15:51:50 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2016-02-26 15:26:32 +03:00
|
|
|
|
2016-02-26 15:51:50 +03:00
|
|
|
Manager::~Manager()
|
|
|
|
{
|
2016-02-26 15:26:32 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::Decode()
|
|
|
|
{
|
2016-03-31 23:00:16 +03:00
|
|
|
// init pools etc
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "START InitPools()" << endl;
|
2016-03-31 23:00:16 +03:00
|
|
|
InitPools();
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "START ParseInput()" << endl;
|
2016-03-31 23:00:16 +03:00
|
|
|
ParseInput(true);
|
2016-02-26 15:35:24 +03:00
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
size_t size = GetInput().GetSize();
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "size=" << size << endl;
|
2016-03-02 00:41:32 +03:00
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
m_inputPaths.Init(GetInput(), *this);
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "CREATED m_inputPaths" << endl;
|
2016-03-02 00:41:32 +03:00
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
m_stacks.Init(*this, size);
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "CREATED m_stacks" << endl;
|
2016-03-01 02:28:24 +03:00
|
|
|
|
2016-04-14 17:55:13 +03:00
|
|
|
for (int startPos = size - 1; startPos >= 0; --startPos) {
|
2016-03-31 23:00:16 +03:00
|
|
|
InitActiveChart(startPos);
|
2016-03-02 00:41:32 +03:00
|
|
|
|
2016-03-31 23:00:16 +03:00
|
|
|
for (int endPos = startPos + 1; endPos < size + 1; ++endPos) {
|
|
|
|
SubPhrase sub = m_input->GetSubPhrase(startPos, endPos - startPos);
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "sub=" << sub << endl;
|
2016-04-15 15:38:01 +03:00
|
|
|
Decode(startPos, endPos);
|
2016-03-31 23:00:16 +03:00
|
|
|
}
|
|
|
|
}
|
2016-02-26 15:26:32 +03:00
|
|
|
}
|
|
|
|
|
2016-03-02 00:41:32 +03:00
|
|
|
void Manager::InitActiveChart(size_t pos)
|
|
|
|
{
|
2016-04-14 17:55:13 +03:00
|
|
|
|
2016-04-15 15:38:01 +03:00
|
|
|
InputPath &path = *m_inputPaths.GetMatrix().GetValue(pos, 0);
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "pos=" << pos << " path=" << path << endl;
|
2016-03-31 23:00:16 +03:00
|
|
|
size_t numPt = system.mappings.size();
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "numPt=" << numPt << endl;
|
2016-03-31 23:00:16 +03:00
|
|
|
|
|
|
|
for (size_t i = 0; i < numPt; ++i) {
|
2016-04-14 17:55:13 +03:00
|
|
|
const PhraseTable &pt = *system.mappings[i];
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "START InitActiveChart" << endl;
|
2016-04-14 17:55:13 +03:00
|
|
|
pt.InitActiveChart(path);
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "FINISHED InitActiveChart" << endl;
|
2016-03-31 23:00:16 +03:00
|
|
|
}
|
2016-04-15 15:38:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::Decode(size_t startPos, size_t endPos)
|
|
|
|
{
|
|
|
|
InputPath &path = *m_inputPaths.GetMatrix().GetValue(startPos, endPos - startPos);
|
|
|
|
|
|
|
|
size_t numPt = system.mappings.size();
|
2016-04-16 16:56:15 +03:00
|
|
|
//cerr << "numPt=" << numPt << endl;
|
2016-04-14 17:55:13 +03:00
|
|
|
|
2016-04-15 15:38:01 +03:00
|
|
|
for (size_t i = 0; i < numPt; ++i) {
|
|
|
|
const PhraseTable &pt = *system.mappings[i];
|
2016-04-16 16:35:42 +03:00
|
|
|
pt.Lookup(GetPool(), system, path);
|
2016-04-15 15:38:01 +03:00
|
|
|
}
|
2016-04-16 16:56:15 +03:00
|
|
|
|
|
|
|
size_t tpsNum = path.targetPhrases.GetSize();
|
|
|
|
if (tpsNum) {
|
|
|
|
cerr << tpsNum << " " << path << endl;
|
|
|
|
}
|
2016-03-02 00:41:32 +03:00
|
|
|
}
|
|
|
|
|
2016-02-26 15:26:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|