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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # Russian Localization Lexicon
                      3: #
1.2     ! albertel    4: # $Id: x_chef.pm,v 1.1 2004/07/20 23:04:38 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=(
                     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: 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
                     99:         | Bbork
                    100:         | an | An
                    101:         | au | Au
                    102:         | ax | Ax
                    103:         | en
                    104:         | ew
                    105:         | edone
                    106:         | ex | Ex
                    107:         | f
                    108:         | ir
                    109:         | i
                    110:         | ow
                    111:         | o | O | xo
                    112:         | the | The | th
                    113:         | tion
                    114:         | u | U | v | V | w | W
1.2     ! albertel  115:         | NW   { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] }
        !           116:         | WC   { $niw = 1; $Apache::localize::x_chef::result .= $item[1] }
        !           117:         | /\n/ { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] }
        !           118: 
        !           119:  end_of_sentence: /[.?!]+/ /\s+/ { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] . "\nBork Bork Bork!\n" }
        !           120: 
        !           121:  Bbork: <reject: $niw> /([Bb]ork)/ ...NW { $Apache::localize::x_chef::result .= "$1" }
        !           122:  an: /an/ { $niw = 1; $Apache::localize::x_chef::result .= 'un' }
        !           123:  An: /An/ { $niw = 1; $Apache::localize::x_chef::result .= 'Un' }
        !           124:  au: /au/ { $niw = 1; $Apache::localize::x_chef::result .= 'oo' }
        !           125:  Au: /Au/ { $niw = 1; $Apache::localize::x_chef::result .= 'Oo' }
        !           126:  ax: /a/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "e" }
        !           127:  Ax: /A/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "E" }
        !           128:  en: /en/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "ee" }
        !           129:  ew: <reject: !$niw> /ew/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
        !           130:  edone: <reject: !$niw> /e/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "e-a" }
        !           131:  ex: <reject: $niw> /e/ { $niw = 1; $Apache::localize::x_chef::result .= "i" }
        !           132:  Ex: <reject: $niw> /E/ { $niw = 1; $Apache::localize::x_chef::result .= "I" }
        !           133:  f: <reject: !$niw> /f/ { $niw = 1; $Apache::localize::x_chef::result .= "ff" }
        !           134:  ir: <reject: !$niw> /ir/ { $niw = 1; $Apache::localize::x_chef::result .= "ur" }
        !           135:  i: <reject: !$niw> <reject: $i_seen> /i/ { $niw=1;$i_seen=1; $Apache::localize::x_chef::result .= "ee" }
        !           136:  ow: <reject: !$niw> /ow/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
        !           137:  o: <reject: $niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
        !           138:  O: <reject: $niw> /O/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
        !           139:  xo: <reject: !$niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "u" }
        !           140:  the: /the/ { $niw = 1; $Apache::localize::x_chef::result .= 'zee' }
        !           141:  The: /The/ { $niw = 1; $Apache::localize::x_chef::result .= 'Zee' }
        !           142:  th: /th/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "t" }
        !           143:  tion: <reject: !$niw> /tion/ { $niw = 1; $Apache::localize::x_chef::result .= "shun" }
        !           144:  u: <reject: !$niw> /u/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
        !           145:  U: <reject: !$niw> /U/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
        !           146:  v: /v/ { $niw = 1; $Apache::localize::x_chef::result .= 'f' }
        !           147:  V: /V/ { $niw = 1; $Apache::localize::x_chef::result .= 'F' }
        !           148:  w: /w/ { $niw = 1; $Apache::localize::x_chef::result .= 'v' }
        !           149:  W: /W/ { $niw = 1; $Apache::localize::x_chef::result .= 'V' }
1.1       albertel  150: 
                    151:  WC: /[A-Za-z']/
                    152:  NW: /[^A-Za-z']/
                    153: 
                    154: };
                    155: }
                    156: 
                    157: sub chefify2 {
                    158:     my ($str) = @_;
1.2     ! albertel  159:     my $backup=$str;
        !           160:     $Apache::localize::x_chef::result='';
1.1       albertel  161:     if (!defined($lexer)) { &create_parser(); }
                    162:     $lexer->chef(\$str);
1.2     ! albertel  163:     $Lexicon{$backup}=$Apache::localize::x_chef::result;
        !           164:     return $Apache::localize::x_chef::result;
1.1       albertel  165: }
                    166: 
                    167: 1;

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