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

MoveSwapMatrix.h « src « mgizapp - github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b1bbf15fcf16b21680db8ac5b314844dff2cb129 (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
/*

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.

*/
/*--
MoveSwapMatrix: Efficient representation for moving and swapping
around in IBM3 training.
Franz Josef Och (30/07/99)
--*/
#ifndef moveswap2_costs_h_defined
#define moveswap2_costs_h_defined
#include "alignment.h"
#include "transpair_model3.h"
#include "myassert.h"

extern short DoViterbiTraining;

template<class TRANSPAIR>
class MoveSwapMatrix : public alignment
{
 private:
  const TRANSPAIR&ef;
  const WordIndex l, m;
  Array2<LogProb, Vector<LogProb> > _cmove, _cswap;
  Array2<char,Vector<char> > delmove,delswap;
  Vector<int> changed;
  int changedCounter;
  const int modelnr;
  bool lazyEvaluation;
  bool centerDeleted;
 public:
  bool check()const
    {
	  return 1;
    }
  const TRANSPAIR&get_ef()const
    {return ef;}
  bool isCenterDeleted()const
    {return centerDeleted;}
  bool isLazy()const
    {return lazyEvaluation;}
  MoveSwapMatrix(const TRANSPAIR&_ef, const alignment&_a);
  void updateJ(WordIndex j, bool,double thisValue);
  void updateI(WordIndex i,double thisValue);
  void doMove(WordIndex _i, WordIndex _j);
  void doSwap(WordIndex _j1, WordIndex _j2);
  void delCenter()
    {
      centerDeleted=1;
    }
  void delMove(WordIndex x, WordIndex y)
    {
      delmove(x,y)=1;
    }
  void delSwap(WordIndex x, WordIndex y)
    {
      massert(y>x);
      delswap(x,y)=1;
      delswap(y,x)=1;
    }
  bool isDelMove(WordIndex x, WordIndex y)const
    {
      return DoViterbiTraining||delmove(x,y);
    }
  bool isDelSwap(WordIndex x, WordIndex y)const
    {
      massert(y>x);
      return DoViterbiTraining||delswap(x,y);
    }
  LogProb cmove(WordIndex x, WordIndex y)const
    {
      massert( get_al(y)!=x );
      massert( delmove(x,y)==0 );
      if( lazyEvaluation )
	return ef.scoreOfMove(*this,x,y);
      else
	{
	  return _cmove(x, y);
	}
    }
  LogProb cswap(WordIndex x, WordIndex y)const
    {
      massert(x<y);
      massert(delswap(x,y)==0);
      massert(get_al(x)!=get_al(y));
      if( lazyEvaluation )
	return ef.scoreOfSwap(*this,x,y);
      else
	{
	  massert(y>x);
	  return _cswap(x, y);
	}
    }
  void printWrongs()const;
  bool isRight()const;
  friend ostream&operator<<(ostream&out, const MoveSwapMatrix<TRANSPAIR>&m)
    {return out << (alignment)m << "\nEF:\n"<< m.ef << "\nCMOVE\n"<<m._cmove << "\nCSWAP\n" << m._cswap << endl;};
};
#endif