AutoHotkey Community

It is currently May 27th, 2012, 1:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 

Do you think this is a potentially useful script?
Yes, keep working on it!
Uh, isn't this what we have Microsoft for?
You may select 1 option

View results
Author Message
 Post subject: AHK Spell Checker
PostPosted: May 11th, 2009, 7:04 am 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
For some reason I kept coming back to a post from this weekend about auto-correcting text on the Clipboard prior to pasting it, for which the answer was pretty much no. I kept thinking to myself, "Of all the possibilities that have been realized in AHK how could something as simple as this have not been attempted?". After searching Scripts & Functions for about 15 minutes I could not find that any serious attempt had been made to do something even similar to that idea, so I figured it was worth a shot.

The intro GUI gives you the option of checking text that you have already saved to the Clipboard or opening a small text editor where you can type text and elect to have it spell checked once you are finished. The corrections are made in a loop that will produce a message box each time a potential correction is found, which will allow you to select whether you would like to keep the correction or dismiss it. You will also be given the option once the loop breaks to keep the corrections and continue or cancel.

This script was actually the easy part; the difficulty is the correction database. I basically had to slice and dice the AutoCorrect script to extract the corrections into a workable format but the list is so massive that it's difficult to test and correct each entry in an effective manner. In other words, the corrections may be bug prone, but if people are willing to test the script out and notify me of potential corrections to the list I can at least fine tune it.

The script for the spell checker itself will be posted here but the text file is depends on to work will have to be downloaded; I have it hosted at autohotkey.net. Any suggestions on how I can improve the functionality of the script or make corrections to the text database are more than welcome:


Code:
;
; AutoHotkey Version: 1.0.48.03
; Language:       English
; Platform:       Win9x/NT
; Author:         sinkfaze <constibooter@gmail.com>
;
; Script Function:
;   This is a script that will allow you to spell check text that you have copied on the Clipboard, or, it will
;   open a small editor where you can type text and elect to have it spell checked when you are finished.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%


Gui, Add, Text, x16 y10 w200 h20 +Center, Which would you like to do?
Gui, Add, Button, yp+20 wp hp gCheckClip, Run spell check on the Clipboard.
Gui, Add, Button, yp+25 wp hp gRunEdit, Open the Editor so I can write.
Gui, Show, AutoSize Center, AHK Spell Checker
Return

CheckClip:

Gui, Destroy
TestVar := Clipboard

Loop, read, SpellCheck.txt
{
   IfInString, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1)
   {
      MsgBox, 68, AHK Spell Checker, % TestVar "`n`n" SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1) " will be changed to " SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1) "`n`nContinue with replacement?"
      ifMsgBox, Yes
         StringReplace, TestVar, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1), % SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1), All
      else
         continue
   }
}

MsgBox, 33, AHK Spell Checker, % TestVar "`n`nAre you sure you would like to replace the Clipboard's contents`nwith the above text?"
IfMsgBox, OK
{
   Clipboard := TestVar
   ClipWait
   MsgBox, The text has been converted and saved to the Clipboard.
   Reload
   return
}
Else
{
   Reload
   Return
}
   
RunEdit:

Gui, Destroy
Gui, 2: Add, Text, x16 y10 w370 h20 +Center, Enter the text you would like to spell check.
Gui, 2: Add, Edit, x16 y30 w370 R16 , ;  h220
Gui, 2: Add, Button, x236 y250 w70 h23 g2SpellCheck, Spell Check
Gui, 2: Add, Button, x316 y250 w70 h23 g2Cancel, Cancel
Gui, 2: Show, AutoSize Center, Spell Check Editor
Return

2SpellCheck:

ControlGetText, TestVar, Edit1, Spell Check Editor
Loop, read, SpellCheck.txt
{
   IfInString, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1)
   {

      MsgBox, 68, AHK Spell Checker, % TestVar "`n`n" SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1) " will be changed to " SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1) "`n`nContinue with replacement?"
      ifMsgBox, Yes
      {
         StringReplace, TestVar, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1), % SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1), All
         Continue
      }
      else
         Continue
   }
}

MsgBox, 33, AHK Spell Checker, % TestVar "`n`n Are you sure you would like to replace the Editor's contents`nwith the above text?"
IfMsgBox, OK
{
   ControlSetText, Edit1, %TestVar%, Spell Check Editor
   MsgBox, The text in the Editor has been converted.
   Return
}
Else
   Reload

GuiClose:
2Cancel:
2GuiClose:
ExitApp


Download SpellCheck.txt

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2009, 4:23 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
Functionality I would greatly appreciate further assistance with if it is at all possible:

- bold the portion of the text that is being corrected while displayed in the message box. Example:

MsgBox wrote:
Don't abondon your principles.

abondon will be replaced with abandon.

Continue with replacement?


- reduce the amount of text displayed in the message box to a snippet of surrounding text rather than the entire swath of text. Example:

MsgBox wrote:
...if we wish to seceed in our mission we will...

seceed will be replaced with succeed.

Continue with replacement?

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 11th, 2009, 9:50 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
For actual BOLD you should probably use something like HTML text (see a function by TIC somewhere). But I used *word* here. I changed the red bits.
Code:
;
; AutoHotkey Version: 1.0.48.03
; Language:       English
; Platform:       Win9x/NT
; Author:         sinkfaze <constibooter@gmail.com>
;
; Script Function:
;   This is a script that will allow you to spell check text that you have copied on the Clipboard, or, it will
;   open a small editor where you can type text and elect to have it spell checked when you are finished.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%


Gui, Add, Text, x16 y10 w200 h20 +Center, Which would you like to do?
Gui, Add, Button, yp+20 wp hp gCheckClip, Run spell check on the Clipboard.
Gui, Add, Button, yp+25 wp hp gRunEdit, Open the Editor so I can write.
Gui, Show, AutoSize Center, AHK Spell Checker
Return

CheckClip:

Gui, Destroy
TestVar := Clipboard

Loop, read, SpellCheck.txt
{
   Check:=SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1)
   IfInString, TestVar, %Check%

   {
      Where:=InStr(TestVar, Check)
      TestVarDisplay:= "... " . SubStr(TestVar,Where-15,Where+18) . " ..."
      StringReplace, TestVarDisplay, TestVarDisplay, Check, *%Check%*

      MsgBox, 68, AHK Spell Checker, % TestVarDisplay "`n`n" SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1) " will be changed to " SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1) "`n`nContinue with replacement?"
      ifMsgBox, Yes
         StringReplace, TestVar, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1), % SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1), All
      else
         continue
   }
}

MsgBox, 33, AHK Spell Checker, % TestVar "`n`nAre you sure you would like to replace the Clipboard's contents`nwith the above text?"
IfMsgBox, OK
{
   Clipboard := TestVar
   ClipWait
   MsgBox, The text has been converted and saved to the Clipboard.
   Reload
   return
}
Else
{
   Reload
   Return
}
   
RunEdit:

Gui, Destroy
Gui, 2: Add, Text, x16 y10 w370 h20 +Center, Enter the text you would like to spell check.
Gui, 2: Add, Edit, x16 y30 w370 R16 , ;  h220
Gui, 2: Add, Button, x236 y250 w70 h23 g2SpellCheck, Spell Check
Gui, 2: Add, Button, x316 y250 w70 h23 g2Cancel, Cancel
Gui, 2: Show, AutoSize Center, Spell Check Editor
Return

2SpellCheck:

ControlGetText, TestVar, Edit1, Spell Check Editor
Loop, read, SpellCheck.txt
{
   IfInString, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1)
   {

      MsgBox, 68, AHK Spell Checker, % TestVar "`n`n" SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1) " will be changed to " SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1) "`n`nContinue with replacement?"
      ifMsgBox, Yes
      {
         StringReplace, TestVar, TestVar, % SubStr(A_LoopReadLine,1,InStr(A_LoopReadLine,"|")-1), % SubStr(A_LoopReadLine,InStr(A_LoopReadLine,"|")+1), All
         Continue
      }
      else
         Continue
   }
}

MsgBox, 33, AHK Spell Checker, % TestVar "`n`n Are you sure you would like to replace the Editor's contents`nwith the above text?"
IfMsgBox, OK
{
   ControlSetText, Edit1, %TestVar%, Spell Check Editor
   MsgBox, The text in the Editor has been converted.
   Return
}
Else
   Reload

GuiClose:
2Cancel:
2GuiClose:
ExitApp


Edit:
HTMLText 1.01 - Write HTML style text to a GUI by tic
http://www.autohotkey.com/forum/topic26860.html

You may also be interested in "Scan and correct text"
http://www.autohotkey.com/forum/viewtopic.php?t=35018

Edit2: of course the above may fail if you CANCEL one first and want
to replace a second instance of the same word it will probably take the
first occurrence due to the stringreplace so you may need to tweak
the TestVarDisplay string a bit further. Perhaps parse on word by word basis (TestVar that is) to make it more reliable

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group