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 | |
---|
9 | use locale; |
---|
10 | #use strict; |
---|
11 | |
---|
12 | ################################################## |
---|
13 | $linesPerFile = 20000; |
---|
14 | |
---|
15 | if (@ARGV < 1) { |
---|
16 | print "usage: prep_user_dict.pl dictionary_file\n"; |
---|
17 | exit; |
---|
18 | } |
---|
19 | |
---|
20 | my $file = shift; # @ARGV; |
---|
21 | my $filenameprefix; |
---|
22 | |
---|
23 | if ($file =~ /(.*)\.dic/) |
---|
24 | { |
---|
25 | $filenameprefix = $1; |
---|
26 | } |
---|
27 | else |
---|
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 | |
---|
41 | print "preparing file..........................................."; |
---|
42 | |
---|
43 | `sed -r "s/([[:punct:]])/\[\\1\]/g" < $file > temp1`; |
---|
44 | |
---|
45 | `cp temp1 temp2`; |
---|
46 | |
---|
47 | print "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 | |
---|
54 | open(IN, "./temp2"); |
---|
55 | |
---|
56 | $lineCount = 0; |
---|
57 | $fileCount = 0; |
---|
58 | |
---|
59 | `mkdir LemTEMP`; |
---|
60 | |
---|
61 | open(FILE, ">LemTEMP/slo_0"); |
---|
62 | |
---|
63 | while (<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 | |
---|
79 | print "building partial automata"; |
---|
80 | |
---|
81 | #32 kropki, fileCount plikow |
---|
82 | $filesPerDot = $fileCount/32; |
---|
83 | $files=$filesPerDot; |
---|
84 | $dots=0; |
---|
85 | |
---|
86 | for ($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 | } |
---|
100 | if ($dots < 32) { |
---|
101 | for ($i=0; $i<32 - $dots; $i++) { |
---|
102 | print "."; |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | print "OK\n"; |
---|
107 | |
---|
108 | `rm LemTEMP/slo_*`; |
---|
109 | |
---|
110 | print "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 | |
---|
120 | for ($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 | |
---|
136 | if ($dots < $ndots) { |
---|
137 | for ($i=0; $i<$ndots - $dots; $i++) { |
---|
138 | print "."; |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | `fsmunion LemTEMP/* > slownik1.fsm`; |
---|
143 | |
---|
144 | print "OK\n"; |
---|
145 | |
---|
146 | print "removing epsilon-transitions............................."; |
---|
147 | |
---|
148 | `fsmrmepsilon slownik1.fsm > slownik2.fsm`; |
---|
149 | |
---|
150 | `rm slownik1.fsm`; |
---|
151 | |
---|
152 | print "OK\n"; |
---|
153 | |
---|
154 | print "determinizing automaton.................................."; |
---|
155 | |
---|
156 | `fsmdeterminize slownik2.fsm > slownik1.fsm`; |
---|
157 | |
---|
158 | `rm slownik2.fsm`; |
---|
159 | |
---|
160 | print "OK\n"; |
---|
161 | |
---|
162 | print "minimizing automaton....................................."; |
---|
163 | |
---|
164 | `fsmminimize slownik1.fsm > slownik.fsm`; |
---|
165 | |
---|
166 | #`rm slownik1.fsm`; |
---|
167 | |
---|
168 | print "OK\n"; |
---|
169 | |
---|
170 | print "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 | |
---|
178 | print "OK\n"; |
---|
179 | |
---|
180 | print "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 | |
---|
190 | print "OK\n"; |
---|