Sign in to follow this  
Followers 0
floodge

Web Based Dictionary w/ batch defining

9 posts in this topic

#1 ·  Posted (edited)

This dictionary grabs and displays definitions from dictionary.com

The program is designed for defining many words at once and formatting them sequentially in a text file.

Words can be searched one at a time, loaded from an INI file, or displayed in an array.

Feel free to edit the source and do whatever you want with it, all I ask is that if you add a new feature or find a better way of doing something, that you tell me :D

Speed depends on the net connection and cpu speed, although it is pretty fast at batch defining on my little netbook with a moderate connection.

Dictionary_Release_Two.rar

Release Two:

No longer physically pastes, all works in the background now. Faster. Lighter.

Edited by floodge

Share this post


Link to post
Share on other sites



Selfless bump for new version

Share this post


Link to post
Share on other sites

hmmm would be nice if you could turn this into a spell checker for programs that don't have built in spell checkers.


Giggity

Share this post


Link to post
Share on other sites

hmmm would be nice if you could turn this into a spell checker for programs that don't have built in spell checkers.

yeah, but theres code floating around that does spell checking (See the autoit text editors) without contacting dictionary.com each time. This program can tell if something is spelled wrong when entered in the batch file and then have a messagebox come up for you to correct the typo or type a different word

Share this post


Link to post
Share on other sites

new version bump ^_^

Share this post


Link to post
Share on other sites

I confess that I've not even downloaded the file but I was wondering whether you've considered http://www.onelook.com which is what I use when I'm cheating at doing crosswords

WBD

Share this post


Link to post
Share on other sites

I confess that I've not even downloaded the file but I was wondering whether you've considered http://www.onelook.com which is what I use when I'm cheating at doing crosswords

WBD

Maybe as a source to get definitions from. I really like the batch functionality in my dictionary, it really helps for when I have a lot of words to define and I dont want to type them in one by one.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Who has the good source please ?

Thanks

Edited by pierrotm777

Share this post


Link to post
Share on other sites

Who has the good source please ?

Thanks

The problem with the script is that many functions were located in the wrong place

#include <GUIConstants.au3>
#include <Array.au3>
#include <INet.au3>
#include <String.au3>
#NoTrayIcon

HotKeySet("{F9}", "_kill")

;Thanks to forum members martin, GEOSoft, Authenticity for help with filter code and arrays.

#Region GUI#

$Dictionary = GUICreate("Dictionary", 251, 110, 313, 256)
$Search = GUICtrlCreateButton("Search", 16, 48, 97, 29, 0)
$Array = GUICtrlCreateButton("Array", 136, 48, 97, 29, 0)
$Input1 = GUICtrlCreateInput("", 16, 16, 217, 21)

$File = GUICtrlCreateMenu("File")

$Save = GUICtrlCreateMenuItem("Save", $File)
$Print = GUICtrlCreateMenuItem("Print", $File)
$Exit = GUICtrlCreateMenuItem("Exit", $File)

$Functions = GUICtrlCreateMenu("Functions")
$Thesaurus = GUICtrlCreateMenuItem("Thesaurus", $Functions)
$Part = GUICtrlCreateMenuItem("Part of Speech", $Functions)
$Speak = GUICtrlCreateMenuItem("Speak", $Functions)


$ini2 = GUICtrlCreateMenu("Ini")
$Load = GUICtrlCreateMenuItem("Load Definitions", $ini2)
$Thes = GUICtrlCreateMenuItem("Load Synonyms", $ini2)
$ini = GUICtrlCreateMenuItem("Write INI", $ini2)

$Help = GUICtrlCreateMenu("Help/About")
$Commands = GUICtrlCreateMenuItem("Help", $Help)
$About = GUICtrlCreateMenuItem("About", $Help)


GUISetState(@SW_SHOW)
#EndRegion GUI#

WinActivate("Dictionary")
$defnumber = 0

While 1
    $nMsg = GUIGetMsg($Input1)
    $str2 = GUICtrlRead($Input1)

    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            WinKill("Untitled - Notepad")
            Exit

        Case $Speak
            $Speak2 = ObjCreate("sapi.SPVoice")
            $Speak2.Speak(GUICtrlRead($Input1))

        Case $Save
            $title = InputBox("File name", "Enter the new file name", "", "", "100", "50")
            $old = FileRead("Untitled.txt")
            FileWrite($title & ".txt", $old)
            FileDelete("Untitled.txt")

        Case $Exit
            WinKill("Untitled - Notepad")
            Sleep(1000)
            Exit

        Case $Print
            WinActivate("Untitled - Notepad")
            Sleep(1000)
            Send("^p")

        Case $About
            MsgBox(64, "About", "Made by Stephen Pretto, April 2009")

        Case $Commands
            MsgBox(64, "Help", "Use the root word, Some words not found on Dictionary.com")


        Case $ini
            $valinc = 0
            $valmax = InputBox("Number of Words", "Enter the number of words", "", "", "100", "50")
            If @error Then
                _restart()
            EndIf

            IniDelete("dictionary.ini", "words")

            While 1
                If $valinc < $valmax Then
                    $valinc = $valinc + 1
                    IniWrite("dictionary.ini", "words", "word" & $valinc, "")
                EndIf

                If $valinc = $valmax Then
                    Run("notepad.exe dictionary.ini", @ScriptDir)
                    ExitLoop
                EndIf

            WEnd

        Case $Load
            ;$list = Inputbox("Name of File", "Enter the File Name / List Week", "", "", "100", "50")

            $valinc = 0
            _StartProgress("Defining Words...")

            While 1
                $valinc = $valinc + 1
                $defnumber = $defnumber + 1

                $str2 = IniRead("dictionary.ini", "words", "word" & $valinc, "NotFound")
                If $str2 = "" Then
                    $valinc = $valinc + 1
                    $str2 = IniRead("dictionary.ini", "words", "word" & $valinc, "NotFound")
                EndIf
                If $str2 = "" Then
                    Run("notepad.exe Untitled.txt", @ScriptDir)
                    _StopProgress()
                    ExitLoop
                EndIf
                If $str2 = "NotFound" Then
                    Run("notepad.exe Untitled.txt", @ScriptDir)
                    _StopProgress()
                    ExitLoop
                EndIf

                iniword()
            WEnd





        Case $Part
            If $str2 = "" Then
                MsgBox(48, "Error", "Enter a word!")
            EndIf

            $mystr = "http://dictionary.reference.com/browse/" & $str2;
            $str = _INetGetSource($mystr)
            $str = _StringBetween($str, '<span class="pg">', '<table class="luna-Ent">')
            $str3 = _StripHTML($str[0])
            MsgBox(64, "Part of Speech - " & $str2, $str3)





        Case $Array
            If $str2 = "" Then
                MsgBox(48, "Error", "Enter a word!")
            EndIf

            $mystr = "http://dictionary.reference.com/browse/" & $str2;
            $str = _INetGetSource($mystr)
            $str = _StringBetween($str, '<span class="pg">', '<span class="rom-inline">')

            ;part of speech checker
            ;$str = _stringbetween($str,'<span class="pg">','<table class="luna-Ent">')
            If IsArray($str) Then
                $str3 = _StripHTML($str[0])
                MsgBox(64, "Definition - " & $str2, $str3)
                ;Run("notepad.exe")
                ;ClipPut($str3)
            EndIf


        Case $Thesaurus
            ;$defnumber = $defnumber + 1

            If $str2 = "" Then
                MsgBox(48, "Error", "Enter a word!")
            EndIf

            $mystr = "http://thesaurus.reference.com/browse/" & $str2;
            $str = _INetGetSource($mystr)


            $str = _StringBetween($str, '<td valign="top"><b>Synonyms:</b></td>', "</table>")


            $str3 = _StripHTMLTHESAURUS($str[0])

            MsgBox(64, "Thesaurus - " & $str2, $str3)

        Case $Thes
            ;$list = Inputbox("Name of File", "Enter the File Name / List Week", "", "", "100", "50")

            _StartProgress("Searching for Similar Words...")
            $valinc = 0

            While 1
                $valinc = $valinc + 1
                $defnumber = $defnumber + 1

                $str2 = IniRead("dictionary.ini", "words", "word" & $valinc, "NotFound")
                If $str2 = "" Then
                    $valinc = $valinc + 1
                    $str2 = IniRead("dictionary.ini", "words", "word" & $valinc, "NotFound")
                EndIf
                If $str2 = "" Then
                    Run("notepad.exe Untitled.txt", @ScriptDir)
                    _StopProgress()
                    ExitLoop
                EndIf
                If $str2 = "NotFound" Then
                    Run("notepad.exe Untitled.txt", @ScriptDir)
                    _StopProgress()
                    ExitLoop
                EndIf

                ;todo make synonym and antonym come separate

                iniwordT()
            WEnd


        Case $Search
            ;$defnumber = $defnumber + 1

            If $str2 = "" Then
                MsgBox(48, "Error", "Enter a word!")
                _restart()
            EndIf

            $mystr = "http://dictionary.reference.com/browse/" & $str2;
            $str = _INetGetSource($mystr)
            $str = _StringBetween($str, '<span class="pg">', 'class="dnindex">2.')

            If $str = "" Then
                $mystr = "http://dictionary.reference.com/browse/" & $str2;
                $str = _INetGetSource($mystr)
                $str = _StringBetween($str, '<span class="pg">', '<div class="tail">')
            EndIf

            $str3 = _StripHTML($str[0])
            MsgBox(64, "Definition - " & $str2, $str3)



    EndSwitch
WEnd



Func iniword()
    $mystr = "http://dictionary.reference.com/browse/" & $str2;
    $str = _INetGetSource($mystr)
    $str = _StringBetween($str, '<span class="pg">', 'class="dnindex">2.')

    If $str = "" Then
        $mystr = "http://dictionary.reference.com/browse/" & $str2;
        $str = _INetGetSource($mystr)
        $str5 = _StringBetween($str, '<span class="pg">', '<div class="tail">')
        $str = $str5

        If $str5 = "" Then
            _StopProgress()
            $str2 = InputBox("Word" & $valinc & $str2 & " - Not found, enter again", "", "", "100", "50")
            IniWrite("dictionary.ini", "words", "word" & $valinc, $str2)
            _StartProgress("Defining Words...")
            $mystr = "http://dictionary.reference.com/browse/" & $str2
            $str = _INetGetSource($mystr)
            $str6 = _StringBetween($str, '<span class="pg">', 'class="dnindex">2.')
            $str = $str6

            If $str6 = "" Then
                $mystr = "http://dictionary.reference.com/browse/" & $str2;
                $str = _INetGetSource($mystr)
                $str6 = _StringBetween($str, '<span class="pg">', '<div class="tail">')
                $str = $str6
            EndIf
            If @error Then
                Exit
            EndIf

            If $str2 = "" Then
                nextword()
            EndIf
        EndIf
    EndIf



    _process($str[0])
EndFunc   ;==>iniword

Func _restart()
    If @Compiled = 1 Then
        Run(FileGetShortName(@ScriptFullPath))
    Else
        Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc   ;==>_restart

Func iniwordT()
    $mystr = "http://thesaurus.reference.com/browse/" & $str2;
    $str = _INetGetSource($mystr)
    $str = _StringBetween($str, '<td valign="top"><b>Synonyms:</b></td>', "</tr>")
    If $str = "" Then
        _StopProgress()
        $str2 = InputBox("Word" & $valinc & $str2 & " - Not found, enter again", "", "", "100", "50")
        If @error Then
            nextwordT()
        EndIf
        If $str2 = "" Then
            nextwordT()
        EndIf
        IniWrite("dictionary.ini", "words", "word" & $valinc, $str2)
        $mystr = "http://thesaurus.reference.com/browse/" & $str2;
        $str = _INetGetSource($mystr)
        $str = _StringBetween($str, '<td valign="top"><b>Synonyms:</b></td>', "</tr>")
        _StartProgress("Searching for Similar Words...")
    EndIf


    _processthes($str[0])
EndFunc   ;==>iniwordT


Func nextword()
    $str2 = IniRead("dictionary.ini", "words", "word" & $valinc, "NotFound")
    iniword()
EndFunc   ;==>nextword

Func nextwordT()
    $str2 = IniRead("dictionary.ini", "words", "word" & $valinc, "NotFound")
    iniwordT()
EndFunc   ;==>nextwordT

Func _process($str)
    $str3 = _StripHTMLINI($str)
    FileWrite("Untitled.txt", $defnumber & ". " & $str2 & ":     " & $str3 & @CRLF & @CRLF)
EndFunc   ;==>_process


Func _processthes($str)
    $str3 = _StripHTMLTHESAURUS($str)
    FileWrite("Untitled.txt", $defnumber & ". " & $str2 & ":     " & $str3 & @CRLF & @CRLF)
EndFunc   ;==>_processthes

Func _StripHTML($sStr)
    $sStr = StringRegExpReplace($sStr, '–', "")
    $sStr = StringRegExpReplace($sStr, 'Origin:', "")
    $aStr = StringRegExp($sStr, "&#(\d+);", 3)
    If Not @error Then
        For $i = 0 To UBound($aStr) - 1
            $sStr = StringReplace($sStr, "&#" & $aStr[$i] & ";", Chr($aStr[$i]))
        Next
    EndIf
    $sStr = StringRegExpReplace($sStr, "(<.*?>)", "")
    $sStr = StringRegExpReplace($sStr, "<span", "")
    $sStr = StringRegExpReplace($sStr, '<td width="35"', "")
    Return $sStr
EndFunc   ;==>_StripHTML


Func _StripHTMLINI($sStr)
    $aStr = StringRegExp($sStr, "&#(\d+);", 3)
    If Not @error Then
        For $i = 0 To UBound($aStr) - 1
            $sStr = StringReplace($sStr, "&#" & $aStr[$i] & ";", Chr($aStr[$i]))
        Next
    EndIf
    $sStr = StringRegExpReplace($sStr, "(<.*?>)", "")
    $sStr = StringRegExpReplace($sStr, "–", "")
    $sStr = StringRegExpReplace($sStr, "Origin:", "")
    $sStr = StringRegExpReplace($sStr, '<td width="35"', "")
    $sStr = StringRegExpReplace($sStr, '1.', "")

    Return $sStr
EndFunc   ;==>_StripHTMLINI

Func _StripHTMLTHESAURUS($sStr)
    $aStr = StringRegExp($sStr, "&#(\d+);", 3)
    If Not @error Then
        For $i = 0 To UBound($aStr) - 1
            $sStr = StringReplace($sStr, "&#" & $aStr[$i] & ";", Chr($aStr[$i]))
        Next
    EndIf
    $sStr = StringRegExpReplace($sStr, "\v", "")
    $sStr = StringRegExpReplace($sStr, "\h", "")
    $sStr = StringRegExpReplace($sStr, ",", " ")

    $sStr = StringRegExpReplace($sStr, "(<.*?>)", "")
    Return $sStr
EndFunc   ;==>_StripHTMLTHESAURUS


Func _StripHTMLTHESAURUS2($sStr)
    $aStr = StringRegExp($sStr, "&#(\d+);", 3)
    If Not @error Then
        For $i = 0 To UBound($aStr) - 1
            $sStr = StringReplace($sStr, "&#" & $aStr[$i] & ";", Chr($aStr[$i]))
        Next
    EndIf
    $sStr = StringRegExpReplace($sStr, "\h", "")
    $sStr = StringRegExpReplace($sStr, "(<.*?>)", "")
    Return $sStr
EndFunc   ;==>_StripHTMLTHESAURUS2

Func _StartProgress($s_comment = "Please Stand By")
    $s_path = @ScriptDir & "\progress.au3"
    $h_file = FileOpen($s_path, 2)
    $s_code = 'AutoItSetOption ("TrayIconHide",1)' & @CRLF & _
            'AutoItWinSetTitle("MyProgressBar")' & @CRLF & _
            'Dim $percent = 0' & @CRLF & _
            'ProgressOn("In Progress...", "' & $s_comment & '")' & @CRLF & _
            'While ProcessExists(' & @AutoItPID & ')' & @CRLF & _
            'ProgressSet($percent)' & @CRLF & _
            '$percent += 5' & @CRLF & _
            'If $percent > 100 Then $percent = 0' & @CRLF & _
            'Sleep(500)' & @CRLF & _
            'WEnd' & @CRLF
    FileWrite($h_file, $s_code)
    FileClose($h_file)
    Run(@AutoItExe & " /AutoIt3ExecuteScript progress.au3", @ScriptDir)
EndFunc   ;==>_StartProgress

Func _StopProgress()
    If WinExists("MyProgressBar") Then WinKill("MyProgressBar")
    FileDelete(@ScriptDir & "\progress.au3")
EndFunc   ;==>_StopProgress

Func _kill()
    Exit
EndFunc   ;==>_kill

Be Green Now or Never (BGNN)!

Share this post


Link to post
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
Sign in to follow this  
Followers 0