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
This commit is contained in:
pawelk 2008-03-20 11:08:21 +00:00
parent 20b4e44e75
commit 389de9abcb
4 changed files with 81 additions and 61 deletions

View File

@ -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]

View File

@ -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 = <STDIN>;
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);

View File

@ -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 (<IN>) {
@ -81,8 +83,8 @@ while (<IN>) {
$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";

View File

@ -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(<FLEX>) {
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;