implemente HReorderingForwardState

This commit is contained in:
Hieu Hoang 2016-03-28 19:45:59 +01:00
parent 6bc2f4a326
commit 0e15cef078
3 changed files with 48 additions and 6 deletions

View File

@ -8,6 +8,7 @@
#include "HReorderingForwardState.h"
#include "../../InputPathBase.h"
#include "../../PhraseBased/Manager.h"
#include "../../PhraseBased/Hypothesis.h"
namespace Moses2 {
@ -76,17 +77,20 @@ void HReorderingForwardState::Expand(const ManagerBase &mgr,
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
Bitmap cov(m_coverage, cur);
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(m_prevRange,cur,cov);
CopyScores(scores, topt, input, reoType);
reoType = m_configuration.GetOrientation(prevPath->range, cur, cov);
CopyScores(mgr.system, scores, hypo.GetTargetPhrase(), reoType);
}
return new HReorderingForwardState(this, topt);
*/
HReorderingForwardState &stateCast = static_cast<HReorderingForwardState&>(state);
stateCast.Init(this, hypo.GetTargetPhrase(), hypo.GetInputPath(), false, &cov);
}
} /* namespace Moses2 */

View File

@ -8,6 +8,7 @@
#include "LRModel.h"
#include "../../legacy/Util2.h"
#include "../../legacy/Range.h"
#include "../../legacy/Bitmap.h"
#include "../../MemPool.h"
#include "util/exception.hh"
#include "PhraseBasedReorderingState.h"
@ -19,6 +20,24 @@ using namespace std;
namespace Moses2 {
bool
IsMonotonicStep(Range const& prev, // words range of last source phrase
Range const& cur, // words range of current source phrase
Bitmap const& cov) // coverage bitmap
{
size_t e = prev.GetEndPos() + 1;
size_t s = cur.GetStartPos();
return (s == e || (s >= e && !cov.GetValue(e)));
}
bool
IsSwap(Range const& prev, Range const& cur, Bitmap const& cov)
{
size_t s = prev.GetStartPos();
size_t e = cur.GetEndPos();
return (e+1 == s || (e < s && !cov.GetValue(s-1)));
}
LRModel::LRModel(const std::string &modelType, LexicalReordering &ff)
: m_modelType(None)
, m_phraseBased(true)
@ -172,4 +191,18 @@ LRState *LRModel::CreateLRState(MemPool &pool) const
return ret;
}
LRModel::ReorderingType
LRModel::
GetOrientation(Range const& prev, Range const& cur,
Bitmap const& cov) const
{
return ((m_modelType == LeftRight)
? cur.GetStartPos() > prev.GetEndPos() ? R : L
: IsMonotonicStep(prev,cur,cov) ? M
: (m_modelType == Monotonic) ? NM
: IsSwap(prev,cur,cov) ? S
: (m_modelType == MSD) ? D
: cur.GetStartPos() > prev.GetEndPos() ? DR : DL);
}
} /* namespace Moses2 */

View File

@ -11,6 +11,7 @@ namespace Moses2 {
class MemPool;
class Range;
class Bitmap;
class LRState;
class LexicalReordering;
@ -71,6 +72,10 @@ public:
ReorderingType // for non-first phrases in phrase-based
GetOrientation(Range const& prev, Range const& cur) const;
ReorderingType // for HReorderingForwardState
GetOrientation(Range const& prev, Range const& cur,
Bitmap const& cov) const;
ReorderingType // for HReorderingBackwarddState
GetOrientation(int const reoDistance) const;