[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
foxr
foxr at source.lon-capa.org
Tue Aug 14 06:22:25 EDT 2012
foxr Tue Aug 14 10:22:25 2012 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
BZ838 - Use Text::Apsell package rather than shelling out aspell directly.
Text::Aspell appears installed on my syste without any intervention on my
part.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1090 loncom/interface/loncommon.pm:1.1091
--- loncom/interface/loncommon.pm:1.1090 Tue Aug 7 10:52:17 2012
+++ loncom/interface/loncommon.pm Tue Aug 14 10:22:25 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1090 2012/08/07 10:52:17 foxr Exp $
+# $Id: loncommon.pm,v 1.1091 2012/08/14 10:22:25 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -70,6 +70,7 @@
use LONCAPA qw(:DEFAULT :match);
use DateTime::TimeZone;
use DateTime::Locale::Catalog;
+use Text::Aspell;
# ---------------------------------------------- Designs
use vars qw(%defaultdesign);
@@ -3063,41 +3064,27 @@
sub check_spelling {
my ($wordlist, $language) = @_;
+ my @misspellings;
+
+ # Generate the speller and set the langauge.
+ # if explicitly selected:
- # Format the command. If $language is null then
- # don't request a language - Note that's dangerous
- # because there's no assurance the server is running the intended default
- # language.
-
- my $langswitch = '';
+ my $speller = Text::Aspell->new;
if ($language) {
- $langswitch = "--lang=$language";
+ $speller->set_option('lang', $language);
}
- my $aspell_command = "aspell -a $language";
- my $full_command = "echo $wordlist | $aspell_command";
-
- my $ispell_result = `$full_command`;
+ # Turn the word list into an array of words by splittingon whitespace
- # The result is several lines of text.
- # the first line will start with @(#). Other wise
- # There's an error. With an error our fallback is to declare
- # all the words are correctly spelled (return empty string).
+ my @words = split(/\s+/, $wordlist);
- my @misspellings;
- my @lines = split(/\n/, $ispell_result);
- my $heading = shift(@lines); # header
- if ($heading =~ /^\@\(#\) /) {
- foreach my $word (split(/\s+/, $wordlist)) {
- my $spellok = pop(@lines);
- if (!($spellok =~ /^\*/)) {
- push(@misspellings, $word);
- }
+ foreach my $word (@words) {
+ if(! $speller->check($word)) {
+ push(@misspellings, $word);
}
- return join(' ', (@misspellings)); # empty if all words ok.
- } else {
- return "";
}
+ return join(' ', @misspellings);
+
}
# -------------------------------------------------------------- Plaintext name
More information about the LON-CAPA-cvs
mailing list