Annotation of loncom/localize/localize/x_chef.pm, revision 1.4

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Russian Localization Lexicon
                      3: #
1.4     ! albertel    4: # $Id: x_chef.pm,v 1.3 2007/11/06 19:35:12 albertel Exp $
1.1       albertel    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=(
1.3       albertel   36: 'char_encoding'=> 'UTF-8',
1.1       albertel   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: sub create_parser {
                     88:     use Parse::RecDescent;
                     89: 
                     90:     $Parse::RecDescent::skip = '';          # skip nothing
                     91: 
                     92:     $lexer = new Parse::RecDescent q
                     93: {
                     94:  { my $niw = 0; my $i_seen = 0; } # set NIW , i_seen at start
                     95: 
                     96:  chef: token(s) /\z/
                     97: 
                     98:  token: end_of_sentence
1.4     ! albertel   99:         | quant
1.1       albertel  100:         | Bbork
                    101:         | an | An
                    102:         | au | Au
                    103:         | ax | Ax
                    104:         | en
                    105:         | ew
                    106:         | edone
                    107:         | ex | Ex
                    108:         | f
                    109:         | ir
                    110:         | i
                    111:         | ow
                    112:         | o | O | xo
                    113:         | the | The | th
                    114:         | tion
                    115:         | u | U | v | V | w | W
1.2       albertel  116:         | NW   { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] }
                    117:         | WC   { $niw = 1; $Apache::localize::x_chef::result .= $item[1] }
                    118:         | /\n/ { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] }
                    119: 
                    120:  end_of_sentence: /[.?!]+/ /\s+/ { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] . "\nBork Bork Bork!\n" }
                    121: 
                    122:  Bbork: <reject: $niw> /([Bb]ork)/ ...NW { $Apache::localize::x_chef::result .= "$1" }
1.4     ! albertel  123:  quant: /(\[.+?\])/ { $Apache::localize::x_chef::result .= $1; }
1.2       albertel  124:  an: /an/ { $niw = 1; $Apache::localize::x_chef::result .= 'un' }
                    125:  An: /An/ { $niw = 1; $Apache::localize::x_chef::result .= 'Un' }
                    126:  au: /au/ { $niw = 1; $Apache::localize::x_chef::result .= 'oo' }
                    127:  Au: /Au/ { $niw = 1; $Apache::localize::x_chef::result .= 'Oo' }
                    128:  ax: /a/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "e" }
                    129:  Ax: /A/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "E" }
                    130:  en: /en/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "ee" }
                    131:  ew: <reject: !$niw> /ew/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
                    132:  edone: <reject: !$niw> /e/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "e-a" }
                    133:  ex: <reject: $niw> /e/ { $niw = 1; $Apache::localize::x_chef::result .= "i" }
                    134:  Ex: <reject: $niw> /E/ { $niw = 1; $Apache::localize::x_chef::result .= "I" }
                    135:  f: <reject: !$niw> /f/ { $niw = 1; $Apache::localize::x_chef::result .= "ff" }
                    136:  ir: <reject: !$niw> /ir/ { $niw = 1; $Apache::localize::x_chef::result .= "ur" }
                    137:  i: <reject: !$niw> <reject: $i_seen> /i/ { $niw=1;$i_seen=1; $Apache::localize::x_chef::result .= "ee" }
                    138:  ow: <reject: !$niw> /ow/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
                    139:  o: <reject: $niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
                    140:  O: <reject: $niw> /O/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
                    141:  xo: <reject: !$niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "u" }
                    142:  the: /the/ { $niw = 1; $Apache::localize::x_chef::result .= 'zee' }
                    143:  The: /The/ { $niw = 1; $Apache::localize::x_chef::result .= 'Zee' }
                    144:  th: /th/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "t" }
                    145:  tion: <reject: !$niw> /tion/ { $niw = 1; $Apache::localize::x_chef::result .= "shun" }
                    146:  u: <reject: !$niw> /u/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
                    147:  U: <reject: !$niw> /U/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
                    148:  v: /v/ { $niw = 1; $Apache::localize::x_chef::result .= 'f' }
                    149:  V: /V/ { $niw = 1; $Apache::localize::x_chef::result .= 'F' }
                    150:  w: /w/ { $niw = 1; $Apache::localize::x_chef::result .= 'v' }
                    151:  W: /W/ { $niw = 1; $Apache::localize::x_chef::result .= 'V' }
1.1       albertel  152: 
                    153:  WC: /[A-Za-z']/
                    154:  NW: /[^A-Za-z']/
                    155: 
                    156: };
                    157: }
                    158: 
1.4     ! albertel  159: sub quant {
        !           160:     my $self = shift;
        !           161:     return &chefify2($self->SUPER::quant(@_));
        !           162: }
        !           163: sub numerate {
        !           164:     my $self = shift;
        !           165:     return &chefify2($self->SUPER::numerate(@_));
        !           166: }
        !           167: 
1.1       albertel  168: sub chefify2 {
                    169:     my ($str) = @_;
1.2       albertel  170:     my $backup=$str;
                    171:     $Apache::localize::x_chef::result='';
1.1       albertel  172:     if (!defined($lexer)) { &create_parser(); }
                    173:     $lexer->chef(\$str);
1.2       albertel  174:     $Lexicon{$backup}=$Apache::localize::x_chef::result;
                    175:     return $Apache::localize::x_chef::result;
1.1       albertel  176: }
                    177: 
                    178: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>