2014-01-16 22:38:23 +04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2014-03-03 17:56:19 +04:00
|
|
|
#include <map>
|
2014-01-16 22:38:23 +04:00
|
|
|
#include "StatefulFeatureFunction.h"
|
|
|
|
#include "FFState.h"
|
2014-09-12 21:03:26 +04:00
|
|
|
#include "InternalTree.h"
|
2014-01-16 22:38:23 +04:00
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2014-03-03 17:56:19 +04:00
|
|
|
typedef int NTLabel;
|
2014-01-16 22:38:23 +04:00
|
|
|
|
2014-03-03 17:56:19 +04:00
|
|
|
|
|
|
|
// mapping from string nonterminal label to int representation.
|
|
|
|
// allows abstraction if multiple nonterminal strings should map to same label.
|
|
|
|
struct LabelSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::map<std::string, NTLabel> string_to_label;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// class to implement language-specific syntactic constraints.
|
2014-09-12 21:03:26 +04:00
|
|
|
// the method SyntacticRules is given pointer to ScoreComponentCollection, so it can add sparse features itself.
|
2014-03-03 17:56:19 +04:00
|
|
|
class SyntaxConstraints
|
|
|
|
{
|
|
|
|
public:
|
2014-09-12 21:03:26 +04:00
|
|
|
virtual void SyntacticRules(TreePointer root, const std::vector<TreePointer> &previous, const FeatureFunction* sp, ScoreComponentCollection* accumulator) = 0;
|
2014-03-03 17:56:19 +04:00
|
|
|
virtual ~SyntaxConstraints() {};
|
2014-01-16 22:38:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-03 17:56:19 +04:00
|
|
|
class TreeStructureFeature : public StatefulFeatureFunction
|
2014-01-16 22:38:23 +04:00
|
|
|
{
|
2014-03-03 17:56:19 +04:00
|
|
|
SyntaxConstraints* m_constraints;
|
|
|
|
LabelSet* m_labelset;
|
2014-01-16 22:38:23 +04:00
|
|
|
public:
|
2014-03-03 17:56:19 +04:00
|
|
|
TreeStructureFeature(const std::string &line)
|
2014-01-20 19:56:36 +04:00
|
|
|
:StatefulFeatureFunction(0, line) {
|
|
|
|
ReadParameters();
|
|
|
|
}
|
2014-03-03 17:56:19 +04:00
|
|
|
~TreeStructureFeature() {delete m_constraints;};
|
2014-01-16 22:38:23 +04:00
|
|
|
|
|
|
|
virtual const FFState* EmptyHypothesisState(const InputType &input) const {
|
|
|
|
return new TreeState(TreePointer());
|
|
|
|
}
|
|
|
|
|
2014-03-03 17:56:19 +04:00
|
|
|
void AddNTLabels(TreePointer root) const;
|
|
|
|
|
2014-01-16 22:38:23 +04:00
|
|
|
bool IsUseable(const FactorMask &mask) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-10 01:35:59 +04:00
|
|
|
void EvaluateInIsolation(const Phrase &source
|
2014-01-16 22:38:23 +04:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection &estimatedFutureScore) const {};
|
2014-07-10 02:06:54 +04:00
|
|
|
void EvaluateWithSourceContext(const InputType &input
|
2014-01-16 22:38:23 +04:00
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
2014-05-08 20:51:45 +04:00
|
|
|
, const StackVec *stackVec
|
2014-01-16 22:38:23 +04:00
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
|
|
|
, ScoreComponentCollection *estimatedFutureScore = NULL) const {};
|
2014-07-10 02:41:08 +04:00
|
|
|
FFState* EvaluateWhenApplied(
|
2014-01-16 22:38:23 +04:00
|
|
|
const Hypothesis& cur_hypo,
|
|
|
|
const FFState* prev_state,
|
|
|
|
ScoreComponentCollection* accumulator) const {UTIL_THROW(util::Exception, "Not implemented");};
|
2014-07-10 02:54:16 +04:00
|
|
|
FFState* EvaluateWhenApplied(
|
2014-01-16 22:38:23 +04:00
|
|
|
const ChartHypothesis& /* cur_hypo */,
|
|
|
|
int /* featureID - used to index the state in the previous hypotheses */,
|
|
|
|
ScoreComponentCollection* accumulator) const;
|
|
|
|
|
2014-03-03 17:56:19 +04:00
|
|
|
void Load();
|
2014-01-16 22:38:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|