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

LexicalReordering.h « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65437be830cfd660793f9b93bf66cdbcc80cc518 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//#ifndef LEXICAL_REORDERING_H
//#define LEXICAL_REORDERING_H

#pragma once

#include <string>
#include <vector>
#include "Factor.h"
#include "Phrase.h"
#include "TypeDef.h"
#include "Util.h"
#include "WordsRange.h"
#include "ScoreProducer.h"

#include "LexicalReorderingTable.h"

namespace Moses
{

class Factor;
class Phrase;
class Hypothesis;
class InputType;

using namespace std;

class LexicalReordering : public ScoreProducer {
 public: //types & consts
  typedef int OrientationType; 
  enum Direction {Forward, Backward, Bidirectional, Unidirectional = Backward};
  enum Condition {F,E,C,FE,FEC};
 public: //con- & destructors 
  LexicalReordering(const std::string &filePath, 
		    const std::vector<float>& weights, 
		    Direction direction, 
		    Condition condition, 
		    std::vector< FactorType >& f_factors, 
		    std::vector< FactorType >& e_factors);
  virtual ~LexicalReordering();
 public: //interface
  //inherited
  virtual size_t GetNumScoreComponents() const {
    return m_NumScoreComponents; 
  };
  
  virtual std::string GetScoreProducerDescription() const {
    return "Generic Lexical Reordering Model... overwrite in subclass.";
  };
  //new 
  virtual int             GetNumOrientationTypes() const = 0;
  virtual OrientationType GetOrientationType(Hypothesis*) const = 0;
  
  std::vector<float> CalcScore(Hypothesis* hypothesis) const;
  void InitializeForInput(const InputType& i){
    m_Table->InitializeForInput(i);
  }

	Score GetProb(const Phrase& f, const Phrase& e) const;
  //helpers
  static std::vector<Condition> DecodeCondition(Condition c);
  static std::vector<Direction> DecodeDirection(Direction d);
 private:
  Phrase auxGetContext(const Hypothesis* hypothesis) const;
 private:
  LexicalReorderingTable* m_Table;
  size_t m_NumScoreComponents;
  std::vector< Direction > m_Direction;
  std::vector< Condition > m_Condition;
  bool m_OneScorePerDirection;
  std::vector< FactorType > m_FactorsE, m_FactorsF, m_FactorsC;
  int m_MaxContextLength;
};


class LexicalMonotonicReordering : public LexicalReordering {
 private:
  enum {Monotone = 0, NonMonotone = 1};
 public:
  LexicalMonotonicReordering(const std::string &filePath, 
			     const std::vector<float>& w, 
			     Direction direction, 
			     Condition condition, 
			     std::vector< FactorType >& f_factors, 
			     std::vector< FactorType >& e_factors)
    : LexicalReordering(filePath, w, direction, condition, f_factors, e_factors){
	std::cerr << "Created lexical monotonic reordering\n";
  }
 public:
  virtual int GetNumOrientationTypes() const {
    return 2; 
  };
  virtual std::string GetScoreProducerDescription() const {
    return "MonotonicLexicalReorderingModel";
  };
  virtual int GetOrientationType(Hypothesis* currHypothesis) const;
};

class LexicalOrientationReordering : public LexicalReordering {
 private:
  enum {Monotone = 0, Swap = 1, Discontinuous = 2};
 public:
    LexicalOrientationReordering(const std::string &filePath, 
			     const std::vector<float>& w, 
			     Direction direction, 
			     Condition condition, 
			     std::vector< FactorType >& f_factors, 
			     std::vector< FactorType >& e_factors)
      : LexicalReordering(filePath, w, direction, condition, f_factors, e_factors){
	  std::cerr << "Created lexical orientation reordering\n";
  }
 public:
  virtual int GetNumOrientationTypes() const {
    return 3; 
  }
  virtual std::string GetScoreProducerDescription() const {
    return "OrientationLexicalReorderingModel";
  };
  virtual OrientationType GetOrientationType(Hypothesis* currHypothesis) const;
};

class LexicalDirectionalReordering : public LexicalReordering {
 private:
  enum {Left = 0, Right = 1};
 public:
 LexicalDirectionalReordering(const std::string &filePath, 
							  const std::vector<float>& w, 
							  Direction direction, 
							  Condition condition, 
							  std::vector< FactorType >& f_factors, 
							  std::vector< FactorType >& e_factors)
   : LexicalReordering(filePath, w, direction, condition, f_factors, e_factors){
   std::cerr << "Created lexical directional Reordering\n";
  }
 public:
  virtual int GetNumOrientationTypes() const {
    return 2; 
  };
  virtual std::string GetScoreProducerDescription() const {
    return "DirectionalLexicalReorderingModel";
  };
  virtual OrientationType GetOrientationType(Hypothesis* currHypothesis) const;
};


}
//#endif //LEXICAL_REORDERING_H