Friday, 23 December 2011


Check spelling is an important feature, and Rebol has integrated in the RebGUI script, just hit CTRL+S in any text area and spell check wik start (remember to download the dictionaries...).
However, if you don't like RebGUI, there are a lot of open source programs that can be used. The most famous are Ispell and Aspell. You can use these programs to check spelling texts with Rebol.
I'll show you Aspell, that is more recent, but you can use any software.
First of all download Aspell for your platform from here:
and install also the dictionaries of your languages.
Then we need a phrase as example:
"Hello, this is Carl; a great warrrior!"
There is an error on warrrior, now let's try with Rebol:

a: "Hello, this is Carl; a great warrrior!"

we should split the original sentences in single words, and is very easy with Rebol:

>> b: parse a none
== ["Hello" "this" "is" "Carl" "a" "great" "warrrior!"]

Now we use Aspell and we create a file were every line is a word checked. If a line starts with *,the word is OK; else the line starts with a &, the word is misspelled and Aspeel gives the suggested word.

call/input " c:\Programmi\Aspell\bin\aspell.exe -a --lang=en > ./spellout.txt " a

The spellout file will be:

@(#) International Ispell Version 3.1.20 (but really Aspell 0.50.3)
& warrrior 10 30: warrior, warriors, warier, worrier, wearier, waterier, warrior's, wartier, wearer, barrio

Now let's show to the user that he misspelled some word:

c: read/lines %spellout.txt
foreach word b [
c: next c ; so we skip the first line with Aspell copyright
if (first c/1) = #"&" [ alert reform ["You misspelled:" word]]

This are the basis of spell-checking. If you want to see something better let's see this example:
view layout [
    a: area
    text "English spellcheck"
    button "Spellcheck" [
        call/input " c:\Programmi\Aspell\bin\aspell.exe -a --lang=en > ./spellout.txt " a/text
        b: parse a/text none
        c: read/lines %spellout.txt
        temp: copy a/text
        foreach word b [
            temp: copy (find/case temp word); so we traverse the text
            c: next c ; so we skip the first line with Aspell copyright
            if (first c/1) = #"&" [
                temp2: copy/part (find/case/tail temp word) 50
                view/new/title layout [
                    text bold red word
                    text 200 temp2
                    box black 200x2
                    text 200 reform ["Suggest words" (find c/1 ":")]
                ] "Spellcheck"

It's just a simple example in 10 lines of code, but here is the result:

No comments:

Post a Comment