1: # The LearningOnline Network with CAPA
2: # Russian Localization Lexicon
3: #
4: # $Id: x_chef.pm,v 1.1 2004/07/20 23:04:38 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ######################################################################
29: ######################################################################
30:
31:
32: package Apache::localize::x_chef;
33: use base qw(Apache::localize);
34:
35: %Lexicon=(
36: 'char_encoding'=> 'ISO-8859-15',
37: 'language_code'=> 'x_chef',
38: 'date_locale' =>
39: '$weekday, $day. $month $year, $twentyfour:$minutes:$seconds',
40: 'date_months' => 'Junooery,Febooery,Merch,Epreel,Mey,Joone-a,Jooly,Oogoost,September,Ooctuber,Nufember,December',
41: 'date_days' => 'So,Mu,To,Ve,Th,Fr,Se',
42: 'date_am' => 'em',
43: 'date_pm' => 'pm',
44: 'textual_remote_display' => 'on',
45: 'htmlarea_lang' => 'en'
46: );
47:
48: sub init {
49: my $lh = $_[0]; # a newborn handle
50: $lh->SUPER::init();
51: $lh->fail_with(\&fail);
52: return;
53: }
54:
55: sub fail {
56: my ($lh,$key,@params) = @_;
57: my $value = $lh->_compile(&chefify2($key));
58:
59: return $$value if ref($value) eq 'SCALAR';
60: return $value unless ref($value) eq 'CODE';
61:
62: {
63: local $SIG{'__DIE__'};
64: eval { $value = &$value($lh, @params) };
65: }
66: return $value;
67: }
68:
69:
70: sub chefify {
71: my ($str)=@_;
72: $str=~s/\\/\\\\/g;
73: $str=~s/\"/\\"/g; #"
74: open(CHEF," echo \"$str\" | chef|");
75: my $result;
76: while (my $a=<CHEF>) { $result.=$a }
77: chomp($result);
78: $result=~s/\n/ /g;
79: close CHEF;
80: return $result;
81: }
82:
83: # chef.pl by Teodor Zlatanov, tzz@iglou.com
84: # March 26, 2000
85: # adpated from chef.l by John Hagerman
86:
87: use vars qw($lexer $result);
88: sub create_parser {
89: use Parse::RecDescent;
90: use strict;
91:
92: $Parse::RecDescent::skip = ''; # skip nothing
93:
94: $lexer = new Parse::RecDescent q
95: {
96: { my $niw = 0; my $i_seen = 0; } # set NIW , i_seen at start
97:
98: chef: token(s) /\z/
99:
100: token: end_of_sentence
101: | Bbork
102: | an | An
103: | au | Au
104: | ax | Ax
105: | en
106: | ew
107: | edone
108: | ex | Ex
109: | f
110: | ir
111: | i
112: | ow
113: | o | O | xo
114: | the | The | th
115: | tion
116: | u | U | v | V | w | W
117: | NW { $niw = 0; $i_seen = 0; $::result .= $item[1] }
118: | WC { $niw = 1; $::result .= $item[1] }
119: | /\n/ { $niw = 0; $i_seen = 0; $::result .= $item[1] }
120:
121: end_of_sentence: /[.?!]+/ /\s+/ { $niw = 0; $i_seen = 0; $::result .= $item[1] . "\nBork Bork Bork!\n" }
122:
123: Bbork: <reject: $niw> /([Bb]ork)/ ...NW { $::result .= "$1" }
124: an: /an/ { $niw = 1; $::result .= 'un' }
125: An: /An/ { $niw = 1; $::result .= 'Un' }
126: au: /au/ { $niw = 1; $::result .= 'oo' }
127: Au: /Au/ { $niw = 1; $::result .= 'Oo' }
128: ax: /a/ ...WC { $niw = 1; $::result .= "e" }
129: Ax: /A/ ...WC { $niw = 1; $::result .= "E" }
130: en: /en/ ...NW { $niw = 1; $::result .= "ee" }
131: ew: <reject: !$niw> /ew/ { $niw = 1; $::result .= "oo" }
132: edone: <reject: !$niw> /e/ ...NW { $niw = 1; $::result .= "e-a" }
133: ex: <reject: $niw> /e/ { $niw = 1; $::result .= "i" }
134: Ex: <reject: $niw> /E/ { $niw = 1; $::result .= "I" }
135: f: <reject: !$niw> /f/ { $niw = 1; $::result .= "ff" }
136: ir: <reject: !$niw> /ir/ { $niw = 1; $::result .= "ur" }
137: i: <reject: !$niw> <reject: $i_seen> /i/ { $niw=1;$i_seen=1; $::result .= "ee" }
138: ow: <reject: !$niw> /ow/ { $niw = 1; $::result .= "oo" }
139: o: <reject: $niw> /o/ { $niw = 1; $::result .= "oo" }
140: O: <reject: $niw> /O/ { $niw = 1; $::result .= "Oo" }
141: xo: <reject: !$niw> /o/ { $niw = 1; $::result .= "u" }
142: the: /the/ { $niw = 1; $::result .= 'zee' }
143: The: /The/ { $niw = 1; $::result .= 'Zee' }
144: th: /th/ ...NW { $niw = 1; $::result .= "t" }
145: tion: <reject: !$niw> /tion/ { $niw = 1; $::result .= "shun" }
146: u: <reject: !$niw> /u/ { $niw = 1; $::result .= "oo" }
147: U: <reject: !$niw> /U/ { $niw = 1; $::result .= "Oo" }
148: v: /v/ { $niw = 1; $::result .= 'f' }
149: V: /V/ { $niw = 1; $::result .= 'F' }
150: w: /w/ { $niw = 1; $::result .= 'v' }
151: W: /W/ { $niw = 1; $::result .= 'V' }
152:
153: WC: /[A-Za-z']/
154: NW: /[^A-Za-z']/
155:
156: };
157: }
158:
159: sub chefify2 {
160: my ($str) = @_;
161: $::result='';
162: if (!defined($lexer)) { &create_parser(); }
163: $lexer->chef(\$str);
164: return $::result;
165: }
166:
167: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>