source: app/src/compiledic/compiledic @ 8d3e6ab

help
Last change on this file since 8d3e6ab was 25ae32e, checked in by obrebski <obrebski@…>, 16 years ago

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@4 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

  • Property mode set to 100755
File size: 3.2 KB
Line 
1#! /usr/bin/env perl
2
3$symfile='~/.utt/pl/pl_PL.iso-8859-2.sym';
4$symfilenoext = $symfile;
5$symfilenoext =~ s/\.sym$//;
6$labfile = $symfilenoext . '.lab';
7$sclfile = $symfilenoext . '.scl';
8
9use locale;
10#use strict;
11
12##################################################
13$linesPerFile = 20000;
14
15if (@ARGV < 1) {
16    print "usage: prep_user_dict.pl dictionary_file\n";
17    exit;
18}
19
20my $file = shift; # @ARGV;
21my $filenameprefix;
22
23if ($file =~ /(.*)\.dic/)
24{
25    $filenameprefix = $1;
26}
27else
28{
29    print "The input file must have .dic extension.";
30    exit(1);
31}
32
33# Przygotowanie etykiet
34
35#`makeLabels.pl > labels.sym`;
36
37`lexmakelab $symfilenoext`;
38
39# Analiza pliku s³ownika
40
41print "preparing file...........................................";
42
43`sed -r "s/([[:punct:]])/\[\\1\]/g" < $file > temp1`;
44
45`cp temp1 temp2`;
46
47print "OK\n";
48
49#dzielimy plik na wiele czê¶ci, uruchamiamy lexcomplex dla ka¿dej
50#czê¶ci osobno, nastêpnie ³±czymy to za pomoc± programu fsmunion
51
52#print "Dzielê s³ownik na mniejsze czê¶ci...";
53
54open(IN, "./temp2");
55
56$lineCount = 0;
57$fileCount = 0;
58
59`mkdir LemTEMP`;
60
61open(FILE, ">LemTEMP/slo_0");
62
63while (<IN>) {
64
65    if (++$lineCount >= $linesPerFile) {
66        $fileCount++;
67        $lineCount = 0;
68
69        close(FILE);
70#       print "Tworzê nowy plik tymczasowy: slo_".$fileCount."\n";
71        open(FILE, ">LemTEMP/slo_".$fileCount);
72    }
73
74    print(FILE $_);
75}
76
77#print "OK\n";
78
79print "building partial automata";
80
81#32 kropki, fileCount plikow
82$filesPerDot = $fileCount/32;
83$files=$filesPerDot;
84$dots=0;
85
86for ($i=0; $i<=$fileCount; $i++) {
87
88    if ($files >= $filesPerDot) {
89        $files = 0;
90        print ".";
91        $dots++;
92    }
93    $files++;
94
95    $command = "lexcomplex -l $labfile -S $sclfile < LemTEMP/slo_".$i." > LemTEMP/slownik_".$i.".fsm";
96
97    `$command`;
98
99}
100if ($dots < 32) {
101    for ($i=0; $i<32 - $dots; $i++) {
102        print ".";
103    }
104}
105
106print "OK\n";
107
108`rm LemTEMP/slo_*`;
109
110print "building final automaton";
111
112#35 kropek...
113$ndots=33;
114$filesPerDot = $fileCount/$ndots;
115$files=$filesPerDot;
116$dots=0;
117
118`cp LemTEMP/slownik_0.fsm slownik1.fsm`;
119
120for ($i=1; $i<=$filecount; $i++) {
121
122    if ($files >= $filesPerDot) {
123        $files = 0;
124        print ".";
125        $dots++;
126    }
127    $files++;
128
129    $command = "fsmunion LemTEMP/slownik_".$i." slownik1.fsm > slownik2.fsm";
130
131    `$command`;
132
133    `mv slownik2.fsm slownik1.fsm`;
134}
135
136if ($dots < $ndots) {
137    for ($i=0; $i<$ndots - $dots; $i++) {
138        print ".";
139    }
140}
141
142`fsmunion LemTEMP/* > slownik1.fsm`;
143
144print "OK\n";
145
146print "removing epsilon-transitions.............................";
147
148`fsmrmepsilon slownik1.fsm > slownik2.fsm`;
149
150`rm slownik1.fsm`;
151
152print "OK\n";
153
154print "determinizing automaton..................................";
155
156`fsmdeterminize slownik2.fsm > slownik1.fsm`;
157
158`rm slownik2.fsm`;
159
160print "OK\n";
161
162print "minimizing automaton.....................................";
163
164`fsmminimize slownik1.fsm > slownik.fsm`;
165
166#`rm slownik1.fsm`;
167
168print "OK\n";
169
170print "converting fsm format to bin.............................";
171
172`fsmprint -i $labfile slownik.fsm > slownik.txt`;
173
174`fsm2aut slownik.txt > slownik.aut`;
175
176`aut2fsa < slownik.aut > $filenameprefix.bin`;
177
178print "OK\n";
179
180print "removing temporary files.................................";
181
182`rm LemTEMP/*`;
183`rmdir LemTEMP`;
184`rm temp2`;
185`rm slownik.fsm`;
186`rm slownik.txt`;
187`rm slownik.aut`;
188`rm labels.*`;
189
190print "OK\n";
Note: See TracBrowser for help on using the repository browser.