File size: 2,528 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 83 84 85 86 87 88 |
/*
* HReorderingForwardState.cpp
*
* Created on: 22 Mar 2016
* Author: hieu
*/
#include "HReorderingForwardState.h"
#include "../../InputPathBase.h"
#include "../../PhraseBased/Manager.h"
#include "../../PhraseBased/Hypothesis.h"
namespace Moses2
{
HReorderingForwardState::HReorderingForwardState(const LRModel &config,
size_t offset) :
LRState(config, LRModel::Forward, offset), m_first(true)
{
prevPath = NULL;
m_coverage = NULL;
}
HReorderingForwardState::~HReorderingForwardState()
{
// TODO Auto-generated destructor stub
}
void HReorderingForwardState::Init(const LRState *prev,
const TargetPhrase<Moses2::Word> &topt, const InputPathBase &path, bool first,
const Bitmap *coverage)
{
prevTP = &topt;
prevPath = &path;
m_first = first;
m_coverage = coverage;
}
size_t HReorderingForwardState::hash() const
{
size_t ret;
ret = hash_value(prevPath->range);
return ret;
}
bool HReorderingForwardState::operator==(const FFState& o) const
{
if (&o == this) return true;
HReorderingForwardState const& other =
static_cast<HReorderingForwardState const&>(o);
int compareScores = (
(prevPath->range == other.prevPath->range) ?
ComparePrevScores(other.prevTP) :
(prevPath->range < other.prevPath->range) ? -1 : 1);
return compareScores == 0;
}
std::string HReorderingForwardState::ToString() const
{
return "HReorderingForwardState " + SPrint(m_offset);
}
void HReorderingForwardState::Expand(const ManagerBase &mgr,
const LexicalReordering &ff, const Hypothesis &hypo, size_t phraseTableInd,
Scores &scores, FFState &state) const
{
const Range &cur = hypo.GetInputPath().range;
// keep track of the current coverage ourselves so we don't need the hypothesis
Manager &mgrCast = const_cast<Manager&>(static_cast<const Manager&>(mgr));
Bitmaps &bms = mgrCast.GetBitmaps();
const Bitmap &cov = bms.GetBitmap(*m_coverage, cur);
if (!m_first) {
LRModel::ReorderingType reoType;
reoType = m_configuration.GetOrientation(prevPath->range, cur, cov);
CopyScores(mgr.system, scores, hypo.GetTargetPhrase(), reoType);
}
HReorderingForwardState &stateCast =
static_cast<HReorderingForwardState&>(state);
stateCast.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false,
&cov);
}
} /* namespace Moses2 */
|