diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-13 15:09:38 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-13 15:09:38 +0300 |
commit | 10c2dabe3d165c1a657e5b226fa1e8d57be5d079 (patch) | |
tree | d532ca7b49407246c518c392a7556167a70787f9 /moses/FF | |
parent | ab025825c4569850cb2f080b3e9ce2ac821b8e5c (diff) |
new FF state API for most Lex reordering FF
Diffstat (limited to 'moses/FF')
-rw-r--r-- | moses/FF/LexicalReordering/LexicalReorderingState.cpp | 61 | ||||
-rw-r--r-- | moses/FF/LexicalReordering/ReorderingStack.cpp | 12 | ||||
-rw-r--r-- | moses/FF/LexicalReordering/ReorderingStack.h | 3 |
3 files changed, 60 insertions, 16 deletions
diff --git a/moses/FF/LexicalReordering/LexicalReorderingState.cpp b/moses/FF/LexicalReordering/LexicalReorderingState.cpp index 53c3c9712..6f368b9a9 100644 --- a/moses/FF/LexicalReordering/LexicalReorderingState.cpp +++ b/moses/FF/LexicalReordering/LexicalReorderingState.cpp @@ -333,12 +333,29 @@ Compare(const FFState& o) const size_t PhraseBasedReorderingState::hash() const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + size_t ret; + ret = hash_value(m_prevRange); + boost::hash_combine(ret, m_direction); + + return ret; } -bool PhraseBasedReorderingState::operator==(const FFState& other) const +bool PhraseBasedReorderingState::operator==(const FFState& o) const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + 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* @@ -375,6 +392,24 @@ Compare(FFState const& o) const return (cmp < 0) ? -1 : cmp ? 1 : m_forward->Compare(*other.m_forward); } +size_t BidirectionalReorderingState::hash() const +{ + size_t ret = m_backward->hash(); + boost::hash_combine(ret, m_forward->hash()); + return ret; +} + +bool BidirectionalReorderingState::operator==(const FFState& o) const +{ + if (&o == this) return 0; + + BidirectionalReorderingState const &other + = static_cast<BidirectionalReorderingState const&>(o); + + bool ret = (*m_backward == *other.m_backward) && (*m_forward == *other.m_forward); + return ret; +} + LRState* BidirectionalReorderingState:: Expand(const TranslationOption& topt, const InputType& input, @@ -385,16 +420,6 @@ Expand(const TranslationOption& topt, const InputType& input, return new BidirectionalReorderingState(m_configuration, newbwd, newfwd, m_offset); } -size_t BidirectionalReorderingState::hash() const -{ - UTIL_THROW2("TODO:Haven't figure this out yet"); -} - -bool BidirectionalReorderingState::operator==(const FFState& other) const -{ - UTIL_THROW2("TODO:Haven't figure this out yet"); -} - /////////////////////////// //HierarchicalReorderingBackwardState @@ -422,12 +447,16 @@ Compare(const FFState& o) const size_t HReorderingBackwardState::hash() const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + size_t ret = m_reoStack.hash(); + return ret; } -bool HReorderingBackwardState::operator==(const FFState& other) const +bool HReorderingBackwardState::operator==(const FFState& o) const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + const HReorderingBackwardState& other + = static_cast<const HReorderingBackwardState&>(o); + bool ret = m_reoStack == other.m_reoStack; + return ret; } LRState* diff --git a/moses/FF/LexicalReordering/ReorderingStack.cpp b/moses/FF/LexicalReordering/ReorderingStack.cpp index 49a723a36..84337b0e8 100644 --- a/moses/FF/LexicalReordering/ReorderingStack.cpp +++ b/moses/FF/LexicalReordering/ReorderingStack.cpp @@ -20,6 +20,18 @@ int ReorderingStack::Compare(const ReorderingStack& o) const return 0; } +size_t ReorderingStack::hash() const +{ + std::size_t ret = boost::hash_range(m_stack.begin(), m_stack.end()); + return ret; +} + +bool ReorderingStack::operator==(const ReorderingStack& o) const +{ + const ReorderingStack& other = static_cast<const ReorderingStack&>(o); + return m_stack == other.m_stack; +} + // Method to push (shift element into the stack and reduce if reqd) int ReorderingStack::ShiftReduce(WordsRange input_span) { diff --git a/moses/FF/LexicalReordering/ReorderingStack.h b/moses/FF/LexicalReordering/ReorderingStack.h index 5a5b80d16..9d837e65d 100644 --- a/moses/FF/LexicalReordering/ReorderingStack.h +++ b/moses/FF/LexicalReordering/ReorderingStack.h @@ -28,6 +28,9 @@ private: public: int Compare(const ReorderingStack& o) const; + size_t hash() const; + bool operator==(const ReorderingStack& other) const; + int ShiftReduce(WordsRange input_span); private: |