Question

Total noob when it comes to using AIML and having a really hard time getting this set up for an asp.net mvc webpage. I have a basic view setup that the user can enter a message in a textbox and I'm trying to get the chatbot to return a response. I've gotten that interaction to work with my text case so I know the function is correctly getting the users response and that I can send back a response and show it in the chatbox, my problem is trying to setup the chatbot to create dynamic responses. Right now in my controller I have:

    String filePath = Server.MapPath("~/aimlBot/aiml/");
    ChatBot catbot = new ChatBot(filePath);
    string ReturnText = catbot.GetOutput(text); //text is just a string no html or fancy stuff in it

and my ChatBot class

    Public class ChatBot : Bot
    {
        private Bot myBot;
        private User myUser;

        public ChatBot(string filepath)
        {
            myBot = new Bot();
            myUser = new User("Human", myBot);
            Initialize(filepath);
        }

        private void Initialize(string filepath)
        {
            AIMLbot.Utils.AIMLLoader loader = new AIMLbot.Utils.AIMLLoader(this.myBot);
            myBot.isAcceptingUserInput = false;
            loader.loadAIML(filepath);          
            myBot.isAcceptingUserInput = true;
        }

        public String GetOutput(String input)
        {
            Request r = new Request(input, myUser, myBot);
            Result res = myBot.Chat(r); //breaks here
            string response = "Bot: " + res.Output;
            return (response);
        }
    }

the problem I'm getting is at the Result res = myBot.Chat(r); the program throws a FormatException

    System.FormatException was unhandled by user code
    Message=Input string was not in a correct format.
    Source=mscorlib
    StackTrace:
    at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
    at System.Convert.ToDouble(String value)
    at AIMLbot.Bot.get_TimeOut()
    at AIMLbot.Utils.Node.evaluate(String path, SubQuery query, Request request, MatchState matchstate, StringBuilder wildcard)
    at AIMLbot.Bot.Chat(Request request)
    at Ira.aimlBot.ChatBot.GetOutput(String input) in C:\Users\Ira\Documents\Visual Studio 2010\Projects\Ira\Ira\aimlBot\ChatBot.cs:line 36
    at Ira.Controllers.ARGController.Speak(String text) in C:\Users\Ira\Documents\Visual Studio 2010\Projects\Ira\Ira\Controllers\ARGController.cs:line 35
    at lambda_method(Closure , ControllerBase , Object[] )
    at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
    at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
    InnerException: 

I have No idea what is wrong with my code. I've tried even changing it from the variable string to just a hardcode case like "Hello how are you" which still caused the same exception.

Was it helpful?

Solution

You have everything perfect except the loadSettings function. Please refer the below snippet to clear your problem!

public ChatBot(string filepath)
{
            myBot = new Bot();
            myBot.loadSettings(); // <----- You have to insert this line to fix the error!
            myUser = new User("Human", myBot);
            Initialize(filepath);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top