separate PhraseBasedReorderingState into its own file

This commit is contained in:
Hieu Hoang 2016-03-23 10:48:16 +00:00
parent be20f2c149
commit ba9a9b3ef9
3 changed files with 11 additions and 97 deletions

View File

@ -2595,6 +2595,16 @@
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/LexicalReordering/LexicalReorderingTable.h</locationURI>
</link>
<link>
<name>FF/LexicalReordering/PhraseBasedReorderingState.cpp</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/LexicalReordering/PhraseBasedReorderingState.cpp</locationURI>
</link>
<link>
<name>FF/LexicalReordering/PhraseBasedReorderingState.h</name>
<type>1</type>
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/LexicalReordering/PhraseBasedReorderingState.h</locationURI>
</link>
<link>
<name>FF/LexicalReordering/ReorderingStack.cpp</name>
<type>1</type>

View File

@ -13,6 +13,7 @@
#include "ReorderingStack.h"
#include "HReorderingForwardState.h"
#include "HReorderingBackwardState.h"
#include "PhraseBasedReorderingState.h"
namespace Moses
{
@ -292,73 +293,6 @@ ComparePrevScores(const TranslationOption *other) const
return 0;
}
// ===========================================================================
// PHRASE BASED REORDERING STATE
// ===========================================================================
bool PhraseBasedReorderingState::m_useFirstBackwardScore = true;
PhraseBasedReorderingState::
PhraseBasedReorderingState(const PhraseBasedReorderingState *prev,
const TranslationOption &topt)
: LRState(prev, topt)
, m_prevRange(topt.GetSourceWordsRange())
, m_first(false)
{ }
PhraseBasedReorderingState::
PhraseBasedReorderingState(const LRModel &config,
LRModel::Direction dir, size_t offset)
: LRState(config, dir, offset)
, m_prevRange(NOT_FOUND,NOT_FOUND)
, m_first(true)
{ }
size_t PhraseBasedReorderingState::hash() const
{
size_t ret;
ret = hash_value(m_prevRange);
boost::hash_combine(ret, m_direction);
return ret;
}
bool PhraseBasedReorderingState::operator==(const FFState& o) const
{
if (&o == this) return true;
const PhraseBasedReorderingState &other = static_cast<const PhraseBasedReorderingState&>(o);
if (m_prevRange == other.m_prevRange) {
if (m_direction == LRModel::Forward) {
int compareScore = ComparePrevScores(other.m_prevOption);
return compareScore == 0;
} else {
return true;
}
} else {
return false;
}
}
LRState*
PhraseBasedReorderingState::
Expand(const TranslationOption& topt, const InputType& input,
ScoreComponentCollection* scores) const
{
// const LRModel::ModelType modelType = m_configuration.GetModelType();
if ((m_direction != LRModel::Forward && m_useFirstBackwardScore) || !m_first) {
LRModel const& lrmodel = m_configuration;
Range const cur = topt.GetSourceWordsRange();
LRModel::ReorderingType reoType = (m_first ? lrmodel.GetOrientation(cur)
: lrmodel.GetOrientation(m_prevRange,cur));
CopyScores(scores, topt, input, reoType);
}
return new PhraseBasedReorderingState(this, topt);
}
///////////////////////////
//BidirectionalReorderingState

View File

@ -226,36 +226,6 @@ public:
ScoreComponentCollection* scores) const;
};
//! State for the standard Moses implementation of lexical reordering models
//! (see Koehn et al, Edinburgh System Description for the 2005 NIST MT
//! Evaluation)
class PhraseBasedReorderingState
: public LRState
{
private:
Range m_prevRange;
bool m_first;
public:
static bool m_useFirstBackwardScore;
PhraseBasedReorderingState(const LRModel &config,
LRModel::Direction dir,
size_t offset);
PhraseBasedReorderingState(const PhraseBasedReorderingState *prev,
const TranslationOption &topt);
virtual size_t hash() const;
virtual bool operator==(const FFState& other) const;
virtual
LRState*
Expand(const TranslationOption& topt,const InputType& input,
ScoreComponentCollection* scores) const;
ReorderingType GetOrientationTypeMSD(Range currRange) const;
ReorderingType GetOrientationTypeMSLR(Range currRange) const;
ReorderingType GetOrientationTypeMonotonic(Range currRange) const;
ReorderingType GetOrientationTypeLeftRight(Range currRange) const;
};