Jump to content

Spell Checker


fmen
 Share

Recommended Posts

I am trying to write my own spell checker based on Skizmata's googler idea from last year:

http://www.autoitscript.com/forum/index.ph...&hl=googler

Thanks, Skizmata. Instead of using google I want to use dictionary.com as the source.

Here is part of the code

#include <INet.au3>
#include <String.au3>

ClipPut("eixtrt"); example of misspelled word

    $PageSource = _INetGetSource ( "http://dictionary.reference.com/search?q=" & Clipget() )
    $Output = _StringBetween($PageSource, 'dictionary.reference.com/search?q=' , '">')
    ConsoleWrite(String($Output[0]));Suggested correct spelling result ---> Extreat>Exit code: 0  Time: 2.102

This gives me only the first of many suggested spelling corrections (in this case, the word "Entreat").

However, I would like to get a list of at least the first 5 or 6 suggested spellings.

_StringBetween is not doing this for me. I envision a loop that searches through $PageSource , extracting each suggested word, but have not been able to implement it. I am probably barking up the wrong tree and a whole different approach using arrays is the way to go, but in all honesty, this is way above my abilities.

Any specific suggestions would be appreciated. I've worked on this off and on for a few days now. I am not asking for anyone to code for me nor directions on how to use the help file or search function. I've tried those. Thanks :)

Edited by fmen
Link to comment
Share on other sites

What you want is inside a table.

Take this way to get it:

#include <IE.au3>
ClipPut("eixtrt"); example of misspelled word

$oIE = _IECreate("http://dictionary.reference.com/search?q=" & Clipget(), 0, 0)
$oTable = _IETableGetCollection($oIE, 0)
If IsObj($oTable) Then 
    $ar = _IETableWriteToArray($oTable, True)
    _ArrayDisplay($ar)
EndIf
_IEQuit($oIE)

;==============================================
; Or another way:

#include <INet.au3>
ClipPut("eixtrt"); example of misspelled word

$source = _INetGetSource("http://dictionary.reference.com/search?q=" & Clipget())
$aRet = StringRegExp($source, '(?:search\?q=[\w\d+%.-]*">)([\w\s\d.!/-]+)', 3)
_ArrayDisplay($aRet)
Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

#include<inet.au3>
#include<array.au3>;; Only for _ArrayDisplay()
ClipPut("eixtrt"); example of misspelled word
$PageSource = _INetGetSource ( "http://dictionary.reference.com/search?q=" & Clipget() )
$aWords = StringRegExp($PageSource,"(?i)<a.+http.+dictionary\.reference\.com/search.*>(\w+?-?)</a>", 3)
_ArrayDisplay($aWords, "Results Returned")

Edit: Forgot to add that if you are going to loop through the array then remember that RegExp arrays are 0 based so it will be

For $I = 0 To Ubound($aWords) -1
   Do whatever here
Next
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

BugFix and GEOSoft, thanks for pointing me to the StringRegExp function. It works really well for my purposes.

I may even use the _ArrayDisplay function as an integral part of the spell check script if I can figure out how to tweak the copy to clipboard feature to copy only the word and not the number before it. Or is there a way of displaying only the column and not the row?

Thanks again.

Link to comment
Share on other sites

BugFix and GEOSoft, thanks for pointing me to the StringRegExp function. It works really well for my purposes.

I may even use the _ArrayDisplay function as an integral part of the spell check script if I can figure out how to tweak the copy to clipboard feature to copy only the word and not the number before it. Or is there a way of displaying only the column and not the row?

Thanks again.

Use a list control instead of a listview and just pass it the values of the array elements.

$List_Words = GUICtrlCreateList("", 10,10, 200, 200
$sListData = ""
For $i = 0 To Ubound($aWords)-1
   $sListData &= "|" & $aWords[$i]
Next
GUICtrlSetData($List_Words, $sListData)

Then you can use the functions from GuiListBox.au3.

_GUICtrlListBox_GetCurSel() to get the index of the selected item and _GUICtrlListBox_GetText() to get the text of that index item.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Use a list control instead of a listview and just pass it the values of the array elements.

$List_Words = GUICtrlCreateList("", 10,10, 200, 200
$sListData = ""
For $i = 0 To Ubound($aWords)-1
   $sListData &= "|" & $aWords[$i]
Next
GUICtrlSetData($List_Words, $sListData)

Then you can use the functions from GuiListBox.au3.

_GUICtrlListBox_GetCurSel() to get the index of the selected item and _GUICtrlListBox_GetText() to get the text of that index item.

Once again, thanks for your help, GEOsoft. That is a great solution.

I found a workaround so that the only word that has to be formatted is the word chosen to replace the misspelled one.

$marker = StringInStr(ClipGet(), "|")
    $cword = StringTrimLeft(ClipGet(), $marker)
    Send($cword & "{bs} ")

I have incorporated this into the the final script and so far it is working well.

I will post the results into Example Scripts and see if it gets any interest.

Thanks once more.......

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...