File size: 3,274 Bytes
fd49381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#pragma once
#include <string>
#include <map>
#include <boost/scoped_ptr.hpp>

namespace Moses
{
class Range;
class Bitmap;
class InputType;
class LRState;
class LexicalReordering;
class SparseReordering;

//! Factory class for lexical reordering states
class LRModel
{
public:
  friend class LexicalReordering;
  enum ModelType { Monotonic, MSD, MSLR, LeftRight, None };
  enum Direction { Forward, Backward, Bidirectional };
  enum Condition { F, E, FE };

  // constants for the different types of reordering
  // (correspond to indices in the respective table)
#if 0
  typedef int ReorderingType;
  static const ReorderingType M   = 0; // monotonic
  static const ReorderingType NM  = 1; // non-monotonic
  static const ReorderingType S   = 1; // swap
  static const ReorderingType D   = 2; // discontinuous
  static const ReorderingType DL  = 2; // discontinuous, left
  static const ReorderingType DR  = 3; // discontinuous, right
  static const ReorderingType R   = 0; // right
  static const ReorderingType L   = 1; // left
  static const ReorderingType MAX = 3; // largest possible
#else
  enum ReorderingType {
    M    = 0, // monotonic
    NM   = 1, // non-monotonic
    S    = 1, // swap
    D    = 2, // discontinuous
    DL   = 2, // discontinuous, left
    DR   = 3, // discontinuous, right
    R    = 0, // right
    L    = 1, // left
    MAX  = 3, // largest possible
    NONE = 4  // largest possible
  };
#endif
  // determine orientation, depending on model:


  ReorderingType // for first phrase in phrase-based
  GetOrientation(Range const& cur) const;

  ReorderingType // for non-first phrases in phrase-based
  GetOrientation(Range const& prev, Range const& cur) const;

  ReorderingType // for HReorderingForwardState
  GetOrientation(Range const& prev, Range const& cur,
                 Bitmap const& cov) const;

  ReorderingType // for HReorderingBackwarddState
  GetOrientation(int const reoDistance) const;

  LRModel(const std::string &modelType);

  void
  ConfigureSparse(const std::map<std::string,std::string>& sparseArgs,
                  const LexicalReordering* producer);

  LRState*
  CreateLRState(const InputType &input) const;

  size_t GetNumberOfTypes() const;
  size_t GetNumScoreComponents() const;
  void SetAdditionalScoreComponents(size_t number);

  LexicalReordering*
  GetScoreProducer() const {
    return m_scoreProducer;
  }

  ModelType GetModelType() const {
    return m_modelType;
  }
  Direction GetDirection() const {
    return m_direction;
  }
  Condition GetCondition() const {
    return m_condition;
  }

  bool
  IsPhraseBased()  const {
    return m_phraseBased;
  }

  bool
  CollapseScores() const {
    return m_collapseScores;
  }

  SparseReordering const*
  GetSparseReordering() const {
    return m_sparse.get();
  }

private:
  void
  SetScoreProducer(LexicalReordering* scoreProducer) {
    m_scoreProducer = scoreProducer;
  }

  std::string const&
  GetModelString() const {
    return m_modelString;
  }

  std::string m_modelString;
  LexicalReordering *m_scoreProducer;
  ModelType m_modelType;
  bool m_phraseBased;
  bool m_collapseScores;
  Direction m_direction;
  Condition m_condition;
  size_t m_additionalScoreComponents;
  boost::scoped_ptr<SparseReordering> m_sparse;
};

}