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

FeatureFunction.h « FF « moses2 - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 828a712b9ece9e259af2aa0b58b97b6503e9531f (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * FeatureFunction.h
 *
 *  Created on: 23 Oct 2015
 *      Author: hieu
 */

#pragma once

#include <cstddef>
#include <string>
#include <vector>
#include "../TypeDef.h"
#include "../Phrase.h"

namespace Moses2
{
template<typename WORD>
class TargetPhrase;

class System;
class PhraseImpl;
class TargetPhrases;
class TargetPhraseImpl;
class Scores;
class ManagerBase;
class MemPool;
class InputType;

namespace SCFG
{
class TargetPhrase;
class TargetPhrases;
class Word;
}

class FeatureFunction
{
public:

  FeatureFunction(size_t startInd, const std::string &line);
  virtual ~FeatureFunction();
  virtual void Load(System &system) {
  }

  size_t GetStartInd() const {
    return m_startInd;
  }
  size_t GetNumScores() const {
    return m_numScores;
  }
  const std::string &GetName() const {
    return m_name;
  }
  void SetName(const std::string &val) {
    m_name = val;
  }

  virtual size_t HasPhraseTableInd() const {
    return false;
  }
  void SetPhraseTableInd(size_t ind) {
    m_PhraseTableInd = ind;
  }
  size_t GetPhraseTableInd() const {
    return m_PhraseTableInd;
  }

  //! if false, then this feature is not displayed in the n-best list.
  // use with care
  virtual bool IsTuneable() const {
    return m_tuneable;
  }

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

  // may have more factors than actually need, but not guaranteed.
  virtual void
  EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
                      const TargetPhraseImpl &targetPhrase, Scores &scores,
                      SCORE &estimatedScore) const = 0;

  // For SCFG decoding, the source can contain non-terminals, NOT the raw
  // source from the input sentence
  virtual void
  EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<SCFG::Word> &source,
                      const TargetPhrase<SCFG::Word> &targetPhrase, Scores &scores,
                      SCORE &estimatedScore) const = 0;

  // used by lexicalised reordering model to add scores to tp data structures
  virtual void EvaluateAfterTablePruning(MemPool &pool,
                                         const TargetPhrases &tps, const Phrase<Moses2::Word> &sourcePhrase) const {
  }

  virtual void EvaluateAfterTablePruning(MemPool &pool,
                                         const SCFG::TargetPhrases &tps, const Phrase<SCFG::Word> &sourcePhrase) const {
  }

  virtual void InitializeForInput(const System &system, const InputType &input) { };

  // clean up temporary memory, called after processing each sentence
  virtual void CleanUpAfterSentenceProcessing(const System &system, const InputType &input) const {
  }

protected:
  size_t m_startInd;
  size_t m_numScores;
  size_t m_PhraseTableInd;
  std::string m_name;
  std::vector<std::vector<std::string> > m_args;
  bool m_tuneable;

  virtual void ReadParameters();
  void ParseLine(const std::string &line);
};

}