File size: 2,821 Bytes
158b61b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once

#include <string>
#include "StatefulFeatureFunction.h"
#include "FFState.h"

namespace Moses
{

class ExampleState : public FFState
{
  int m_targetLen;
public:
  ExampleState(int targetLen)
    :m_targetLen(targetLen) {
  }

  virtual size_t hash() const {
    return (size_t) m_targetLen;
  }
  virtual bool operator==(const FFState& o) const {
    const ExampleState& other = static_cast<const ExampleState&>(o);
    return m_targetLen == other.m_targetLen;
  }

};

class ExampleStatefulFF : public StatefulFeatureFunction
{
public:
  ExampleStatefulFF(const std::string &line);

  bool IsUseable(const FactorMask &mask) const {
    return true;
  }
  virtual const FFState* EmptyHypothesisState(const InputType &input) const {
    return new ExampleState(0);
  }

  // An empty implementation of this function is provided by StatefulFeatureFunction.
  // Unless you are actually implementing this, please remove this declaration here
  // and the empty skeleton implementation from the corresponding .cpp
  // file to reduce code clutter.
  void
  EvaluateInIsolation(const Phrase &source
                      , const TargetPhrase &targetPhrase
                      , ScoreComponentCollection &scoreBreakdown
                      , ScoreComponentCollection &estimatedScores) const;

  // An empty implementation of this function is provided by StatefulFeatureFunction.
  // Unless you are actually implementing this, please remove this declaration here
  // and the empty skeleton implementation from the corresponding .cpp
  // file to reduce code clutter.
  void
  EvaluateWithSourceContext(const InputType &input
                            , const InputPath &inputPath
                            , const TargetPhrase &targetPhrase
                            , const StackVec *stackVec
                            , ScoreComponentCollection &scoreBreakdown
                            , ScoreComponentCollection *estimatedScores = NULL) const;

  // An empty implementation of this function is provided by StatefulFeatureFunction.
  // Unless you are actually implementing this, please remove this declaration here
  // and the empty skeleton implementation from the corresponding .cpp
  // file to reduce code clutter.
  void
  EvaluateTranslationOptionListWithSourceContext
  ( const InputType &input , const TranslationOptionList &translationOptionList) const;

  FFState* EvaluateWhenApplied(
    const Hypothesis& cur_hypo,
    const FFState* prev_state,
    ScoreComponentCollection* accumulator) const;
  FFState* EvaluateWhenApplied(
    const ChartHypothesis& /* cur_hypo */,
    int /* featureID - used to index the state in the previous hypotheses */,
    ScoreComponentCollection* accumulator) const;

  void SetParameter(const std::string& key, const std::string& value);

};


}