dupa

Author Topic: Hal plugin programming issue  (Read 25009 times)

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Hal plugin programming issue
« on: March 02, 2016, 12:15:27 pm »
Hi guys, I'm stumped!! I'm trying to create a hal plugin that will go out to wikipedia and grab a portion of the content and display it. I created a vbscript program that does this and works fine on its own, however when I try to put it in a uhp file and add it as a plugin it doesn't work, so many different errors no matter what I do. Below is the code, please let me know there is a way to get it working.


Rem Type=Plugin
Rem Name=KITT Wiki
Rem Author= Victor
Rem Host=Assistant

'------------------------------------------------------------------------------------------------------
' KITTWiki.uhp - Release 1.0 by Victor Yacobucci. 02-25-2016
'------------------------------------------------------------------------------------------------------
Rem PLUGIN: PLUGINAREA1

vrToSearch = ""
vrToSearch = UCase(HalBrain.SearchPattern(UserSentence, "*search for*", 2))
GetResponse = "searching for "& vrToSearch &" "


'    Declaration of variables
Dim ie
 '    Declaration of subroutines
'    Sub WaitForLoad waits for webpage to finish loading
'    before proceeding with next line of code
Sub WaitForLoad
    Do while ie.Busy or ie.readystate <> 4
        wscript.sleep 2000
    Loop
End Sub
 '    Open windows Internet explorer and surf to website
set ie = CreateObject("InternetExplorer.Application")
With ie
    .Navigate "https://en.wikipedia.org/wiki/Michael_Jordan"
    .Toolbar=0
    .StatusBar=0
    .Height=560
    .Width=1000
    .Top=0
    .Left=0
    .Resizable=0
    WaitForLoad
    .Visible = false
end with
 '  Add code below to display in a msgbox the contents of each cell in column 0 (first column) should loop for each row.
 dim element
 dim counter
 dim item
Set element = ie.document.getElementById("mw-content-text").getElementsByTagName("p")
   counter = 1
   For Each x In element
      If(counter < 3) Then
      content = Replace(x.innerText,"[","")
      content = Replace(x.innerText,"]","")
      content = Replace(x.innerText,"(","")
      content = Replace(x.innerText,")","")
          MsgBox content
        End If
        counter = counter + 1
    Next



Carl2

  • Hero Member
  • *****
  • Posts: 1220
    • View Profile
Re: Hal plugin programming issue
« Reply #1 on: March 02, 2016, 02:48:55 pm »
  I've also done a little work on a Wiki plugin, it gets me to wiki and that's about it.  VR, (Rossi) of Virtual Humans website also has a vrWeb plugin which can get you to Wiki, actually I haven't tried it yet.  I'm familiar wit the error codes that get generated and usually find the errors sooner or latter.  I'm not familiar with your coding and there are statements new to me. 
This is what I came up with:
Rem Type=Plugin
Rem Name=Wiki
Rem Author=Zabaware ModifiedCJ
Rem Host=Assistant

'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
    lblPlugin(0).Caption = "Hal will open your browser and enter a Wiki query if you use the keyword "Wiki"
    lblPlugin(0).Move 120, 120, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
End Sub

    Rem PLUGIN: PLUGINAREA1
    'The comment above tells Ultra Hal Assistant to insert the following code
    'on-the-fly into the main brain code in the section referenced.
    SearchEngine = "https://en.wikipedia.org/wiki/English_language"
    If InStr(1, UserSentence, "Wiki", 1) > 0 Then
        SearchKeywords = LCase(Replace(Trim(HalBrain.AlphaNumericalOnly(HalBrain.ExtractKeywords(UserSentence))), " ", "+"))
        SearchKeyWords = Replace(SearchKeywords, "find+", "")
        SearchKeyWords = Replace(SearchKeywords, "research+", "")
        SearchKeyWords = Replace(SearchKeywords, "locate+", "")
        SearchKeyWords = Replace(SearchKeywords, "search+", "")
        HalCommands = HalCommands & "<RUNPROG>" & SearchEngine & SearchKeywords & "</RUNPROG>"
        GetResponse = GetResponse & "I will help you research this topic on the Internet. "
    End If
This is the vrWeb plugin:
Rem Type=Plugin
Rem Name=Customized Web Searches
Rem Author=VR
Rem Host=Assistant

'------------------------------------------------------------------------------------------------------
' VR_Web.uhp - Release 1.0 by VR Consulting sas.
' This script shall not be sold or used for any purpose unless specifically authorized by the author
' in writing. Personal (non-business) use of this script is free for users of Ultra Hal Assistant.
' If you want to use this software in business applications, you must contact us at info@vrconsulting.it
' This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
' VR CONSULTING DISCLAIMS ALL WARRANTIES WITH RESPECT TO THIS SOFTWARE, EXPRESS, IMPLIED, OR OTHERWISE,
' INCLUDING WITHOUT LIMITATION, ALL WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
' OR NONINFRINGEMENT.
' VR CONSULTING SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
' DAMAGES, INCLUDING, WITHOUT LIMITATION, LOST REVENUES, LOST PROFITS, OR LOSS OF PROSPECTIVE ECONOMIC ADVANTAGE,
' RESULTING FROM THE USE OR MISUSE OF THIS SOFTWARE.
' This software is made available free by the author. Although he is interested in your feedback,
' he is under no obligation to address bugs, enhancements, or answer questions.
'------------------------------------------------------------------------------------------------------

'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
    lblPlugin(0).Caption = "This replaces the standard Google plugin. It manages Google queries, Viki searches and other customizable topics such as local news, weather or mail. Click below for more info"
    lblPlugin(0).Move 120, 120, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
    cmdPlugin(0).Move 800, 1300, 2100, 375
    cmdPlugin(0).Caption = "Help on this plugin"
    cmdPlugin(0).Visible = True
End Sub

Sub cmdPlugin_Click(Index)
    Select Case Index
        Case 0
          HalMenu.HalCommand "<RUNPROG>vrwebhelp.html</RUNPROG>"
    End Select
End Sub


Rem PLUGIN: PLUGINAREA1
'The comment above tells Ultra Hal Assistant to insert the following code
'on-the-fly into the main brain code in the section referenced.

' If the table vrWeb does not exist, I create it and fill it with some default values
' each user will need to add other links and/or change these
   If HalBrain.CheckTableExistence("vrWeb") = False Then
   ' I store temporarily the Read Only status
        vrReadOnlyMode = HalBrain.ReadOnlyMode
      HalBrain.ReadOnlyMode = False
      HalBrain.CreateTable "vrWeb", "PatternMatch", "miscData"
      HalBrain.AddToTable "vrWeb", "PatternMatch", "*Hal Help*", "welcome.html"
      HalBrain.AddToTable "vrWeb", "PatternMatch", "*local weather*", "http://uk.weather.com/weather/local/ITXX0067"
      HalBrain.AddToTable "vrWeb", "PatternMatch", "*local news*", "http://www.nytimes.com/"
      HalBrain.AddToTable "vrWeb", "PatternMatch", "*yahoo mail*", "http://my.yahoo.com/"
      HalBrain.AddToTable "vrWeb", "PatternMatch", "*zabaware forum*", "http://www.zabaware.com/forum/"
      HalBrain.AddToTable "vrWeb", "PatternMatch", "*virtual humans forum*", "http://www.vrconsulting.it/vhf/"
      ' Set ReadOnly Mode to its previous state
      HalBrain.ReadOnlyMode = vrReadOnlyMode
   End If

'Run the corresponding Web page, if the user question contains one of the searched words    
    vrAddress = ""
    vrAddress = HalBrain.PatternDB(OriginalSentence, "vrWeb")
    If vrAddress <> "" Then
       HalCommands = HalCommands & "<RUNPROG>" & vrAddress & "</RUNPROG>"
      Select Case (Int(Rnd * 4) + 1)
      Case 1
         GetResponse = "Here is the page you asked me for." & vbCrLf
      Case 2
         GetResponse = "Now you can access it." & vbCrLf
      Case 3
         GetResponse = "I am really happy to give you this information." & vbCrLf
      Case 4
         GetResponse = "OK. Here it is." & vbCrLf
      Case 5
         GetResponse = "Now look at this." & vbCrLf
      End Select
      HalBrain.ReadOnlyMode = True
   End If

'------------------
' Google search
'------------------
SearchEngine = "http://www.google.com/search?q="
If InStr(1, UserSentence, "google ", 1) > 0 Then
   SearchKeywords = LCase(Replace(Trim(HalBrain.AlphaNumericalOnly(HalBrain.ExtractKeywords(UserSentence))), " ", "+"))
   SearchKeyWords = Replace(SearchKeywords, "google+", "")
   HalCommands = HalCommands & "<RUNPROG>" & SearchEngine & SearchKeywords & "</RUNPROG>"
   GetResponse = "I will help you research this topic on Google. "
   HalBrain.ReadOnlyMode = True
End If

' This is too invasive: any input containing common words as "find" activates this search
'SearchEngine = "http://www.google.com/search?q="
'If InStr(1, UserSentence, "search ", 1) > 0 Or InStr(1, UserSentence, "find ", 1) > 0 Or InStr(1, UserSentence, "locate ", 1) > 0 Then
'   SearchKeywords = LCase(Replace(Trim(HalBrain.AlphaNumericalOnly(HalBrain.ExtractKeywords(UserSentence))), " ", "+"))
'   SearchKeyWords = Replace(SearchKeywords, "find+", "")
'   SearchKeyWords = Replace(SearchKeywords, "research+", "")
'   SearchKeyWords = Replace(SearchKeywords, "locate+", "")
'   SearchKeyWords = Replace(SearchKeywords, "search+", "")
'   HalCommands = HalCommands & "<RUNPROG>" & SearchEngine & SearchKeywords & "</RUNPROG>"
'   GetResponse = "I will help you research this topic on the Internet. "
'   HalBrain.ReadOnlyMode = True
'End If

'------------------
' Wiki Search
'------------------

If InStr(1, UserSentence, "wiki ", 1) > 0 Then
   SearchKeywords = LCase(Replace(Trim(HalBrain.AlphaNumericalOnly(HalBrain.ExtractKeywords(UserSentence))), " ", "+"))
   SearchKeyWords = Replace(SearchKeywords, "wiki+", "")
   HalCommands = HalCommands & "<RUNPROG>http://en.wikipedia.org/wiki/" & Keywords & "</RUNPROG>"
   GetResponse = "Here is what Wiki says about " & SearchKeywords
   HalBrain.ReadOnlyMode = True
End If

What vr has done is ask his program to insert some tables in the brain, in the past I've found these tables do not get put into hals brain and you would have to do this yourself. The process is simple using the brain editor.
I hope this info has been helpful, let us know how you make out.
Carl2
 

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #2 on: March 02, 2016, 03:18:52 pm »
Thanks for the reply Carl2! I'm trying to take the "wiki" a step further. I want to give Hal a search term like "Michael Jordan" then have Hal go to the wiki page for Michael Jordan then grab and save the text from the first few paragraphs in a variable, then I want to have Hal read the paragraph (text) that was stored. I attached the working code in a standard vbs file. It grabs the first two paragraphs no problem but I cant get it to work in the plugin. 

Calhoone

  • Sr. Member
  • ****
  • Posts: 289
    • View Profile
Re: Hal plugin programming issue
« Reply #3 on: March 02, 2016, 06:29:25 pm »
Just a thought,

CLoad did implement something like this in either his AIML plugin or his modified version of the freewill plugin.  With it you can say to Hal "What do you know about Micheal Jordan" or Tell me about such and such". Hal will grab the first couple paragraphs from wikipedia and speak them to you.  There might be something in those plugins to help you.
 

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #4 on: March 03, 2016, 09:13:02 am »
Thanks for the info! That would be perfect! I'll check it out! Is there a link to his plugin?

Calhoone

  • Sr. Member
  • ****
  • Posts: 289
    • View Profile
Re: Hal plugin programming issue
« Reply #5 on: March 03, 2016, 05:26:38 pm »
 

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #6 on: March 09, 2016, 06:03:49 pm »
Hey guys, I finally got it to work! If you tell Hal "search for michael jordan" Hal will search Wikipedia and return you the first paragraph of content. Works pretty good but there is always room for improvement. If you search for a name that doesnt exist Hal will respond with "Sorry, I can't find anything" however if you type in something like "search for fjskfjkfjksf" Hal throws an object required error for the ie.document.getElementById. I cant figure out how to have Hal check to see if the object exists. If anyone could figure that out please feel free to update the plugin. Otherwise have fun with it! Let me know what you think!

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #7 on: March 09, 2016, 06:05:03 pm »
I'd like to add that Hal will speak the content that is returned from Wikipedia!

Art

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3848
    • View Profile
Re: Hal plugin programming issue
« Reply #8 on: March 10, 2016, 08:47:03 am »
Victor,

That is a very nice Plugin! Good job!
In the world of AI it's the thought that counts!

- Art -

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #9 on: March 10, 2016, 09:08:52 am »
Thanks Art!

lightspeed

  • Hero Member
  • *****
  • Posts: 6761
    • View Profile
Re: Hal plugin programming issue
« Reply #10 on: March 10, 2016, 11:10:29 am »

knight2000 , sounds like you did a good job on improving the plug in , and i take it your words of i can't find that can be customized. i myself am trying to make hal sound more human as if hal knows the answers etc. instead of searching or referencing searching for something . i didn't ask but your improved program just retreaves the answer , right , doesn't open the web page up. (that's what hal used to do but someone ? fixed it and hal just retrived the answer which is better to me . )

 i might ad a custom answer back like " sorry, i really don't know about that, guess i'll have to check sometime and see if i can find the answer !"

anyway , enough rambling on,  nice job you did !!  :) ;)
 

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #11 on: March 10, 2016, 01:24:13 pm »
Thanks Lightspeed!
Yes, Hal will read you back the content rather than opening a webpage. I wanted to make Hal seem more like Watson were he has this endless amount of knowledge of pretty much anyone you ask about. I think your right on about Hal sounding more human, I should probably change the "search for" to "what do you know about" or something like that. Anyways, I plan on making more updates to the plugin, I'm thinking of adding the ability to have Hal continue reading more of the content on the page, maybe by saying something like "anything else?". Currently Hal only reads the first paragraph which in most cases provide plenty of good info, some searches only have a few words of info.

Art

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3848
    • View Profile
Re: Hal plugin programming issue
« Reply #12 on: March 11, 2016, 11:37:30 am »
Several revisions of Hal ago, would allow "him" to check for emails or make phone calls (land line / dialup) which worked fairly well.
I guess he could be made to check for messages or emails or RSS feeds but that would require it (Hal) to constantly monitor the possible incoming events and would likely affect it's chat performance / ability.

I've had a ton of ideas for Hal over the many years and now that I've finally retired, hopefully, I've have a bit more time to experiment with the program.

Good luck and keep Plugin-ing away!  ;)
In the world of AI it's the thought that counts!

- Art -

knight2000

  • Full Member
  • ***
  • Posts: 155
    • View Profile
Re: Hal plugin programming issue
« Reply #13 on: March 11, 2016, 03:54:58 pm »
Well, you know what they say...the sky is the limit! So many cool possibilities for this program! One thing I've been trying to figure out is to have Hal respond quicker when talking to him. Currently there is a 5 second delay before he answers. I remember in another post someone said that it was a setting in one of the DLL files and cant be changed. I really hope we can find a way to remove the delay.

Art

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3848
    • View Profile
Re: Hal plugin programming issue
« Reply #14 on: March 12, 2016, 08:37:27 am »
I'm not sure about your system but my Hal answers me between 1 and 3 seconds...certainly not 5 or more.

From the time I press the Enter key, I count one, and before I get to two, she (Hal) answers me. I have repeated this numerous times and it's always 1 to 2 seconds.

My system is an i7 (Intel) quad core running Windows 10, 1 TB drive, 8 GB Ram. YMMV


In the world of AI it's the thought that counts!

- Art -