source: app/src/compiledic/compiledic @ 25b4022

Last change on this file since 25b4022 was e1942be, checked in by obrebski <obrebski@…>, 16 years ago

poprawiony compiledic, dziala

tyle, ze compiledic.conf dorobilem recznie i plik .sym umiescilem recznie
w jakims tam katalogu (zostal znaleziony)

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

  • Property mode set to 100755
File size: 4.9 KB
Line 
1#! /usr/bin/env perl
2
3#package:       UAM Text Tools
4#component:     compiledic
5#version:       1.0
6#author:        Tomasz Obrebski
7
8use strict;
9use locale;
10use File::HomeDir;
11use File::Basename;
12use File::Temp;
13use File::Copy;
14use Getopt::Long;
15
16
17my $linesPerFile = 20000;
18
19
20my $systemconfigfile='/usr/local/etc/utt/compiledic.conf';
21my $userconfigfile=home()."/.utt/compiledic.conf";
22
23Getopt::Long::Configure('no_ignore_case_always');
24
25#my $symfile='~/.utt/pl/pl_PL.iso-8859-2.sym';
26my $symbols=0;
27my $help=0;
28
29
30
31#read configuration files###########################
32my $file;
33foreach $file ($systemconfigfile, $userconfigfile){
34  if(open(CONFIG, $file)){
35        while (<CONFIG>) {
36                chomp;                 
37                s/#.*//;               
38                s/^\s+//;               
39                s/\s+$//;               
40                next unless length;     
41                my ($name, $value) = split(/\s*=\s*/, $_, 2);
42                if($name eq "symbols"){
43                        $symbols=$value;
44                }
45                elsif(($name eq "help")or($name eq "h")){
46                        $help=1;
47                }
48       
49        } 
50        close CONFIG;
51  }
52}
53#########################################################
54
55GetOptions("symbols=s" => \$symbols,
56           "help|h" => \$help);
57
58if($help)
59{
60    print <<'END'
61Usage: compiledic [OPTIONS] dictionaryfile
62
63Options:
64   --help -h                      Help.
65   --symbols=FILE                 Symbol file.
66END
67;
68    exit 0;
69}
70
71##################################################
72
73-f $symbols or die("Symbol file not found.");
74
75@ARGV > 0   or die("Source dictionary not given.");
76
77my $file = shift;
78
79-f $file or die("Source dictionary not found.");
80
81$file =~ /(.*)\.dic/ or die("The input file must have .dic extension.");
82
83my $filenameprefix = $1;
84
85##################################################
86
87# Tworzymy katalog tymczasowy, gdzie wszystko bedzie umieszczane.
88my $tmp_root = File::Temp::tempdir( CLEANUP => 1 );
89
90(undef, my $symfile) = File::Temp::tempfile( DIR => $tmp_root, SUFFIX => ".sym" );
91my $symfilenoext=$symfile;
92$symfilenoext =~ s/\.sym$//;
93my $labfile = $symfilenoext . '.lab';
94my $sclfile = $symfilenoext . '.scl';
95
96copy($symbols, $symfile);
97
98# Przygotowanie etykiet
99
100`lexmakelab $symfilenoext`;
101
102
103# Analiza pliku slownika
104
105print "preparing file...........................................";
106#print "... sed section .....\n";
107(undef, my $file_sed) = File::Temp::tempfile( DIR => $tmp_root, SUFFIX => ".sed" );
108`sed -r "s/([[:punct:]])/\[\\1\]/g" < $file > $file_sed`;
109
110print "OK\n";
111
112#dzielimy plik na wiele czesci, uruchamiamy lexcomplex dla kazdej
113#czesci osobno, nastepnie laczymy to za pomoca programu fsmunion
114
115#print "Dziele slownik na mniejsze czesci...";
116
117open(IN, $file_sed);
118
119my $lineCount = 0;
120my $fileCount = 0;
121
122open(FILE, ">$tmp_root/slo_$fileCount");
123
124while (<IN>) {
125
126    if (++$lineCount >= $linesPerFile) {
127        $fileCount++;
128        $lineCount = 0;
129
130        close(FILE);
131#       print "Tworze nowy plik tymczasowy: slo_".$fileCount."\n";
132        open(FILE, ">$tmp_root/slo_".$fileCount);
133    }
134
135    print(FILE $_);
136}
137
138#print "OK\n";
139
140print "building partial automata";
141
142#32 kropki, fileCount plikow
143my $filesPerDot = $fileCount/32;
144my $files=$filesPerDot;
145my $dots=0;
146
147for (my $i=0; $i<=$fileCount; $i++) {
148
149    if ($files >= $filesPerDot) {
150        $files = 0;
151        print ".";
152        $dots++;
153    }
154    $files++;
155
156    `lexcomplex -l $labfile -S $sclfile < $tmp_root/slo_$i > $tmp_root/slownik_$i.fsm`;
157
158}
159if ($dots < 32) {
160    for (my $i=0; $i<32 - $dots; $i++) {
161        print ".";
162    }
163}
164
165print "OK\n";
166
167unlink <$tmp_root/slo_*>;
168
169print "building final automaton";
170
171#35 kropek...
172my $ndots=33;
173$filesPerDot = $fileCount/$ndots;
174$files=$filesPerDot;
175$dots=0;
176
177copy("$tmp_root/slownik_0.fsm", "$tmp_root/slownik1.fsm");
178
179for (my $i=1; $i<=$fileCount; $i++) {
180
181    if ($files >= $filesPerDot) {
182        $files = 0;
183        print ".";
184        $dots++;
185    }
186    $files++;
187
188    `fsmunion $tmp_root/slownik_$i slownik1.fsm > $tmp_root/slownik2.fsm`;
189
190    move("$tmp_root/slownik2.fsm", "$tmp_root/slownik1.fsm") || die "Unable to move $tmp_root/slownik2.fsm!\n";
191}
192
193if ($dots < $ndots) {
194    for (my $i=0; $i<$ndots - $dots; $i++) {
195        print ".";
196    }
197}
198
199#`fsmunion $tmp_root/* > $tmp_root/slownik1.fsm`;
200
201print "OK\n";
202
203print "removing epsilon-transitions.............................";
204
205`fsmrmepsilon $tmp_root/slownik1.fsm > $tmp_root/slownik2.fsm`;
206
207unlink ("$tmp_root/slownik1.fsm");
208
209print "OK\n";
210
211print "determinizing automaton..................................";
212
213`fsmdeterminize $tmp_root/slownik2.fsm > $tmp_root/slownik1.fsm`;
214
215unlink ("$tmp_root/slownik2.fsm");
216
217print "OK\n";
218
219print "minimizing automaton.....................................";
220
221`fsmminimize $tmp_root/slownik1.fsm > $tmp_root/slownik.fsm`;
222
223#`rm slownik1.fsm`;
224
225print "OK\n";
226
227print "converting fsm format to bin.............................";
228
229`fsmprint -i $labfile $tmp_root/slownik.fsm > $tmp_root/slownik.txt`;
230
231`fsm2aut $tmp_root/slownik.txt > $tmp_root/slownik.aut`;
232
233`aut2fsa < $tmp_root/slownik.aut > $filenameprefix.bin`;
234
235print "OK\n";
236
237print "removing temporary files.................................";
238
239unlink <$tmp_root/*>;
240unlink ($tmp_root);
241
242print "OK\n";
Note: See TracBrowser for help on using the repository browser.