add input path to chart cell label

This commit is contained in:
Hieu Hoang 2014-06-16 00:55:36 +01:00
parent 6e3b6d013b
commit e2dc889150
9 changed files with 76 additions and 12 deletions

View File

@ -20,11 +20,11 @@
***********************************************************************/ ***********************************************************************/
#pragma once #pragma once
#include <boost/ptr_container/ptr_vector.hpp>
#include "InputType.h" #include "InputType.h"
#include "ChartCell.h" #include "ChartCell.h"
#include "WordsRange.h" #include "WordsRange.h"
#include "InputPath.h"
#include <boost/ptr_container/ptr_vector.hpp>
namespace Moses namespace Moses
{ {
@ -36,6 +36,9 @@ class ChartCellCollectionBase
public: public:
template <class Factory> ChartCellCollectionBase(const InputType &input, const Factory &factory) : template <class Factory> ChartCellCollectionBase(const InputType &input, const Factory &factory) :
m_cells(input.GetSize()) { m_cells(input.GetSize()) {
CreateInputPaths(input);
size_t size = input.GetSize(); size_t size = input.GetSize();
for (size_t startPos = 0; startPos < size; ++startPos) { for (size_t startPos = 0; startPos < size; ++startPos) {
std::vector<ChartCellBase*> &inner = m_cells[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, * 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. * 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(); 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 { const ChartCellBase &GetBase(const WordsRange &coverage) const {
return *m_cells[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()]; return *m_cells[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()];
} }
@ -70,6 +105,19 @@ private:
std::vector<std::vector<ChartCellBase*> > m_cells; std::vector<std::vector<ChartCellBase*> > m_cells;
boost::ptr_vector<ChartCellLabel> m_source; 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 /** Hold all the chart cells for 1 input sentence. A variable of this type is held by the ChartManager

View File

@ -90,6 +90,7 @@ public:
private: private:
const WordsRange &m_coverage; const WordsRange &m_coverage;
const Word &m_label; const Word &m_label;
//const InputPath &m_inputPath;
Stack m_stack; Stack m_stack;
mutable float m_bestScore; mutable float m_bestScore;
}; };

View File

@ -72,6 +72,8 @@ public:
size_t idx = w[0]->GetId(); size_t idx = w[0]->GetId();
if (! ChartCellExists(idx)) { if (! ChartCellExists(idx)) {
m_size++; m_size++;
m_map[idx] = new ChartCellLabel(m_coverage, w); m_map[idx] = new ChartCellLabel(m_coverage, w);
} }
} }

View File

@ -16,6 +16,13 @@ int SkeletonState::Compare(const FFState& other) const
return (m_targetLen < otherState.m_targetLen) ? -1 : +1; return (m_targetLen < otherState.m_targetLen) ? -1 : +1;
} }
////////////////////////////////////////////////////////////////
SkeletonStatefulFF::SkeletonStatefulFF(const std::string &line)
:StatefulFeatureFunction(3, line)
{
ReadParameters();
}
void SkeletonStatefulFF::Evaluate(const Phrase &source void SkeletonStatefulFF::Evaluate(const Phrase &source
, const TargetPhrase &targetPhrase , const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &scoreBreakdown

View File

@ -21,9 +21,7 @@ public:
class SkeletonStatefulFF : public StatefulFeatureFunction class SkeletonStatefulFF : public StatefulFeatureFunction
{ {
public: public:
SkeletonStatefulFF(const std::string &line) SkeletonStatefulFF(const std::string &line);
:StatefulFeatureFunction(3, line)
{}
bool IsUseable(const FactorMask &mask) const { bool IsUseable(const FactorMask &mask) const {
return true; return true;

View File

@ -7,6 +7,12 @@ using namespace std;
namespace Moses namespace Moses
{ {
SkeletonStatelessFF::SkeletonStatelessFF(const std::string &line)
:StatelessFeatureFunction(2, line)
{
ReadParameters();
}
void SkeletonStatelessFF::Evaluate(const Phrase &source void SkeletonStatelessFF::Evaluate(const Phrase &source
, const TargetPhrase &targetPhrase , const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &scoreBreakdown

View File

@ -9,9 +9,7 @@ namespace Moses
class SkeletonStatelessFF : public StatelessFeatureFunction class SkeletonStatelessFF : public StatelessFeatureFunction
{ {
public: public:
SkeletonStatelessFF(const std::string &line) SkeletonStatelessFF(const std::string &line);
:StatelessFeatureFunction(2, line)
{}
bool IsUseable(const FactorMask &mask) const { bool IsUseable(const FactorMask &mask) const {
return true; return true;

View File

@ -8,6 +8,12 @@ using namespace std;
namespace Moses namespace Moses
{ {
SyntaxRHS::SyntaxRHS(const std::string &line)
:StatelessFeatureFunction(1, line)
{
ReadParameters();
}
void SyntaxRHS::Evaluate(const Phrase &source void SyntaxRHS::Evaluate(const Phrase &source
, const TargetPhrase &targetPhrase , const TargetPhrase &targetPhrase
, ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &scoreBreakdown

View File

@ -9,9 +9,7 @@ namespace Moses
class SyntaxRHS : public StatelessFeatureFunction class SyntaxRHS : public StatelessFeatureFunction
{ {
public: public:
SyntaxRHS(const std::string &line) SyntaxRHS(const std::string &line);
:StatelessFeatureFunction(2, line)
{}
bool IsUseable(const FactorMask &mask) const { bool IsUseable(const FactorMask &mask) const {
return true; return true;