source: app/dist/common/utt_make_config.pl @ 6b3be72

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

Pierwsza przymiarka do umieszczenia plikow w ~/.local/utt. Obsługa nowych opcji domyslnych. Nieskonczona dystrybucja tarball.

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