From 389de9abcbd0bbec63c04912b2d253b58dc5145c Mon Sep 17 00:00:00 2001 From: pawelk Date: Thu, 20 Mar 2008 11:08:21 +0000 Subject: [PATCH] Program generujacy konfiguracje pyta sie o wybor slownika. Dolozylem obsluge plikow tymczasowych w compiledict. Zamienilem system na ` w perlu. git-svn-id: svn://atos.wmid.amu.edu.pl/utt@14 e293616e-ec6a-49c2-aa92-f4a8b91c5d16 --- app/TODO | 6 +-- app/dist/common/utt_make_config.pl | 56 ++++++++++++++++++------ app/src/compiledic/compiledic | 69 ++++++++++++++---------------- app/src/ser/ser | 11 ++--- 4 files changed, 81 insertions(+), 61 deletions(-) diff --git a/app/TODO b/app/TODO index 3e41a41..7aa9934 100644 --- a/app/TODO +++ b/app/TODO @@ -7,15 +7,15 @@ * mar nie obsluguje plikow konfiguracyjnych [JW] -* compiledic - plik tymczasowe [PK] +* DONE compiledic - plik tymczasowe [PK] * ser i grp - parametr tags (zeby bral wskazany program tag2re) [TO] -* lista zaleznosci dla komend system w perlu [PK] +* DONE lista zaleznosci dla komend system w perlu [PK] * polaczyc sen'y [TO] -* poprawic utt_make_conf (wykrywanie slownikow) [PK] +* DONE poprawic utt_make_conf (wykrywanie slownikow) [PK] * generowanie i sprawdzanie zaleznosci dla tarballa [PK] diff --git a/app/dist/common/utt_make_config.pl b/app/dist/common/utt_make_config.pl index 3d63420..f4ede47 100644 --- a/app/dist/common/utt_make_config.pl +++ b/app/dist/common/utt_make_config.pl @@ -11,12 +11,13 @@ my $sys_home = catdir(dirname(abs_path($0)), ".."); my $usr_home = catdir(home(), '.utt'); prepareUttUsrHome($usr_home); +conf_utt(catfile($usr_home, 'utt.conf'), $sys_home); + conf_cor(catfile($usr_home, 'cor.conf'), $sys_home); conf_grp(catfile($usr_home, 'grp.conf'), $sys_home); conf_gue(catfile($usr_home, 'gue.conf'), $sys_home); conf_lem(catfile($usr_home, 'lem.conf'), $sys_home); conf_ser(catfile($usr_home, 'ser.conf'), $sys_home); -conf_utt(catfile($usr_home, 'utt.conf'), $sys_home); print "UTT user configuration created in $usr_home\n"; @@ -26,17 +27,19 @@ print "UTT user configuration created in $usr_home\n"; sub prepareUttUsrHome() { my $dir = shift; - if(-d $dir) { - print "Old configuration will be deleted!\n"; - my $cnt = unlink <$dir/*>; - print "$cnt files deleted.\n"; - } - else { - print "Creating directory $dir\n"; - if(1 != mkdir $dir) { - die "Unable to create UTT user configuration!\n"; - } + print "Preparing user configuration.\n"; + + if(-d $dir) { + print "Old configuration detected. "; + my $cnt = unlink <$dir/*>; + print "($cnt files deleted)\n"; + } + else { + print "Creating directory $dir\n"; + if(1 != mkdir $dir) { + die "Unable to create UTT user configuration!\n"; } + } } # Tworzy naglowek dla wszystkich plikow konfiguracyjnych @@ -113,15 +116,42 @@ sub conf_ser() { sub conf_utt() { my $utt_file = shift; my $utthome = shift; + + my $lang = getUserLanguage(abs_path(catdir($utthome, "share/utt"))); + open(FILE, ">$utt_file"); print FILE makeConfigHeader(); - print FILE "# user locale\n"; - print FILE "language=", findLocale(), "\n"; + print FILE "# user locale (dictionary)\n"; + print FILE "language=", $lang, "\n"; close FILE; } +sub getUserLanguage() { + my $dict_dir = shift; + + print "Setup dictionaries.\n"; + + opendir(DIR, $dict_dir) || die "Install dictionary first!\n"; + @files = grep(/[^\.{1,2}]/ && -d "$dict_dir/$_", readdir(DIR)); + closedir DIR; + my $cnt = scalar @files; + print "$cnt dictionary(ies) found.\n"; + if(0 == $cnt) { + die("Install dictionary first!\n"); + } + + foreach my $file (@files) { + print "Do you select dictionary $file [yes/no]? "; + my $ans = ; + if($ans =~ /y(es)?/i) { + return $file; + } + } + die "No dictionary selected - setup failed!\n"; +} + # Szuka locali u uzytkownika sub findLocale() { $cur_locale = setlocale(LC_CTYPE); diff --git a/app/src/compiledic/compiledic b/app/src/compiledic/compiledic index 26e72a2..f2ba801 100755 --- a/app/src/compiledic/compiledic +++ b/app/src/compiledic/compiledic @@ -10,6 +10,7 @@ use locale; use File::HomeDir; use File::Basename; use File::Temp; +use File::Copy; use Getopt::Long; my $systemconfigfile=''; @@ -50,29 +51,30 @@ else `lexmakelab $symfilenoext`; -# Analiza pliku słownika +# Tworzymy katalog tymczasowy, gdzie wszystko bedzie umieszczane. +$tmp_root = tempdir( CLEANUP => 1 ); -print "preparing file..........................................."; -`sed -r "s/([[:punct:]])/\[\\1\]/g" < $file > temp1`; +# Analiza pliku slownika -`cp temp1 temp2`; +print "preparing file...........................................\n"; +print "... sed section .....\n"; +(undef, my $file_sed) = File::Temp::tempfile( DIR => $tmp_root, SUFFIX => ".sed" ); +`sed -r "s/([[:punct:]])/\[\\1\]/g" < $file > $file_sed`; print "OK\n"; -#dzielimy plik na wiele części, uruchamiamy lexcomplex dla każdej -#części osobno, następnie łączymy to za pomocą programu fsmunion +#dzielimy plik na wiele czesci, uruchamiamy lexcomplex dla kazdej +#czesci osobno, nastepnie laczymy to za pomoca programu fsmunion -#print "Dzielę słownik na mniejsze części..."; +#print "Dziele slownik na mniejsze czesci..."; -open(IN, "./temp2"); +open(IN, $file_sed); $lineCount = 0; $fileCount = 0; -`mkdir LemTEMP`; - -open(FILE, ">LemTEMP/slo_0"); +open(FILE, ">$tmp_root/slo_$fileCount"); while () { @@ -81,8 +83,8 @@ while () { $lineCount = 0; close(FILE); -# print "Tworzę nowy plik tymczasowy: slo_".$fileCount."\n"; - open(FILE, ">LemTEMP/slo_".$fileCount); +# print "Tworze nowy plik tymczasowy: slo_".$fileCount."\n"; + open(FILE, ">$tmp_root/slo_".$fileCount); } print(FILE $_); @@ -106,9 +108,7 @@ for ($i=0; $i<=$fileCount; $i++) { } $files++; - $command = "lexcomplex -l $labfile -S $sclfile < LemTEMP/slo_".$i." > LemTEMP/slownik_".$i.".fsm"; - - `$command`; + `lexcomplex -l $labfile -S $sclfile < $tmp_root/slo_$i > $tmp_root/slownik_$i.fsm`; } if ($dots < 32) { @@ -119,7 +119,7 @@ if ($dots < 32) { print "OK\n"; -`rm LemTEMP/slo_*`; +unlink <$tmp_root/slo_*>; print "building final automaton"; @@ -129,7 +129,7 @@ $filesPerDot = $fileCount/$ndots; $files=$filesPerDot; $dots=0; -`cp LemTEMP/slownik_0.fsm slownik1.fsm`; +copy("$tmp_root/slownik_0.fsm", "$tmp_root/slownik1.fsm"); for ($i=1; $i<=$filecount; $i++) { @@ -140,11 +140,9 @@ for ($i=1; $i<=$filecount; $i++) { } $files++; - $command = "fsmunion LemTEMP/slownik_".$i." slownik1.fsm > slownik2.fsm"; + `fsmunion $tmp_root/slownik_$i slownik1.fsm > $tmp_file/slownik2.fsm`; - `$command`; - - `mv slownik2.fsm slownik1.fsm`; + move("$tmp_root/slownik2.fsm", "$tmp_root/slownik1.fsm") || die "Unable to move $tmp_root/slownik2.fsm!\n"; } if ($dots < $ndots) { @@ -153,29 +151,29 @@ if ($dots < $ndots) { } } -`fsmunion LemTEMP/* > slownik1.fsm`; +`fsmunion $tmp_root/* > $tmp_root/slownik1.fsm`; print "OK\n"; print "removing epsilon-transitions............................."; -`fsmrmepsilon slownik1.fsm > slownik2.fsm`; +`fsmrmepsilon $tmp_root/slownik1.fsm > $tmp_root/slownik2.fsm`; -`rm slownik1.fsm`; +unlink ("$tmp_root/slownik1.fsm"); print "OK\n"; print "determinizing automaton.................................."; -`fsmdeterminize slownik2.fsm > slownik1.fsm`; +`fsmdeterminize $tmp_root/slownik2.fsm > $tmp_root/slownik1.fsm`; -`rm slownik2.fsm`; +unlink ("$tmp_root/slownik2.fsm"); print "OK\n"; print "minimizing automaton....................................."; -`fsmminimize slownik1.fsm > slownik.fsm`; +`fsmminimize $tmp_root/slownik1.fsm > $tmp_root/slownik.fsm`; #`rm slownik1.fsm`; @@ -183,22 +181,17 @@ print "OK\n"; print "converting fsm format to bin............................."; -`fsmprint -i $labfile slownik.fsm > slownik.txt`; +`fsmprint -i $labfile $tmp_root/slownik.fsm > $tmp_root/slownik.txt`; -`fsm2aut slownik.txt > slownik.aut`; +`fsm2aut $tmp_root/slownik.txt > $tmp_root/slownik.aut`; -`aut2fsa < slownik.aut > $filenameprefix.bin`; +`aut2fsa < $tmp_root/slownik.aut > $filenameprefix.bin`; print "OK\n"; print "removing temporary files................................."; -`rm LemTEMP/*`; -`rmdir LemTEMP`; -`rm temp2`; -`rm slownik.fsm`; -`rm slownik.txt`; -`rm slownik.aut`; -`rm labels.*`; +unlink <$tmp_root/*>; +unlink ($tmp_root); print "OK\n"; diff --git a/app/src/ser/ser b/app/src/ser/ser index 9a3cca8..86164aa 100755 --- a/app/src/ser/ser +++ b/app/src/ser/ser @@ -155,11 +155,10 @@ my $defaultaction = ($only_matching) ? '' : 'ECHO'; (undef, my $tmpfile_x) = File::Temp::tempfile(); -system "m4 \"--define=PATTERN=$flexpattern\" \"--define=DEFAULTACTION=$defaultaction\" $flextemplate > $tmpfile_l"; +`m4 "--define=PATTERN=$flexpattern" "--define=DEFAULTACTION=$defaultaction" $flextemplate > $tmpfile_l`; if($flex) { - #system "cat $tmpfile_l"; if(open(FLEX, $tmpfile_l)) { while() { print @_; @@ -172,12 +171,10 @@ if($flex) exit 0; } -system "flex -o$tmpfile_c $tmpfile_l"; -system "cc -O3 -o $tmpfile_x $tmpfile_c -lfl"; -system "$tmpfile_x"; +`flex -o$tmpfile_c $tmpfile_l`; +`cc -O3 -o $tmpfile_x $tmpfile_c -lfl`; +`$tmpfile_x`; -#system "rm -f $tmpfile_l $tmpfile_c $tmpfile_x"; unlink $tmpfile_l; unlink $tmpfile_c; unlink $tmpfile_x; -