mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
add input path to chart cell label
This commit is contained in:
parent
6e3b6d013b
commit
e2dc889150
@ -20,11 +20,11 @@
|
||||
***********************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <boost/ptr_container/ptr_vector.hpp>
|
||||
#include "InputType.h"
|
||||
#include "ChartCell.h"
|
||||
#include "WordsRange.h"
|
||||
|
||||
#include <boost/ptr_container/ptr_vector.hpp>
|
||||
#include "InputPath.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -36,6 +36,9 @@ class ChartCellCollectionBase
|
||||
public:
|
||||
template <class Factory> ChartCellCollectionBase(const InputType &input, const Factory &factory) :
|
||||
m_cells(input.GetSize()) {
|
||||
|
||||
CreateInputPaths(input);
|
||||
|
||||
size_t size = input.GetSize();
|
||||
for (size_t startPos = 0; startPos < size; ++startPos) {
|
||||
std::vector<ChartCellBase*> &inner = m_cells[startPos];
|
||||
@ -47,12 +50,44 @@ public:
|
||||
* gets it from there :-(. The span is actually stored as a reference,
|
||||
* which needs to point somewhere, so I have it refer to the ChartCell.
|
||||
*/
|
||||
m_source.push_back(new ChartCellLabel(inner[0]->GetCoverage(), input.GetWord(startPos)));
|
||||
const WordsRange &range = inner[0]->GetCoverage();
|
||||
InputPath &path = GetInputPath(range.GetStartPos(), range.GetEndPos());
|
||||
|
||||
m_source.push_back(new ChartCellLabel(range, input.GetWord(startPos)));
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~ChartCellCollectionBase();
|
||||
|
||||
void CreateInputPaths(const InputType &input)
|
||||
{
|
||||
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;
|
||||
std::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 *path;
|
||||
if (range.GetNumWordsCovered() == 1) {
|
||||
path = new InputPath(subphrase, labels, range, NULL, NULL);
|
||||
vec.push_back(path);
|
||||
} else {
|
||||
const InputPath &prevPath = GetInputPath(startPos, endPos - 1);
|
||||
path = new InputPath(subphrase, labels, range, &prevPath, NULL);
|
||||
vec.push_back(path);
|
||||
}
|
||||
|
||||
m_inputPathQueue.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const ChartCellBase &GetBase(const WordsRange &coverage) const {
|
||||
return *m_cells[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()];
|
||||
}
|
||||
@ -70,6 +105,19 @@ private:
|
||||
std::vector<std::vector<ChartCellBase*> > m_cells;
|
||||
|
||||
boost::ptr_vector<ChartCellLabel> m_source;
|
||||
|
||||
typedef std::vector< std::vector<InputPath*> > InputPathMatrix;
|
||||
InputPathMatrix m_inputPathMatrix; /*< contains translation options */
|
||||
|
||||
InputPathList m_inputPathQueue;
|
||||
|
||||
InputPath &GetInputPath(size_t startPos, size_t endPos)
|
||||
{
|
||||
size_t offset = endPos - startPos;
|
||||
assert(offset < m_inputPathMatrix[startPos].size());
|
||||
return *m_inputPathMatrix[startPos][offset];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** Hold all the chart cells for 1 input sentence. A variable of this type is held by the ChartManager
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
private:
|
||||
const WordsRange &m_coverage;
|
||||
const Word &m_label;
|
||||
//const InputPath &m_inputPath;
|
||||
Stack m_stack;
|
||||
mutable float m_bestScore;
|
||||
};
|
||||
|
@ -72,6 +72,8 @@ public:
|
||||
size_t idx = w[0]->GetId();
|
||||
if (! ChartCellExists(idx)) {
|
||||
m_size++;
|
||||
|
||||
|
||||
m_map[idx] = new ChartCellLabel(m_coverage, w);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,13 @@ int SkeletonState::Compare(const FFState& other) const
|
||||
return (m_targetLen < otherState.m_targetLen) ? -1 : +1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
SkeletonStatefulFF::SkeletonStatefulFF(const std::string &line)
|
||||
:StatefulFeatureFunction(3, line)
|
||||
{
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
void SkeletonStatefulFF::Evaluate(const Phrase &source
|
||||
, const TargetPhrase &targetPhrase
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
|
@ -21,9 +21,7 @@ public:
|
||||
class SkeletonStatefulFF : public StatefulFeatureFunction
|
||||
{
|
||||
public:
|
||||
SkeletonStatefulFF(const std::string &line)
|
||||
:StatefulFeatureFunction(3, line)
|
||||
{}
|
||||
SkeletonStatefulFF(const std::string &line);
|
||||
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
return true;
|
||||
|
@ -7,6 +7,12 @@ using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
SkeletonStatelessFF::SkeletonStatelessFF(const std::string &line)
|
||||
:StatelessFeatureFunction(2, line)
|
||||
{
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
void SkeletonStatelessFF::Evaluate(const Phrase &source
|
||||
, const TargetPhrase &targetPhrase
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
|
@ -9,9 +9,7 @@ namespace Moses
|
||||
class SkeletonStatelessFF : public StatelessFeatureFunction
|
||||
{
|
||||
public:
|
||||
SkeletonStatelessFF(const std::string &line)
|
||||
:StatelessFeatureFunction(2, line)
|
||||
{}
|
||||
SkeletonStatelessFF(const std::string &line);
|
||||
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
return true;
|
||||
|
@ -8,6 +8,12 @@ using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
SyntaxRHS::SyntaxRHS(const std::string &line)
|
||||
:StatelessFeatureFunction(1, line)
|
||||
{
|
||||
ReadParameters();
|
||||
}
|
||||
|
||||
void SyntaxRHS::Evaluate(const Phrase &source
|
||||
, const TargetPhrase &targetPhrase
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
|
@ -9,9 +9,7 @@ namespace Moses
|
||||
class SyntaxRHS : public StatelessFeatureFunction
|
||||
{
|
||||
public:
|
||||
SyntaxRHS(const std::string &line)
|
||||
:StatelessFeatureFunction(2, line)
|
||||
{}
|
||||
SyntaxRHS(const std::string &line);
|
||||
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user