2015-10-24 01:19:31 +03:00
|
|
|
/*
|
|
|
|
* InputPaths.cpp
|
|
|
|
*
|
|
|
|
* Created on: 23 Oct 2015
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
2015-10-24 04:02:50 +03:00
|
|
|
#include <iostream>
|
2015-10-24 01:19:31 +03:00
|
|
|
#include "InputPaths.h"
|
|
|
|
#include "Phrase.h"
|
2015-10-26 00:20:55 +03:00
|
|
|
#include "System.h"
|
2015-11-11 18:08:47 +03:00
|
|
|
#include "legacy/Range.h"
|
2015-10-24 01:19:31 +03:00
|
|
|
|
2015-10-24 04:02:50 +03:00
|
|
|
using namespace std;
|
|
|
|
|
2015-12-10 23:49:30 +03:00
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
2015-11-06 21:23:40 +03:00
|
|
|
InputPaths::~InputPaths() {
|
2015-12-16 16:31:19 +03:00
|
|
|
delete m_blank;
|
2015-11-06 21:23:40 +03:00
|
|
|
}
|
|
|
|
|
2015-11-03 17:20:10 +03:00
|
|
|
void InputPaths::Init(const PhraseImpl &input, const System &system)
|
2015-10-24 01:19:31 +03:00
|
|
|
{
|
2015-11-05 14:19:37 +03:00
|
|
|
size_t numPt = system.mappings.size();
|
2015-10-24 01:19:31 +03:00
|
|
|
size_t size = input.GetSize();
|
2015-11-06 21:50:25 +03:00
|
|
|
size_t maxLength = min(size, system.maxPhraseLength);
|
|
|
|
|
2015-12-16 16:31:19 +03:00
|
|
|
// create blank path for initial hypo
|
|
|
|
Range range(NOT_FOUND, NOT_FOUND);
|
|
|
|
SubPhrase subPhrase = input.GetSubPhrase(NOT_FOUND, NOT_FOUND);
|
|
|
|
m_blank = new InputPath(subPhrase, range, numPt, NULL);
|
|
|
|
|
|
|
|
// create normal paths of subphrases through the sentence
|
2015-11-06 22:06:41 +03:00
|
|
|
for (size_t startPos = 0; startPos < size; ++startPos) {
|
|
|
|
const InputPath *prefixPath = NULL;
|
|
|
|
|
|
|
|
for (size_t phaseSize = 1; phaseSize <= maxLength; ++phaseSize) {
|
|
|
|
size_t endPos = startPos + phaseSize - 1;
|
|
|
|
|
|
|
|
if (endPos >= size) {
|
|
|
|
break;
|
|
|
|
}
|
2015-10-24 01:19:31 +03:00
|
|
|
|
|
|
|
SubPhrase subPhrase = input.GetSubPhrase(startPos, endPos);
|
2015-11-11 18:08:47 +03:00
|
|
|
Range range(startPos, endPos);
|
2015-10-24 04:02:50 +03:00
|
|
|
|
2015-11-06 22:06:41 +03:00
|
|
|
InputPath path(subPhrase, range, numPt, prefixPath);
|
2015-10-24 01:19:31 +03:00
|
|
|
m_inputPaths.push_back(path);
|
2015-11-06 22:06:41 +03:00
|
|
|
|
|
|
|
prefixPath = &m_inputPaths.back();
|
2015-10-24 01:19:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-06 21:23:40 +03:00
|
|
|
void InputPaths::DeleteUnusedPaths()
|
|
|
|
{
|
|
|
|
size_t ind = 0;
|
|
|
|
while (ind < m_inputPaths.size()) {
|
|
|
|
const InputPath &path = m_inputPaths[ind];
|
2015-12-08 19:01:37 +03:00
|
|
|
if (!path.IsUsed()) {
|
2015-11-06 21:23:40 +03:00
|
|
|
m_inputPaths.erase(m_inputPaths.begin() + ind);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++ind;
|
|
|
|
}
|
|
|
|
}
|
2015-10-24 01:19:31 +03:00
|
|
|
}
|
|
|
|
|
2015-12-10 23:49:30 +03:00
|
|
|
}
|
|
|
|
|