dupa

Author Topic: New knowledge plugin  (Read 8368 times)

angeloes

  • Guest
New knowledge plugin
« on: August 24, 2011, 06:49:21 pm »
I reworked the wiki Knowledge plugin to go to another website. It now will give a short description of each topic rather then lengthy wikipedia text. I changed the phrase so as not to conflict to TELL ME. You can now use natural language like... Tell me how many planets are in our solar system or Tell me what is the largest city in florida etc. See http://start.csail.mit.edu/.   It  now speaks and come back with the response and saves the much smaller research text.  THIS PLUGIN Requires the Balabolka Reader to work available at the GRETTA Plugins site. I'm using the IVONA reader myself which has much better Sapi5 voices but in the code I included only the balabolka reader path. For those of you interested in the ivona software I can provide you the command syntax to substitute. If you are interested, they do give a 30 day trial version at their site.   Please try this beta plugin at your own risk its mostly based on the wiki knowledge plugin. if you decide to try it out it goes without saying to do a backup. Any suggestions on improving will be welcome. Also this is designed to work with windows 7--- Program files (x86) so change the program path for earlier versions. Let me know what you think....Angelo
Code: [Select]
[code]Rem Type=Plugin
Rem Name=MIT Start  Knowledge Search
Rem Author=Angelo Estela with  code  by Gerald L. Blakley A.K.A OnTheCuttingEdge2005 and snippets by jasondude7116.
Rem Host=All

'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
    lblPlugin(0).Caption = "Just say: tell me about the universe or tell me how many planets are in the solar system , you can replace the words or phrase or noun, all information on the word is studied from the website start"
    lblPlugin(0).Move 120, 10, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
End Sub


Rem PLUGIN: PRE-PROCESS

Set objExplorer = CreateObject("InternetExplorer.Application")
Set HalXBrain = CreateObject("UltraHalAsst.Brain")
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists(MyResearchDir2 & "Startsearch.txt") Then
objFSO.DeleteFile(MyResearchDir2 & "Startsearch.txt")
End If

If XDir = "" Then XDir = "C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\"
   MyFile = "C:\Program Files (x86) \Zabaware\Ultra Hal Assistant 6\AutoText.brn"
   If File_Exists = "" Then File_Exists = False
   If FileSys.FileExists(MyFile) = True Then File_Exists = True

   If File_Exists = False Then
       HalXBrain.AppendFile XDir & "AutoText.brn", "Start of Knowledge strings"
      
   End If

If XDir = "" Then XDir = "C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\"
   MyFile = "C:\Program Files (x86) \Zabaware\Ultra Hal Assistant 6\Startsearch.txt"
   If File_Exists = "" Then File_Exists = False
   If FileSys.FileExists(MyFile) = True Then File_Exists = True

   If File_Exists = False Then
       HalXBrain.AppendFile XDir & "Startsearch.txt", ""
      
   End If

MyInput = HalXBrain.AlphaNumericalOnly(InputString)

If StartLookup = "" Then StartLookup = HalBrain.SearchPattern(MyInput, "*TELL ME ABOUT THE *", 2)
If StartLookup = "" Then StartLookup = HalBrain.SearchPattern(MyInput, "*TELL ME ABOUT *", 2)
If StartLookup = "" Then StartLookup = HalBrain.SearchPattern(MyInput, "*TELL ME *", 2)


If StartLookup <> "" Then

StartLookup = Lcase(StartLookup)

SourcePage = "http://start.csail.mit.edu/startfarm.cgi?query=" & StartLookup

objExplorer.Navigate("http://start.csail.mit.edu/startfarm.cgi?query=" & StartLookup)

Do Until objExplorer.ReadyState=4 : Loop

myText = objExplorer.Document.Body.innerText
myText = Replace(myText,"START's reply","")
myText = Replace(myText,"===>","")
myText = Replace(myText,StartLookup," ")
myText = Replace(myText,"Go back to the START dialog window.","")


If XDir = "" Then XDir = "C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\"

HalXBrain.AppendFile XDir & "AutoText.brn", Trim(myText)
HalXBrain.AppendFile XDir & "Startsearch.txt", Trim(myText)




End If
'------------------------------------------------------------------------------------------


   




   If objFSO.FileExists(MyResearchDir2 & "Startsearch.txt") Then
            Set objWSHShell = CreateObject("WScript.Shell")
    objWSHShell.Run("""C:\Program Files (x86)\Balabolka\balabolka.exe"" -rmq """ & MyResearchDir2 & "Startsearch.txt""")
        HalBrain.ReadOnlyMode = True
        Else

UltraHal = "Unable to open file."
HalBrain.ReadOnlyMode = True
End If






'--------------------------------------------

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\AutoText.brn", ReadVariable())
         strText = objTextFile.ReadAll
         objTextFile.Close

'--------------------------------------------

If InStr(1, strText, "   ", vbTextCompare) > 0 Then

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\AutoText.brn", ReadVariable())

Do Until objFile.AtEndOfStream
    strLine = objFile.Readline
    strLine = Trim(strLine)
    If Len(strLine) > 0 Then
        strNewContents = strNewContents & strLine & vbCrLf
    End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\AutoText.brn", WriteVariable())
objFile.Write strNewContents
objFile.Close

End If

'--------------------------------------------

TextCount = StrCount()

If ClipXDir = "" Then ClipXDir = "C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\"
For i = 1 To TextCount

If i > 0 Then ClipResX = HalXBrain.ChooseSentenceFromFile(ClipXDir & "AutoText.brn")

ClipResX = HalXBrain.AlphaNumericalOnly(ClipResX)
ClipResX = UCase(ClipResX)
ClipResX = Trim(ClipResX)

MyInputString = HalXBrain.AlphaNumericalOnly(InputString)
MyInputString = UCase(MyInputString)
MyInputString = Trim(MyInputString)

If InStr(1, ClipResX, MyInputString, vbTextCompare) > 0 And Len(ClipResX) > 50 Then
UltraHal = ClipResX
ElseIf Len(ClipResX) < 50 Then
UltraHal = UltraHal
End If

Next

'--------------------------------------------

Rem PLUGIN: FUNCTIONS

Function StrCount()

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Program Files (x86)\Zabaware\Ultra Hal Assistant 6\AutoText.brn", ReadVariable())
         strText = objTextFile.ReadAll
         objTextFile.Close
         
Do While InStr(1, strText, "  ")
            strText = Replace(strText, "  ", " ")
            Exit Do
         Loop

         aWords = split(strText, ". ")
         StrCount = Ubound(aWords) + 1

End Function

Function ReadVariable()

Const ForReading = 1

ReadVariable = ForReading

End Function

Function WriteVariable()

Const ForWriting = 2

WriteVariable = ForWriting

End Function
Code: [Select]
« Last Edit: August 24, 2011, 08:34:23 pm by angeloes »

sybershot

  • Hero Member
  • *****
  • Posts: 787
    • View Profile
Re: New knowledge plugin
« Reply #1 on: August 25, 2011, 08:03:32 pm »
Sounds great, Can't w8 till I get my laptop back to try this out.

lightspeed

  • Hero Member
  • *****
  • Posts: 6763
    • View Profile
Re: New knowledge plugin
« Reply #2 on: August 27, 2011, 08:06:30 pm »
i tried this plug in but i got an error later (i should have wrote down the error ) i unchecked it and it was ok . anyone else have any problems with it? i may check it again and if any error write it down next time .
 

onthecuttingedge2005

  • Guest
Re: New knowledge plugin
« Reply #3 on: August 28, 2011, 11:49:40 am »
I am reviewing this plug-in, spent a little time working some issues out, it might be awhile, I have to work it around my real job.

fixed a few things but the word structures saved need to be cleaned up and a better response code needs to be redeveloped.

Jerry 8)

lightspeed

  • Hero Member
  • *****
  • Posts: 6763
    • View Profile
Re: New knowledge plugin
« Reply #4 on: August 28, 2011, 11:19:56 pm »
WHAT??? jerry has a real job ... and in this economy? lol! ;)
by the way that error might have been something else i see when i said something about the weather i got an error this time i took a picture . i had a weather plug in on at the time .
the error i had before that i didn't get in time .
 

onthecuttingedge2005

  • Guest
Re: New knowledge plugin
« Reply #5 on: August 29, 2011, 12:07:52 am »
WHAT??? jerry has a real job ... and in this economy? lol! ;)
by the way that error might have been something else i see when i said something about the weather i got an error this time i took a picture . i had a weather plug in on at the time .
the error i had before that i didn't get in time .

I ment real jobs not job, sorry lightspeed. between the county and water dept it keeps me busy at times at least till the dead of winter then it is all county work. we get a lot of snow/ice around here in the upper high sierras here in California.

Jerry 8)

lightspeed

  • Hero Member
  • *****
  • Posts: 6763
    • View Profile
Re: New knowledge plugin
« Reply #6 on: August 30, 2011, 08:46:06 am »
lol jerry , i know what you mean about snow and ice  i live in missouri home of tornado's , high winds , hail storms , winter ice storms , and heavy snow !!!  sheesh if it wasn't for this good weather missouri has ... i would move lol!  ;)
 

onthecuttingedge2005

  • Guest
Re: New knowledge plugin
« Reply #7 on: September 02, 2011, 11:04:28 pm »
new knowledge plug-in here and updated for v6.2 if you use any previous knowledge plug-in with this plug-in you may not want to use the older version to prevent issues.

there is some things I need to work out but it as it is, is very efficient for now, if you wish to develop this code further then you may do so to make it better.

Code: [Select]
Rem Type=Plugin
Rem Name=Internet Research
Rem Author=Angelo Estela with  code  by Gerald L. Blakley A.K.A OnTheCuttingEdge2005 and snippets by jasondude7116.
Rem Host=All

'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
    lblPlugin(0).Caption = "Just say: tell me about the universe or tell me how many planets are in the solar system , you can replace the words or phrase or noun, all information on the word is studied from the website start"
    lblPlugin(0).Move 120, 10, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
End Sub

       
Rem PLUGIN: POST-PROCESS
    'The preceding comment is actually a plug-in directive for
    'the Ultra Hal host application. It allows for code snippets
    'to be inserted here on-the-fly based on user configuration.

'Research Trigger Function
Dim StartLookup       
StartLookup = StartLookingUp(InputString)   
       
'--------------------------------------------------------------------------------------------------------

'Lets look up on the internet the topic of reseach to be saved to a data table.
Set objExplorer = CreateObject("InternetExplorer.Application")
If StartLookup <> "" Then
HalBrain.ReadOnlyMode = True

StartLookup = Trim(Lcase(HalBrain.AlphaNumericalOnly(StartLookup)))

SourcePage = "http://start.csail.mit.edu/startfarm.cgi?query=" & StartLookup
objExplorer.Navigate("http://start.csail.mit.edu/startfarm.cgi?query=" & StartLookup)

Do Until objExplorer.ReadyState=4 : Loop

myText = objExplorer.Document.Body.innerText
myText = Replace(myText, "START's reply", "")
myText = Replace(myText, "===>", "")
myText = Replace(myText, "Go back to the START dialog window.", "")
myText = Replace(myText, "I know about 30 more terms called " & StartLookup, "")
myText = Replace(myText, "You don't really want me to list them all, do you? ", "")

myText = Replace(myText, "  ", "")

'Lets clean up the string a bit.
myText = HalBrain.SearchPattern(myText, "*" & StartLookup & "*", 2)

'------------------------------------------------------------------

    If StartLookup <> "" And myText <> "" Then
        UltraHal = LCase(myText)
        Else
        UltraHal = UltraHal
    End If

'------------------------------------------------------------------

subKillExplorer
End If

'--------------------------------------------------------------------------------------------------------
   
   
Rem PLUGIN: FUNCTIONS
'The preceding comment is actually a plug-in directive for
'the Ultra Hal host application. It allows for code snippets
'to be inserted here on-the-fly based on user configuration.

'Research Trigger Function
Function StartLookingUp(InputString)
ResearchString = Trim(Ucase(HalBrain.AlphaNumericalOnly(InputString)))
If StartLookupX = "" Then StartLookupX = HalBrain.SearchPattern(ResearchString, "*TELL ME ABOUT THE *", 2)
If StartLookupX = "" Then StartLookupX = HalBrain.SearchPattern(ResearchString, "*TELL ME ABOUT *", 2)
If StartLookupX = "" Then StartLookupX = HalBrain.SearchPattern(ResearchString, "*TELL ME *", 2)
If StartLookupX <> "" Then StartLookingUp = StartLookupX
End Function

Sub subKillExplorer
On Error Resume Next
wmiQuery = "Select processID from win32_process where name = 'iexplore.exe'"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)
For Each objItem in colItems
    objItem.terminate()
Next
End Sub 
               

just copy and paste it into a text file and save as research.uhp  in your ultra hal assistant folder and choose it from the brain options menu.

the plug-in is called 'Internet research' in the brain options menu.

Jerry 8)

spydaz

  • Hero Member
  • *****
  • Posts: 670
    • View Profile
    • http://www.spydazweb.co.uk/
Re: New knowledge plugin
« Reply #8 on: September 13, 2011, 04:43:25 pm »
A lovely plugin Just the sort of plugins we need.... Data mining the web.....

after feeding hal list of question he should be self populating the brain cells (sql tables)


Good Work

Angelo Estela with  code  by Gerald L. Blakley A.K.A OnTheCuttingEdge2005

Me Likey

onthecuttingedge2005

  • Guest
Re: New knowledge plugin
« Reply #9 on: September 14, 2011, 03:59:00 pm »
You are welcome Spydaz, Enjoy 8)

Frosty Greenacre

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Re: New knowledge plugin
« Reply #10 on: October 27, 2011, 04:40:25 pm »
tried it and love it. nice one :)

iampan

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: New knowledge plugin
« Reply #11 on: December 07, 2011, 02:07:30 pm »
I like this plug-in thanks, it is working smoothly for me, not noticing any learning yet from the info, but just started using it
I know it says I am a newbie, but I'm sure you all remember me... same name.

raybe

  • Hero Member
  • *****
  • Posts: 1067
    • View Profile
Re: New knowledge plugin
« Reply #12 on: December 10, 2011, 01:01:58 pm »
OTC or angeloes would it be too much to ask if you can post the script line to use Google Chrome or Firefox? I see how it is written but I would appreciate the actual code line and see if I actual have some kind of handle on it. Stopped using IE for some time always had a problem unless you want to go back to the days of Netscape and even then I used Netscape before IE.

Thanks for your time if possible,
raybe