Quote:
Originally Posted by tateu
I didn't think to check that because I didn't know you could get those characters on a blackberry.
|
You can press and hold a letter key and then roll the thumbwheel to scroll through international/accent characters, equation symbols and other marks.
That is #4 under "Composing a Message" on my "Blackberry Tips and Tricks" page which is currently here:
http://webpages.charter.net/gwgaston...nd_Tricks.html
At least while I'm editing it for the next few weeks. There are still lots of additions (and corrections) to make.
Quote:
Originally Posted by tateu
So do your changes work? And if so, what are they?
|
Yeah, although I ultimately went with a completely different approach that uses a different backend and a new BB client, the code below was working fine for me. Note that you will need to grab the Unicode::Normalize module (if haven't already grabbed it for something else) and will likely need to adjust other parts like the path to Aspell, language file used, and options passed... Some of the replacements could be removed (like for the accent characters I brought up) as they are covered in the decomposition. Also, you could do things like have œ (\x{0153}) replaced with a capital O, so that when used anywhere but the first char it would still prompt you to correct the word.
Anyway here it is:
Code:
#!c:/perl/bin/perl
#
# BBSpellCheck Server
#
# This script accepts a block of text from the BlackBerry software
# BBSpellCheck, runs it through Aspell, and returns an XML packet
# indicating spelling errors.
#
# NOTES:
#
# - It is recommended you protect this script with some form of HTTP
# authentication. BBSpellCheck is setup to handle Basic Authentication.
#
# 2005-06-04 GWGaston:
# Added code to convert to plain ASCII (wack symbols, glyphs, diacritics)
use CGI qw(:standard Vars);
use File::Temp qw/ tempfile tempdir /;
# The Aspell executable
my $cmdAspellExe = "\"C:/Program Files/Aspell/bin/aspell\"";
# Language is US English
# my $lang = "en_US";
my $lang = "en";
use utf8;
# Options for Aspell. Puts Aspell into Ispell compatibility mode
# so that its output is written to stdout
my $cmdAspellOptions = "-a --lang=$lang --repl=.en.prepl ";
my %FORM = Vars();
# Get the block of text from the HTTP parameter "check"
my $text2Check = "$FORM{check}";
# Convert line endings to a common format. In this case whatever
# line ending combination we get (CRLF, LF, etc), we convert to a standard
# format of LF
$text2Check =~ s/\x0D\x0A|\r/\n/g;
use Encode;
use Unicode::Normalize;
my $tmptext = Encode::decode( 'utf-8', $text2Check );
$text2Check = NFD( $tmptext ); ## Decompose using Normalization Form D
$text2Check =~ s/\pM//g; ## Remove combining characters
# A lot of the replacements below are now redundant...
# but I left 'em in anyway. -GWGaston
$text2Check =~ s/ß/b/g;
$text2Check =~ s/Ð/D/g;
$text2Check =~ s/ð/d/g;
$text2Check =~ s/×/x/g;
$text2Check =~ s/þ/T/g;
$text2Check =~ s/¿/?/g;
$text2Check =~ s/[§xxx346;xxx348;xxx350;Š]/S/g;
$text2Check =~ s/[xxx347;xxx349;xxx351;š]/s/g;
$text2Check =~ s/[xxx284;xxx286;xxx288;xxx290;]/G/g;
$text2Check =~ s/[xxx285;xxx287;xxx289;xxx291;]/G/g;
$text2Check =~ s/[xxx294;xxx292;]/H/g;
$text2Check =~ s/[xxx293;xxx295;]/h/g;
$text2Check =~ s/[xxx257;xxx259;xxx261;àáâãäåæª]/a/g;
$text2Check =~ s/[xxx256;xxx258;xxx260;ÀÁÂÃÄÅÆ]/A/g;
$text2Check =~ s/[èéêë]/e/g;
$text2Check =~ s/[ÈÉÊË]/E/g;
$text2Check =~ s/[ìíîï¡]/i/g;
$text2Check =~ s/[ÌÍÎÏ]/I/g;
$text2Check =~ s/[òóôõöøxxx333;xxx335;xxx337;xxx972;œ]/o/g;
$text2Check =~ s/[ÒÓÔÕÖØxxx332;xxx334;xxx336;Œ]/O/g;
$text2Check =~ s/çxxx263;xxx265;xxx267;xxx269;/c/g;
$text2Check =~ s/[Çxxx262;xxx264;xxx266;xxx268;]/C/g;
$text2Check =~ s/[ùúûüµ]/u/g;
$text2Check =~ s/[ÙÚÛÜ]/U/g;
$text2Check =~ s/[ýÿ]/y/g;
$text2Check =~ s/Ý/Y/g;
$text2Check =~ s/ñ/n/g;
$text2Check =~ s/Ñ/N/g;
$text2Check =~ s/([^[:ascii:]]+)/' '/eg;
# Create a temporary file to store our block of text
my $dirTemp = tempdir( CLEANUP => 1 );
my( $tempHandle, $tempFilename ) = tempfile( DIR => $dir );
# Split block of text into lines and write to temp file
@lines = split( /\n/, $text2Check );
for my $line ( @lines ) {
# Force Aspell to check whole line via ^ contol character
print $tempHandle "^$line\n";
}
close $tempHandle;
# XML packet has format such as:
# <spell-results>
# <error>
# <word>maan</word>
# <position>12</position>
# <suggest>Man</suggest>
# <suggest>man</suggest>
# <suggest>moan</suggest>
# </error>
# <error>
# <word>helllo</word>
# <position>33</position>
# <suggest>hello</suggest>
# </error>
# <error>
# <word>chris</word>
# <position>41</position>
# <suggest>Chris</suggest>
# <suggest>Charis</suggest>
# </error>
# </spell-results>
my $xmlPacket = "<spell-results>";
# Do this here so that when we are debugging we can display it in return output
print header;
# Keeps track of current line number
my $lineNum = 0;
# Keeps track of the absolute position in the block of text
my $posAbsolute = 0;
# Execute Aspell
my $cmd = "$cmdAspellExe $cmdAspellOptions < $tempFilename 2>&1";
# TODO: $status most likely only tracks wether the fork failed or not, not
# whether the actual command we are running (ie: aspell) failed
my $status = open ASPELL, "$cmd |";
if ($status > 0) {
# Parse Aspell output
for my $cmdReturn (<ASPELL>) {
chomp($cmdReturn);
#print "$cmdReturn<br>\n";
if( $cmdReturn =~ /^\*/ ) {
# Line begins with *. Do nothing.
} elsif( $cmdReturn =~ /^(&|#)/ ) {
# Line begins with & or #.
# Start error element
$xmlPacket .= "<error>";
# Split return line up for easier access
my @tokens = split(" ", $cmdReturn, 5);
# Add word element which contains original misspelled word
$xmlPacket .= "<word>$tokens[1]</word>";
# Need to work out absolute position in file, not just position in current line
my $offsetIdx = 3;
if ($cmdReturn =~ /^\#/) {
$offsetIdx--;
}
my $pos = $posAbsolute + ($tokens[$offsetIdx] - 1);
$xmlPacket .= "<position>".$pos."</position>";
# Add suggestions
my @suggestions = ();
if ($tokens[4]) {
@suggestions = split(", ", $tokens[4]);
for my $suggestion (@suggestions) {
$xmlPacket .= "<suggest>$suggestion</suggest>";
}
}
# End error element
$xmlPacket .= "</error>";
} elsif( $cmdReturn =~ /^$/ ) {
# We have a blank line which indicates a line of text has been processed
my $line = $lines[$lineNum];
$posAbsolute += (length($line) + 1);
$lineNum++;
}
}
close ASPELL;
} else {
$xmlPacket .= "<exception>BBSpellCheck Server has encountered an error ($!)</exception>";
}
# Delete the temp file
#unlink $tempFilename;
# End results XML packet
$xmlPacket .= "</spell-results>";
#print "check = $text2Check<p>\n";
my( $tempHandle, $tempFilename ) = tempfile( DIR => $dir );
print $tempHandle "$xmlPacket\n";
close $tempHandle;
# Return XML packet back to client
print "$xmlPacket\n";
Gerald W. Gaston