Jump to content
Sign in to follow this  
dantay9

Dictionary

Recommended Posts

dantay9

I have the basis of my dictionary finished, but there are certain words that crash the script (ter, tel). I can't figure out why. I also need an error handler. The errors I have currently don't cover very much.

Dictionary.au3

Edited by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
MrMitchell

Lines 48 and 49:

$Source = _StringBetween($Source, '<td width="35" class="dnindex">1.</td> <td>', '<span class="sectionLabel">Synonyms:')
    $Text = StringSplit($Source[0], '<td width="35" class="dnindex">', 1)

Edit: The failure is at those lines, $Source is not an array so it errors out when trying to use $Source[0]

Edited by MrMitchell

Share this post


Link to post
Share on other sites
rajeshontheweb
MrMitchell

"ter" and "tel" ...so it looks like after all the processing of $Source, the following line fails (currently line 48):

$Source = _StringBetween($Source, '<td width="35" class="dnindex">1.</td> <td>', '<span class="sectionLabel">Synonyms:')

because all instances (2) of "<span class="sectionLabel">Synonyms:" come before your single instance of "<td width="35" class="dnindex">1.</td> <td>".

Just check out $Source before your code reaches that line.

Share this post


Link to post
Share on other sites
rajeshontheweb

i have a bit of different opinion.

actually it is not that 'ter' is not found. 'ter' is found but can we alter the logic a little bit? may be it will drag the work too long. but here's my proposal.

  • Currenly Your logic retrieves the first shown meaning 's results
  • We could probably include all the variants
  • All the words do not end with synonyms shown so, we can terminate our search at
    $Source = _StringBetween($Source, '<td width="35" class="dnindex">1.</td> <td>', '<div class="result_copyright">')
    this can be even shown in footnote as copright disclaimer which will be helpful.
  • but of course, this requires bit more of coding as you will see there are more results, viz., test would show test1 test2 ,etc
Edited by rajeshontheweb

Share this post


Link to post
Share on other sites
rajeshontheweb

this works well,

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Inet.au3>
#include <String.au3>

$Main = GUICreate("English Dictionary", 600, 370)
$Edit = GUICtrlCreateEdit("", 15, 15, 570, 300, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL))
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$Input = GUICtrlCreateInput("", 15, 330, 405, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Search = GUICtrlCreateButton("Search", 435, 330, 150, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $Search
            GUICtrlSetData($Edit, "Looking up dictionary.com....")
            $Result = Look_Up(GUICtrlRead($Input))
            If $Result = -1 Then
                MsgBox(262192, "ERROR", "That word is not in the dictionary!")
                GUICtrlSetData($Edit, "")
            Else
                GUICtrlSetData($Edit, $Result)
            EndIf
        Case - 3
            Exit
    EndSwitch
WEnd

Func Look_Up($Word)
    If StringRegExp($Word, "[^a-zA-Z+]") = 1 Then Return -1
    $Website = "http://dictionary.reference.com/browse/" & $Word & "&search=search"
;~  http://dictionary.reference.com/dic?q=ter&search=search
    
    $Source = _INetGetSource($Website)
    
    $Test = _StringBetween($Source, '<div id="Heading" class="Heading">', '<i>')
    If Not @error And StringStripWS(StringLower($Test[0]), 3) = "no results found for" Then Return -1
    
    
    $CopyRight = _StringBetween($Source,'<div class="result_copyright">','<a')
    $CopyRight = @CRLF & StringReplace($CopyRight[0],"<br", @CRLF & @TAB)
    $CopyRight = StringReplace($CopyRight,"/>", " ")
    $CopyRight = StringReplace($CopyRight,"&copy;", "(c)")
    

    $Source = StringTrimLeft($Source, StringInStr($Source, '<span class="pg">') + 15)
;~  $Source = StringReplace($Source, '<div class="ety"> <b>Origin:', '<span class="sectionLabel">Synonyms:') i didnt use this..
    
    $string = _StringBetween($Source, ">", "</span>")
    $Line1 = $string[0]
    If StringInStr($Line1, ",") Then $Line1 = StringLeft($Line1, StringInStr($Line1, ",") - 1)
    $Line1 = StringRegExpReplace($Line1, "[^a-zA-Z]", "") & @CRLF

;~  $Source = _StringBetween($Source, '<td width="35" class="dnindex">1.</td> <td>', '<span class="sectionLabel">Synonyms:') ; doesnt work on words sans synonyms
;~  $Source = _StringBetween($Source, '<td width="35" class="dnindex">1.</td> <td>', '<div class="result_copyright">'); for full information needs working, i am no good at regex 
    $Source = _StringBetween($Source, '<td width="35" class="dnindex">1.</td> <td>', '<b>Origin: </b>')

    $Text = StringSplit($Source[0], '<td width="35" class="dnindex">', 1)
    $Text[1] = "1. " & $Text[1]

    For $n = 0 To $Text[0]
        $Text[$n] = StringRegExpReplace($Text[$n], "(<.*?>)", "")
    Next

    $Text = "1. " & StringReplace($Source[0], '<td width="35" class="dnindex">', @CRLF)

    $Text = StringRegExpReplace($Text, "(<.*?>)", "")
    $Text = "--" & $Line1 & @CRLF & $Text

    $Replace = StringReplace($Text, "â", "--")
    If $Replace Then $Text = $Replace
    $Array = StringSplit($Text, @CRLF)
    _ArrayDelete($Array, 0)
    $x = 0
    While 1
        If $x >= UBound($Array) - 1 Then ExitLoop
        If Not StringRegExp($Array[$x], '[^\w\p{P}\040]+') Then
            _ArrayDelete($Array, $x)
            $x -= 1
        EndIf
        $x += 1
    WEnd
    $Text = _ArrayToString($Array, @CRLF)
    $Text = StringReplace($Text, "--", @CRLF & @CRLF & "--")
    $Text = StringStripWS($Text, 3)
    Return $Text & @CRLF & $CopyRight
EndFunc   ;==>Look_Up

of Course, this doesnt retrieve variants but will get rid of the issue currently in hand. works with ter, tel, etc.

Edited by rajeshontheweb

Share this post


Link to post
Share on other sites
dantay9

Thanks for all your help guys!


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

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  

×