File size: 1,929 Bytes
158b61b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// -*- mode: c++; indent-tabs-mode: nil; tab-width:2  -*-
#pragma once
#include <vector>
#include <string>

#include "moses/Hypothesis.h"
#include "moses/ScoreComponentCollection.h"
#include "moses/Range.h"
#include "moses/Bitmap.h"
#include "moses/TranslationOption.h"
#include "moses/FF/FFState.h"
#include "LRModel.h"

namespace Moses
{

//! Abstract class for lexical reordering model states
class LRState : public FFState
{
public:

  typedef LRModel::ReorderingType ReorderingType;

  virtual
  LRState*
  Expand(const TranslationOption& hypo, const InputType& input,
         ScoreComponentCollection* scores) const = 0;

  static
  LRState*
  CreateLRState(const std::vector<std::string>& config,
                LRModel::Direction dir,
                const InputType &input);

protected:

  const LRModel& m_configuration;

  // The following is the true direction of the object, which can be
  // Backward or Forward even if the Configuration has Bidirectional.
  LRModel::Direction m_direction;
  size_t m_offset;
  //forward scores are conditioned on prev option, so need to remember it
  const TranslationOption *m_prevOption;

  inline
  LRState(const LRState *prev,
          const TranslationOption &topt)
    : m_configuration(prev->m_configuration)
    , m_direction(prev->m_direction)
    , m_offset(prev->m_offset)
    , m_prevOption(&topt)
  { }

  inline
  LRState(const LRModel &config,
          LRModel::Direction dir,
          size_t offset)
    : m_configuration(config)
    , m_direction(dir)
    , m_offset(offset)
    , m_prevOption(NULL)
  { }

  // copy the right scores in the right places, taking into account
  // forward/backward, offset, collapse
  void
  CopyScores(ScoreComponentCollection* scores,
             const TranslationOption& topt,
             const InputType& input, ReorderingType reoType) const;

  int
  ComparePrevScores(const TranslationOption *other) const;
};





}