Included AlignmentInfo in TargetPhrase hash

This commit is contained in:
Barry Haddow 2012-10-11 22:18:56 +01:00
parent 2bef14a43e
commit 732b299ba3
4 changed files with 24 additions and 24 deletions

View File

@ -39,7 +39,6 @@ class AlignmentInfo
{
friend std::ostream& operator<<(std::ostream &, const AlignmentInfo &);
friend struct AlignmentInfoOrderer;
friend struct AlignmentInfoComparator;
friend struct AlignmentInfoHasher;
friend class AlignmentInfoCollection;
@ -73,6 +72,13 @@ class AlignmentInfo
size_t GetSize() const { return m_collection.size(); }
std::vector< const std::pair<size_t,size_t>* > GetSortedAlignments() const;
bool operator==(const AlignmentInfo& rhs) const
{
return m_collection == rhs.m_collection &&
m_terminalCollection == rhs.m_terminalCollection &&
m_nonTermIndexMap == rhs.m_nonTermIndexMap;
}
private:
//! AlignmentInfo objects should only be created by an AlignmentInfoCollection
@ -119,18 +125,6 @@ struct AlignmentInfoOrderer
}
};
/**
* Equality functoid
**/
struct AlignmentInfoComparator
{
inline bool operator()(const AlignmentInfo &a, const AlignmentInfo &b) const {
return a.m_collection == b.m_collection &&
a.m_terminalCollection == b.m_terminalCollection &&
a.m_nonTermIndexMap == b.m_nonTermIndexMap;
}
};
/**
* Hashing functoid
**/
@ -147,4 +141,9 @@ struct AlignmentInfoHasher
};
inline size_t hash_value(const AlignmentInfo& a) {
static AlignmentInfoHasher hasher;
return hasher(a);
}
}

View File

@ -56,13 +56,12 @@ struct AlignmentInfoFixture {
BOOST_FIXTURE_TEST_CASE(comparator, AlignmentInfoFixture)
{
AlignmentInfoComparator comp;
BOOST_CHECK(comp(*ai1,*ai2));
BOOST_CHECK(comp(*ai1,*ai1));
BOOST_CHECK(comp(*ai2,*ai2));
BOOST_CHECK(comp(*ai3,*ai3));
BOOST_CHECK(!comp(*ai2,*ai3));
BOOST_CHECK(!comp(*ai1,*ai3));
BOOST_CHECK(*ai1 == *ai2);
BOOST_CHECK(*ai1 == *ai1);
BOOST_CHECK(*ai2 == *ai2);
BOOST_CHECK(*ai3 == *ai3);
BOOST_CHECK(!(*ai2 == *ai3));
BOOST_CHECK(!(*ai1 == *ai3));
}
BOOST_FIXTURE_TEST_CASE(hasher, AlignmentInfoFixture)

View File

@ -72,7 +72,7 @@ private:
StackVec m_emptyStackVec;
//! Some features should be calculated prior to search
boost::unordered_map<TargetPhrase,ScoreComponentCollection, RuleHash, RuleComparator> m_precalculatedScores;
boost::unordered_map<TargetPhrase,ScoreComponentCollection, TargetPhraseHasher, TargetPhraseComparator> m_precalculatedScores;
//! Pre-calculate most stateless feature values
void PreCalculateScores();

View File

@ -177,23 +177,25 @@ std::ostream& operator<<(std::ostream&, const TargetPhrase&);
/**
* Hasher that looks at source and target phrase.
**/
struct RuleHash
struct TargetPhraseHasher
{
inline size_t operator()(const TargetPhrase& targetPhrase) const
{
size_t seed = 0;
boost::hash_combine(seed, targetPhrase);
boost::hash_combine(seed, targetPhrase.GetSourcePhrase());
boost::hash_combine(seed, targetPhrase.GetAlignmentInfo());
return seed;
}
};
struct RuleComparator
struct TargetPhraseComparator
{
inline bool operator()(const TargetPhrase& lhs, const TargetPhrase& rhs) const
{
return lhs.Compare(rhs) == 0 &&
lhs.GetSourcePhrase().Compare(rhs.GetSourcePhrase()) == 0;
lhs.GetSourcePhrase().Compare(rhs.GetSourcePhrase()) == 0 &&
lhs.GetAlignmentInfo() == rhs.GetAlignmentInfo();
}
};