source: app/dist/common/utt_make_config.pl @ a5fdde9

help
Last change on this file since a5fdde9 was a5fdde9, checked in by pawelk <pawelk@…>, 16 years ago

Wprowadzilem globalne pliki konfiguracyjne. Dokonalem drobnych poprawek w strukturze.

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

  • Property mode set to 100644
File size: 6.0 KB
Line 
1#!/usr/bin/perl
2#c:\usr\perl\bin\perl.exe
3
4use Cwd 'abs_path';
5use File::Basename;
6use File::HomeDir;
7use File::Spec::Functions;
8use POSIX;
9
10my $sys_home = catdir(dirname(abs_path($0)), "..");
11my $usr_home = catdir(home(), '.utt');
12
13prepareUttUsrHome($usr_home);
14conf_utt(catfile($usr_home, 'utt.conf'), $sys_home);
15
16conf_compiledic(catfile($usr_home, 'compiledic.conf'), $sys_home);
17conf_cor(catfile($usr_home, 'cor.conf'), $sys_home);
18conf_dgc(catfile($usr_home, 'dgc.conf'), $sys_home);
19conf_grp(catfile($usr_home, 'grp.conf'), $sys_home);
20conf_gue(catfile($usr_home, 'gue.conf'), $sys_home);
21conf_kor(catfile($usr_home, 'kor.conf'), $sys_home);
22conf_lem(catfile($usr_home, 'lem.conf'), $sys_home);
23conf_ser(catfile($usr_home, 'ser.conf'), $sys_home);
24
25print "UTT user configuration created in $usr_home\n";
26
27
28
29#Kasuje stare configi i tworzy katalog .utt
30sub prepareUttUsrHome() {
31    my $dir = shift;
32
33    print "Preparing user configuration.\n";
34
35    if(-d $dir) {
36                print "Old configuration detected. ";
37                my $cnt = unlink <$dir/*>;
38                print "($cnt files deleted)\n";
39    }
40    else {
41                print "Creating directory $dir\n";
42                if(1 != mkdir $dir) {
43                    die "Unable to create UTT user configuration!\n";
44                }
45    }
46}
47
48# Tworzy naglowek dla wszystkich plikow konfiguracyjnych
49sub makeConfigHeader() {
50  return "# ************************************************************\n".
51                 "# * This file was created automatically during installation. *\n".
52                 "# * If you don't need do not change it.                      *\n".
53                 "# *                                                          *\n".
54                 "# * UAM Text Tools                                           *\n".
55                 "# * Adam Mickiewicz University, Poland                       *\n".
56                 "# * http://utt.amu.edu.pl                                    *\n".
57                 "# ************************************************************\n".
58                 "#\n".
59                 "# All lines must looks like:\n".
60                 "# parameter_name [=] value\n".
61                 "#\n\n";
62}
63
64sub conf_compiledic() {
65        my $compiledic_file = shift;
66        my $utthome = shift;
67  open(FILE, ">$compiledic_file");
68
69  print FILE makeConfigHeader();
70  my $hm = home();
71  my $lang=`grep language $hm/.utt/utt.conf | cut -d= -f 2`;
72  chomp $lang;
73# powinno byc $utthome/share/utt/pl_PL.ISO-8859-2/pl_PL.ISO-8892-2.sym
74# ale to bez sensu
75  print FILE "symbols=", abs_path("$utthome/share/utt");
76  print FILE "/$lang/$lang.sym\n";
77
78  close FILE;
79}
80
81sub conf_grp() {
82        my $grp_file = shift;
83        my $utthome = shift;
84  open(FILE, ">$grp_file");
85
86  print FILE makeConfigHeader();
87  print FILE "macros=", abs_path("$utthome/lib/utt/terms.m4"), "\n";
88
89  close FILE;
90}
91
92sub conf_cor() {
93        my $cor_file = shift;
94        my $utthome = shift;
95  open(FILE, ">$cor_file");
96
97  print FILE makeConfigHeader();
98  print FILE "dictionary-home=", abs_path("$utthome/share/utt"), "\n";
99
100  close FILE;
101}
102
103sub conf_kor() {
104        my $kor_file = shift;
105        my $utthome = shift;
106  open(FILE, ">$kor_file");
107
108  print FILE makeConfigHeader();
109  print FILE "dictionary-home=", abs_path("$utthome/share/utt"), "\n";
110  print FILE "weights=", abs_path("$utthome/lib/utt/weights.kor"), "\n";
111  print FILE "threshold=1.0\n";
112
113  close FILE;
114}
115
116sub conf_grp() {
117        my $grp_file = shift;
118        my $utthome = shift;
119  open(FILE, ">$grp_file");
120
121  print FILE makeConfigHeader();
122  print FILE "macros=", abs_path("$utthome/lib/utt/terms.m4"), "\n";
123
124  close FILE;
125}
126
127sub conf_gue() {
128        my $gue_file = shift;
129        my $utthome = shift;
130  open(FILE, ">$gue_file");
131
132  print FILE makeConfigHeader();
133
134  close FILE;
135}
136
137sub conf_lem() {
138        my $lem_file = shift;
139        my $utthome = shift;
140  open(FILE, ">$lem_file");
141
142  print FILE makeConfigHeader();
143  print FILE "dictionary-home=", abs_path("$utthome/share/utt"), "\n";
144
145  close FILE;
146}
147
148sub conf_ser() {
149        my $ser_file = shift;
150        my $utthome = shift;
151  open(FILE, ">$ser_file");
152
153  print FILE makeConfigHeader();
154  print FILE "macros=", abs_path("$utthome/lib/utt/terms.m4"), "\n";
155  print FILE "flex-template=", abs_path("$utthome/lib/utt/ser.l.template"), "\n";
156
157  close FILE;
158}
159
160sub conf_utt() {
161        my $utt_file = shift;
162        my $utthome = shift;
163
164        my $lang = getUserLanguage(abs_path(catdir($utthome, "share/utt")));
165
166  open(FILE, ">$utt_file");
167
168  print FILE makeConfigHeader();
169  print FILE "# user locale (dictionary)\n";
170  print FILE "language=", $lang, "\n";
171
172  close FILE;
173}
174
175sub getUserLanguage() {
176    my $dict_dir = shift;
177
178    print "Setup dictionaries.\n";
179   
180    opendir(DIR, $dict_dir) || die "Install dictionary first!\n";
181    @files = grep(/[^\.{1,2}]/ && -d "$dict_dir/$_", readdir(DIR));
182    closedir DIR;
183    my $cnt = scalar @files;
184    print "$cnt dictionary(ies) found.\n";
185    if(0 == $cnt) {
186        die("Install dictionary first!\n");
187    }
188
189    foreach my $file (@files) {
190        print "Do you select dictionary $file [yes/no]? ";
191        my $ans = <STDIN>;
192        if($ans =~ /y(es)?/i) {
193            return $file;
194        }
195    }
196    die "No dictionary selected - setup failed!\n";
197}
198
199# Szuka locali u uzytkownika
200sub findLocale() {
201        $cur_locale = setlocale(LC_CTYPE);
202
203        # we replace Latinx to ISO-8859-x
204        $cur_locale =~ s/(.+?)Latin(.+?)/$1ISO\-8859\-$2/g;
205
206        if($cur_locale =~ /\w+_\w+\.\S+/) {
207          $best_locale = $cur_locale;
208        }
209        elsif($cur_locale =~ /\w+_\w+/) {
210          $best_locale = $cur_locale.".UTF-8";
211        }
212        else {
213          $best_locale = toupper($cur_locale).'_'.tolower($cur_locale).'.UTF-8';
214        }
215        return $best_locale;
216}
217
218sub conf_dgc() {
219        my $dgc_file = shift;
220        my $utthome = shift;
221  open(FILE, ">$dgc_file");
222
223  print FILE makeConfigHeader();
224  print FILE "categories=", abs_path("$utthome/lib/utt/cats.dgc"), "\n";
225  print FILE "grammar=", abs_path("$utthome/lib/utt/gram.dgc"), "\n";
226
227  close FILE;
228 
229 
230  open(FILE, ">$utthome/bin/Makefile.go");
231  print FILE "\ngram.dgp: ", abs_path("$utthome/lib/utt/gram.dgc"), "\n";
232  print FILE "\tdgc -c ", abs_path("$utthome/lib/utt/cats.dgc"), " < ", abs_path("$utthome/lib/utt/gram.dgc"), " > gram.dgp\n";
233  close FILE;
234 
235}
236
Note: See TracBrowser for help on using the repository browser.