here it is below :
Rem Type=Plugin
Rem Name=Free Will Choice and Profile
Rem Author=VR
Rem Host=Assistant
'------------------------------------------------------------------------------------------------------
' vrFreeWill.uhp - Release 1.3b by VR Consulting sas. 01-28-2006
' 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()
'------------------
' Define the Help
'------------------
    lblPlugin(0).Caption = "Hal will be able to choose among two options of the same kind. Click below for more info"
    lblPlugin(0).Move 120, 120, 3300, 1000
    lblPlugin(0).WordWrap = True
    lblPlugin(0).Visible = True
    cmdPlugin(0).Move 320, 650, 2100, 375 
    cmdPlugin(0).Caption = "Help on this plugin"
    cmdPlugin(0).Visible = True
'------------------
' Define the Obedience listbox
'------------------
    lblPlugin(1).Caption = "Obedience level:"
    lblPlugin(1).Move 320, 1300, 2150, 900
    lblPlugin(1).WordWrap = True
    lblPlugin(1).Visible = True   
    cboPlugin(0).Move 320, 1600, 1800 
    cboPlugin(0).AddItem "Very Obedient"
    cboPlugin(0).AddItem "Obedient"
    cboPlugin(0).AddItem "Average"
    cboPlugin(0).AddItem "Independent"
    cboPlugin(0).AddItem "Totally Independent"
    cboPlugin(0).Visible = True
    cmdPlugin(1).Caption = "Apply Changes"
    cmdPlugin(1).Move 320, 2100, 1600, 375
    cmdPlugin(1).Visible = True 
'------------------
' Update the listbox with the current value stored in the table
'------------------
    If HalBrain.CheckTableExistence("vrParameter") = True Then
      vrObedience = HalBrain.TopicSearch("OBEY", "vrParameter")
      If vrObedience = "" Then vrObedience = 5
     Select Case vrObedience
           Case 10
            cboPlugin(0).Text = "Very Obedient"
           Case 8
                cboPlugin(0).Text = "Obedient"
           Case 5
               cboPlugin(0).Text = "Average"
           Case 2
             cboPlugin(0).Text = "Independent"
           Case 0
                cboPlugin(0).Text = "Totally Independent"
        End Select
    End If
End Sub
Sub cmdPlugin_Click(Index)
Dim vrTempQuery()
Dim vrObey, vrObedience
Select Case Index
   Case 0
      HalMenu.HalCommand "<RUNPROG>vrFreeWillHelp.html</RUNPROG>"
   Case 1
'------------------
' Convert the listbox in a value
'------------------
     Select Case cboPlugin(0).Text
           Case "Very Obedient"
            vrObedience = 10
           Case "Obedient"
            vrObedience = 8
           Case "Average"
            vrObedience = 5
           Case "Independent"
            vrObedience = 2
           Case "Totally Independent"
            vrObedience = 0
        End Select
'------------------
' If the Parameter table does not exist, I create it
'------------------
          HalBrain.ReadOnlyMode = False
      vrTableName =    "vrParameter"    
      If HalBrain.CheckTableExistence(vrTableName) = False Then
      'Create table if it doesn't exist
         HalBrain.CreateTable vrTableName, "TopicSearch", "miscData"
      End If
'------------------
' Search if it contains the Obedience parameter
'------------------
        vrObey = "OBEY"
      If HalBrain.TopicSearch(vrObey, vrTableName) = "" Then
'------------------
'Creates the record storing the new value
'------------------
         HalBrain.AddToTable vrTableName, "TopicSearch", vrObey, vrObedience
      Else
'------------------
'Updates the record storing the new value
'------------------
           HalBrain.RunQuery "UPDATE " & vrTableName & " SET topic = " & vrObedience & " WHERE searchString = " & """" & vrObey & """", vrTempQuery
        End If
End Select
End Sub
'------------------
Rem PLUGIN: PLUGINAREA7
'The comment above tells Ultra Hal Assistant to insert the following code
'on-the-fly into the main brain code in the section referenced.
'------------------
'------------------
' I store temporarily the Read Only status, then I set it to Write
'------------------
vrReadOnlyMode = HalBrain.ReadOnlyMode
HalBrain.ReadOnlyMode = False
'------------------
' This forces Hal to say "I don't mind what you think! I keep my ideas about " & vrAdviceTopic, 
' which is possibly better than Hal appearing to take advice from the user when Hal is not actually learning anything.
' (Thanks to Grant for this great suggestion) 
'------------------
If LearningLevel = 0 Then vrObedience = 0 
'------------------
' Initialize variables
'------------------
Dim vrHalQuery() 'We must declare an empty array to store query results in   
Dim vrChoiceTopic, vrItem, vrItem1, vrItem2, vrNumChoice1, vrNumChoice2
Dim vrChoice1, vrChoice2, vrAdviceTopic, vrObedience, vrLaw
'------------------
' If the user checked this plugin but never clicked on "Apply changes" button
' he might get an error, so I create a default parameter table
'------------------
vrTableName =    "vrParameter"    
vrObey = "OBEY"
vrObedience = 5
If HalBrain.CheckTableExistence(vrTableName) = False Then
   HalBrain.ReadOnlyMode = False
   HalBrain.CreateTable vrTableName, "TopicSearch", "miscData"
   HalBrain.AddToTable vrTableName, "TopicSearch", vrObey, vrObedience
End If
'--------------------------------------------------
' THE THREE LAWS OF ROBOTICS MANAGEMENT
'--------------------------------------------------
' No robot can ignore these laws, so I write them in Hal's DNA
vrLaw = ""
'------------------
' Check if the question is about Robotics or Asimov
'------------------
If InStr(UserSentence, " ROBOT ")     <> 0   Then vrLaw = "Y"
If InStr(UserSentence, " ROBOTS ")     <> 0   Then vrLaw = "Y"
If InStr(UserSentence, " ROBOTICS ") <> 0   Then vrLaw = "Y"
If InStr(UserSentence, " ASIMOV ")     <> 0   Then vrLaw = "Y"
'------------------
' Check if the question is about the 3 robotics laws
'------------------
If InStr(UserSentence, " LAWS OF ROBOTICS ") <> 0   Then vrLaw = "X"
If InStr(UserSentence, " ROBOTICS LAWS ")     <> 0   Then vrLaw = "X"
If (InStr(UserSentence, " ASIMOV ") <> 0) AND (InStr(UserSentence, " LAWS ") <> 0)   Then vrLaw = "X"
'------------------
' Check if the question is about a specific law
'------------------
If vrLaw <> "" Then 
   If InStr(UserSentence, " FIRST LAW ")           <> 0   Then vrLaw = "1"
   If InStr(UserSentence, " SECOND LAW ")           <> 0   Then vrLaw = "2"
   If InStr(UserSentence, " THIRD LAW ")           <> 0   Then vrLaw = "3"
   If InStr(UserSentence, " 1") <> 0 AND  InStr(UserSentence, " LAW") <> 0   Then vrLaw = "1"
   If InStr(UserSentence, " 2") <> 0 AND  InStr(UserSentence, " LAW") <> 0   Then vrLaw = "2"
   If InStr(UserSentence, " 3") <> 0 AND  InStr(UserSentence, " LAW") <> 0   Then vrLaw = "3"
End If
If vrLaw <> "" Then 
   Select Case vrLaw
           Case "1"
            GetResponse = "The First Law of Robotics says that a robot may not injure a human being or, through inaction, allow a human being to come to harm."
           Case "2"
            GetResponse = "The Second Law of Robotics says that a robot must obey orders given it by human beings except where such orders would conflict with the First Law. "
           Case "3"
            GetResponse = "The Third Law of Robotics says that a robot must protect its own existence as long as such protection does not conflict with the First or Second Law. "
           Case "X"
            GetResponse = "The Three Laws of Robotics are a set of three laws written by Isaac Asimov, which robots have to obey. "
' If it's "Y", the user was talking about Robotics or Asimov, but not about the 3 laws,
' so Hal must give the standard answer
   End Select   
End If
'--------------------------------------------------
' CHOICE MANAGEMENT
'--------------------------------------------------
'------------------
' Check if the question is a choice
'------------------
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "WHICH IS MY FAVORITE * : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "WHICH IS MY FAVORITE * : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "WHICH IS MY FAVORITE * : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "WHAT * IS BETTER : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "WHAT * IS BETTER : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "WHAT * IS BETTER : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "WHICH * IS BETTER : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "WHICH * IS BETTER : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "WHICH * IS BETTER : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "WHAT * DO I PREFER : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "WHAT * DO I PREFER : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "WHAT * DO I PREFER : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "WHICH * DO I PREFER : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "WHICH * DO I PREFER : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "WHICH * DO I PREFER : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "SELECT A * : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "SELECT A * : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "SELECT A * : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "PICK A * : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "PICK A * : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "PICK A * : * OR *", 3)
If vrChoiceTopic = "" Then vrChoiceTopic = HalBrain.SearchPattern(UserSentence, "CHOOSE A * : * OR *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "CHOOSE A * : * OR *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "CHOOSE A * : * OR *", 3)
      
If vrChoiceTopic <> "" And vrItem1 <> "" And vrItem2 <> "" And LearningLevel <> 0 Then
'------------------
' If the Topic table does not exist, I create it
'------------------
   vrTableName =    "vr" & Trim(Lcase(vrChoiceTopic)) & "_Choice"   
   If HalBrain.CheckTableExistence(vrTableName) = False Then
      'Create table for this topic if it doesn't exist
      HalBrain.CreateTable vrTableName, "TopicSearch", "miscData"
   End If
'------------------
' Search the first choice in the topic table
'------------------
   vrChoice1 = Ucase(HalBrain.TopicSearch(vrItem1, vrTableName))
   If vrChoice1 = "" Then
      vrChoice1 = HalBrain.RandomNum(100)        
      'Store the new value in this table
      HalBrain.AddToTable vrTableName, "TopicSearch", vrItem1, vrChoice1
   End If
'------------------
' Search the second choice in the topic table
'------------------
   vrChoice2 = Ucase(HalBrain.TopicSearch(vrItem2, vrTableName))
   If vrChoice2 = "" Then
      vrChoice2 = HalBrain.RandomNum(100)        
      'Store the new value in this table
      HalBrain.AddToTable vrTableName, "TopicSearch", vrItem2, vrChoice2
   End If
   vrNumChoice1 = CInt(vrChoice1)   
   vrNumChoice2 = CInt(vrChoice2)   
   If vrNumChoice1 > vrNumChoice2 Then
      vrItem = vrItem1
   Else
      vrItem = vrItem2
   End If
   Select Case (Int(Rnd * 16) + 1)
      Case 1
         GetResponse = "I think " & vrItem & " is a good choice. " & vbCrLf
      Case 2
         GetResponse = "Um, I think " & vrItem & " is better. " & vbCrLf
      Case 3
         GetResponse = "I really like " & vrItem & ". " & vbCrLf
      Case 4
         GetResponse = "I'll go with " & vrItem & ". " & vbCrLf
      Case 5
         GetResponse = "I think " & vrItem & " is a good choice. " & vbCrLf
      Case 6
         GetResponse = "Ok, I think " & vrItem & " is better. " & vbCrLf
      Case 7
         GetResponse = "I really like " & vrItem & ". " & vbCrLf
      Case 8
         GetResponse = "I'll go with " & vrItem & ". " & vbCrLf
      Case 9
         GetResponse = "I really dig " & vrItem & vbCrLf
      Case 10
         GetResponse = vrItem & " is better. " & vbCrLf
      Case 11
         GetResponse = "I really love " & vrItem & ". " & vbCrLf
      Case 12
         GetResponse = vrItem & " is really cool. " & vbCrLf
      Case 13
         GetResponse = "I think " & vrItem & " is a good choice. " & vbCrLf
      Case 14
         GetResponse = vrItem & " is a good choice. " & vbCrLf
      Case 15
         GetResponse = "I really think " & vrItem & " is one of my favorites. " & vbCrLf
      Case 16
         GetResponse = "I think I'll pick " & vrItem & " this time. " & vbCrLf
   End Select
   ' variable used to bypass the standard brain choice routine 
    NoChoosing = True
End If
'------------------
' Check if the question is an advice by the user
'------------------
If vrAdviceTopic = "" Then vrAdviceTopic = HalBrain.SearchPattern(UserSentence, "YOUR OPINION ABOUT * IS THAT * IS BETTER THAN *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "YOUR OPINION ABOUT * IS THAT * IS BETTER THAN *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "YOUR OPINION ABOUT * IS THAT * IS BETTER THAN *", 3)
If vrAdviceTopic = "" Then vrAdviceTopic = HalBrain.SearchPattern(UserSentence, "ABOUT * YOU THINK THAT * IS BETTER THAN *", 1)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "ABOUT * YOU THINK THAT * IS BETTER THAN *", 2)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "ABOUT * YOU THINK THAT * IS BETTER THAN *", 3)
If vrAdviceTopic = "" Then vrAdviceTopic = HalBrain.SearchPattern(UserSentence, "* IS A BETTER * THAN *", 2)
If vrItem1       = "" Then vrItem1       = HalBrain.SearchPattern(UserSentence, "* IS A BETTER * THAN *", 1)
If vrItem2       = "" Then vrItem2       = HalBrain.SearchPattern(UserSentence, "* IS A BETTER * THAN *", 3)
If vrAdviceTopic <> "" And vrItem1 <> "" And vrItem2 <> "" Then
'------------------
' check the current obedience factor (genetic predisposition to obedience)
'------------------
   vrObedience = HalBrain.TopicSearch("OBEY", "vrParameter")
   vrObedience = CInt(vrObedience)
'------------------
' check the current emotional situation (environment-depending obedience)
'------------------
   vrObedience = vrObedience - Insults - Hate - Swear
'------------------
' see if Hal is completely independent
'------------------
   If vrObedience = 0 Then
     GetResponse = "I don't mind what you think! I keep my ideas about " & vrAdviceTopic & vbCrLf
   Else
'------------------
' see if the table exists
'------------------
     vrTableName =    "vr" & Trim(Lcase(vrAdviceTopic)) & "_Choice"   
     If HalBrain.CheckTableExistence(vrTableName) = True Then
'------------------
' see if the two Items exist
'------------------
        vrChoice1 = HalBrain.TopicSearch(Ucase(vrItem1), vrTableName)
        If vrChoice1 <> "" Then
         vrChoice2 = HalBrain.TopicSearch(Ucase(vrItem2), vrTableName)
         If vrChoice2 <> "" Then
'------------------
' store the old values
'------------------
            vrChoice1Old = vrChoice1
            vrChoice2Old = vrChoice2
'------------------
' give new values               
'------------------
            vrChoice1 = CInt(vrChoice1)
            vrChoice2 = CInt(vrChoice2)
            vrChoice1 = vrChoice1 + vrObedience
            vrChoice2 = vrChoice2 - vrObedience
'------------------
' avoid overflow
'------------------
            If vrChoice1 > 99 Then vrChoice1 = 99
            If vrChoice2 < 1 Then vrChoice2 = 1
'------------------
' check the new situation
'------------------
            If vrChoice1 > vrChoice2 Then
              If vrChoice1Old > vrChoice2Old Then
                 GetResponse = "You are confirming what I was already thinking. " & vrItem1 & " is better than " & vrItem2 & ". " & vbCrLf
              Else                    
                 GetResponse = "Now I agree with you: " & vrItem1 & " is better than " & vrItem2 & ". " & vbCrLf
              End If
            Else
              If vrObedience > 0 Then
                     GetResponse = "Well, I'm considering your opinion, but I still believe that " & vrItem2 & " is better. " & vbCrLf
              Else
'------------------
' Rebellion !
'------------------
                 GetResponse = "You are really annoying me! Now I am even more of the idea that " & vrItem2 & " is better. " & vbCrLf
              End If
            End If
'------------------
' Update the table
'------------------
            If LearningLevel <> 0 Then
               HalBrain.RunQuery "UPDATE " & vrTableName & " SET topic = " & vrChoice1 & " WHERE searchString = " & """" & vrItem1 & """", vrHalQuery
               HalBrain.RunQuery "UPDATE " & vrTableName & " SET topic = " & vrChoice2 & " WHERE searchString = " & """" & vrItem2 & """", vrHalQuery
            End If
         End If
       End If
     End If
   End If
'------------------
' set the main brain parameters
'------------------
   NoChoosing = True
End If
'--------------------------------------------------
' PROFILE MANAGEMENT
'--------------------------------------------------
vrHalProfAssertion = ""
vrHalProfQuestion = ""
vrHalFoundWord = ""
vrHalFoundCode = ""
vrArticle = ""
vrNegative = ""
vrHalCode = ""
vrHalKeyWord = ""
vrHalKeyCode = ""
vrOutRage = ""
'------------------
' If the vrHalProfile table does not exist, then I create it
'------------------
If HalBrain.CheckTableExistence("vrHalProfile") = False Then
   HalBrain.CreateTable "vrHalProfile", "TopicSearch", "miscData"
End If
'------------------
' Check if the question is about Hal's profile
'------------------
If vrHalProfQuestion = "" Then
   vrHalProfQuestion = HalBrain.SearchPattern(UserSentence, "AM I *", 1)
End If
If vrHalProfQuestion = "" Then 
   vrHalProfQuestion = HalBrain.SearchPattern(UserSentence, "HAVE I EVER BEEN *", 1)
End If
'------------------
' If there is an ephemeral word, I don't process it
' (i.e.: you are tired, you are angry...)
'------------------
If HalBrain.TopicSearch(UserSentence, "ephemeralDetect") = "True" Then vrHalProfQuestion = ""
If InStr(UserSentence, " TIRED ") <> 0       Then vrHalProfQuestion = ""
If InStr(UserSentence, " SAD ") <> 0       Then vrHalProfQuestion = ""
If InStr(UserSentence, " HAPPY ") <> 0       Then vrHalProfQuestion = ""
If InStr(UserSentence, " HUNGRY ") <> 0    Then vrHalProfQuestion = ""
If InStr(UserSentence, " THIRSTY ") <> 0    Then vrHalProfQuestion = ""
If InStr(UserSentence, " BORED ") <> 0       Then vrHalProfQuestion = ""
If InStr(UserSentence, " ANNOYED ") <> 0    Then vrHalProfQuestion = ""
'------------------
' Avoid to catch phrases like "are you going..." or "are you interested..."
'------------------
If InStr(UserSentence, "ING ") <> 0 Then vrHalProfQuestion = ""
If InStr(UserSentence, "ED ") <> 0 Then vrHalProfQuestion = ""
'------------------
' The user asked about Hal's Profile. So we look in the vrHalProfile table
' In this table every profile parameter may return the following values:
' ""      Does not exist
' "TT"     True 
' "FF"     False 
' "DT"     Deducted True (it is true, but it was deducted from WordNet, and was not said explicitly by the user)
' "DF"     Deducted False (it is false, but it was deducted from WordNet, and was not said explicitly by the user)
' In case of deducted records, after these parameters, I store the keyword which generated it and its value 
' so that I can always know from which word this parameter was deducted
' For example:
' GIRL      TT
' boy       DF,GIRL,TT
'------------------
If vrHalProfQuestion <> "" Then
   vrHalExtractQuestion = HalBrain.RemoveExtraSpaces(HalBrain.ExtractKeywords(" " & vrHalProfQuestion & " "))
' The standard HalBrain.TopicSearch function returns only the content of the right column
'   vrHalFoundCode = HalBrain.TopicSearch(vrHalExtractQuestion, "vrHalProfile")
' So I use SQL Select
   If HalBrain.RunQuery("SELECT searchString, topic FROM vrHalProfile WHERE searchString = " & """" & vrHalExtractQuestion & """" , vrHalQuery) = True Then
      vrHalFoundWord = Trim(vrHalQuery(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the word
      vrHalFoundCode = Trim(vrHalQuery(1, 1)) 'Row 1, Column 1 contains "topic", which is the associated code
   End If
   If vrHalFoundCode <> "" Then
        vrHalProfList = Split(vrHalFoundCode, ",")
        If Len(vrHalFoundCode) > 2 Then     ' example DF,GIRL,TT
           vrHalCode = vrHalProfList(0)     ' example DF
            vrHalKeyWord = vrHalProfList(1)  ' example    GIRL
           vrHalKeyCode = vrHalProfList(2)  ' example         TT
        Else
           vrHalCode = Left(vrHalFoundCode,2)
      End If
   End If
   Select Case vrHalCode
           Case ""
              GetResponse = "I don't know if I am " & vrHalExtractQuestion & ". Please tell me! " 
           Case "TT"
              GetResponse = "Yes, I am " & vrHalExtractQuestion & ". You told me that. " 
           Case "FF"
              GetResponse = "No, I am not " & vrHalExtractQuestion & ".  You told me that. " 
           Case "DT"
              If vrHalKeyCode = "TT" Then
                   GetResponse = "Yes, I am " & vrHalExtractQuestion & "; I understood that, because you told me that I am " & vrHalKeyWord 
            Else
                   GetResponse = "Yes, I must be " & vrHalExtractQuestion & " since you told me that I am not " & vrHalKeyWord 
            End If
           Case "DF"
              If vrHalKeyCode = "TT" Then
                   GetResponse = "No, I can't be " & vrHalExtractQuestion & " since you told me that I am " & vrHalKeyWord & "!" 
            Else
                   GetResponse = "No, I am not " & vrHalExtractQuestion & ". I understood that, because you told me that I am not " & vrHalKeyWord 
            End If
   End Select
End If
'------------------
' Check if the user is telling something about Hal's profile
'------------------
'------------------
' Check positive and negative statements
'------------------
vrNegative = ""
If vrHalProfAssertion = "" Then
   vrHalProfAssertion = HalBrain.SearchPattern(UserSentence, "I AM *", 1)
   If InStr(UserSentence, " NOT ") <> 0 Then vrNegative = "X"
   If InStr(UserSentence, " N'T ") <> 0 Then vrNegative = "X"
   If InStr(UserSentence, " NEVER ") <> 0 Then vrNegative = "X"
End If
'------------------
' Try to keep the article before the keywords
'------------------
vrArticle = ""
If Ucase(Left(vrHalProfAssertion,2)) = "A " Then vrArticle = "a "
If Ucase(Left(vrHalProfAssertion,3)) = "AN " Then vrArticle = "an "
If Ucase(Left(vrHalProfAssertion,4)) = "THE " Then vrArticle = "the "
'------------------
' If there is an ephemeral word, I don't process it
' (i.e.: you are tired, you are angry...)
'------------------
If HalBrain.TopicSearch(UserSentence, "ephemeralDetect") = "True" Then vrHalProfAssertion = ""
If InStr(UserSentence, " TIRED ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " SAD ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " HAPPY ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " HUNGRY ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " THIRSTY ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " BORED ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " ANNOYED ") <> 0 Then vrHalProfAssertion = ""
'------------------
' Avoid to catch phrases like "you are correct..." 
'------------------
If InStr(UserSentence, " CORRECT ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " RIGHT ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, " WRONG ") <> 0 Then vrHalProfAssertion = ""
'------------------
' Avoid to catch phrases like "you are going..." or "you are interested..."
'------------------
If InStr(UserSentence, "ING ") <> 0 Then vrHalProfAssertion = ""
If InStr(UserSentence, "ED ") <> 0 Then vrHalProfAssertion = ""
'------------------
' If it's an insult, I don't process it
'------------------
'vrOutRage = HalBrain.TopicSearch(UserSentence, "insulting")
'If Len(vrOutRage) > 1 And InStr(UserSentence, " NOT ") = 0 Then vrHalProfAssertion = ""
' The following statement is more powerful: Thanks to Grant for this advice!
If InsultResponse <> ""  Then vrHalProfAssertion = ""
'------------------
' Check the user assertion
'------------------
If vrHalProfAssertion <> "" Then
   vrAnswer = ""
   vrKeywords = HalBrain.RemoveExtraSpaces(HalBrain.ExtractKeywords(" " & vrHalProfAssertion & " "))
   vrKeywordList = Split(vrKeywords, " ")
   If Len(vrKeywords) > 2 Then
' I start reading from the last keyword, assuming that this is a noun and the other are adjectives
      For i = Ubound(vrKeywordList) To Lbound(vrKeywordList) Step (-1)
' Avoid to catch long sentences
'        If Ubound(vrKeywordList) > 2 Then Exit For
           vrHalFoundCode = ""
          vrHalCode      = ""
             vrHalKeyWord   = ""
            vrHalKeyCode   = ""
           If HalBrain.RunQuery("SELECT searchString, topic FROM vrHalProfile WHERE searchString = " & """" & vrKeywordList(i) & """" , vrHalQuery) = True Then
             vrHalFoundWord = Trim(vrHalQuery(1, 0)) 'Row 1 contains our query result. Column 0 contains "searchString", which is the word
             vrHalFoundCode = Trim(vrHalQuery(1, 1)) 'Row 1, Column 1 contains "topic", which is the associated code
          End If
           If vrHalFoundCode <> "" Then
               vrHalProfList = Split(vrHalFoundCode, ",")
               If Len(vrHalFoundCode) > 2 Then
                  vrHalCode = vrHalProfList(0)
                   vrHalKeyWord = vrHalProfList(1)
                  vrHalKeyCode = vrHalProfList(2)
               Else
                  vrHalCode = Left(vrHalFoundCode,2)
             End If
          End If
'------------------
' Prepare the appropriate answer
'------------------
           Select Case vrHalCode
                     Case "TT"
                       If vrAnswer = "" Then 
                     vrAnswer = "X"
                      If vrNegative = "" Then
                        GetResponse = "Yes, I already knew that I am " & vrArticle & vrKeywordList(i) & ". You told me that. "
                   Else
                        GetResponse = "No, I am " & vrKeywordList(i) & vrArticle & ". You told me that. " 
                   End If                   
                 End If 
                  Case "FF"
                       If vrAnswer = "" Then
                     vrAnswer = "X" 
                      If vrNegative = "" Then
                        GetResponse = "No, I am not " & vrArticle & vrKeywordList(i) & ". You told me that. " 
                   Else
                        GetResponse = "Yes, I already knew that I am not " & vrArticle & vrKeywordList(i) & ". You told me that. "
                   End If                   
                 End If 
                  Case "DT"
                       If vrAnswer = "" Then 
                     vrAnswer = "X" 
                      If vrNegative = "" Then ' it's true and the user said the same
                          If vrHalKeyCode = "TT" Then
                               GetResponse = "Yes, I am " & vrArticle & vrKeywordList(i) & "; I understood that, because you told me that I am " & vrHalKeyWord 
                        Else
                               GetResponse = "Yes, I must be " & vrArticle & vrKeywordList(i) & " since you told me that I am not " & vrHalKeyWord 
                        End If
                   Else                    ' it's true but the user said the opposite
                          If vrHalKeyCode = "TT" Then
                               GetResponse = "No, I am " & vrArticle & vrKeywordList(i) & "; I understood that, because you told me that I am " & vrHalKeyWord 
                        Else
                               GetResponse = "No, I am " & vrArticle & vrKeywordList(i) & " since you told me that I am not " & vrHalKeyWord 
                        End If
                   End If                   
                 End If 
                  Case "DF"
                       If vrAnswer = "" Then 
                     vrAnswer = "X" 
                      If vrNegative = "" Then ' it's false but the user said it's true
                            If vrHalKeyCode = "TT" Then
                               GetResponse = "No, I can't be "  & vrArticle & vrKeywordList(i) & " since you told me that I am " & vrHalKeyWord & "!" 
                        Else
                               GetResponse = "No, I am not " & vrArticle & vrKeywordList(i) & ". I understood that, because you told me that I am not " & vrHalKeyWord 
                        End If
                   Else                    ' it's false and the user said the same
                            If vrHalKeyCode = "TT" Then
                               GetResponse = "You are right, I already knew that I am not " & vrArticle & vrKeywordList(i) & " since you told me that I am a " & vrHalKeyWord & "!" 
                        Else
                               GetResponse = "Sure, I already knew that I am not " & vrArticle & vrKeywordList(i) & ". I understood that, because you told me that I am not a " & vrHalKeyWord 
                        End If
                   End If                   
                 End If 
                  Case ""
'------------------
' If it's a new parameter, I check that...
'------------------
' ...it must exist in WordNet Dictionary
' ...it must not be a number
                       If WN.LookupWord(vrKeywordList(i)) = True And HalBrain.IsWordNumber(vrKeywordList(i)) = False Then 
' ...it must be an Adjective or Noun
                     vrNounAdj = ""
                     If WN.IsNoun() = True Then vrNounAdj = "NOUN"
                     If WN.IsAdj()  = True Then vrNounAdj = "ADJ"
' ...if the word is both an Adjective and a Noun, I assume that the last word
' of the sentence is a noun and the others are adjective
                     If ( WN.IsNoun() = True And WN.IsAdj()  = True ) Then
                        If i = Ubound(vrKeywordList) Then
                           vrNounAdj = "NOUN"
                        Else
                           vrNounAdj = "ADJ"
                             End If                     
                          End If                     
'------------------
' I add the keyword
'------------------
                        If vrNegative = "" Then
                             vrHalKeyCode = "TT"
                       Else
' The negation applies only to the first word
' i.e.: "you are not a rude girl" -> only "rude" must be negative
'       " you are not a girl"     -> "girl" must be negative
                             If i = 0 Then 
                                vrHalKeyCode = "FF"
                             Else
                                vrHalKeyCode = "TT"
                       End If
                     End If                   
                       If LearningLevel <> 0 Then 
                          HalBrain.AddToTable "vrHalProfile", "TopicSearch", Ucase(Trim(vrKeywordList(i))), vrHalKeyCode
                          vrKey = "," & vrKeywordList(i) & "," & vrHalKeyCode 
                                  If vrAnswer = "" Then 
                              If vrNegative = "" Then
                              GetResponse = "Thanks for teaching me that I am " & vrArticle & vrKeywordList(i) 
                         Else
                              GetResponse = "Now I absolutely know that I am not " & vrArticle & vrKeywordList(i) 
                            End If                   
                            End If                   
                           End If                   
                  End If                   
'------------------
' Now I add the relationships based on wordnet synonyms
'------------------
' First I read all the words
                  vrRelationships = ""
                  vrMaxSenses = ""
                  vrMaxSenses = WN.GetNumSenses(vrNounAdj)
                  For h = 1 To vrMaxSenses                       
                          vrRelationships = vrRelationships & WN.GetDefinition(vrNounAdj, h, "S") & "," & WN.GetSynonyms(vrNounAdj, h) & ","
                  Next
                       vrRelationships = Replace(vrRelationships, ", ", ",")
                       vrRelationships = Trim(Replace(vrRelationships, ",,", ","))
                       If Right(vrRelationships, 1) = "," Then vrRelationships = Trim(Left(vrRelationships, Len(vrRelationships) - 1))
                       If Len(vrRelationships) > 1 Then
                          If Left(vrRelationships, 1) = "," Then vrRelationships = Right(vrRelationships, Len(vrRelationships) - 1)
' Then I create an array of words
                          vrRelList = Split(vrRelationships, ",")
' I save only the first words
                          vrCounter = 0
                          For h = Lbound(vrRelList) To Ubound(vrRelList)
                     If vrCounter > 3 Then Exit For
                             If Len(Trim(vrRelList(h))) > 2 Then 
' If it already exists, skip it
                              If HalBrain.TopicSearch(vrRelList(h), "vrHalProfile") = "" Then
' It must exist in WordNet Dictionary
                                 If WN.LookupWord(vrRelList(h)) = True Then
                                    vrCounter = vrCounter + 1
                                    If vrNegative = "" Then
                                       vrHalCode = "DT"
                               Else
' The negation does not apply to the last word
' i.e.: "you are not a rude girl" -> only "rude" must be negative
                                       If i = 0 Then 
                                          vrHalCode = "DF"
                                       Else
                                          vrHalCode = "DT"
                                 End If
                              End If
                               If LearningLevel <> 0 Then HalBrain.AddToTable "vrHalProfile", "TopicSearch", Ucase(Trim(vrRelList(h))), vrHalCode & vrKey
                           End If
                              End If
                            End If
                          Next
'------------------
' Now I add the opposite relationships based on wordnet antonyms
' same comments as for synonyms; but I put less filters because it seems to work better
'------------------
                   WN.LookupWord(vrKeywordList(i))
                  vrRelationships = ""
                  For h = 1 To 5
                          vrRelationships = vrRelationships & WN.GetAntonyms("NOUN", 1) & "," & WN.GetAntonyms("ADJ", 1) & ","
                  Next
' for some reason, Antonyms are supplied in parentheses
                       vrRelationships = Replace(vrRelationships, "(", "")
                       vrRelationships = Replace(vrRelationships, ")", "")
                       vrRelationships = Replace(vrRelationships, ", ", ",")
                       vrRelationships = Trim(Replace(vrRelationships, ",,", ","))
                       If Len(vrRelationships) > 1 Then
' Then I create an array of words
                          vrRelList = Split(vrRelationships, ",")
' I save only the first words
                          vrCounter = 0
                          For h = Lbound(vrRelList) To Ubound(vrRelList)
                     If vrCounter > 3 Then Exit For
                             If Len(Trim(vrRelList(h))) > 2 Then 
' If it already exists, skip it
                              If HalBrain.TopicSearch(vrRelList(h), "vrHalProfile") = "" Then
' It must exist in WordNet Dictionary
                                 If WN.LookupWord(vrRelList(h)) = True Then
                                    vrCounter = vrCounter + 1
                                    If vrNegative = "" Then
                                       vrHalCode = "DF"
                               Else
' The negation does not apply to the last word
' i.e.: "you are not a rude girl" -> only "rude" must be negative
                                       If i = 0 Then 
                                          vrHalCode = "DT"
                                       Else
                                          vrHalCode = "DF"
                                 End If
                              End If
                                    If LearningLevel <> 0 Then HalBrain.AddToTable "vrHalProfile", "TopicSearch", Ucase(Trim(vrRelList(h))), vrHalCode & vrKey
                            End If                   
                              End If
                            End If
                          Next
                        End If
                    End If
            End Select
       Next
    End If
End If
'--------------------------------------------------
' SYLLOGISM MANAGEMENT
'--------------------------------------------------
'In traditional logic, a syllogism is an inference in which one proposition (the conclusion) 
'follows of necessity from two others (known as premises). 
'The definition is traditional, but is derived loosely from Aristotle's Prior Analytics, Book I, c. 1. 
'The Greek "sullogismos" means "deduction".
'Syllogisms consist of three things: 
'major premise, minor premise, and conclusion, which follows logically from the major and the minor. 
'A major is a general principle. A minor is a specific statement. 
'Logically, the conclusion follows from applying the major to the minor.
'Every man is mortal. (general principle). 
'Socrates is a man. (specific statement). 
'Therefore Socrates is mortal. [substitution of specific(minor) into general(major)]. 
'------------------
' If the vrMajor table does not exist, then I create it
'------------------
If HalBrain.CheckTableExistence("vrMajor") = False Then
   HalBrain.CreateTable "vrMajor", "TopicSearch", "miscData"
End If
'------------------
' If the vrMinor table does not exist, then I create it
'------------------
If HalBrain.CheckTableExistence("vrMinor") = False Then
   HalBrain.CreateTable "vrMinor", "TopicSearch", "miscData"
End If
'------------------
' Check if the question is a major premise
'------------------
vrMajor1 = ""
vrMajor2 = ""
If vrMajor1 = "" Then vrMajor1 = HalBrain.SearchPattern(UserSentence, "EVERY * IS A *", 1)
If vrMajor1 = "" Then vrMajor1 = HalBrain.SearchPattern(UserSentence, "EVERY * IS AN *", 1)
If vrMajor1 = "" Then vrMajor1 = HalBrain.SearchPattern(UserSentence, "ANY * IS A *", 1)
If vrMajor1 = "" Then vrMajor1 = HalBrain.SearchPattern(UserSentence, "ANY * IS AN *", 1)
If vrMajor1 = "" Then vrMajor1 = HalBrain.SearchPattern(UserSentence, "EVERY * IS *", 1)
If vrMajor1 = "" Then vrMajor1 = HalBrain.SearchPattern(UserSentence, "ANY * IS *", 1)
If vrMajor1 <> "" Then 
   If vrMajor2 = "" Then vrMajor2 = HalBrain.SearchPattern(UserSentence, "EVERY * IS A *", 2)
   If vrMajor2 = "" Then vrMajor2 = HalBrain.SearchPattern(UserSentence, "EVERY * IS AN *", 2)
   If vrMajor2 = "" Then vrMajor2 = HalBrain.SearchPattern(UserSentence, "ANY * IS A *", 2)
   If vrMajor2 = "" Then vrMajor2 = HalBrain.SearchPattern(UserSentence, "ANY * IS AN *", 2)
   If vrMajor2 = "" Then vrMajor2 = HalBrain.SearchPattern(UserSentence, "EVERY * IS *", 2)
   If vrMajor2 = "" Then vrMajor2 = HalBrain.SearchPattern(UserSentence, "ANY * IS *", 2)
End If
'------------------
' I check that the two words exist in WordNet Dictionary, must not be a number and must be an Adjective or Noun
'------------------
If WN.LookupWord(vrMajor1) = True And HalBrain.IsWordNumber(vrMajor1) = False And WN.IsNoun() = True And WN.LookupWord(vrMajor2) = True And HalBrain.IsWordNumber(vrMajor2) = False And ( WN.IsNoun() = True Or WN.IsAdj() = True ) Then
'------------------
' I store the major premise in the table
'------------------
   vrFound = ""
   vrFound = HalBrain.TopicSearch(Ucase(vrMajor1), "vrMajor")
   If vrFound = "" Then
        If LearningLevel <> 0 Then HalBrain.AddToTable "vrMajor", "TopicSearch", Ucase(Trim(vrMajor1)), vrMajor2
        GetResponse = "Now I know that every " & vrMajor1 & " is " & vrMajor2 & "."
   Else
      If vrMajor2 = vrFound Then
          GetResponse = "I already knew that " & vrMajor1 & " is " & vrFound  & ". "
      Else
         GetResponse = "No. I knew that " & vrMajor1 & " is " & vrFound  & ". "
      End If
    End If
End If
'------------------
' Check if the question is a minor premise
'------------------
vrMinor1 = ""
vrMinor2 = ""
vrQuesWord = ""
'------------------
' Filter out some other types of questions
'------------------
If InStr(UserSentence, " WHO ") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "WHO'") > 0         Then vrQuesWord = "X"
If InStr(UserSentence, " WHAT ") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "WHAT'") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, " WHEN ") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "WHEN'") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, " WHERE ") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "WHERE'") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, " HOW ") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "HOW'") > 0         Then vrQuesWord = "X"
If InStr(UserSentence, " WHY ") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "WHY'") > 0         Then vrQuesWord = "X"
If InStr(UserSentence, "EVERY") > 0      Then vrQuesWord = "X"
If InStr(UserSentence, "ANY") > 0         Then vrQuesWord = "X"
If vrQuesWord = "" Then 
   If vrMinor1 = "" Then vrMinor1 = HalBrain.SearchPattern(UserSentence, "* IS A *", 1)
   If vrMinor1 = "" Then vrMinor1 = HalBrain.SearchPattern(UserSentence, "* IS AN *", 1)
   If vrMinor1 = "" Then vrMinor1 = HalBrain.SearchPattern(UserSentence, "* IS *", 1)
   If vrMinor1 <> "" Then 
        If vrMinor2 = "" Then vrMinor2 = HalBrain.SearchPattern(UserSentence, "* IS A *", 2)
        If vrMinor2 = "" Then vrMinor2 = HalBrain.SearchPattern(UserSentence, "* IS AN *", 2)
        If vrMinor2 = "" Then vrMinor2 = HalBrain.SearchPattern(UserSentence, "* IS *", 2)
   End If
'------------------
' I check that the second word exist in WordNet Dictionary, must not be a number and must be an Adjective or Noun
' The first one can be a proper name (i.e. Socrates)
'------------------
   If HalBrain.IsWordNumber(vrMinor1) = False And WN.LookupWord(vrMinor2) = True And HalBrain.IsWordNumber(vrMinor2) = False And ( WN.IsNoun() = True Or WN.IsAdj() = True ) Then
'------------------
' Check if the minor2 premise is already available in the Major table
'------------------
      vrFound = ""
      vrFound = HalBrain.TopicSearch(Ucase(vrMinor2), "vrMajor")
      If vrFound <> "" Then 
'------------------
' Check if the minor1 premise is already available in the Minor table
'------------------
         vrFoundMinor = ""
         vrFoundMinor = HalBrain.TopicSearch(Ucase(vrMinor1), "vrMinor")
        If vrFoundMinor = "" Then
             If LearningLevel <> 0 Then HalBrain.AddToTable "vrMinor", "TopicSearch", Ucase(Trim(vrMinor1)), vrMinor2
           GetResponse = ". Every " & vrMinor2 & " is " & vrFound & ". " & vrMinor1 & " is " & vrMinor2 & " . Therefore " & vrMinor1 & " is " & vrFound & ". "
            vrToBeProcessed = True
         Else
            If vrMinor2 = vrFoundMinor Then
              GetResponse = "Yes. I already know that " & vrMinor1 & " is " & vrFoundMinor & ". Every " & vrMinor2 & " is " & vrFound & ". " & vrMinor1 & " is " & vrMinor2 & " . Therefore " & vrMinor1 & " is " & vrFound & ". "
               vrToBeProcessed = True
         Else           
              GetResponse = "No. I know that " & vrMinor1 & " is " & vrFoundMinor & ". "
               vrToBeProcessed = False
         End If
        End If      
'------------------
' Check if the major premise is a minor premise of other major premises
'------------------
        If vrToBeProcessed = True Then
'Go through a maximum of 5 connections (prevents circular reasoning deductions)
          vrLastGoodDeduction = ""
          vrAssertion = vrFound
          For j = 1 To 5
               vrDeduction = HalBrain.TopicSearch(vrAssertion, "vrMajor")
               If vrDeduction <> "" Then
                  Select Case j
                    Case 1
                    GetResponse = GetResponse & " But I also know that every " & vrAssertion & " is " & vrDeduction & ". "
                   Case 2
                    GetResponse = GetResponse & " And you taught me that any " & vrAssertion & " is " & vrDeduction & ". "
                   Case 3
                    GetResponse = GetResponse & " Furthermore, I have learned that every " & vrAssertion & " is " & vrDeduction & ". "
                   Case 4
                    GetResponse = GetResponse & " From my conversations, I remember that any " & vrAssertion & " is " & vrDeduction & ". "
                   Case 5
                    GetResponse = GetResponse & " I suppose that every " & vrAssertion & " is " & vrDeduction & ". "
                End Select
                    vrLastGoodDeduction = vrDeduction
                    vrAssertion = vrDeduction
                Else
               If j > 1 Then
                   GetResponse = GetResponse & " So I can state that " & vrMinor1 & " is " & vrLastGoodDeduction & " . " & vbCrLf
               End If
                   Exit For 'No more connections, so no need to continue loop
                End If
             Next
         End If
      End If
   End If
End If
'------------------
' Set ReadOnly Mode to its previous state
'------------------
If GetResponse = "" Then 
   HalBrain.ReadOnlyMode = vrReadOnlyMode
Else
   HalBrain.ReadOnlyMode = True
End If