Diff for /loncom/interface/spellcheck.pm between versions 1.1 and 1.2

version 1.1, 2012/08/21 10:31:52 version 1.2, 2012/08/27 11:09:56
Line 26 Line 26
 #  #
 #  #
 package Apache::spellcheck;  package Apache::spellcheck;
   use CGI qw(:standard);
   use Apache::Constants qw(:common);
 use strict;  use strict;
 use Text::Aspell;  use Text::Aspell;
   
Line 79  sub spell_check { Line 81  sub spell_check {
     my @mis_spelled;      my @mis_spelled;
     foreach my $word (@word_list) {      foreach my $word (@word_list) {
  if (!$checker->check($word)) {   if (!$checker->check($word)) {
     push (@mis_spelled $word);      push (@mis_spelled, $word);
  }   }
     }      }
     return &array_to_json(\@mis_spelled);      return &array_to_json(\@mis_spelled);
Line 98  sub suggest_spellings { Line 100  sub suggest_spellings {
     my $checker = Text::Aspell->new;      my $checker = Text::Aspell->new;
     $checker->set_option('lang', $lang);      $checker->set_option('lang', $lang);
   
     @suggestions = $checker->suggest($word);      my @suggestions = $checker->suggest($word);
   
     return &array_to_json(\@suggestions);      return &array_to_json(\@suggestions);
 }  }
Line 115  sub suggest_spellings { Line 117  sub suggest_spellings {
   
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
       my $raw_params;
   
       if ($r->method eq 'POST') {
    $raw_params = $r->content();
       } else {
    $raw_params = $r->args();
       }
       my $query = CGI->new($raw_params);
   
     # Figure out the language defaulting to english.      # Figure out the language defaulting to english.
   
     my $language = "en-US";      my $language = "en-US";
     if ($r->param{'lang'}) {      if ($query->param('lang')) {
  $language = $r->param{'lang'};   $language = $query->param('lang');
     }      }
     #  Regardless, response Content type: is application/json:      #  Regardless, response Content type: is application/json:
   
     $h->header_out('Content-Type', 'application/json');      $r->content_type( 'application/json');
       $r->send_http_header;
   
     # Whether we are suggesting or spell checking      # Whether we are suggesting or spell checking
     # depends on which of the suggest or text args are present:      # depends on which of the suggest or text args are present:
Line 132  sub handler { Line 143  sub handler {
   
     my $data;      my $data;
   
     if ($h->args{'text'}) {      if ($query->param('text')) {
  $data =  &spell_check($h->args{'text'}, $language);   $data =  &spell_check($query->param('text'), $language);
     } eslif ($h->args{'suggest'}) {      } elsif ($query->param('suggest')) {
  $data = &suggest_spellings($h->args{'suggest'}, $language);   $data = &suggest_spellings($query->param('suggest'), $language);
     } else {      } else {
  die "Invalid request";   die "Invalid request";
     }      }
     $r->print($data);      $r->print($data);
   
       return OK;
 }  }
   
       1;
   __END__

Removed from v.1.1  
changed lines
  Added in v.1.2


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