PDA

View Full Version : Spell checker in Flex 2.0


meeVar0506
08-10-2007, 07:30 AM
Can anybody advice me which is a good spellchecker to intergrate to flex 2.0?

Flash Gordon
08-10-2007, 07:31 AM
subscribed.

meeVar0506
08-10-2007, 07:48 AM
I need to integrate a spell check for my flex 2.0 application where I need to spell check text input, text area and rich text controls where styles may have been applied. After word is replaced, style should be retained. Can some body tell me about a good spell checker?

dr_zeus
08-10-2007, 06:23 PM
As far as I know, there are no spell-checking libraries out there for AS3 right now. However, I've heard through the grapevine that something may be coming from a non-Adobe source soon. I'm sorry, but I can't share details.

drkstr
08-10-2007, 06:31 PM
I've always used a server side library for this. For instance with GNU Aspell, you could post the text to the server and then pipe the file through aspell when the user wants to spell check.


aspell -a < "uploaded_text"


This will return a list of '*'s for every clean word, and something like this for a mismatch:

Original word: directiry

& directiry 15 4: directory, director, directors, directer, directly, directing, directive, directory's, rectory, direct, director's, directrix, directed, directorate, directs


You would then take the info and send it back to the client for processing.

This is not an ideal solution however since words can't be checked on the fly (unless you made a server call any time a word was edited, which could get ugly).

I am interested to know if there are any client side spell check libraries for actionscript 3.

Let us know if you find anything!

Best regards,
...aaron

drkstr
08-11-2007, 01:09 PM
This actually tickled my curiosity bone a little. A few pots of coffee and one less nights sleep later, I have a working demo for a spell check library. Not real time yet (if ever), but oh well.

Here is a demo if anyone is interested:

http://labs.splashlabs.com/spellcheck/

I will release the code once I have a chance to clean it up a bit. But if you have any questions on how I did it, feel free to ask.

Best regards,
...aaron

PS:

multiple requests at the same time will break the buffering until I get around fixing it. Sorry. I'm lazy. [edit: fixed]

drkstr
08-13-2007, 01:06 AM
Here is the code if any one is interested.

http://labs.splashlabs.com/spellcheck/src/index.html

And here is a demo.
http://labs.splashlabs.com/spellcheck/index.html

There are still a lot of things needed to be cleaned up for it to be usable as a full spell checking solution, but I am hoping that by making it open source some of the experts out there can help make it better.

Also, my server doesn't seem to want to serve the PHP in the code browser, so I will post it here so you don't have to download the whole zip if you just wanted to look at it.

Best regards,
...aaron

<?php

//$BASE_DIR = 'C:/wamp/www/spellcheck';
//$ASPELL = 'C:/wamp/Aspell/bin/aspell.exe'

$BASE_DIR = '/var/www/spellcheck';
$ASPELL = 'aspell';

$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "$BASE_DIR/error-output.txt", "a") // stderr is a file to write to
);

$timestamp = time();

while( file_exists("$BASE_DIR/$timestamp") ) {
$timestamp++;
}

$buffer_file = "$BASE_DIR/$timestamp";

if( $_POST['text'] ) {
file_put_contents( $buffer_file, $_POST['text'] );
}

$process = proc_open("$ASPELL -a < $buffer_file", $descriptorspec, $pipes );

$output = stream_get_contents($pipes[1]);
fclose($pipes[1]);
@unlink($buffer_file);

print '<?xml version="1.0" encoding="UTF-8"?>'."\n";
print '<checkresult>';

$index = -1;
foreach( explode( "\n", trim($output)) as $line ) {
//skip first line (garbage)
if( $index == -1 ) {
$index++;
continue;
}

$line = trim($line);
if( $line != '*' ) {
print '<mismatch index="'.$index.'" >';
$sugestions = explode( ',', substr($line, strpos($line, ':')+1) );
foreach( $sugestions as $word ) {
print '<word>'.trim($word).'</word>';
}

print '</mismatch>';
}

$index++;
}

print '</checkresult>';

?>

And here is an example XML response.


<checkresult>
<mismatch index="1">
<word>creel</word>
<word>crawl</word>
<word>cruel</word>
<word>crewel</word>
<word>Creole</word>
<word>crawly</word>
<word>creole</word>
<word>crew</word>
<word>carrel</word>
<word>crews</word>
<word>growl</word>
<word>creels</word>
<word>Creek</word>
<word>creek</word>
<word>Carrol</word>
<word>Corella</word>
<word>Cree</word>
<word>corral</word>
<word>cruelly</word>
<word>reel</word>
</mismatch>
<mismatch index="5">
<word>here</word>
<word>her</word>
<word>Herr</word>
<word>hewer</word>
<word>jeer</word>
<word>hexer</word>
<word>hear</word>
<word>heir</word>
<word>hoer</word>
<word>cheer</word>
<word>sheer</word>
<word>Heep</word>
<word>heed</word>
<word>heel</word>
<word>beer</word>
<word>deer</word>
<word>leer</word>
<word>peer</word>
<word>seer</word>
<word>veer</word>
<word>weer</word>
</mismatch>
</checkresult>

Flash Gordon
08-13-2007, 01:12 AM
thanks for posting this stuff!

drkstr
08-13-2007, 02:43 AM
No problem at all! FYI, if you downloaded the source already, you should grab it again. I just fixed a pretty major bug w/ the regular expressions.

Regards,
...aaron

*edit*
last update as of now.

drkstr
06-17-2008, 11:20 PM
Did anyone ever download the source to the spell checker? If so, can you reply with it as an attachment. I lost it in a hard drive crash and I ended up needing it again.


Thanks!
~Aaron