[f1563c0] | 1 | #! /usr/bin/env perl |
---|
| 2 | |
---|
| 3 | use locale; |
---|
| 4 | #use strict; |
---|
| 5 | |
---|
| 6 | # |
---|
| 7 | ################################################## |
---|
| 8 | $linesPerFile = 20000; |
---|
| 9 | |
---|
| 10 | if (@ARGV < 1) { |
---|
| 11 | print "usage: prep_user_dict.pl dictionary_file\n"; |
---|
| 12 | exit; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | $file = shift; # @ARGV; |
---|
| 16 | |
---|
| 17 | # Przygotowanie etykiet |
---|
| 18 | |
---|
| 19 | `makeLabels.pl > labels.sym`; |
---|
| 20 | |
---|
| 21 | `lexmakelab labels`; |
---|
| 22 | |
---|
| 23 | # Analiza pliku s³ownika |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | print "Kanonizujê opisy........................................."; |
---|
| 27 | |
---|
| 28 | `canon.pl <$file >temp1`; |
---|
| 29 | |
---|
| 30 | print "OK\n"; |
---|
| 31 | |
---|
| 32 | print "Sortujê plik............................................."; |
---|
| 33 | |
---|
| 34 | `sort -t \\~ -k1,1 -k2,2nr <temp1 > temp2`; |
---|
| 35 | |
---|
| 36 | print "OK\n"; |
---|
| 37 | |
---|
| 38 | print "Minimalizujê plik s³ownika..............................."; |
---|
| 39 | |
---|
| 40 | #`rmDup.pl < temp2 > temp1`; |
---|
| 41 | #`rmDup2.pl < temp1 > temp2`; |
---|
| 42 | |
---|
| 43 | `cp temp1 temp2`; |
---|
| 44 | |
---|
| 45 | `rm temp1`; |
---|
| 46 | |
---|
| 47 | print "OK\n"; |
---|
| 48 | |
---|
| 49 | print "Czyszczê pliki..........................................."; |
---|
| 50 | |
---|
| 51 | `sed -r "s/([[:punct:]])/[\\1]/g" < temp2 > temp1`; |
---|
| 52 | |
---|
| 53 | `cp temp1 temp2`; |
---|
| 54 | `rm temp1`; |
---|
| 55 | |
---|
| 56 | print "OK\n"; |
---|
| 57 | |
---|
| 58 | #dzielimy plik na wiele czê¶ci, uruchamiamy lexcomplex dla ka¿dej |
---|
| 59 | #czê¶ci osobno, nastêpnie ³±czymy to za pomoc± programu fsmunion |
---|
| 60 | |
---|
| 61 | print "Dzielê s³ownik na mniejsze czê¶ci........................"; |
---|
| 62 | |
---|
| 63 | open(IN, "./temp2"); |
---|
| 64 | |
---|
| 65 | $lineCount = 0; |
---|
| 66 | $fileCount = 0; |
---|
| 67 | |
---|
| 68 | `mkdir LemTEMP`; |
---|
| 69 | |
---|
| 70 | open(FILE, ">LemTEMP/slo_0"); |
---|
| 71 | |
---|
| 72 | while (<IN>) { |
---|
| 73 | |
---|
| 74 | if (++$lineCount >= $linesPerFile) { |
---|
| 75 | $fileCount++; |
---|
| 76 | $lineCount = 0; |
---|
| 77 | |
---|
| 78 | close(FILE); |
---|
| 79 | # print "Tworzê nowy plik tymczasowy: slo_".$fileCount."\n"; |
---|
| 80 | open(FILE, ">LemTEMP/slo_".$fileCount); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | print(FILE $_); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | print "OK\n"; |
---|
| 87 | |
---|
| 88 | print "Tworzê automaty po¶rednie"; |
---|
| 89 | |
---|
| 90 | #32 kropki, fileCount plikow |
---|
| 91 | $filesPerDot = $fileCount/32; |
---|
| 92 | $files=$filesPerDot; |
---|
| 93 | $dots=0; |
---|
| 94 | |
---|
| 95 | for ($i=0; $i<=$fileCount; $i++) { |
---|
| 96 | |
---|
| 97 | if ($files >= $filesPerDot) { |
---|
| 98 | $files = 0; |
---|
| 99 | print "."; |
---|
| 100 | $dots++; |
---|
| 101 | } |
---|
| 102 | $files++; |
---|
| 103 | |
---|
| 104 | $command = "lexcomplex -l labels.lab -S labels.scl < LemTEMP/slo_".$i." > LemTEMP/slownik_".$i.".fsm"; |
---|
| 105 | |
---|
| 106 | `$command`; |
---|
| 107 | |
---|
| 108 | } |
---|
| 109 | if ($dots < 32) { |
---|
| 110 | for ($i=0; $i<32 - $dots; $i++) { |
---|
| 111 | print "."; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | print "OK\n"; |
---|
| 116 | |
---|
| 117 | `rm LemTEMP/slo_*`; |
---|
| 118 | |
---|
| 119 | print "Tworzê automat koñcowy"; |
---|
| 120 | |
---|
| 121 | #35 kropek... |
---|
| 122 | $filesPerDot = $fileCount/35; |
---|
| 123 | $files=$filesPerDot; |
---|
| 124 | $dots=0; |
---|
| 125 | |
---|
| 126 | `cp LemTEMP/slownik_0.fsm slownik1.fsm`; |
---|
| 127 | |
---|
| 128 | for ($i=1; $i<=$filecount; $i++) { |
---|
| 129 | |
---|
| 130 | if ($files >= $filesPerDot) { |
---|
| 131 | $files = 0; |
---|
| 132 | print "."; |
---|
| 133 | $dots++; |
---|
| 134 | } |
---|
| 135 | $files++; |
---|
| 136 | |
---|
| 137 | $command = "fsmunion LemTEMP/slownik_".$i." slownik1.fsm > slownik2.fsm"; |
---|
| 138 | |
---|
| 139 | `$command`; |
---|
| 140 | |
---|
| 141 | `mv slownik2.fsm slownik1.fsm`; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if ($dots < 35) { |
---|
| 145 | for ($i=0; $i<35 - $dots; $i++) { |
---|
| 146 | print "."; |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | `fsmunion LemTEMP/* > slownik1.fsm`; |
---|
| 151 | |
---|
| 152 | print "OK\n"; |
---|
| 153 | |
---|
| 154 | print "Usuwam epsilon-przejscia................................."; |
---|
| 155 | |
---|
| 156 | `fsmrmepsilon slownik1.fsm > slownik2.fsm`; |
---|
| 157 | |
---|
| 158 | `rm slownik1.fsm`; |
---|
| 159 | |
---|
| 160 | print "OK\n"; |
---|
| 161 | |
---|
| 162 | print "Determinizujê automat...................................."; |
---|
| 163 | |
---|
| 164 | `fsmdeterminize slownik2.fsm > slownik1.fsm`; |
---|
| 165 | |
---|
| 166 | `rm slownik2.fsm`; |
---|
| 167 | |
---|
| 168 | print "OK\n"; |
---|
| 169 | |
---|
| 170 | print "Minimalizujê automat....................................."; |
---|
| 171 | |
---|
| 172 | `fsmminimize slownik1.fsm > slownik.fsm`; |
---|
| 173 | |
---|
| 174 | `rm slownik1.fsm`; |
---|
| 175 | |
---|
| 176 | print "OK\n"; |
---|
| 177 | |
---|
| 178 | print "Konwertujê automat do formatu fsa........................"; |
---|
| 179 | |
---|
| 180 | `fsmprint -i labels.lab slownik.fsm > slownik.txt`; |
---|
| 181 | |
---|
| 182 | `../fsm2aut slownik.txt > slownik.aut`; |
---|
| 183 | |
---|
| 184 | `../aut2fsa < slownik.aut > gue.bin`; |
---|
| 185 | |
---|
| 186 | print "OK\n"; |
---|
| 187 | |
---|
| 188 | print "Czyszczê pliki pomocnicze................................"; |
---|
| 189 | |
---|
| 190 | `rm LemTEMP/*`; |
---|
| 191 | `rmdir LemTEMP`; |
---|
| 192 | `rm temp2`; |
---|
| 193 | `rm slownik.fsm`; |
---|
| 194 | `rm slownik.txt`; |
---|
| 195 | `rm slownik.aut`; |
---|
| 196 | |
---|
| 197 | print "OK\n"; |
---|