File:  [LON-CAPA] / loncom / localize / localize / x_chef.pm
Revision 1.5: download - view: text, annotated - select for diffs
Wed Nov 9 13:14:16 2011 UTC (12 years, 7 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, language_hyphenation_merge, language_hyphenation, HEAD, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
Remove remains of remote control. "textual_remote_display" switch doesn't exist anymore.

    1: # The LearningOnline Network with CAPA
    2: # Russian Localization Lexicon
    3: #
    4: # $Id: x_chef.pm,v 1.5 2011/11/09 13:14:16 bisitz 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'=> 'UTF-8',
   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: 'htmlarea_lang' => 'en'
   45: );
   46: 
   47: sub init {
   48:     my $lh = $_[0];  # a newborn handle
   49:     $lh->SUPER::init();
   50:     $lh->fail_with(\&fail);
   51:     return;
   52: }
   53: 
   54: sub fail {
   55:     my ($lh,$key,@params) = @_;
   56:     my $value = $lh->_compile(&chefify2($key));
   57:     
   58:     return $$value if ref($value) eq 'SCALAR';
   59:     return $value unless ref($value) eq 'CODE';
   60:     
   61:     {
   62: 	local $SIG{'__DIE__'};
   63: 	eval { $value = &$value($lh, @params) };
   64:     }
   65:     return $value;
   66: }
   67: 
   68: 
   69: sub chefify {
   70:     my ($str)=@_;
   71:     $str=~s/\\/\\\\/g;
   72:     $str=~s/\"/\\"/g; #"
   73:     open(CHEF," echo \"$str\" | chef|");
   74:     my $result;
   75:     while (my $a=<CHEF>) { $result.=$a }
   76:     chomp($result);
   77:     $result=~s/\n/ /g;
   78:     close CHEF;
   79:     return $result;
   80: }
   81: 
   82: # chef.pl by Teodor Zlatanov, tzz@iglou.com
   83: # March 26, 2000
   84: # adpated from chef.l by John Hagerman
   85: 
   86: sub create_parser {
   87:     use Parse::RecDescent;
   88: 
   89:     $Parse::RecDescent::skip = '';          # skip nothing
   90: 
   91:     $lexer = new Parse::RecDescent q
   92: {
   93:  { my $niw = 0; my $i_seen = 0; } # set NIW , i_seen at start
   94: 
   95:  chef: token(s) /\z/
   96: 
   97:  token: end_of_sentence
   98:         | quant
   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
  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:  quant: /(\[.+?\])/ { $Apache::localize::x_chef::result .= $1; }
  123:  an: /an/ { $niw = 1; $Apache::localize::x_chef::result .= 'un' }
  124:  An: /An/ { $niw = 1; $Apache::localize::x_chef::result .= 'Un' }
  125:  au: /au/ { $niw = 1; $Apache::localize::x_chef::result .= 'oo' }
  126:  Au: /Au/ { $niw = 1; $Apache::localize::x_chef::result .= 'Oo' }
  127:  ax: /a/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "e" }
  128:  Ax: /A/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "E" }
  129:  en: /en/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "ee" }
  130:  ew: <reject: !$niw> /ew/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
  131:  edone: <reject: !$niw> /e/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "e-a" }
  132:  ex: <reject: $niw> /e/ { $niw = 1; $Apache::localize::x_chef::result .= "i" }
  133:  Ex: <reject: $niw> /E/ { $niw = 1; $Apache::localize::x_chef::result .= "I" }
  134:  f: <reject: !$niw> /f/ { $niw = 1; $Apache::localize::x_chef::result .= "ff" }
  135:  ir: <reject: !$niw> /ir/ { $niw = 1; $Apache::localize::x_chef::result .= "ur" }
  136:  i: <reject: !$niw> <reject: $i_seen> /i/ { $niw=1;$i_seen=1; $Apache::localize::x_chef::result .= "ee" }
  137:  ow: <reject: !$niw> /ow/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
  138:  o: <reject: $niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
  139:  O: <reject: $niw> /O/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
  140:  xo: <reject: !$niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "u" }
  141:  the: /the/ { $niw = 1; $Apache::localize::x_chef::result .= 'zee' }
  142:  The: /The/ { $niw = 1; $Apache::localize::x_chef::result .= 'Zee' }
  143:  th: /th/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "t" }
  144:  tion: <reject: !$niw> /tion/ { $niw = 1; $Apache::localize::x_chef::result .= "shun" }
  145:  u: <reject: !$niw> /u/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
  146:  U: <reject: !$niw> /U/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
  147:  v: /v/ { $niw = 1; $Apache::localize::x_chef::result .= 'f' }
  148:  V: /V/ { $niw = 1; $Apache::localize::x_chef::result .= 'F' }
  149:  w: /w/ { $niw = 1; $Apache::localize::x_chef::result .= 'v' }
  150:  W: /W/ { $niw = 1; $Apache::localize::x_chef::result .= 'V' }
  151: 
  152:  WC: /[A-Za-z']/
  153:  NW: /[^A-Za-z']/
  154: 
  155: };
  156: }
  157: 
  158: sub quant {
  159:     my $self = shift;
  160:     return &chefify2($self->SUPER::quant(@_));
  161: }
  162: sub numerate {
  163:     my $self = shift;
  164:     return &chefify2($self->SUPER::numerate(@_));
  165: }
  166: 
  167: sub chefify2 {
  168:     my ($str) = @_;
  169:     my $backup=$str;
  170:     $Apache::localize::x_chef::result='';
  171:     if (!defined($lexer)) { &create_parser(); }
  172:     $lexer->chef(\$str);
  173:     $Lexicon{$backup}=$Apache::localize::x_chef::result;
  174:     return $Apache::localize::x_chef::result;
  175: }
  176: 
  177: 1;

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