use strict ; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use HTML::Template; use Data::Dumper; use Unicode::String; my $q = new CGI; print $q->header(); #my $template = "wsillafu.tmpl"; my $template = "bbc/lemma/wsillafu.tmpl"; my $tmpl = new HTML::Template( filename => $template, associate => $q ); my $errorchecker = "0";my $memoryoverloadchecker = "0"; my $memorychecker = "0"; my $dictionarychecker = "0";my $otherchecker = "0";my $memoryfinder = "0"; if ($q->param()) { (my $spellingcheck, my $error) = lookup($q->param("brawddeg")); #print Dumper( $spellingcheck ); #print "error = $error
"; $tmpl->param( spellingcheck => $spellingcheck ); if($error == 1){$errorchecker = "1"; $memoryfinder = "1";} if($error == -1){$memoryoverloadchecker = "1"; $memoryfinder = "1";} if($error == -2){$memorychecker = "1"; $memoryfinder = "1";} if($error == -3){$dictionarychecker = "1"; $memoryfinder = "1";} if($error == -4){$otherchecker = "1"; $memoryfinder = "1";} } print $tmpl->output; if( $dictionarychecker eq "1" ) { print "

Nid yw\'r geiriadur ar-lein ar gael. E-bostiwch meistr y wefan am gymorth \n"; } if( $otherchecker eq "1" ) { print "

Mae gwall yn y gwirydd. E-bostwich meistr y wefan am gymorth \n"; } if( $memoryoverloadchecker eq "1" ) { print "

Roedd mwy na 10 gwall yn y testun. Dim ond y 10 gwall cyntaf sydd wedi ei cywiro.
Cywirwch rhain cyn cario ymlaen i gywiro.\n"; } if( $memorychecker eq "1" ) { print "

Mae'r gwirydd wedi rhedeg allan o gof. E-bostiwch meistr y wefan am gymorth.\n"; } if( $errorchecker eq "1" ) { print "

Mae rhai gwallau yng nghorff y testun.
Dewiswch air â gynhigir yn y blwch tynnu i lawr i bob gair sydd wedi ei sillafu'n anghywir.
Yna gwagswch y botwm gwirio isod i gael eich testun wedi ei wirio.
\n"; print "
\n"; print "
\n"; } if( $memoryfinder eq "0" ) {print "

Nid oedd gwall yn y frawddeg\n";} use lemma; sub lookup() { $_ = shift(@_); #print "Paramater: $_ \n"; #my $br = ""; #$br->String::latin1( $_ ); #print "Latin1 $br \n"; (my $errors, my $str) = lemma::GetCysillSpellingErrors($_, 10); #print "$str\n"; my @fields = split ("([^<]*)", $str); #print Dumper(@fields); my $error = ( @fields > 1); my @spellingcheck = (); for(my $i=0; $i<@fields; $i+=2) { my %pair; if($i+1 == @fields) { %pair = (text=> @fields[$i]); } else { @fields[$i+1] =~ s/<[^>]*>//g; my @SuggestionList = split /,/, @fields[$i+1]; #print "SuggestionList = ",Dumper(@SuggestionList); my @suggestions = (); my $suggestion; foreach $suggestion (@SuggestionList) { my %hash = (suggestion=> $suggestion); push @suggestions, \%hash; } %pair = (text=> @fields[$i], thesuggestions=>\@suggestions); } push @spellingcheck, \%pair; } #print Dumper(@spellingcheck); return (\@spellingcheck, $errors) ; }