Skip to content

Building a response

toncho11 edited this page Jun 6, 2019 · 3 revisions

GetChance function

The GetChance() function applies the uniform distribution on a array of strings and it either returns one uniformly selected or it uses a parameter as in GetChance(3) which says that it should return true with 33% probability. Setting 2 gives 50% and 4 equals to 25%. GetChance() allows us to easily make a text has the same meaning or objective, but does not sound exactly the same every time the bot says it.

 string text = KorraModelHelper.GetChance(new string[] 
 {
          "How about this " + type + " " + movieName + "? I recommend it.", //1
          "I have a new " + type + " suggestion for you. It is called : " + movieName + ". You should try it.", //2
          (KorraModelHelper.GetChance(3) ? "Do you feel bored? " : "") + "I recommend you to watch the " + type + " " + movieName + ".", //3
          "Time for something interesting to watch. Try this one: " + movieName + ".", //4
          "You are going to like this " + type + ": " + movieName + ". I highly recommend it." //5
 });

Response function example

public string ProcessAge(string value, out bool isValid)
        {
            int result;
            isValid = Int32.TryParse(value, out result);

            if (!isValid)
            {
                return "Sorry, I could not get your age.";
            }

            if (isValid && result <= 10)
            {
                return "Wow, Aren't you a bit young?";
            }
            else if (isValid && result > 10 && result <= 19)
            {
                return "OK, a teenager.";
            }
            else if (isValid && result > 99)
            {
                return "No kidding... That sounds like a lot! Are you sure about that?";
            }

            return "";
        }
Clone this wiki locally