Jump to content

Hello. Question here, not language specific idk if that's important. (i only know visual basic at the moment from school :/ but I'm learning c#). If I'm making an AI type program kind of like cleverbot i guess, rather than using a million if then statements, how could i make it so i could just type something in and then what response it should give back? Like how could i make a program where I could create the structure for a conversation and it would create and save the if then statements for me? Idk if this is making any sense sorry. Hopefully it does. I'm probably going to use c# but i might just use vb just to test out the concept of it and then move over to learning it on c# once i know how to do it. Thanks for any help in advance.

Just a normal guy with a constant desire to modify everything he owns. 

Check out my current build here:

https://linustechtips.com/main/topic/1006447-the-cake-is-a-lie-water-cooled-portal-pc/

 

Link to comment
https://linustechtips.com/topic/479238-how-would-i-do-this/
Share on other sites

Link to post
Share on other sites

so you want to make a program that you would type hello how are you and it would reply with I'm okay or are you after a program that will reply back with present text no matter what is said to it so you would say go away and it would reply with hello how are you 

Case:- 4U Rack Mount Case | Cooler:- Antec Kuhler H600 | CPU:- Intel i5 4690K @ 4.50GHz GPU:- Zotac GeForce GTX 970 4GB AMP! Omega Core Edition @ 1449MHz | Motherboard:- MSI Z97S SLI Krait | PSU:- XFX XTR 650W Gold | RAM:- HyperX DDR3 1866MHz 4GB White (x2) Black (x2) | Storage:- Kingston V300 120GB | Storage 2:- Seagate FireCuda 1TB | Build Log |

 

 

 

Link to comment
https://linustechtips.com/topic/479238-how-would-i-do-this/#findComment-6426942
Share on other sites

Link to post
Share on other sites

so you want to make a program that you would type hello how are you and it would reply with I'm okay or are you after a program that will reply back with present text no matter what is said to it so you would say go away and it would reply with hello how are you

The first one. Like it would respond differently depending on what i say. I know i could just do that with a ton of if then statements but how could i make it so i could type them in and hit enter and it would create the if then statements for me rather than typing them all out myself?

Just a normal guy with a constant desire to modify everything he owns. 

Check out my current build here:

https://linustechtips.com/main/topic/1006447-the-cake-is-a-lie-water-cooled-portal-pc/

 

Link to comment
https://linustechtips.com/topic/479238-how-would-i-do-this/#findComment-6427037
Share on other sites

Link to post
Share on other sites

Is this what you're looking for (VB):

Select Case inputString     Case "hello"          Your code here

Much simpler, it takes the input variable and then you just write "case" and whatever you're checking for.

˙ǝɯᴉʇ ɹnoʎ ƃuᴉʇsɐʍ ǝɹɐ noʎ 'sᴉɥʇ pɐǝɹ oʇ ƃuᴉʎɹʇ ǝɹɐ noʎ ɟI

Link to comment
https://linustechtips.com/topic/479238-how-would-i-do-this/#findComment-6427073
Share on other sites

Link to post
Share on other sites

A very simple solution could be to create key-value pairs in a file, where the key is the user's input and the value is the bot's response. Your application could read in the key-value pairs and store them in a Dictionary (if using C#). You could then ask the user for input, look up the input in the Dictionary and print the response.

 

Here's my quick implementation:

class Program{    static void Main(string[] args)    {        Dictionary<string, string> responses = LoadResponses("responses");        string userInput;        while (!(userInput = Console.ReadLine()).Equals("exit"))        {            Console.WriteLine(responses[userInput]);        }    }    static Dictionary<string, string> LoadResponses(string filePath)    {        Dictionary<string, string> responses = new Dictionary<string, string>();        foreach (var line in File.ReadLines(filePath))        {            string[] inputAndResponse = line.Split('=');            responses[inputAndResponse[0]] = inputAndResponse[1];        }        return responses;    }}

Here's what my responses file contains:

Hello=Hello, how are you?I'm good thanks, how are you?=Can't complain
Link to comment
https://linustechtips.com/topic/479238-how-would-i-do-this/#findComment-6428039
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×