diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2016-03-23 18:18:20 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2016-03-23 18:18:20 +0300 |
commit | 4c07496eb2c5d21ca238abdcad11fad7b93657d4 (patch) | |
tree | 3bd65f557f6d3357e50a55b91cc5471b285b6637 /moses/FF | |
parent | dccaa63b31258300c8503d25545b0a99e463fb17 (diff) |
compile error with suffix array
Diffstat (limited to 'moses/FF')
4 files changed, 193 insertions, 0 deletions
diff --git a/moses/FF/LexicalReordering/HReorderingBackwardState.cpp b/moses/FF/LexicalReordering/HReorderingBackwardState.cpp new file mode 100644 index 000000000..252a2ce94 --- /dev/null +++ b/moses/FF/LexicalReordering/HReorderingBackwardState.cpp @@ -0,0 +1,50 @@ +#include "HReorderingBackwardState.h" + +namespace Moses +{ + +/////////////////////////// +//HierarchicalReorderingBackwardState + +HReorderingBackwardState:: +HReorderingBackwardState(const HReorderingBackwardState *prev, + const TranslationOption &topt, + ReorderingStack reoStack) + : LRState(prev, topt), m_reoStack(reoStack) +{ } + +HReorderingBackwardState:: +HReorderingBackwardState(const LRModel &config, size_t offset) + : LRState(config, LRModel::Backward, offset) +{ } + +size_t HReorderingBackwardState::hash() const +{ + size_t ret = m_reoStack.hash(); + return ret; +} + +bool HReorderingBackwardState::operator==(const FFState& o) const +{ + const HReorderingBackwardState& other + = static_cast<const HReorderingBackwardState&>(o); + bool ret = m_reoStack == other.m_reoStack; + return ret; +} + +LRState* +HReorderingBackwardState:: +Expand(const TranslationOption& topt, const InputType& input, + ScoreComponentCollection* scores) const +{ + HReorderingBackwardState* nextState; + nextState = new HReorderingBackwardState(this, topt, m_reoStack); + Range swrange = topt.GetSourceWordsRange(); + int reoDistance = nextState->m_reoStack.ShiftReduce(swrange); + ReorderingType reoType = m_configuration.GetOrientation(reoDistance); + CopyScores(scores, topt, input, reoType); + return nextState; +} + +} + diff --git a/moses/FF/LexicalReordering/HReorderingBackwardState.h b/moses/FF/LexicalReordering/HReorderingBackwardState.h new file mode 100644 index 000000000..cfb017b6f --- /dev/null +++ b/moses/FF/LexicalReordering/HReorderingBackwardState.h @@ -0,0 +1,33 @@ +#pragma once +#include "LRState.h" +#include "ReorderingStack.h" + +namespace Moses +{ + +//! State for a hierarchical reordering model (see Galley and Manning, A +//! Simple and Effective Hierarchical Phrase Reordering Model, EMNLP 2008) +//! backward state (conditioned on the previous phrase) +class HReorderingBackwardState : public LRState +{ +private: + ReorderingStack m_reoStack; +public: + HReorderingBackwardState(const LRModel &config, size_t offset); + HReorderingBackwardState(const HReorderingBackwardState *prev, + const TranslationOption &topt, + ReorderingStack reoStack); + virtual size_t hash() const; + virtual bool operator==(const FFState& other) const; + + virtual LRState* Expand(const TranslationOption& hypo, const InputType& input, + ScoreComponentCollection* scores) const; + +private: + ReorderingType GetOrientationTypeMSD(int reoDistance) const; + ReorderingType GetOrientationTypeMSLR(int reoDistance) const; + ReorderingType GetOrientationTypeMonotonic(int reoDistance) const; + ReorderingType GetOrientationTypeLeftRight(int reoDistance) const; +}; + +} diff --git a/moses/FF/LexicalReordering/PhraseBasedReorderingState.cpp b/moses/FF/LexicalReordering/PhraseBasedReorderingState.cpp new file mode 100644 index 000000000..8509cc723 --- /dev/null +++ b/moses/FF/LexicalReordering/PhraseBasedReorderingState.cpp @@ -0,0 +1,72 @@ +#include "PhraseBasedReorderingState.h" + +namespace Moses +{ +// =========================================================================== +// 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); +} + +} + diff --git a/moses/FF/LexicalReordering/PhraseBasedReorderingState.h b/moses/FF/LexicalReordering/PhraseBasedReorderingState.h new file mode 100644 index 000000000..cb8bb68e2 --- /dev/null +++ b/moses/FF/LexicalReordering/PhraseBasedReorderingState.h @@ -0,0 +1,38 @@ +#pragma once +#include "LRState.h" + +namespace Moses +{ +//! 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; +}; + +} + |