Zabaware Support Forums

Zabaware Forums => Programming using the Ultra Hal Brain Editor => Topic started by: onthecuttingedge2005 on August 17, 2005, 03:02:17 PM

Title: To Rob, Script add-in for NewName
Post by: onthecuttingedge2005 on August 17, 2005, 03:02:17 PM
Hi Rob.

Could you alter your script in Ultra Hal 6:
'RESPOND: USER TELLS US THEIR NAME OR NICKNAME
I added an extra function to it for the benefits of changing the currentSubject to UserName or the Users real Name as the subject.

This is what I changed:

'RESPOND: USER TELLS US THEIR NAME OR NICKNAME
   HalBrain.CreateTable "AllUsers", "TopicSearch", ""
   If InStr(UserSentence, " NOT ") = 0 And InStr(UserSentence, " MIDDLE ") = 0 And InStr(UserSentence, " LAST ") = 0 Then
       'If Hal asked the user their name in the previous sentence, then we can assume the name mentioned
       'is the user's name
       If InStr(1, PrevSent, "WHAT", vbTextCompare) And InStr(1, PrevSent, "YOU", vbTextCompare) And InStr(1, PrevSent, "NAME", vbTextCompare) And MentionedName <> "" Then NickName = MentionedName
       'The following are patterns where we are sure that the person is trying to tell us thier name
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "MY *NAME IS *", 2)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "* IS *MY *NAME", 1)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "I'M *CALLED *", 2)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "I AM *CALLED *", 2)
       If NickName <> "" Then Definetelyname = True
       'The following are patterns where we are not sure if the person is trying to tell us their name
       'unless we recognize the name in the name database.
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "*CALL ME *", 2)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "*I AM *", 2)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "*I'M *", 2)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "I GO BY *", 1)
       If NickName = "" Then NickName = HalBrain.SearchPattern(OriginalSentence, "THIS IS *", 1)
       If NickName <> "" Then
           NickName = HalBrain.AlphaNumericalOnly(Trim(NickName))
           If InStr(NickName, " ") Then
               TempArray = Split(NickName, " ")
               NickName = Trim(TempArray(0))
           End If
           If UCase(MentionedName) = UCase(NickName) And Not (wn.LookUpWord(NickName) = True And Definetelyname = False) Then 'Name is found in database
               NewName = MentionedName        
     'Ziggy's Collect all user names for other scripts.
     GetUser = HalBrain.TopicSearch(UserName, "AllUsers")
     If UserKnown = "" Then UserKnown = 0
     If UCase(GetUser) <> "" Then UserKnown = 1
     If UserKnown = 0 Then HalBrain.AddToTable "AllUsers", "TopicSearch", Trim(UCase(UserName)), Trim(UCase(UserName))
     If UserKnown = 0 Then HalBrain.AddToTable "AllUsers", "TopicSearch", Trim(UCase(NewName)), Trim(UCase(NewName))
     If UserKnown = 0 Then HalBrain.AddToTable "AllUsers", "TopicSearch", Trim(UCase(NewName)), Trim(UCase(UserName))
     If UserKnown = 0 Then HalBrain.AddToTable "AllUsers", "TopicSearch", Trim(UCase(UserName)), Trim(UCase(NewName))
               'End of Ziggy's Name Collection.
               Select Case MentionedSex
                   Case "M"  'Name is definetely masculine
                       GetResponse = HalBrain.ChooseSentenceFromFile("maleGreeting")
                       GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
                       UserSex = "M"
                   Case "F"  'Name is definetely feminine
                       GetResponse = HalBrain.ChooseSentenceFromFile("femaleGreeting")
                       GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
                       UserSex = "F"
                   Case "MF" 'Name is either gender, usually male
                       GetResponse = HalBrain.ChooseSentenceFromFile("genericGreeting") & HalBrain.ChooseSentenceFromFile("maybeMale")
                       GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
                       UserSex = ""
                   Case "FM" 'Name is either gender, usually female
                       GetResponse = HalBrain.ChooseSentenceFromFile("genericGreeting") & HalBrain.ChooseSentenceFromFile("maybeFemale")
                       GetResponse = Replace(GetResponse, "<NickName>", MentionedName, 1, -1, vbTextCompare)
                       UserSex = ""
               End Select
           ElseIf Definetelyname = True Then 'Name not in DB but user says its their name
               If wn.LookUpWord(NickName) Then 'Name is a word in dictionary
                   GetResponse = HalBrain.ChooseSentenceFromFile("fakeName")
                   GetResponse = Replace(GetResponse, "<NickName>", NickName, 1, -1, vbTextCompare)
                   GetResponse = Replace(GetResponse, "<Definition>", wn.GetDefinition(wn.GuessPartOfSpeech, 1, "D"), 1, -1, vbTextCompare)
                   GetResponse = Replace(GetResponse, "<PartOfSpeech>", wn.GuessPartOfSpeech, 1, -1, vbTextCompare)
               Else 'Name is not a word in dictionary
                   GetResponse = HalBrain.ChooseSentenceFromFile("uniqueName")
                   GetResponse = Replace(GetResponse, "<NickName>", NickName, 1, -1, vbTextCompare)
                   NewName = NickName
                   UserSex = ""
               End If
           End If
       End If
   End If

'And I added this function to work with it:

'PROCESS: FIGURE OUT THE CURRENT SUBJECT
   'Here we attempt to figure out the subject of the user's sentence. We call
   'the WordNet class to find the first occurence of a noun in the User's
   'sentence. Very often this is the subject of the sentence, but if not it
   'will still most likely be relevant to the conversation.
   CurrentSubject = wn.FindFirstNoun(UserSentence, True)
   
   'Ziggy Pro Bot, If User is talking about another User make that User the Subject.
   GetUser = HalBrain.TopicSearch(UserSentence, "AllUsers")
   If UCase(GetUser) <> "" Then CurrentSubject = UCase(GetUser)

'It becomes useful to be able to make the User the subject when
'asked about a user or just talking about a user as the subject.

Thanks.
Jerry.[8D]
Title: To Rob, Script add-in for NewName
Post by: Medeksza on August 21, 2005, 07:11:15 PM
Thanks, I'll make the changes to Hal 6.0.
Title: To Rob, Script add-in for NewName
Post by: onthecuttingedge2005 on August 22, 2005, 03:38:43 PM
Thanks Rob, You're the greatest.

Jerry.