mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-06 19:49:41 +03:00
add InputPath
This commit is contained in:
parent
8b8b1b35b8
commit
dfeb77b30f
60
contrib/other-builds/moses2/PhraseBased/InputPaths.cpp
Normal file
60
contrib/other-builds/moses2/PhraseBased/InputPaths.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* InputPaths.cpp
|
||||
*
|
||||
* Created on: 23 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
#include <iostream>
|
||||
#include "../InputPathsBase.h"
|
||||
#include "../Sentence.h"
|
||||
#include "../System.h"
|
||||
#include "../legacy/Range.h"
|
||||
#include "Manager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
void InputPaths::Init(const Sentence &input, const Manager &mgr)
|
||||
{
|
||||
MemPool &pool = mgr.GetPool();
|
||||
size_t numPt = mgr.system.mappings.size();
|
||||
size_t size = input.GetSize();
|
||||
size_t maxLength = min(size, mgr.system.maxPhraseLength);
|
||||
|
||||
m_matrix = new (pool.Allocate< Matrix<InputPath*> >()) Matrix<InputPath*>(pool, size, maxLength);
|
||||
m_matrix->Init(NULL);
|
||||
|
||||
// create blank path for initial hypo
|
||||
Range range(NOT_FOUND, NOT_FOUND);
|
||||
SubPhrase subPhrase = input.GetSubPhrase(NOT_FOUND, NOT_FOUND);
|
||||
m_blank = new (pool.Allocate<InputPath>()) InputPath(pool, subPhrase, range, numPt, NULL);
|
||||
|
||||
// create normal paths of subphrases through the sentence
|
||||
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;
|
||||
}
|
||||
|
||||
SubPhrase subPhrase = input.GetSubPhrase(startPos, endPos);
|
||||
Range range(startPos, endPos);
|
||||
|
||||
InputPath *path = new (pool.Allocate<InputPath>()) InputPath(pool, subPhrase, range, numPt, prefixPath);
|
||||
m_inputPaths.push_back(path);
|
||||
|
||||
prefixPath = m_inputPaths.back();
|
||||
|
||||
m_matrix->SetValue(startPos, phaseSize - 1, path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
38
contrib/other-builds/moses2/PhraseBased/InputPaths.h
Normal file
38
contrib/other-builds/moses2/PhraseBased/InputPaths.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* InputPaths.h
|
||||
*
|
||||
* Created on: 23 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "InputPath.h"
|
||||
#include "../MemPool.h"
|
||||
#include "../InputPathsBase.h"
|
||||
#include "../legacy/Matrix.h"
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
class Sentence;
|
||||
class System;
|
||||
class Manager;
|
||||
|
||||
class InputPaths : public InputPathsBase
|
||||
{
|
||||
public:
|
||||
void Init(const Sentence &input, const Manager &mgr);
|
||||
|
||||
const InputPath &GetBlank() const
|
||||
{ return *m_blank; }
|
||||
|
||||
protected:
|
||||
InputPath *m_blank;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user