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/FF | |
parent | ee3dd5b60d3fdc4e9fb6f967c28e53a5394ce79f (diff) |
new FF state API for more FF
Diffstat (limited to 'moses/FF')
-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 |
8 files changed, 53 insertions, 29 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: |