Newbie: Spell-Check
[1/5] 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
[2/5] from: al:bri:xtra at: 28-Oct-2002 17:22
Matt wrote:
> 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 couldn't figure it out either. :(
A spell checker really has to ask the user/writer, "is this [gobeleegook]
really a word or is it a mistake?" and then change it's store of right words
appropriately, and then repeat the above for the next suspicious word (if
necessary).
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
-><-
----- Original Message -----
From: "Matthew Kim" <[mattymattkim--hotmail--com]>
To: <[rebol-list--rebol--com]>
Sent: Monday, October 28, 2002 4:06 PM
Subject: [REBOL] Newbie: Spell-Check
> Hi,
> I've stumbled upon the Spell-Check algorithm put together wonderfully by
<<quoted lines omitted: 31>>
> 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
<<quoted lines omitted: 60>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
-- Attached file included as plaintext by Listar --
-- File: Spell.r
[
Rebol [
Name: 'Spell
Title: "Spell Checker and Corrector"
File: %Spell.r
Home: http://members.nbci.com/AndrewMartin/Rebol/Units/Spell.r
Author: "Andrew Martin"
eMail: [Al--Bri--xtra--co--nz]
Date: 22/Jan/2001
]
Spell!: make object! [
Directory: join wd %Spell/
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
set 'Spell function [
{Spell checks and corrects (with user interaction) the text supplied.}
Text [string!]
][
WordStart WordEnd Original Correction Before After Cancelled
][
parse/case/all Text [
some [
WordStart: [some Alpha opt [[{'} | {-}] some Alpha]] 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
][
view layout [
across
label "Not in Dictionary:" return
text Before field Correction text After return
button "Ignore" [
unview/all
]
button "Ignore All" [
append Ignored Original
unview/all
]
return
button "Add" [
append Additions Original
unview/all
]
button "Change" [
WordEnd: change/part WordStart Correction WordEnd
unview/all
]
button "Change All" [
replace/case/all WordStart Original Correction
unview/all
]
button "Cancel" [
Cancelled: yes
unview/all
]
return
button "Quit" [
quit
]
]
]
]
) :WordEnd
| skip
]
]
if not any [
Cancelled
empty? Additions
][
append Dictionary Additions
clear Additions
save Directory/:File make block! sort/case Dictionary
]
Text
]
]
]
[3/5] from: mattymattkim:hotma:il at: 27-Oct-2002 23:51
Hehe... didn't you write the spell check program Andrew?
Perhaps my view is overly simplistic, but doesn't it just scan through the
dictionary.txt file and determine a best matching word?
Matt
>From: "Andrew Martin" <[Al--Bri--xtra--co--nz]>
>Reply-To: [rebol-list--rebol--com]
<<quoted lines omitted: 238>>
>[rebol-request--rebol--com] with "unsubscribe" in the
>subject, without the quotes.
Matt Kim
If everything is under control, you are going too slow
-Mario Andretti
_________________________________________________________________
Unlimited Internet access for only $21.95/month. Try MSN!
http://resourcecenter.msn.com/access/plans/2monthsfree.asp
[4/5] from: al:bri:xtra at: 28-Oct-2002 18:39
Matt wrote:
> Perhaps my view is overly simplistic, but doesn't it just scan through the
dictionary.txt file and determine a best matching word?
No. It's doesn't do that. :) I was going to use something like Allen's
soundex to guess appropriate words that would be suitable replacements.
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[5/5] from: greggirwin:mindspring at: 28-Oct-2002 9:15
I know Volker has developed a bit of spell checking stuff, but I'm not sure
what state it's in, or if he's planning on publishing it anywhere. Maybe
he'll jump in here.
--Gregg
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted