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

BidirectionalReorderingState.cpp « LexicalReordering « FF « moses2 « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc27f2a68b1fc998ced4c7b11aef83d1b5e00edd (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
/*
 * BidirectionalReorderingState.cpp
 *
 *  Created on: 22 Mar 2016
 *      Author: hieu
 */
#include <boost/functional/hash_fwd.hpp>
#include "BidirectionalReorderingState.h"
#include "../../legacy/Util2.h"
#include "../../PhraseBased/Manager.h"

using namespace std;

namespace Moses2
{

BidirectionalReorderingState::BidirectionalReorderingState(
    const LRModel &config, LRState *bw, LRState *fw, size_t offset) :
    LRState(config, LRModel::Bidirectional, offset), m_backward(bw), m_forward(
        fw)
{
}

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

void BidirectionalReorderingState::Init(const LRState *prev,
    const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
    const Bitmap *coverage)
{
  if (m_backward) {
    m_backward->Init(prev, topt, path, first, coverage);
  }
  if (m_forward) {
    m_forward->Init(prev, topt, path, first, coverage);
  }
}

std::string BidirectionalReorderingState::ToString() const
{
  return "BidirectionalReorderingState " + SPrint(this) + " "
      + SPrint(m_backward) + " " + SPrint(m_forward);
}

size_t BidirectionalReorderingState::hash() const
{
  size_t ret = m_backward->hash();
  boost::hash_combine(ret, m_forward->hash());

  return ret;
}

bool BidirectionalReorderingState::operator==(const FFState& o) const
{
  if (&o == this) return 0;

  BidirectionalReorderingState const &other =
      static_cast<BidirectionalReorderingState const&>(o);

  bool ret = (*m_backward == *other.m_backward)
      && (*m_forward == *other.m_forward);
  return ret;
}

void BidirectionalReorderingState::Expand(const ManagerBase &mgr,
    const LexicalReordering &ff, const Hypothesis &hypo, size_t phraseTableInd,
    Scores &scores, FFState &state) const
{
  BidirectionalReorderingState &stateCast =
      static_cast<BidirectionalReorderingState&>(state);
  m_backward->Expand(mgr, ff, hypo, phraseTableInd, scores,
      *stateCast.m_backward);
  m_forward->Expand(mgr, ff, hypo, phraseTableInd, scores,
      *stateCast.m_forward);
}

} /* namespace Moses2 */