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

StatefulFeatureFunction.h « FF « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cafa2c469f0b10c62b0acbf83307bc797b3e4bc3 (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
85
86
87
88
89
90
91
92
93
94
95
96
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2  -*-
#pragma once

#include "FeatureFunction.h"


namespace Moses
{
class FFState;

namespace Syntax
{
struct SHyperedge;
}

/** base class for all stateful feature functions.
 * eg. LM, distortion penalty
 */
class StatefulFeatureFunction: public FeatureFunction
{
  //All statefull FFs
  static std::vector<const StatefulFeatureFunction*> m_statefulFFs;

public:
  static const std::vector<const StatefulFeatureFunction*>&
  GetStatefulFeatureFunctions() {
    return m_statefulFFs;
  }

  StatefulFeatureFunction(const std::string &line, bool registerNow);
  StatefulFeatureFunction(size_t numScoreComponents, const std::string &line);

  /**
   * \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* EvaluateWhenApplied(
    const Hypothesis& cur_hypo,
    const FFState* prev_state,
    ScoreComponentCollection* accumulator) const = 0;

  // virtual FFState* EvaluateWhenAppliedWithContext(
  //   ttasksptr const& ttasks,
  //   const Hypothesis& cur_hypo,
  //   const FFState* prev_state,
  //   ScoreComponentCollection* accumulator) const {
  //   return EvaluateWhenApplied(cur_hypo, prev_state, accumulator);
  // }

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

  virtual FFState* EvaluateWhenApplied(
    const Syntax::SHyperedge& /* cur_hypo */,
    int /* featureID - used to index the state in the previous hypotheses */,
    ScoreComponentCollection* accumulator) const {
    assert(false);
    return 0; /* FIXME */
  }

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

  bool IsStateless() const {
    return false;
  }


  virtual void
  EvaluateInIsolation
  (Phrase const& source, TargetPhrase const& targetPhrase,
   ScoreComponentCollection &scoreBreakdown,
   ScoreComponentCollection &estimatedScores) const {}

  virtual void
  EvaluateWithSourceContext
  (InputType const&input, InputPath const& inputPath, TargetPhrase const& targetPhrase,
   StackVec const* stackVec, ScoreComponentCollection &scoreBreakdown,
   ScoreComponentCollection *estimatedFutureScore = NULL) const {}

  virtual void
  EvaluateTranslationOptionListWithSourceContext
  (const InputType &input, const TranslationOptionList &translationOptionList) const {}

};


}