mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-06 19:49:41 +03:00
implemente HReorderingForwardState
This commit is contained in:
parent
6bc2f4a326
commit
0e15cef078
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user