Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Newbie: Spell-Check

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 > 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 > > -- > To unsubscribe from this list, please send an email to > [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 ] ] ]