Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FeatureFunction.h « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ef85ecd943250f4d2bf0d924156814744b56f74 (plain)
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
#ifndef moses_FeatureFunction_h
#define moses_FeatureFunction_h

#include <vector>

#include "ScoreProducer.h"

namespace Moses
{

class TargetPhrase;
class Hypothesis;
class ChartHypothesis;
class FFState;
class InputType;
class ScoreComponentCollection;

class FeatureFunction: public ScoreProducer
{

public:
  FeatureFunction(const std::string& description, size_t numScoreComponents) :
    ScoreProducer(description, numScoreComponents) {}
  virtual bool IsStateless() const = 0;	
  virtual ~FeatureFunction();

};

class StatelessFeatureFunction: public FeatureFunction
{

public:
  StatelessFeatureFunction(const std::string& description, size_t numScoreComponents) :
    FeatureFunction(description, numScoreComponents) {}
  //! Evaluate for stateless feature functions. Implement this.
  virtual void Evaluate(const Hypothesis& cur_hypo,
  											ScoreComponentCollection* accumulator) const;

  virtual void EvaluateChart(const ChartHypothesis& cur_hypo,
  													 int featureID,
                             ScoreComponentCollection* accumulator) const;

  // If true, this value is expected to be included in the
  // ScoreBreakdown in the TranslationOption once it has been
  // constructed.
  // Default: false
  virtual bool ComputeValueInTranslationOption() const;

  bool IsStateless() const;
};

class StatefulFeatureFunction: public FeatureFunction
{

public:
  StatefulFeatureFunction(const std::string& description, size_t numScoreComponents) :
    FeatureFunction(description,numScoreComponents) {}

  /**
   * \brief This interface should be implemented.
   * Notes: When evaluating the value of this feature function, you should avoid
   * calling hypo.GetPrevHypo().  If you need something from the "previous"
   * hypothesis, you should store it in an FFState object which will be passed
   * in as prev_state.  If you don't do this, you will get in trouble.
   */
  virtual FFState* Evaluate(
    const Hypothesis& cur_hypo,
    const FFState* prev_state,
    ScoreComponentCollection* accumulator) const = 0;

  virtual FFState* EvaluateChart(
    const ChartHypothesis& /* cur_hypo */,
    int /* featureID */,
    ScoreComponentCollection* accumulator) const = 0;

  //! return the state associated with the empty hypothesis for a given sentence
  virtual const FFState* EmptyHypothesisState(const InputType &input) const = 0;

  bool IsStateless() const;
};

}

#endif