1
當使用AIML並且很難將這個設置成一個asp.net mvc網頁時,總noob會發生這種情況。我有一個基本的視圖設置,用戶可以在文本框中輸入消息,我試圖讓chatbot返回響應。我已經獲得了與我的文本案例的交互,所以我知道該函數正確地獲取用戶響應,並且我可以發回回覆並將其顯示在聊天箱中,我的問題是試圖設置chatbot以創建動態響應。現在在我的控制,我有:在asp.net MVC中設置AIML(FormatException錯誤)
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);
}
}
,我發現了問題出在 結果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:
我不知道什麼是錯我的代碼。我試過甚至把它從變量字符串改爲只是一個硬編碼的例子,比如「你好嗎?」,它仍然導致了相同的異常。