[LON-CAPA-cvs] cvs: loncom /localize/localize x_chef.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 20 Jul 2004 23:12:30 -0000


albertel		Tue Jul 20 19:12:30 2004 EDT

  Modified files:              
    /loncom/localize/localize	x_chef.pm 
  Log:
  - Parse::RecDescent is slow, so save the result after we do it once.
  
  
Index: loncom/localize/localize/x_chef.pm
diff -u loncom/localize/localize/x_chef.pm:1.1 loncom/localize/localize/x_chef.pm:1.2
--- loncom/localize/localize/x_chef.pm:1.1	Tue Jul 20 19:04:38 2004
+++ loncom/localize/localize/x_chef.pm	Tue Jul 20 19:12:29 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Russian Localization Lexicon
 #
-# $Id: x_chef.pm,v 1.1 2004/07/20 23:04:38 albertel Exp $
+# $Id: x_chef.pm,v 1.2 2004/07/20 23:12:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -84,10 +84,8 @@
 # March 26, 2000
 # adpated from chef.l by John Hagerman
 
-use vars qw($lexer $result);
 sub create_parser {
     use Parse::RecDescent;
-    use strict;
 
     $Parse::RecDescent::skip = '';          # skip nothing
 
@@ -114,41 +112,41 @@
         | the | The | th
         | tion
         | u | U | v | V | w | W
-        | NW   { $niw = 0; $i_seen = 0; $::result .= $item[1] }
-        | WC   { $niw = 1; $::result .= $item[1] }
-        | /\n/ { $niw = 0; $i_seen = 0; $::result .= $item[1] }
-
- end_of_sentence: /[.?!]+/ /\s+/ { $niw = 0; $i_seen = 0; $::result .= $item[1] . "\nBork Bork Bork!\n" }
-
- Bbork: <reject: $niw> /([Bb]ork)/ ...NW { $::result .= "$1" }
- an: /an/ { $niw = 1; $::result .= 'un' }
- An: /An/ { $niw = 1; $::result .= 'Un' }
- au: /au/ { $niw = 1; $::result .= 'oo' }
- Au: /Au/ { $niw = 1; $::result .= 'Oo' }
- ax: /a/ ...WC { $niw = 1; $::result .= "e" }
- Ax: /A/ ...WC { $niw = 1; $::result .= "E" }
- en: /en/ ...NW { $niw = 1; $::result .= "ee" }
- ew: <reject: !$niw> /ew/ { $niw = 1; $::result .= "oo" }
- edone: <reject: !$niw> /e/ ...NW { $niw = 1; $::result .= "e-a" }
- ex: <reject: $niw> /e/ { $niw = 1; $::result .= "i" }
- Ex: <reject: $niw> /E/ { $niw = 1; $::result .= "I" }
- f: <reject: !$niw> /f/ { $niw = 1; $::result .= "ff" }
- ir: <reject: !$niw> /ir/ { $niw = 1; $::result .= "ur" }
- i: <reject: !$niw> <reject: $i_seen> /i/ { $niw=1;$i_seen=1; $::result .= "ee" }
- ow: <reject: !$niw> /ow/ { $niw = 1; $::result .= "oo" }
- o: <reject: $niw> /o/ { $niw = 1; $::result .= "oo" }
- O: <reject: $niw> /O/ { $niw = 1; $::result .= "Oo" }
- xo: <reject: !$niw> /o/ { $niw = 1; $::result .= "u" }
- the: /the/ { $niw = 1; $::result .= 'zee' }
- The: /The/ { $niw = 1; $::result .= 'Zee' }
- th: /th/ ...NW { $niw = 1; $::result .= "t" }
- tion: <reject: !$niw> /tion/ { $niw = 1; $::result .= "shun" }
- u: <reject: !$niw> /u/ { $niw = 1; $::result .= "oo" }
- U: <reject: !$niw> /U/ { $niw = 1; $::result .= "Oo" }
- v: /v/ { $niw = 1; $::result .= 'f' }
- V: /V/ { $niw = 1; $::result .= 'F' }
- w: /w/ { $niw = 1; $::result .= 'v' }
- W: /W/ { $niw = 1; $::result .= 'V' }
+        | NW   { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] }
+        | WC   { $niw = 1; $Apache::localize::x_chef::result .= $item[1] }
+        | /\n/ { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] }
+
+ end_of_sentence: /[.?!]+/ /\s+/ { $niw = 0; $i_seen = 0; $Apache::localize::x_chef::result .= $item[1] . "\nBork Bork Bork!\n" }
+
+ Bbork: <reject: $niw> /([Bb]ork)/ ...NW { $Apache::localize::x_chef::result .= "$1" }
+ an: /an/ { $niw = 1; $Apache::localize::x_chef::result .= 'un' }
+ An: /An/ { $niw = 1; $Apache::localize::x_chef::result .= 'Un' }
+ au: /au/ { $niw = 1; $Apache::localize::x_chef::result .= 'oo' }
+ Au: /Au/ { $niw = 1; $Apache::localize::x_chef::result .= 'Oo' }
+ ax: /a/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "e" }
+ Ax: /A/ ...WC { $niw = 1; $Apache::localize::x_chef::result .= "E" }
+ en: /en/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "ee" }
+ ew: <reject: !$niw> /ew/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
+ edone: <reject: !$niw> /e/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "e-a" }
+ ex: <reject: $niw> /e/ { $niw = 1; $Apache::localize::x_chef::result .= "i" }
+ Ex: <reject: $niw> /E/ { $niw = 1; $Apache::localize::x_chef::result .= "I" }
+ f: <reject: !$niw> /f/ { $niw = 1; $Apache::localize::x_chef::result .= "ff" }
+ ir: <reject: !$niw> /ir/ { $niw = 1; $Apache::localize::x_chef::result .= "ur" }
+ i: <reject: !$niw> <reject: $i_seen> /i/ { $niw=1;$i_seen=1; $Apache::localize::x_chef::result .= "ee" }
+ ow: <reject: !$niw> /ow/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
+ o: <reject: $niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
+ O: <reject: $niw> /O/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
+ xo: <reject: !$niw> /o/ { $niw = 1; $Apache::localize::x_chef::result .= "u" }
+ the: /the/ { $niw = 1; $Apache::localize::x_chef::result .= 'zee' }
+ The: /The/ { $niw = 1; $Apache::localize::x_chef::result .= 'Zee' }
+ th: /th/ ...NW { $niw = 1; $Apache::localize::x_chef::result .= "t" }
+ tion: <reject: !$niw> /tion/ { $niw = 1; $Apache::localize::x_chef::result .= "shun" }
+ u: <reject: !$niw> /u/ { $niw = 1; $Apache::localize::x_chef::result .= "oo" }
+ U: <reject: !$niw> /U/ { $niw = 1; $Apache::localize::x_chef::result .= "Oo" }
+ v: /v/ { $niw = 1; $Apache::localize::x_chef::result .= 'f' }
+ V: /V/ { $niw = 1; $Apache::localize::x_chef::result .= 'F' }
+ w: /w/ { $niw = 1; $Apache::localize::x_chef::result .= 'v' }
+ W: /W/ { $niw = 1; $Apache::localize::x_chef::result .= 'V' }
 
  WC: /[A-Za-z']/
  NW: /[^A-Za-z']/
@@ -158,10 +156,12 @@
 
 sub chefify2 {
     my ($str) = @_;
-    $::result='';
+    my $backup=$str;
+    $Apache::localize::x_chef::result='';
     if (!defined($lexer)) { &create_parser(); }
     $lexer->chef(\$str);
-    return $::result;
+    $Lexicon{$backup}=$Apache::localize::x_chef::result;
+    return $Apache::localize::x_chef::result;
 }
 
 1;