/* 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. */ /* --------------------------------------------------------------------------* * * * Module :ATables * * * * Prototypes File: ATables.h * * * * Objective: Defines clases and methods for handling I/O for distortion & * * alignment tables. * *****************************************************************************/ #ifndef _atables_h #define _atables_h 1 #include "defs.h" #include #include #include #include #include #include #include "Vector.h" #include #if __GNUC__>2 #include using __gnu_cxx::hash_map; #else #include #endif #include #include "Array4.h" #include "myassert.h" extern bool CompactADTable; extern float amodel_smooth_factor; extern short NoEmptyWord; /* ------------------- Class Defintions of amodel ---------------------------*/ /* Class Name: amodel: Objective: This defines the underlying data structure for distortiont prob. and count tables. They are defined as a hash table. Each entry in the hash table is the probability (d(j/l,m,i), where j is word target position, i is source word position connected to it, m is target sentence length, and l is source sentence length) or count collected for it. The probability and the count are represented as log integer probability as defined by the class LogProb . This class is used to represents a Tables (probabiliity) and d (distortion) tables and also their corresponding count tables . *--------------------------------------------------------------------------*/ inline int Mabs(int a) { if(a<0) return -a; else return a; } template class amodel { public: Array4 a; bool is_distortion ; WordIndex MaxSentLength; bool ignoreL, ignoreM; VALTYPE get(WordIndex aj, WordIndex j, WordIndex l, WordIndex m)const { massert( (!is_distortion) || aj<=m );massert( (!is_distortion) || j<=l );massert( (!is_distortion) || aj!=0 ); massert( is_distortion || aj<=l );massert( is_distortion || j<=m );massert( (is_distortion) || j!=0 ); massert( l void normalize(amodel& aTable)const { WordIndex i, j, l, m ; COUNT total; int nParam=0; for(l=0;l