[REBOL] Newbie: Spell-Check
From: mattymattkim::hotmail::com at: 27-Oct-2002 22:06
Hi,
I've stumbled upon the Spell-Check algorithm put together wonderfully by
Andrew Martin (and edited by a few others).
I would like to use the spell check (without the GUI) for simple spell
checking functionality in my scripts. However, after trying to understand
the code, I can't figure out how to use it!
I've stripped the part involving the GUI and this is what I'm left with (i
hope).
To use it, would I write:
Output: spell "Helo, this is a test."
Secondly, how would I use the "Spell-HTML" function to ignore any email
address posted in the sentance?
Ex. "Helo, I'm writing from [joe--example--com]".
Thanks!!!
Matt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rebol [
Name: 'Spell
Title: "Spell Checker and Corrector"
File: %Spell.r
]
wd: %./ ;insert your Spell directory path here
Spell!: make object! [
Directory: join wd %Spell/
if not exists? Directory [make-dir Directory]
File: %Dictionary.txt
Dictionary: make block! 0
Ignored: make block! 0
Additions: make block! 0
error? try [Dictionary: make hash! sort/case load Directory/:File]
Lower: charset [#"a" - #"z"]
Upper: charset [#"A" - #"Z"]
Alpha: union Upper Lower
WordMatch: [some Alpha opt [[{'} | {-}] some Alpha]]
WordStart: WordEnd: Original: Correction: Before: After: Cancelled: None
set 'Spell func [
{Spell checks and corrects (with user interaction) the text
supplied.}
Text [string!]
/extra {Extra rule to match before matching words.
The rule may of course include actions.}
rule [block!]
][
Cancelled: no
if not extra [rule: " "]
parse/case/all Text [
some [rule |
WordStart: WordMatch WordEnd: (
Before: copy/part WordStart -29
Original: copy/part WordStart WordEnd
After: copy/part WordEnd +29
Correction: copy Original
if not Cancelled [
if not found? any [
find/case Ignored Original
find/case Additions Original
find/case Dictionary Original
][
;Show-GUI
]
]
) :WordEnd
| skip
]
]
if not any [
Cancelled
empty? Additions
][
append Dictionary Additions
clear Additions
save Directory/:File make block! sort/case Dictionary
]
Text
]
]
Spell-HTML!: make object! [
alpha: copy Spell!/Alpha
non-space: complement charset " ^-^/"
to-space: [some non-space | end]
tag: ["<" thru ">"]
url: [some alpha ":/" to-space]
email: [some [alpha | integer! | "."] "@" to-space]
rule: [tag | url | email]
set 'Spell-HTML func [
{Spell checks and corrects (with user interaction) the HTML
supplied.}
Text [string!]
][
Spell/extra Text rule
]
]
_________________________________________________________________
Broadband? Dial-up? Get reliable MSN Internet Access.
http://resourcecenter.msn.com/access/plans/default.asp