diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-14 17:21:37 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-14 17:21:37 +0300 |
commit | 36cab5b7883da6df8bb764a612bc59efc5402669 (patch) | |
tree | ac1f9e2435257086b31004819bbcd1aae31dad87 /moses | |
parent | ee3dd5b60d3fdc4e9fb6f967c28e53a5394ce79f (diff) |
new FF state API for more FF
Diffstat (limited to 'moses')
-rw-r--r-- | moses/FF/BleuScoreFeature.cpp | 22 | ||||
-rw-r--r-- | moses/FF/BleuScoreFeature.h | 5 | ||||
-rw-r--r-- | moses/FF/ConstrainedDecoding.cpp | 7 | ||||
-rw-r--r-- | moses/FF/ConstrainedDecoding.h | 5 | ||||
-rw-r--r-- | moses/FF/CoveredReferenceFeature.cpp | 14 | ||||
-rw-r--r-- | moses/FF/CoveredReferenceFeature.h | 5 | ||||
-rw-r--r-- | moses/FF/PhraseBoundaryFeature.cpp | 14 | ||||
-rw-r--r-- | moses/FF/PhraseBoundaryFeature.h | 10 | ||||
-rw-r--r-- | moses/LM/BackwardLMState.cpp | 12 | ||||
-rw-r--r-- | moses/LM/BackwardLMState.h | 16 | ||||
-rw-r--r-- | moses/LM/BilingualLM.h | 3 | ||||
-rw-r--r-- | moses/LM/ChartState.h | 39 |
12 files changed, 105 insertions, 47 deletions
diff --git a/moses/FF/BleuScoreFeature.cpp b/moses/FF/BleuScoreFeature.cpp index 1f3549536..d5e1a1f10 100644 --- a/moses/FF/BleuScoreFeature.cpp +++ b/moses/FF/BleuScoreFeature.cpp @@ -51,7 +51,27 @@ int BleuScoreState::Compare(const FFState& o) const size_t BleuScoreState::hash() const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + if (StaticData::Instance().IsSyntax()) + return 0; + + size_t ret = hash_value(m_words); + return ret; +} + +bool BleuScoreState::operator==(const FFState& o) const +{ + if (&o == this) + return true; + + if (StaticData::Instance().IsSyntax()) + return true; + + const BleuScoreState& other = static_cast<const BleuScoreState&>(o); + int c = m_words.Compare(other.m_words); + if (c == 0) + return true; + + return false; } std::ostream& operator<<(std::ostream& out, const BleuScoreState& state) diff --git a/moses/FF/BleuScoreFeature.h b/moses/FF/BleuScoreFeature.h index 612db3ab0..b6c9f766d 100644 --- a/moses/FF/BleuScoreFeature.h +++ b/moses/FF/BleuScoreFeature.h @@ -27,10 +27,7 @@ public: BleuScoreState(); virtual int Compare(const FFState& other) const; size_t hash() const; - virtual bool operator==(const FFState& other) const - { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } + virtual bool operator==(const FFState& other) const; void print(std::ostream& out) const; diff --git a/moses/FF/ConstrainedDecoding.cpp b/moses/FF/ConstrainedDecoding.cpp index ae2cc9a96..16605c8a7 100644 --- a/moses/FF/ConstrainedDecoding.cpp +++ b/moses/FF/ConstrainedDecoding.cpp @@ -35,6 +35,13 @@ size_t ConstrainedDecodingState::hash() const return ret; } +bool ConstrainedDecodingState::operator==(const FFState& other) const +{ + const ConstrainedDecodingState &otherFF = static_cast<const ConstrainedDecodingState&>(other); + bool ret = m_outputPhrase == otherFF.m_outputPhrase; + return ret; +} + ////////////////////////////////////////////////////////////////// ConstrainedDecoding::ConstrainedDecoding(const std::string &line) :StatefulFeatureFunction(1, line) diff --git a/moses/FF/ConstrainedDecoding.h b/moses/FF/ConstrainedDecoding.h index e03ab723c..5c61eff38 100644 --- a/moses/FF/ConstrainedDecoding.h +++ b/moses/FF/ConstrainedDecoding.h @@ -19,10 +19,7 @@ public: int Compare(const FFState& other) const; virtual size_t hash() const; - virtual bool operator==(const FFState& other) const - { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } + virtual bool operator==(const FFState& other) const; const Phrase &GetPhrase() const { return m_outputPhrase; diff --git a/moses/FF/CoveredReferenceFeature.cpp b/moses/FF/CoveredReferenceFeature.cpp index b8479ac01..3ad93c2f0 100644 --- a/moses/FF/CoveredReferenceFeature.cpp +++ b/moses/FF/CoveredReferenceFeature.cpp @@ -44,14 +44,12 @@ int CoveredReferenceState::Compare(const FFState& other) const size_t CoveredReferenceState::hash() const { - size_t ret = 0; - boost::hash<string> strHash; - BOOST_FOREACH(const string &str, m_coveredRef) { - size_t hash = strHash(str); - boost::hash_combine(ret, hash); - } - - return ret; + UTIL_THROW2("TODO:Haven't figure this out yet"); +} + +bool CoveredReferenceState::operator==(const FFState& other) const +{ + UTIL_THROW2("TODO:Haven't figure this out yet"); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/moses/FF/CoveredReferenceFeature.h b/moses/FF/CoveredReferenceFeature.h index 399745e5f..6265b0a74 100644 --- a/moses/FF/CoveredReferenceFeature.h +++ b/moses/FF/CoveredReferenceFeature.h @@ -21,10 +21,7 @@ public: int Compare(const FFState& other) const; virtual size_t hash() const; - virtual bool operator==(const FFState& other) const - { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } + virtual bool operator==(const FFState& other) const; }; diff --git a/moses/FF/PhraseBoundaryFeature.cpp b/moses/FF/PhraseBoundaryFeature.cpp index 3fdcf27f9..67cc93605 100644 --- a/moses/FF/PhraseBoundaryFeature.cpp +++ b/moses/FF/PhraseBoundaryFeature.cpp @@ -17,6 +17,20 @@ int PhraseBoundaryState::Compare(const FFState& other) const return Word::Compare(*m_sourceWord,*(rhs.m_sourceWord)); } +size_t PhraseBoundaryState::hash() const { + size_t ret = hash_value(*m_targetWord); + boost::hash_combine(ret, hash_value(*m_sourceWord)); + + return ret; +} +bool PhraseBoundaryState::operator==(const FFState& other) const +{ + const PhraseBoundaryState& rhs = dynamic_cast<const PhraseBoundaryState&>(other); + bool ret = *m_targetWord == *rhs.m_targetWord && *m_sourceWord == *rhs.m_sourceWord; + return ret; +} + +///////////////////////////////////////////////////////////////////////////////////// PhraseBoundaryFeature::PhraseBoundaryFeature(const std::string &line) : StatefulFeatureFunction(0, line) { diff --git a/moses/FF/PhraseBoundaryFeature.h b/moses/FF/PhraseBoundaryFeature.h index 0bc32ff4a..9d12303e9 100644 --- a/moses/FF/PhraseBoundaryFeature.h +++ b/moses/FF/PhraseBoundaryFeature.h @@ -24,14 +24,8 @@ public: return m_targetWord; } virtual int Compare(const FFState& other) const; - - virtual size_t hash() const { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } - virtual bool operator==(const FFState& other) const - { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } + virtual size_t hash() const; + virtual bool operator==(const FFState& other) const; private: diff --git a/moses/LM/BackwardLMState.cpp b/moses/LM/BackwardLMState.cpp index 466c4b655..12203828e 100644 --- a/moses/LM/BackwardLMState.cpp +++ b/moses/LM/BackwardLMState.cpp @@ -31,4 +31,16 @@ int BackwardLMState::Compare(const FFState &o) const return state.left.Compare(other.state.left); } +size_t BackwardLMState::hash() const +{ + size_t ret = hash_value(state.left); + return ret; +} +bool BackwardLMState::operator==(const FFState& o) const +{ + const BackwardLMState &other = static_cast<const BackwardLMState &>(o); + bool ret = state.left == other.state.left; + return ret; +} + } diff --git a/moses/LM/BackwardLMState.h b/moses/LM/BackwardLMState.h index d0b23a1fa..765a8350d 100644 --- a/moses/LM/BackwardLMState.h +++ b/moses/LM/BackwardLMState.h @@ -47,22 +47,10 @@ class BackwardLMState : public FFState public: - /* - int Compare(const FFState &o) const { - const BackwardLMState &other = static_cast<const BackwardLMState &>(o); - return state.left.Compare(other.state.left); - } - */ int Compare(const FFState &o) const; - size_t hash() const - { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } - virtual bool operator==(const FFState& other) const - { - UTIL_THROW2("TODO:Haven't figure this out yet"); - } + size_t hash() const; + virtual bool operator==(const FFState& other) const; // Allow BackwardLanguageModel to access the private members of this class template <class Model> friend class BackwardLanguageModel; diff --git a/moses/LM/BilingualLM.h b/moses/LM/BilingualLM.h index 16be7866a..8b27443f3 100644 --- a/moses/LM/BilingualLM.h +++ b/moses/LM/BilingualLM.h @@ -44,7 +44,8 @@ public: } virtual bool operator==(const FFState& other) const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + const BilingualLMState &otherState = static_cast<const BilingualLMState&>(other); + return m_hash == otherState.m_hash; } }; diff --git a/moses/LM/ChartState.h b/moses/LM/ChartState.h index 3ebc2de9e..9bdea6c34 100644 --- a/moses/LM/ChartState.h +++ b/moses/LM/ChartState.h @@ -170,11 +170,44 @@ public: size_t hash() const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + size_t ret; + + // prefix + ret = m_hypo.GetCurrSourceRange().GetStartPos() > 0; + if (m_hypo.GetCurrSourceRange().GetStartPos() > 0) { // not for "<s> ..." + size_t hash = hash_value(GetPrefix()); + boost::hash_combine(ret, hash); + } + + // suffix + size_t inputSize = m_hypo.GetManager().GetSource().GetSize(); + boost::hash_combine(ret, m_hypo.GetCurrSourceRange().GetEndPos() < inputSize - 1); + if (m_hypo.GetCurrSourceRange().GetEndPos() < inputSize - 1) { // not for "... </s>" + size_t hash = m_lmRightContext->hash(); + boost::hash_combine(ret, hash); + } + + return ret; } - virtual bool operator==(const FFState& other) const + virtual bool operator==(const FFState& o) const { - UTIL_THROW2("TODO:Haven't figure this out yet"); + const LanguageModelChartState &other = + dynamic_cast<const LanguageModelChartState &>( o ); + + // prefix + if (m_hypo.GetCurrSourceRange().GetStartPos() > 0) { // not for "<s> ..." + bool ret = GetPrefix() == other.GetPrefix(); + if (ret == false) + return false; + } + + // suffix + size_t inputSize = m_hypo.GetManager().GetSource().GetSize(); + if (m_hypo.GetCurrSourceRange().GetEndPos() < inputSize - 1) { // not for "... </s>" + bool ret = (*other.GetRightContext()) == (*m_lmRightContext); + return ret; + } + return true; } }; |