File size: 2,018 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
/*
 * HReorderingBackwardState.cpp
 *
 *  Created on: 22 Mar 2016
 *      Author: hieu
 */

#include "HReorderingBackwardState.h"
#include "../../PhraseBased/Hypothesis.h"
#include "../../PhraseBased/Manager.h"

namespace Moses2
{

HReorderingBackwardState::HReorderingBackwardState(MemPool &pool,
    const LRModel &config, size_t offset) :
  LRState(config, LRModel::Backward, offset), reoStack(pool)
{
  // TODO Auto-generated constructor stub

}

HReorderingBackwardState::~HReorderingBackwardState()
{
  // TODO Auto-generated destructor stub
}

void HReorderingBackwardState::Init(const LRState *prev,
                                    const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
                                    const Bitmap *coverage)
{
  prevTP = &topt;
  reoStack.Init();
}

size_t HReorderingBackwardState::hash() const
{
  size_t ret = reoStack.hash();
  return ret;
}

bool HReorderingBackwardState::operator==(const FFState& o) const
{
  const HReorderingBackwardState& other =
    static_cast<const HReorderingBackwardState&>(o);
  bool ret = reoStack == other.reoStack;
  return ret;
}

std::string HReorderingBackwardState::ToString() const
{
  return "HReorderingBackwardState " + SPrint(m_offset);
}

void HReorderingBackwardState::Expand(const ManagerBase &mgr,
                                      const LexicalReordering &ff, const Hypothesis &hypo, size_t phraseTableInd,
                                      Scores &scores, FFState &state) const
{
  HReorderingBackwardState &nextState =
    static_cast<HReorderingBackwardState&>(state);
  nextState.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false,
                 NULL);
  nextState.reoStack = reoStack;

  const Range &swrange = hypo.GetInputPath().range;
  int reoDistance = nextState.reoStack.ShiftReduce(swrange);
  ReorderingType reoType = m_configuration.GetOrientation(reoDistance);
  CopyScores(mgr.system, scores, hypo.GetTargetPhrase(), reoType);
}

} /* namespace Moses2 */