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"
|
2015-07-17 19:27:31 +03:00
|
|
|
#include "moses/Word.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.
|
2015-01-14 14:07:42 +03:00
|
|
|
struct LabelSet {
|
2014-03-03 17:56:19 +04:00
|
|
|
public:
|
2015-01-14 14:07:42 +03:00
|
|
|
std::map<std::string, NTLabel> string_to_label;
|
2014-03-03 17:56:19 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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:
|
2015-01-14 14:07:42 +03:00
|
|
|
virtual void SyntacticRules(TreePointer root, const std::vector<TreePointer> &previous, const FeatureFunction* sp, ScoreComponentCollection* accumulator) = 0;
|
|
|
|
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;
|
2015-03-18 20:36:32 +03:00
|
|
|
bool m_binarized;
|
2015-07-17 19:27:31 +03:00
|
|
|
Word m_send;
|
|
|
|
Word m_send_nt;
|
|
|
|
|
2014-01-16 22:38:23 +04:00
|
|
|
public:
|
2014-03-03 17:56:19 +04:00
|
|
|
TreeStructureFeature(const std::string &line)
|
2015-03-18 20:36:32 +03:00
|
|
|
:StatefulFeatureFunction(0, line)
|
|
|
|
, m_binarized(false) {
|
2015-01-14 14:07:42 +03:00
|
|
|
ReadParameters();
|
2015-07-17 19:27:31 +03:00
|
|
|
std::vector<FactorType> factors;
|
|
|
|
factors.push_back(0);
|
|
|
|
m_send.CreateFromString(Output, factors, "</s>", false);
|
|
|
|
m_send_nt.CreateFromString(Output, factors, "SEND", true);
|
2015-01-14 14:07:42 +03: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());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsUseable(const FactorMask &mask) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-18 20:36:32 +03:00
|
|
|
void SetParameter(const std::string& key, const std::string& value);
|
|
|
|
|
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,
|
2015-01-14 14:07:42 +03:00
|
|
|
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;
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void Load(AllOptions::ptr const& opts);
|
2014-01-16 22:38:23 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|