00001 #pragma once
00002
00003 #include <string>
00004 #include <map>
00005 #include "StatefulFeatureFunction.h"
00006 #include "FFState.h"
00007 #include "moses/Word.h"
00008 #include "InternalTree.h"
00009
00010 namespace Moses
00011 {
00012
00013 typedef int NTLabel;
00014
00015
00016
00017
00018 struct LabelSet {
00019 public:
00020 std::map<std::string, NTLabel> string_to_label;
00021 };
00022
00023
00024
00025
00026 class SyntaxConstraints
00027 {
00028 public:
00029 virtual void SyntacticRules(TreePointer root, const std::vector<TreePointer> &previous, const FeatureFunction* sp, ScoreComponentCollection* accumulator) = 0;
00030 virtual ~SyntaxConstraints() {};
00031 };
00032
00033
00034 class TreeStructureFeature : public StatefulFeatureFunction
00035 {
00036 SyntaxConstraints* m_constraints;
00037 LabelSet* m_labelset;
00038 bool m_binarized;
00039 Word m_send;
00040 Word m_send_nt;
00041
00042 public:
00043 TreeStructureFeature(const std::string &line)
00044 :StatefulFeatureFunction(0, line)
00045 , m_binarized(false) {
00046 ReadParameters();
00047 std::vector<FactorType> factors;
00048 factors.push_back(0);
00049 m_send.CreateFromString(Output, factors, "</s>", false);
00050 m_send_nt.CreateFromString(Output, factors, "SEND", true);
00051 }
00052 ~TreeStructureFeature() {
00053 delete m_constraints;
00054 };
00055
00056 virtual const FFState* EmptyHypothesisState(const InputType &input) const {
00057 return new TreeState(TreePointer());
00058 }
00059
00060 bool IsUseable(const FactorMask &mask) const {
00061 return true;
00062 }
00063
00064 void SetParameter(const std::string& key, const std::string& value);
00065
00066 FFState* EvaluateWhenApplied(
00067 const Hypothesis& cur_hypo,
00068 const FFState* prev_state,
00069 ScoreComponentCollection* accumulator) const {
00070 UTIL_THROW(util::Exception, "Not implemented");
00071 };
00072 FFState* EvaluateWhenApplied(
00073 const ChartHypothesis& ,
00074 int ,
00075 ScoreComponentCollection* accumulator) const;
00076
00077 void Load(AllOptions::ptr const& opts);
00078 };
00079
00080
00081 }