implemente HReorderingForwardState

This commit is contained in:
Hieu Hoang 2016-03-28 18:49:24 +01:00
parent aaed013bf7
commit 76df27eb27
11 changed files with 84 additions and 28 deletions

View File

@ -31,13 +31,14 @@ BidirectionalReorderingState::~BidirectionalReorderingState() {
void BidirectionalReorderingState::Init(const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first)
bool first,
const Bitmap *coverage)
{
if (m_backward) {
m_backward->Init(prev, topt, path, first);
m_backward->Init(prev, topt, path, first, coverage);
}
if (m_forward) {
m_forward->Init(prev, topt, path, first);
m_forward->Init(prev, topt, path, first, coverage);
}
}

View File

@ -23,7 +23,8 @@ public:
void Init(const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first);
bool first,
const Bitmap *coverage);
size_t hash() const;
virtual bool operator==(const FFState& other) const;

View File

@ -25,7 +25,8 @@ HReorderingBackwardState::~HReorderingBackwardState() {
void HReorderingBackwardState::Init(const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first)
bool first,
const Bitmap *coverage)
{
prevTP = &topt;
}
@ -57,7 +58,7 @@ void HReorderingBackwardState::Expand(const System &system,
FFState &state) const
{
HReorderingBackwardState &nextState = static_cast<HReorderingBackwardState&>(state);
nextState.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false);
nextState.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false, NULL);
nextState.reoStack = reoStack;
const Range &swrange = hypo.GetInputPath().range;

View File

@ -22,7 +22,8 @@ public:
virtual void Init(const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first);
bool first,
const Bitmap *coverage);
virtual ~HReorderingBackwardState();

View File

@ -6,35 +6,66 @@
*/
#include "HReorderingForwardState.h"
#include "../../InputPathBase.h"
namespace Moses2 {
HReorderingForwardState::HReorderingForwardState(const LRModel &config,
LRModel::Direction dir,
size_t offset)
:LRState(config, dir, offset)
HReorderingForwardState::HReorderingForwardState(
const LRModel &config,
size_t offset)
: LRState(config, LRModel::Forward, offset)
, m_first(true)
{
// TODO Auto-generated constructor stub
prevPath = NULL;
m_coverage = NULL;
}
HReorderingForwardState::~HReorderingForwardState() {
// TODO Auto-generated destructor stub
}
size_t HReorderingForwardState::hash() const
void HReorderingForwardState::Init(
const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first,
const Bitmap *coverage)
{
prevTP = &topt;
prevPath = &path;
m_first = first;
m_coverage = coverage;
}
bool HReorderingForwardState::operator==(const FFState& other) const
size_t HReorderingForwardState::hash() const
{
size_t ret;
ret = (size_t) &prevPath->range;
boost::hash_combine(ret, m_direction);
return ret;
}
bool HReorderingForwardState::operator==(const FFState& o) const
{
if (&o == this) return true;
const HReorderingForwardState &other = static_cast<const HReorderingForwardState&>(o);
if (&prevPath->range == &other.prevPath->range) {
if (m_direction == LRModel::Forward) {
int compareScore = ComparePrevScores(other.prevTP);
return compareScore == 0;
} else {
return true;
}
} else {
return false;
}
}
std::string HReorderingForwardState::ToString() const
{
return "HReorderingForwardState";
}
void HReorderingForwardState::Expand(const System &system,

View File

@ -8,15 +8,25 @@
#include "LRState.h"
namespace Moses2 {
class Range;
class Bitmap;
class InputPathBase;
class HReorderingForwardState : public LRState
{
public:
HReorderingForwardState(const LRModel &config,
LRModel::Direction dir,
size_t offset);
HReorderingForwardState(
const LRModel &config,
size_t offset);
virtual ~HReorderingForwardState();
void Init(
const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first,
const Bitmap *coverage);
size_t hash() const;
virtual bool operator==(const FFState& other) const;
virtual std::string ToString() const;
@ -27,6 +37,12 @@ public:
Scores &scores,
FFState &state) const;
protected:
bool m_first;
//const Range &m_prevRange;
const InputPathBase *prevPath;
const Bitmap *m_coverage;
};
} /* namespace Moses2 */

View File

@ -162,7 +162,7 @@ LRState *LRModel::CreateLRState(MemPool &pool) const
//cerr << "fwd=" << fwd << fwd->ToString() << endl;
}
else {
//fwd = new HReorderingForwardState(*this, input.GetSize(), offset);
fwd = new HReorderingForwardState(*this, offset);
}
offset += m_collapseScores ? 1 : GetNumberOfTypes();
if (m_direction == Forward) return fwd;

View File

@ -8,6 +8,7 @@ class LexicalReordering;
class Hypothesis;
class System;
class Scores;
class Bitmap;
class TargetPhrase;
class InputType;
class InputPathBase;
@ -25,7 +26,8 @@ public:
virtual void Init(const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first) = 0;
bool first,
const Bitmap *coverage) = 0;
virtual void Expand(const System &system,
const LexicalReordering &ff,

View File

@ -126,7 +126,7 @@ void LexicalReordering::EmptyHypothesisState(FFState &state,
const Hypothesis &hypo) const
{
BidirectionalReorderingState &stateCast = static_cast<BidirectionalReorderingState&>(state);
stateCast.Init(NULL, hypo.GetTargetPhrase(), hypo.GetInputPath(), true);
stateCast.Init(NULL, hypo.GetTargetPhrase(), hypo.GetInputPath(), true, &hypo.GetBitmap());
}
void LexicalReordering::EvaluateInIsolation(MemPool &pool,

View File

@ -8,6 +8,7 @@
#include "PhraseBasedReorderingState.h"
#include "LexicalReordering.h"
#include "../../PhraseBased/Hypothesis.h"
#include "../../InputPathBase.h"
using namespace std;
@ -24,12 +25,12 @@ PhraseBasedReorderingState::PhraseBasedReorderingState(
prevTP = NULL;
}
void PhraseBasedReorderingState::Init(
const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first)
bool first,
const Bitmap *coverage)
{
prevTP = &topt;
prevPath = &path;
@ -76,7 +77,7 @@ void PhraseBasedReorderingState::Expand(const System &system,
}
PhraseBasedReorderingState &stateCast = static_cast<PhraseBasedReorderingState&>(state);
stateCast.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false);
stateCast.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false, NULL);
}
} /* namespace Moses2 */

View File

@ -7,10 +7,11 @@
#pragma once
#include "LRState.h"
#include "../../InputPathBase.h"
namespace Moses2 {
class InputPathBase;
class PhraseBasedReorderingState : public LRState
{
public:
@ -24,7 +25,8 @@ public:
void Init(const LRState *prev,
const TargetPhrase &topt,
const InputPathBase &path,
bool first);
bool first,
const Bitmap *coverage);
size_t hash() const;
virtual bool operator==(const FFState& other) const;