00001 #pragma once
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "tables-core.h"
00011
00012 #include <vector>
00013 #include <set>
00014 #include <map>
00015
00016 namespace MosesTraining
00017 {
00018
00019
00020 class PhraseAlignment
00021 {
00022 protected:
00023 PHRASE phraseS;
00024 PHRASE phraseT;
00025
00026 std::map<size_t, std::pair<size_t, size_t> > m_ntLengths;
00027
00028 void createAlignVec(size_t sourceSize, size_t targetSize);
00029 void addNTLength(const std::string &tok);
00030 public:
00031 float pcfgSum;
00032 float count;
00033 int sentenceId;
00034 std::string domain;
00035
00036 std::vector< std::set<size_t> > alignedToT;
00037 std::vector< std::set<size_t> > alignedToS;
00038
00039 void create( char*, int, bool );
00040 void clear();
00041 bool equals( const PhraseAlignment& );
00042 bool match( const PhraseAlignment& );
00043
00044 int Compare(const PhraseAlignment &compare) const;
00045 inline bool operator<(const PhraseAlignment &compare) const {
00046 return Compare(compare) < 0;
00047 }
00048
00049 const PHRASE &GetSource() const {
00050 return phraseS;
00051 }
00052 const PHRASE &GetTarget() const {
00053 return phraseT;
00054 }
00055
00056 const std::map<size_t, std::pair<size_t, size_t> > &GetNTLengths() const {
00057 return m_ntLengths;
00058 }
00059
00060 };
00061
00062 class PhraseAlignment;
00063
00064 typedef std::vector<PhraseAlignment*> PhraseAlignmentCollection;
00065
00066
00067 class PhraseAlignmentCollectionOrderer
00068 {
00069 public:
00070 bool operator()(const PhraseAlignmentCollection &collA, const PhraseAlignmentCollection &collB) const {
00071 assert(collA.size() > 0);
00072 assert(collB.size() > 0);
00073
00074 const PhraseAlignment &objA = *collA[0];
00075 const PhraseAlignment &objB = *collB[0];
00076 bool ret = objA < objB;
00077
00078 return ret;
00079 }
00080 };
00081
00082
00083
00084
00085 class PhrasePairGroup
00086 {
00087 private:
00088 typedef std::set<PhraseAlignmentCollection, PhraseAlignmentCollectionOrderer> Coll;
00089 Coll m_coll;
00090
00091
00092 public:
00093 typedef Coll::iterator iterator;
00094 typedef Coll::const_iterator const_iterator;
00095 typedef std::vector<const PhraseAlignmentCollection *> SortedColl;
00096
00097 std::pair<Coll::iterator,bool> insert ( const PhraseAlignmentCollection& obj );
00098
00099 const SortedColl &GetSortedColl() const {
00100 return m_sortedColl;
00101 }
00102 size_t GetSize() const {
00103 return m_coll.size();
00104 }
00105
00106 private:
00107 SortedColl m_sortedColl;
00108
00109 };
00110
00111
00112 }
00113