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

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

Uaktualnilismy kora.

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

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