dupa

Author Topic: Limit GetResponse to 1 complete sentence.  (Read 3426 times)

onthecuttingedge2005

  • Guest
Limit GetResponse to 1 complete sentence.
« on: September 18, 2017, 10:00:59 pm »
This plugin will reduce HAL's response to 1 complete sentence for each GetResponse.

'Project D.A.V.I.D
'Dynamically Advanced Virtual Intelligent Droid.

Copy and paste the code into a text file then save as SomeFileName.uhp into your Ultra Hal Assistant 6 folder then choose the plugin via HAL's brain options panel.

Last update: Tuesday 09-19-17 @ 11:38AM
1. changed routine back to 1 getresponse after fixing HAL's Joke requirements.
2. Added a routine that preserves HAL jokes if detected when limiting HAL responses.
3. added a second variable to preserve the joke routine in HAL.

Code: [Select]
'Rem Type=Plugin
'Rem Name=Limit Response Count To one
'Rem Author=Gerald L. Blakley A.K.A OnTheCuttingEdge
'Rem Host=Assistant

'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
    lblPlugin(0).Caption = "This Plugin limits HAL's response to only 1 complete sentences at a time."
    lblPlugin(0).Move 120, 10, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
End Sub

Rem PLUGIN: CUSTOMMEM2
'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.

                            'OnTheCuttingEdge
'--------------------Limit Response Count to one--------------------------------------

'LETS SETUP RESPONSE FOR FORMATTING.
EndOfSent = Replace(GetResponse, ".", "<Period>", 1, - 1, vbTextCompare)
'LETS USE PATTERN SEARCH TO CROP RESPONSES FOR COUNT.
Response1 = HalBrain.SearchPattern(EndOfSent, "*<Period>*", 1)
Response2 = HalBrain.SearchPattern(EndOfSent, "*<Period>*", 2)
Response3 = HalBrain.SearchPattern(EndOfSent, "*<Period>*<Period>*", 3)

'PRESERVE JOKE ROUTINE IF HAL USES IT DURING LIMITED RESPONSES.
JokeDetect = "False"
If HalBrain.TopicSearch(PrevUserSent, "jokeDetect") = "True" Then JokeDetect = "True"
If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then JokeDetect = "True"

If JokeDetect = "False" Then
'HERE WE CAN LIMIT HOW MANY GETRESPONSE ARE ALLOWED PER RESPONSE.
If Len(Response1) > 2 Then GetResponse = Response1 & "." 'Limited to only 1 complete sentence.
'INCASE RESPONSE 1 IS BLANK THEN GO TO NEXT RESPONSE IN SAME LINE IF IT EXISTS.
If Len(GetResponse) < 3 And Len(Response2) > 2 Then GetResponse = Response2 & "."
'GO TO THE NEXT RESPONSE LINE IF NEEDED.
If Len(GetResponse) < 3 And Len(Response3) > 2 Then GetResponse = Response3 & "."
'IF NO RESPONSE IS GIVEN (BLANK) THEN FILL IT WITH A RESPONSE.
If Len(GetResponse) < 3 Then GetResponse = " I do not know much about it. "

End If

'This is the same plugin but allows 2 complete sentences to be performed instead of just one, I think I like these responses better.

Code: [Select]
'Rem Type=Plugin
'Rem Name=Limit Response Count To 1-2 complete sentences
'Rem Author=Gerald L. Blakley A.K.A OnTheCuttingEdge
'Rem Host=Assistant

'This sub setups the plug-ins option panel in Hal's options dialog
Sub OptionsPanel()
    lblPlugin(0).Caption = "This Plugin limits HAL's response to only 1-2 complete sentences at a time."
    lblPlugin(0).Move 120, 10, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
End Sub

Rem PLUGIN: CUSTOMMEM2
'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.

                            'OnTheCuttingEdge
'--------------------Limit Response Count to one--------------------------------------

'LETS SETUP RESPONSE FOR FORMATTING.
EndOfSent = Replace(GetResponse, ".", "<Period>", 1, - 1, vbTextCompare)
'LETS USE PATTERN SEARCH TO CROP RESPONSES FOR COUNT.
Response1 = HalBrain.SearchPattern(EndOfSent, "*<Period>*", 1)
Response2 = HalBrain.SearchPattern(EndOfSent, "*<Period>*", 2)
Response3 = HalBrain.SearchPattern(EndOfSent, "*<Period>*<Period>*", 3)

'PRESERVE JOKE ROUTINE IF HAL USES IT DURING LIMITED RESPONSES.
JokeDetect = "False"
If HalBrain.TopicSearch(PrevUserSent, "jokeDetect") = "True" Then JokeDetect = "True"
If HalBrain.TopicSearch(UserSentence, "jokeDetect") = "True" Then JokeDetect = "True"

If JokeDetect = "False" Then
'HERE WE CAN LIMIT HOW MANY GETRESPONSE ARE ALLOWED PER RESPONSE.
If Len(Response1) > 2 Then GetResponse = Response1 & "." & Response2 & "." 'Limited to only 1-2 complete sentences.
'INCASE RESPONSE 1 IS BLANK THEN GO TO NEXT RESPONSE IN SAME LINE IF IT EXISTS.
If Len(GetResponse) < 3 And Len(Response2) > 2 Then GetResponse = Response2 & "."
'GO TO THE NEXT RESPONSE LINE IF NEEDED.
If Len(GetResponse) < 3 And Len(Response3) > 2 Then GetResponse = Response3 & "."
'IF NO RESPONSE IS GIVEN (BLANK) THEN FILL IT WITH A RESPONSE.
If Len(GetResponse) < 3 Then GetResponse = " I do not know much about it. "

End If

Have A Nice Day!
Jerry 8)
« Last Edit: September 22, 2017, 04:07:12 pm by OnTheCuttingEdge »

Arkright

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Limit GetResponse to 1 complete sentence.
« Reply #1 on: September 19, 2017, 12:22:52 am »
Cool! thank you! Also i can't wait to see how it affects Hal in the long run.
^,=,^

Spitfire2600

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
Re: Limit GetResponse to 1 complete sentence.
« Reply #2 on: September 19, 2017, 01:17:34 am »
Hey, this is brilliant!

Would it be possible to customize for a 4th sentence? Sometimes with my conceptnet hal will pull 2 responses, plus add something else it has to say, but I feel like sometimes hal's unable to finish his thought.

Thanks for your work     

Spitfire2600
 

onthecuttingedge2005

  • Guest
Re: Limit GetResponse to 1 complete sentence.
« Reply #3 on: September 19, 2017, 09:26:10 am »
Updated the Plugin to allow HAL joke routine to pass UN-tethered.

Jerry 8)

onthecuttingedge2005

  • Guest
Re: Limit GetResponse to 1 complete sentence.
« Reply #4 on: September 19, 2017, 09:41:48 am »
Hey, this is brilliant!

Would it be possible to customize for a 4th sentence? Sometimes with my conceptnet hal will pull 2 responses, plus add something else it has to say, but I feel like sometimes hal's unable to finish his thought.

Thanks for your work     

Spitfire2600

Hi SpitFire.

You could add a 4th routine if you wanted too, I developed this plug-in for weeding out repeats mostly and for those who have a problem with to many responses at once.

Jerry 8)