1

在使用 AIML 并且很难为 asp.net mvc 网页设置此设置时,完全是菜鸟。我有一个基本的视图设置,用户可以在文本框中输入一条消息,我试图让聊天机器人返回一个响应。我已经让这种交互与我的文本案例一起工作,所以我知道该功能正确地获得了用户响应,并且我可以发回响应并将其显示在聊天框中,我的问题是尝试设置聊天机器人以创建动态响应. 现在在我的控制器中,我有:

    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

和我的聊天机器人课

    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);
        }
    }

我遇到的问题是 Result res = myBot.Chat(r); 程序抛出 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: 

我不知道我的代码有什么问题。我什至尝试将其从变量字符串更改为硬编码情况,例如“你好,你好吗”,但仍然导致相同的异常。

4

1 回答 1

2

除了loadSettings功能,您拥有一切完美的东西。请参考以下代码段来解决您的问题!

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);
}
于 2012-09-02T18:48:07.603 回答