diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-17 23:43:03 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-10-18 00:09:36 +0300 |
commit | 2683b58b537e12b23993c99f3a4e38b4106b2b34 (patch) | |
tree | eb30e3a7196aabb6db55c9217be00ad19ff71c83 /moses/FF | |
parent | 5754a46905346987cdcc9eead16a3a06458b787b (diff) |
clean up comparison functions for Words and Phrases
Diffstat (limited to 'moses/FF')
-rw-r--r-- | moses/FF/BleuScoreFeature.cpp | 6 | ||||
-rw-r--r-- | moses/FF/ControlRecombination.cpp | 3 | ||||
-rw-r--r-- | moses/FF/NieceTerminal.cpp | 7 | ||||
-rw-r--r-- | moses/FF/NieceTerminal.h | 4 | ||||
-rw-r--r-- | moses/FF/TargetNgramFeature.cpp | 14 | ||||
-rw-r--r-- | moses/FF/TargetNgramFeature.h | 6 |
6 files changed, 16 insertions, 24 deletions
diff --git a/moses/FF/BleuScoreFeature.cpp b/moses/FF/BleuScoreFeature.cpp index cbf891ccf..2cbf26efc 100644 --- a/moses/FF/BleuScoreFeature.cpp +++ b/moses/FF/BleuScoreFeature.cpp @@ -40,11 +40,7 @@ bool BleuScoreState::operator==(const FFState& o) const 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; + return m_words == other.m_words; } std::ostream& operator<<(std::ostream& out, const BleuScoreState& state) diff --git a/moses/FF/ControlRecombination.cpp b/moses/FF/ControlRecombination.cpp index 5b7d2eb08..10c2898b1 100644 --- a/moses/FF/ControlRecombination.cpp +++ b/moses/FF/ControlRecombination.cpp @@ -50,8 +50,7 @@ bool ControlRecombinationState::operator==(const FFState& other) const const ControlRecombinationState &otherFF = static_cast<const ControlRecombinationState&>(other); if (m_ff.GetType() == SameOutput) { - int ret = m_outputPhrase.Compare(otherFF.m_outputPhrase); - return ret == 0; + return m_outputPhrase == otherFF.m_outputPhrase; } else { // compare hypo address. Won't be equal unless they're actually the same hypo if (m_hypo == otherFF.m_hypo) diff --git a/moses/FF/NieceTerminal.cpp b/moses/FF/NieceTerminal.cpp index 6bd65f37c..a467ce2b1 100644 --- a/moses/FF/NieceTerminal.cpp +++ b/moses/FF/NieceTerminal.cpp @@ -1,5 +1,4 @@ #include <vector> -#include <set> #include "NieceTerminal.h" #include "moses/ScoreComponentCollection.h" #include "moses/TargetPhrase.h" @@ -45,7 +44,7 @@ void NieceTerminal::EvaluateWithSourceContext(const InputType &input const Phrase *ruleSource = targetPhrase.GetRuleSource(); assert(ruleSource); - std::set<Word> terms; + boost::unordered_set<Word> terms; for (size_t i = 0; i < ruleSource->GetSize(); ++i) { const Word &word = ruleSource->GetWord(i); if (!word.IsNonTerminal()) { @@ -81,9 +80,9 @@ void NieceTerminal::EvaluateWhenApplied(const ChartHypothesis &hypo, bool NieceTerminal::ContainTerm(const InputType &input, const WordsRange &ntRange, - const std::set<Word> &terms) const + const boost::unordered_set<Word> &terms) const { - std::set<Word>::const_iterator iter; + boost::unordered_set<Word>::const_iterator iter; for (size_t pos = ntRange.GetStartPos(); pos <= ntRange.GetEndPos(); ++pos) { const Word &word = input.GetWord(pos); diff --git a/moses/FF/NieceTerminal.h b/moses/FF/NieceTerminal.h index 2ee019443..008e34212 100644 --- a/moses/FF/NieceTerminal.h +++ b/moses/FF/NieceTerminal.h @@ -1,6 +1,6 @@ #pragma once -#include <set> +#include <boost/unordered_set.hpp> #include <string> #include "StatelessFeatureFunction.h" @@ -46,7 +46,7 @@ protected: bool m_hardConstraint; bool ContainTerm(const InputType &input, const WordsRange &ntRange, - const std::set<Word> &terms) const; + const boost::unordered_set<Word> &terms) const; }; } diff --git a/moses/FF/TargetNgramFeature.cpp b/moses/FF/TargetNgramFeature.cpp index 7f8da1979..ee2b46554 100644 --- a/moses/FF/TargetNgramFeature.cpp +++ b/moses/FF/TargetNgramFeature.cpp @@ -21,23 +21,23 @@ size_t TargetNgramState::hash() const bool TargetNgramState::operator==(const FFState& other) const { const TargetNgramState& rhs = dynamic_cast<const TargetNgramState&>(other); - int result; + bool result; if (m_words.size() == rhs.m_words.size()) { for (size_t i = 0; i < m_words.size(); ++i) { - result = Word::Compare(m_words[i],rhs.m_words[i]); - if (result != 0) return false; + result = m_words[i] == rhs.m_words[i]; + if (!result) return false; } return true; } else if (m_words.size() < rhs.m_words.size()) { for (size_t i = 0; i < m_words.size(); ++i) { - result = Word::Compare(m_words[i],rhs.m_words[i]); - if (result != 0) return false; + result = m_words[i] == rhs.m_words[i]; + if (!result) return false; } return true; } else { for (size_t i = 0; i < rhs.m_words.size(); ++i) { - result = Word::Compare(m_words[i],rhs.m_words[i]); - if (result != 0) return false; + result = m_words[i] == rhs.m_words[i]; + if (!result) return false; } return true; } diff --git a/moses/FF/TargetNgramFeature.h b/moses/FF/TargetNgramFeature.h index 7826cdf4f..7c694a65e 100644 --- a/moses/FF/TargetNgramFeature.h +++ b/moses/FF/TargetNgramFeature.h @@ -182,14 +182,12 @@ public: // prefix if (m_startPos > 0) { // not for "<s> ..." - int ret = GetPrefix().Compare(other.GetPrefix()); - if (ret != 0) + if (GetPrefix() != other.GetPrefix()) return false; } if (m_endPos < m_inputSize - 1) { // not for "... </s>" - int ret = GetSuffix().Compare(other.GetSuffix()); - if (ret != 0) + if (GetSuffix() != other.GetSuffix()) return false; } return true; |