|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
#include <iostream> |
|
#include <ostream> |
|
#include <set> |
|
#include <vector> |
|
#include <cstdlib> |
|
|
|
#include <boost/functional/hash.hpp> |
|
#include "TypeDef.h" |
|
namespace Moses |
|
{ |
|
|
|
class AlignmentInfoCollection; |
|
|
|
|
|
|
|
|
|
class AlignmentInfo |
|
{ |
|
friend std::ostream& operator<<(std::ostream &, const AlignmentInfo &); |
|
friend struct AlignmentInfoOrderer; |
|
friend struct AlignmentInfoHasher; |
|
friend class AlignmentInfoCollection; |
|
friend class VW; |
|
|
|
public: |
|
typedef std::set<std::pair<size_t,size_t> > CollType; |
|
typedef std::vector<size_t> NonTermIndexMap; |
|
typedef CollType::const_iterator const_iterator; |
|
|
|
const_iterator begin() const { |
|
return m_collection.begin(); |
|
} |
|
const_iterator end() const { |
|
return m_collection.end(); |
|
} |
|
|
|
void Add(size_t sourcePos, size_t targetPos) { |
|
m_collection.insert(std::pair<size_t, size_t>(sourcePos, targetPos)); |
|
} |
|
|
|
|
|
|
|
|
|
const NonTermIndexMap &GetNonTermIndexMap() const { |
|
return m_nonTermIndexMap; |
|
} |
|
|
|
|
|
|
|
const NonTermIndexMap &GetNonTermIndexMap2() const { |
|
return m_nonTermIndexMap2; |
|
} |
|
|
|
const CollType &GetAlignments() const { |
|
return m_collection; |
|
} |
|
|
|
std::set<size_t> GetAlignmentsForSource(size_t sourcePos) const; |
|
std::set<size_t> GetAlignmentsForTarget(size_t targetPos) const; |
|
|
|
size_t GetSize() const { |
|
return m_collection.size(); |
|
} |
|
|
|
std::vector< const std::pair<size_t,size_t>* > |
|
GetSortedAlignments(WordAlignmentSort SortOrder) const; |
|
|
|
std::vector<size_t> GetSourceIndex2PosMap() const; |
|
|
|
bool operator==(const AlignmentInfo& rhs) const { |
|
return m_collection == rhs.m_collection && |
|
m_nonTermIndexMap == rhs.m_nonTermIndexMap; |
|
} |
|
|
|
private: |
|
|
|
explicit AlignmentInfo(const std::set<std::pair<size_t,size_t> > &pairs); |
|
explicit AlignmentInfo(const std::vector<unsigned char> &aln); |
|
|
|
|
|
explicit AlignmentInfo(const std::string &str); |
|
|
|
void BuildNonTermIndexMaps(); |
|
|
|
CollType m_collection; |
|
NonTermIndexMap m_nonTermIndexMap; |
|
NonTermIndexMap m_nonTermIndexMap2; |
|
}; |
|
|
|
|
|
|
|
|
|
struct AlignmentInfoOrderer { |
|
bool operator()(const AlignmentInfo &a, const AlignmentInfo &b) const { |
|
if (a.m_collection == b.m_collection) { |
|
return a.m_nonTermIndexMap < b.m_nonTermIndexMap; |
|
} else { |
|
return a.m_collection < b.m_collection; |
|
} |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
struct AlignmentInfoHasher { |
|
size_t operator()(const AlignmentInfo& a) const { |
|
size_t seed = 0; |
|
boost::hash_combine(seed,a.m_collection); |
|
boost::hash_combine(seed,a.m_nonTermIndexMap); |
|
return seed; |
|
} |
|
|
|
}; |
|
|
|
inline size_t hash_value(const AlignmentInfo& a) |
|
{ |
|
static AlignmentInfoHasher hasher; |
|
return hasher(a); |
|
} |
|
|
|
} |
|
|