add InputPath objects of chart decoding. Start on lattice input for chart decoding

This commit is contained in:
Hieu Hoang 2013-08-08 21:29:22 +01:00
parent 15132a04aa
commit 59e7a179ca
3 changed files with 62 additions and 4 deletions

View File

@ -50,7 +50,7 @@ ChartManager::ChartManager(InputType const& source)
,m_start(clock())
,m_hypothesisId(0)
,m_parser(source, m_hypoStackColl)
,m_translationOptionList(StaticData::Instance().GetRuleLimit())
,m_translationOptionList(StaticData::Instance().GetRuleLimit(), source)
{
}
@ -342,5 +342,4 @@ void ChartManager::CreateDeviantPaths(
}
}
} // namespace Moses

View File

@ -19,25 +19,68 @@
#include <algorithm>
#include <iostream>
#include <vector>
#include "StaticData.h"
#include "ChartTranslationOptionList.h"
#include "ChartTranslationOptions.h"
#include "ChartCellCollection.h"
#include "WordsRange.h"
#include "InputType.h"
#include "InputPath.h"
using namespace std;
namespace Moses
{
ChartTranslationOptionList::ChartTranslationOptionList(size_t ruleLimit)
ChartTranslationOptionList::ChartTranslationOptionList(size_t ruleLimit, const InputType &input)
: m_size(0)
, m_ruleLimit(ruleLimit)
{
m_scoreThreshold = std::numeric_limits<float>::infinity();
// create input paths
size_t size = input.GetSize();
m_inputPathMatrix.resize(size);
for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
size_t endPos = startPos + phaseSize -1;
vector<InputPath*> &vec = m_inputPathMatrix[startPos];
WordsRange range(startPos, endPos);
Phrase subphrase(input.GetSubString(WordsRange(startPos, endPos)));
const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos);
InputPath *node;
if (range.GetNumWordsCovered() == 1) {
node = new InputPath(subphrase, labels, range, NULL, NULL);
vec.push_back(node);
} else {
const InputPath &prevNode = GetInputPath(startPos, endPos - 1);
node = new InputPath(subphrase, labels, range, &prevNode, NULL);
vec.push_back(node);
}
//m_phraseDictionaryQueue.push_back(node);
}
}
}
ChartTranslationOptionList::~ChartTranslationOptionList()
{
RemoveAllInColl(m_collection);
InputPathMatrix::const_iterator iterOuter;
for (iterOuter = m_inputPathMatrix.begin(); iterOuter != m_inputPathMatrix.end(); ++iterOuter) {
const std::vector<InputPath*> &outer = *iterOuter;
std::vector<InputPath*>::const_iterator iterInner;
for (iterInner = outer.begin(); iterInner != outer.end(); ++iterInner) {
InputPath *path = *iterInner;
delete path;
}
}
}
void ChartTranslationOptionList::Clear()
@ -142,4 +185,11 @@ void ChartTranslationOptionList::ApplyThreshold()
m_size = std::distance(m_collection.begin(), bound);
}
InputPath &ChartTranslationOptionList::GetInputPath(size_t startPos, size_t endPos)
{
size_t offset = endPos - startPos;
CHECK(offset < m_inputPathMatrix[startPos].size());
return *m_inputPathMatrix[startPos][offset];
}
}

View File

@ -30,12 +30,14 @@ namespace Moses
class TargetPhraseCollection;
class WordsRange;
class InputType;
class InputPath;
//! a vector of translations options for a specific range, in a specific sentence
class ChartTranslationOptionList : public ChartParserCallback
{
public:
ChartTranslationOptionList(size_t);
ChartTranslationOptionList(size_t ruleLimit, const InputType &input);
~ChartTranslationOptionList();
const ChartTranslationOptions &Get(size_t i) const {
@ -74,6 +76,13 @@ private:
size_t m_size;
float m_scoreThreshold;
const size_t m_ruleLimit;
// input paths
typedef std::vector< std::vector<InputPath*> > InputPathMatrix;
InputPathMatrix m_inputPathMatrix; /*< contains translation options */
InputPath &GetInputPath(size_t startPos, size_t endPos);
};
}