Jump to content

Recommended Posts

Posted (edited)

Hey guys, I couldn't find this anywhere else and needed it for my AI. Suggestions are VERY welcome!!!

It does include a little from my AI but most has been stripped.

Requires you to download an excel file and Grammar.au3 from the link below. -This Grammar.au3 includes updates and is required even if you have another.

Include in same directory as script.

Files:

http://cid-dad9dc46d450d472.skydrive.live....=A1lYomScyNI%24

#Region ;Includes
#include <Array.au3>
#include <Excel.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <string.au3>
#include "Grammar.au3"
#EndRegion 
#Region ;HotKeys
HotKeySet("{ENTER}", "_Entry")
HotKeySet("{ESC}", "_Terminate")
#EndRegion 
#Region ;Variables
Dim $avArray, $sStr
$UserName = InputBox("Who are you?", "Please Enter Your Name", @UserName)
#EndRegion 
#Region ;Database
$oExcel = _ExcelBookOpen(@ScriptDir & "\List.xls", 0)
Global $sArray[10] = ["Name", "Adverb", "Adjective", "Verb", "Noun", "Article", "Conjunction", "Preposition", "Pronoun", "Helping Verb"]
Global $pArray[10] = ["Name", "Adverb", "Adjective", "Verb", "Noun", "Article", "Conjunction", "Preposition", "Pronoun", "Helping Verb"]
For $p = 0 To UBound($pArray) - 1
    ToolTip("Uploading " & $pArray[$p] & "s", 0, 0)
    _ExcelSheetActivate($oExcel, $pArray[$p])
    $pArray[$p] = _ExcelReadSheetToArray($oExcel, 1, 1, 0, 1, 1)
Next
ToolTip("Complete", 0, 0)

#EndRegion 
#Region ;Gui
$hWnd = GUICreate(" Talk to me!", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, $WS_EX_TOPMOST)
$Input = GUICtrlCreateInput("", 10, 35, 300, 20)
GUISetState(@SW_SHOW)
#EndRegion 
#Region ;Main Loop
While 1
    Sleep(10) ;Keep the Gui Open
WEnd
#EndRegion 
#Region ;Functions
Func _Entry()
    $sStr = GUICtrlRead($Input)
    GUICtrlSetData($Input, "")
    $sStr = _Grammar_AintRight($sStr)
    $sStr = _Grammar_RemoveContractions($sStr)
    $sStr = _Grammar_RemovePluralization($sStr)
    _Search()
EndFunc   ;==>_Entry

Func _Search()
    ToolTip("Searching", 0, 0)
    $Words = _StringExplode($sStr, " ")
    Local $avArray[11][UBound($Words)]
;~  _ArrayDisplay($Words)
    For $w = 0 To UBound($Words) - 1
        $avArray[0][$w] = $Words[$w]
        For $p = 0 To UBound($pArray) - 1
            $iIndex = _ArraySearch($pArray[$p], $Words[$w])
            If Not @error Then
                ConsoleWrite($Words[$w] & " is a " & $sArray[$p] & @CRLF)
                $avArray[$p+1][$w] = $sArray[$p]
            ElseIf StringLen($Words[$w]) > 3 And StringRight($Words[$w], 1) = "s" Then
                $sStr2 = StringLeft($Words[$w], StringLen($Words[$w]) - 1)
                $iIndex = _ArraySearch($pArray[$p], $sStr2)
                If Not @error Then
                    ConsoleWrite($Words[$w] & " is a " & $sArray[$p] & @CRLF)
                    $avArray[1][$w] = $sArray[$p]
                EndIf
            ElseIf StringLen($Words[$w]) > 3 And StringRight($Words[$w], 1) = "g" Then
                $sStr2 = StringLeft($Words[$w], StringLen($Words[$w]) - 3)
                $iIndex = _ArraySearch($pArray[$p], $sStr2)
                If Not @error Then
                    ConsoleWrite($Words[$w] & " is a " & $sArray[$p] & @CRLF)
                    $avArray[1][$w] = $sArray[$p]
                EndIf
            EndIf
        Next
    Next
    _ArrayDisplay($avArray)
    ToolTip("Complete", 0, 0)
EndFunc   ;==>_Search

Func _Terminate()
    _ExcelBookClose($oExcel, 1, 0) ;Close, Save, No Errors
    Exit 0
EndFunc   ;==>_Terminate
#EndRegion
Edited by John117
Posted

Hey guys, I couldn't find this anywhere else and needed it for my AI. Suggestions are VERY welcome!!!

It does include a little from my AI but most has been stripped.

Requires you to download an excel file and Grammar.au3 from the link below. -This Grammar.au3 includes updates and is required even if you have another.

Include in same directory as script.

Thanks for sharing!

I haven't the time at the mo, to play around with this very much, but it could be very useful for the Sentence Case idea I've had floating around in my brain for some time ... for which nouns in particular, need to be capitalized, etc. In fact, anyone who wants to work on a Case UDF, is welcome to have a go - obviously you would also need to support lower, upper & proper too - but with the features for proper that I've provided here. Mind you, the space tests used, should probably be updated to a test for a non-alpha character, to be truly perfect. You might also like to include what I call an iCase option (second letter capitalized), to be in-line with current web naming titles these days.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted (edited)

I have done something similar in my dictionary program, which queries the web for each word and will then tell the part of speech. It should be simple enough to take each word of a sentence one by one and then contact some sort of database as to what part of speech the words are.

I see this being very tricky as some words can be used in many different ways. Things like prepositions will most always be the same, but otherwise a word can be a toss up between a few different parts of speech. The method I have works pretty well however, but the downside is that you must query the web for each word. I guess that is better than keeping a massive database but this is just my .02

Edited by floodge

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
  • Recently Browsing   0 members

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