Welcome to mirror list, hosted at ThFree Co, Russian Federation.

AlignTables.h « src « MGIZA « alignment-enabled « experimental - github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 773b17283cfae78b185fb4dae4ace36dd51c2641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*

EGYPT Toolkit for Statistical Machine Translation
Written by Yaser Al-Onaizan, Jan Curin, Michael Jahr, Kevin Knight, John Lafferty, Dan Melamed, David Purdy, Franz Och, Noah Smith, and David Yarowsky.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
USA.

*/
#ifndef _aligntables_h
#define _aligntables_h 1

#include "defs.h"
 

#include <cassert>
 
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
//#include <vector>
#include "Vector.h"
#include <utility>
#if __GNUC__>2
#include <ext/hash_map>
using __gnu_cxx::hash_map;
#else
#include <hash_map>
#endif
#include <math.h>
#include <fstream>
#include "transpair_model1.h"


/* ----------------- Class Defintions for hashmyalignment --------------------
   Objective: This class is used to define a hash mapping function to map
   an alignment (defined as a vector of integers) into a hash key
 ----------------------------------------------------------------------------*/

class hashmyalignment : public unary_function< Vector<WordIndex>, size_t >
{
public:
  size_t operator() (const Vector<WordIndex>& key) const
    // to define the mapping function. it takes an alignment (a vector of
    // integers) and it returns an integer value (hash key). 
    {
      WordIndex j ;
      size_t s  ;
      size_t key_sum = 0 ;
      //      logmsg << "For alignment:" ;
      for (j = 1 ; j < key.size() ; j++){
	//	logmsg << " " << key[j] ;
	key_sum += (size_t) (int) pow(double(key[j]), double((j % 6)+1));
      }
      //      logmsg << " , Key value was : " <<  key_sum;
      s = key_sum % 1000000 ;      
      //      logmsg << " h(k) = " << s << endl ;
      return(s);
    }
};

class equal_to_myalignment{
  // returns true if two alignments are the same (two vectors have same enties)
public:
  bool operator()(const Vector<WordIndex> t1, 
		  const Vector<WordIndex> t2) const
    {WordIndex j ;
    if (t1.size() != t2.size())
      return(false);
    for (j = 1 ; j < t1.size() ; j++)
      if (t1[j] != t2[j])
	return(false);
    return(true);
    }
    
};

/* ---------------- End of Class Defnition for hashmyalignment --------------*/


/* ------------------ Class Defintions for alignmodel -----------------------
 Class Name: alignmodel
 Objective: Alignments neighborhhoods (collection of alignments) are stored in
 a hash table (for easy lookup). Each alignment vector is mapped into a hash 
 key using the operator defined above.
 *--------------------------------------------------------------------------*/

class alignmodel{
private:
  hash_map<Vector<WordIndex>, LogProb, hashmyalignment, equal_to_myalignment > a;
private:
  //  void erase(Vector<WordIndex>&);
public:

  // methods;

  inline hash_map<Vector<WordIndex>, LogProb, hashmyalignment, equal_to_myalignment >::iterator begin(void){return a.begin();} // begining of hash
  inline hash_map<Vector<WordIndex>, LogProb, hashmyalignment, equal_to_myalignment >::iterator end(void){return a.end();} // end of hash
  inline const hash_map<Vector<WordIndex>, LogProb, hashmyalignment, equal_to_myalignment >& getHash() const {return a;}; // reference to hash table
  bool insert(Vector<WordIndex>&, LogProb val=0.0); // add a alignmnet
 //  void setValue(Vector<WordIndex>&, LogProb val); // not needed
  LogProb getValue(Vector<WordIndex>&)const; // retrieve prob. of alignment
  inline void clear(void){ a.clear();}; // clear hash table 
  //  void printTable(const char* filename);
  inline void resize(WordIndex n) {a.resize(n);}; // resize table

};

/* -------------- End of alignmode Class Definitions ------------------------*/
#endif