Blame view

tools/lia_ltbox/lia_tagg/src/libgram/compile_arpa.c 4.42 KB
e6be5137b   Jean-François Rey   reinitialized pro...
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  /*
  #    --------------------------------------------------------
  #    LIA_TAGG: a statistical POS tagger + syntactic bracketer
  #    --------------------------------------------------------
  #
  #    Copyright (C) 2001 FREDERIC BECHET
  #
  #    ..................................................................
  #
  #    This file is part of LIA_TAGG
  #
  #    LIA_TAGG 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
  #    ..................................................................
  #
  #    Contact :
  #              FREDERIC BECHET - LIA - UNIVERSITE D'AVIGNON
  #              AGROPARC BP1228 84911  AVIGNON  CEDEX 09  FRANCE
  #              frederic.bechet@lia.univ-avignon.fr
  #    ..................................................................
  */
  /*  Compile un fichier ARPA  */
  /*  FRED 0399  */
  
  #include <libgram.h>
  #include <compile_gram.h>
  
  #define TailleLigne	200
  
  void main(int argc ,char **argv )
  {
  int n,si_log_e,si_2g,si_dicho,si_code;
  FILE *file;
  double coef1,coef2,coef3;
  ty_lexique pt_lexique;
  ty_ml pt_ml;
  
  if ((argc==2)&&(!strcmp(argv[1],"-h")))
   {
   fprintf(stderr,"Syntaxe : %s [-h] <-lexique fich_lexique ou -code> <fich arpa> <log_10/log_e>\
   <2g/3g> [-dicho | <coef 1g> <coef 2g> <coef 3g>]
  \
   avec :
  \
   \t-lexique fich_lexique = si le fichier arpa contient des graphies, il faut un lexique compile
  \
   \t\tcompile au format sirocco pour obtenir les codes
  \
   \tou
  \
   \t-code = le fichier arpa contient des codes, et donc on a pas besoin de lexique
  \
   \t<fich arpa> = nom du fichier ML au format arpa
  \
   \t<log_10/log_e> = proba stockees en log base 10 ou log base e
  \
   \t<2g/3g> = compilation d'un modele bigramme ou trigramme
  \
   \t-dicho = flag signifiant que l'on veut utiliser la dichotomie comme recherche des elements
  \
   \t<coef 1g> <coef 2g> <coef 3g> : coeff de remplissage des tableaux de Hachage si l'on n'utilise
  \
   \tpas la dichotomie
  ",argv[0]);
   exit(0);
   }
  
  if (argc<6)
   {
   fprintf(stderr,"Syntaxe : %s [-h] <-lexique fich_lexique ou -code> <fich arpa> <log_10/log_e>\
   <2g/3g> [-dicho | <coef 1g> <coef 2g> <coef 3g>]
  ",argv[0]);
   exit(0);
   }
  
  n=1;
  
  if (!strcmp(argv[n],"-lexique"))
   {
   fprintf(stderr,"Chargement du lexique -> ");
   pt_lexique=ChargeLexique(argv[++n]);
   fprintf(stderr,"Terminee
  ");
   si_code=0;
   }
  else
   {
   fprintf(stderr,"Le fichier ARPA contient des codes a la place des graphies
  \
   On a donc pas besoin de lexique
  ");
   si_code=1;
   }
  
  n++;
  
  /*  Log base e ou base 10  */
  
  if (!strcmp(argv[n+1],"log_e"))
   {
   si_log_e=1;
   fprintf(stderr,"On compile le ML en log neperien
  ");
   }
  else
   {
   si_log_e=0;
   fprintf(stderr,"On compile le ML en log base 10
  ");
   }
  
  /*  Bigramme ou trigramme  */
  
  if (!strcmp(argv[n+2],"2g")) 
   {
   si_2g=1;
   fprintf(stderr,"On compile un modele bigramme
  ");
   }
  else
   {
   si_2g=0;
   fprintf(stderr,"On compile un modele trigramme
  ");
   }
  
  /*  Dichotomie ou hash code  */
  
  if (!strcmp(argv[n+3],"-dicho")) si_dicho=1; else si_dicho=0;
  
  /*  Creation des fichiers n-gram a partir d'un fichier ARPA  */
  
  fprintf(stderr,"Initialisation des tableaux 1.2.3-grams -> 
  ");
  
  if (si_dicho)
   {
   coef1=coef2=coef3=1.;
   pt_ml=InitGram(argv[n],argv[n],coef1,coef2,coef3,si_dicho,si_log_e,si_2g);
   }
  else
   {
   sscanf(argv[n+3],"%lf",&coef1); sscanf(argv[n+4],"%lf",&coef2);
   if (si_2g) coef3=1.; else sscanf(argv[n+5],"%lf",&coef3);
   pt_ml=InitGram(argv[n],argv[n],coef1,coef2,coef3,si_dicho,si_log_e,si_2g);
   }
  
  fprintf(stderr,"Terminee
  ");
  
  pt_ml->lexique=pt_lexique;
  
  fprintf(stderr,"Lecture du fichier n-gram DARPA et creation des n-grams
  ");
  if (!(file=fopen(argv[n],"r"))) { fprintf(stderr,"Je ne peux lire: %s",argv[n]); exit(0); }
  
  LisFichDARPA(file,si_log_e,si_2g,si_code,pt_ml);
  fclose(file);
  
  if (si_dicho)
   {
   fprintf(stderr,"Tri des tableaux de Hash pour la dichotomie -> ");
   SortHash(pt_ml);
   fprintf(stderr,"Termine
  ");
   }
  SauveGram(argv[n],pt_ml);
  
  delete_ml(pt_ml);
  }