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

transpair_model1.h « src « MGIZA « alignment-enabled « experimental - github.com/moses-smt/mgiza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 00d7875612758becb40a09d344f57c7f72ac55bd (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
/*

Copyright (C) 2000,2001  Franz Josef Och (RWTH Aachen - Lehrstuhl fuer Informatik VI)

This file is part of GIZA++ ( extension of GIZA ).

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 transpair_model1_h_fjo_defined
#define transpair_model1_h_fjo_defined
//#include "logprob.h"
#include "defs.h"
#include "Array2.h"
#include "defs.h"
#include "Vector.h"
#include "NTables.h"
#include "ATables.h"
#include "TTables.h"
#include "alignment.h"
#include <math.h>
#include <algorithm>
#include "Array2.h"
#include "mystl.h"

class transpair_model1 
{
 public:
  bool verboseTP;
  Array2<PROB, Vector<PROB> > t;
  WordIndex l, m;
  Vector<WordIndex> E,F;
  void setMode(bool)
    {}
  transpair_model1(const Vector<WordIndex>&es, const Vector<WordIndex>&fs, const tmodel<COUNT, PROB>&tTable)
    : verboseTP(0),t(es.size(), fs.size()),l(es.size()-1), m(fs.size()-1),E(es),F(fs)
    {
      WordIndex l=es.size()-1,m=fs.size()-1;
      for(WordIndex i=0;i<=l;i++)
	for(WordIndex j=1;j<=m;j++)
	  {
	    t(i, j)=tTable.getProb(es[i], fs[j]);
	    if( !(t(i,j)>=PROB_SMOOTH) )
	      cerr << "ERROR IN PROBABILITY: " << t(i,j) << " " << PROB_SMOOTH << endl;
	  }
    }
  /*  transpair_model1(const Vector<WordIndex>&es, const Vector<WordIndex>&fs)
    : verboseTP(0),t(es.size(), fs.size()),l(es.size()-1), m(fs.size()-1),E(es),F(fs)
    {
      WordIndex l=es.size()-1,m=fs.size()-1;
      for(WordIndex i=0;i<=l;i++)
	for(WordIndex j=1;j<=m;j++)
	  {
	    const string&estr=globeTrainVcbList->getVocabList()[es[i]].word;
	    const string&fstr=globfTrainVcbList->getVocabList()[fs[j]].word;
	    if( lev(estr,fstr)==0 )
	      t(i,j)=1.0;
	    else
	      t(i,j)=1/100.0;
	    massert( t(i,j)>=PROB_SMOOTH );
	  }
}*/
  WordIndex get_l()const
    {return l;}
  WordIndex get_m()const
    {return m;}
  const PROB&get_t(WordIndex i, WordIndex j)const
    {massert( t(i,j)>=PROB_SMOOTH);
    return t(i, j);}
  WordIndex get_es(int i)const {return E[i];}
  WordIndex get_fs(int j)const {return F[j];}
  bool greedyHillClimbing()const
    {return 0;}
  void computeScores(const alignment&,vector<double>&)const
    {}
  LogProb scoreOfMove(const alignment&a, WordIndex new_i, WordIndex j,double=-1.0)const
    {
      int old_i=a(j);
      return (t(new_i, j) /t(old_i, j));
    }
  LogProb scoreOfSwap(const alignment&a, WordIndex j1, WordIndex j2,double=-1.0)const 
    {
      WordIndex i1=a(j1), i2=a(j2);
      return (t(i2, j1)/t(i1, j1))*(t(i1, j2)/t(i2, j2));
    }
  LogProb prob_of_target_and_alignment_given_source(const alignment&al)const
    {
      LogProb prob=1.0;
      int lp1=al.get_l()+1;
      for(unsigned int j=1;j<=al.get_m();++j)
	prob*=t(al(j),j)/lp1;
      return prob;
    }
};
#endif