7 Replies - 1847 Views - Last Post: 11 June 2014 - 04:57 AM Rate Topic: -----

#1 datenziday  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Problems with creating chatbot in VB 2010

Posted 10 June 2014 - 12:19 AM

Hi so i have an assignment and decided to make a chatbot, now i want to make the bot display the pre-scripted sentence everytime my question contain a trigger word, for example if i ask it "who ____" then it will answer the sentence because "who" is the trigger word. For this i decided to use Select Case
  
Dim TestA as integer
Select Case TestA
    Case 1
      Label3.Text = "Hello, how are you today?"
    Case 2
      Label3.Text = "Greetings. What would you like to talk about?"
    Case 3
      Label3.Text = "How's your day"
    Case 4
      Label3.Text = "Do you have any questions?"
    Case 5
      Label3.Text = "Whenever you ready."
    Case Else
      Label3.Text = "Hello, what is your question?"
  End Select


but that code does not have the trigger function, so im having trouble creating 1, whats steps should i use to create this, i saw some code of this in VB 6.0 but i dont know how to rewrite it in 2010.
 Question = UCase(Question)

  Do ' This Do-Until loop keeps ELIZA from repeating herself
    Do
  
  ' Check for "How", "Who", "What", "When", "Why", or "Where" keywords
    If ((InStr(Question, "HOW")) > 0) Or ((InStr(Question, "WHO")) > 0) Or ((InStr(Question, "WHAT")) > 0) Or ((InStr(Question, "WHEN")) > 0) Or ((InStr(Question, "WHERE")) > 0) Or ((InStr(Question, "WHY")) > 0) Then
      Choice = CInt(9 * Rnd + 1)


this is what he used for VB 6.0, does anyone have any clues to write something similar to this that can check keywords in a sentence for VB 2010?
Thank you and have a good day

Is This A Good Question/Topic? 0
  • +

Replies To: Problems with creating chatbot in VB 2010

#2 Asskilled21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 20-October 12

Re: Problems with creating chatbot in VB 2010

Posted 10 June 2014 - 02:21 AM

I don't know if this will work but try something like this. Use The Function Contains In String

    Dim Str As String = "Write Something Here"
    If Str.Contains("Write") Then
       'Do Things In Here
    End If


Was This Post Helpful? 0
  • +
  • -

#3 datenziday  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Re: Problems with creating chatbot in VB 2010

Posted 10 June 2014 - 02:35 AM

you think that use parallel array to store keywords then iterate on loops would work?
Was This Post Helpful? -1
  • +
  • -

#4 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: Problems with creating chatbot in VB 2010

Posted 10 June 2014 - 05:19 AM

Try something with Regex. I wrote this to check if some process's were running or allowed to run, and have reworded it for you:

  Imports System.Text.RegularExpressions
        Private Function Word(ByVal EachWord As String) As Boolean
        Dim Disallowed As New Regex("skype|devenv|explorer|SomeWord")'Put the words you want to check here.
        If Disallowed.IsMatch(EachWord) Then
            Return False 'If the word is not allowed its false.
        Else
            Return True 'And true if it is allowed.
        End If
    End Function


And you would use or call it something like this:

Dim MyWord As String = "SomeWord"
Dim MyString As String = ""
If Word(EachWord:=MyWord) = True Then

                                                
MyString = MyWord
'MyString = StrConv(ProcessName, VbStrConv.ProperCase) I used StrConv to convert the string case to proper case.

                                                End If


I am only awake, so i hope i wrote that correct. :)

This post has been edited by Sheepings: 10 June 2014 - 05:33 AM

Was This Post Helpful? 1
  • +
  • -

#5 datenziday  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Re: Problems with creating chatbot in VB 2010

Posted 10 June 2014 - 06:20 AM

 
Dim MyWord As String = "SomeWord"
Dim MyString As String = ""
If Word(EachWord:=MyWord) = True Then




Sorry but what can i put in this sentence
Was This Post Helpful? 0
  • +
  • -

#6 Sheepings  Icon User is offline

  • D.I.C Addict

Reputation: 73
  • View blog
  • Posts: 571
  • Joined: 05-December 13

Re: Problems with creating chatbot in VB 2010

Posted 10 June 2014 - 07:04 AM

I have reworded it and reordered the return options for you.

Private Function Word(ByVal EachWord As String) As Boolean
        Dim Question As New Regex("How|Who|What|Where|Why|When")'Put the words you want to check here.
        If Question.IsMatch(EachWord) Then' If Question contains one of the words in the Regular Expression above, it will return true.
            Return True'If the word is not one of the words in the Regular Expression, it will be false.
        Else
            Return False 'So the EachWord = to MyWord word was not found. 
        End If
    End Function


The method I have given you would be best used as a one word function. Ie. Change it like so:

Dim Question As New Regex("How|Who|What|Where|Why|When")
to Dim Question As New Regex("How") OR
Dim QuestionHow As New Regex("How")
Dim QuestionWho As New Regex("Who")
        

Now it will only check for one word so you can recreate the function over and over (Just change the function name) or add more if statements to check other words and send back return values. Regex will check against your string ' MyWord ':
Dim MyWord As String = "How"'This is the word you are checking to see if it was asked in the function. 
Dim MyString As String = ""

In the If Statement, I ask:
If Word(EachWord:=MyWord) = True Then'If the Word inside the String variable ' MyWord ' is in the Regular Expression, it will return true
MsgBox("You asked How, and I shall tell you how. :)/>")
Else'If it's not True, it will be false
MsgBox("How was not a question I was asked. :)/>")
End If


In my instance of If statement is the function returning true, then MyString would = MyWord
MyWord is the word you want to check in the function.
MyString is just a string to = another string. You can put whatever you like there.

Let me know if it works for you. Time for some coffee.
Was This Post Helpful? 0
  • +
  • -

#7 datenziday  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Re: Problems with creating chatbot in VB 2010

Posted 11 June 2014 - 04:50 AM

I have a couple of problems such as
- the code is check for the expression base on the regex
meaning the line:
 Dim Question as New Regex("How")

and
 Dim MyWord As String = "How" 

Must be the same and it will display the =True MgsBox if the 2 line expressions not the same,it will return Else MgsBox rather than it searching for what I am entering.
Was This Post Helpful? 0
  • +
  • -

#8 datenziday  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 10-June 14

Re: Problems with creating chatbot in VB 2010

Posted 11 June 2014 - 04:57 AM

So as long as the 2 line the same, whatever i enter will be irrelevant, i can enter a blank or meaningless sentence and it would still return true as long as the 2 line the same.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1