Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么不是';在我的C#WPF聊天机器人中找不到我的输入?_C#_Wpf_Formatexception_Chatbot_Aiml - Fatal编程技术网

为什么不是';在我的C#WPF聊天机器人中找不到我的输入?

为什么不是';在我的C#WPF聊天机器人中找不到我的输入?,c#,wpf,formatexception,chatbot,aiml,C#,Wpf,Formatexception,Chatbot,Aiml,我正试图创建一个聊天机器人的代码为基础的控制台机器人位于 当我输入一个输入后运行程序时,我遇到了一个异常:“没有发生格式异常 已处理的“”输入字符串格式不正确。在第行的“alice”类中: Result result = myBot.Chat(request); 请求似乎返回null。有人能帮我弄清楚为什么在AIML文件中找不到我的输入和/或为什么它返回null吗 以下是主要课程: using System; using System.Collections.Generic; using Sy

我正试图创建一个聊天机器人的代码为基础的控制台机器人位于

当我输入一个输入后运行程序时,我遇到了一个异常:“没有发生格式异常 已处理的“”输入字符串格式不正确。在第行的“alice”类中:

Result result = myBot.Chat(request);
请求似乎返回null。有人能帮我弄清楚为什么在AIML文件中找不到我的输入和/或为什么它返回null吗

以下是主要课程:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AIMLbot;

namespace Chatbot
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        String userInput = null;
        alice myAlice = new alice();
        public MainWindow()
        {
            InitializeComponent();
        }

        private void inputButtonClick(object sender, RoutedEventArgs e)
        {
            userInput = inputTextBox.Text;
            outPutTextBlock.Text = myAlice.getOutput(userInput);
            inputTextBox.Text = "";
            userInput = null;
        }
    } 
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用AIMLbot;
名称空间聊天机器人
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
字符串userInput=null;
alice myAlice=新的alice();
公共主窗口()
{
初始化组件();
}
private void inputButtonClick(对象发送方,路由目标)
{
userInput=inputTextBox.Text;
outPutTextBlock.Text=myAlice.getOutput(userInput);
InputExtBox.Text=“”;
userInput=null;
}
} 
}
以下是“alice”类代码:

//Written by Matt Gonzalez
//with help from Nicholas H.Tollervey's ConsoleBot2.5
//and AIML base files from the A.L.I.C.E Bot project

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AIMLbot;

namespace Chatbot
{
    class alice
    {
        private Bot myBot;
        private User myUser;

        /// <summary> 
        /// Create a new instance of the ALICE object 
        /// </summary>

        public alice()
        {
            myBot = new Bot();
            myUser = new User("consoleUser", myBot);
        }

        /// <summary> 
        /// This initialization can be put in the alice() method 
        /// but I kept it seperate due to the nature of my program. 
        /// This method loads all the AIML files located in the \AIML folder 
        /// </summary>

        public void Initialize()
        {
            myBot.loadSettings();
            myBot.isAcceptingUserInput = false;
            myBot.loadAIMLFromFiles();
            myBot.isAcceptingUserInput = true;
        }

        /// <summary> 
        /// This method takes an input string, then finds a response using the the AIMLbot
        /// library and returns it 
        /// </summary> 
        /// <param name="input">Input Text</param> 
        /// <returns>Response</returns>

        public String getOutput(String input)
        {
            Request request = new Request(input, myUser, myBot);
            Result result = myBot.Chat(request);
            return (result.Output);
        }
    }

}
//马特·冈萨雷斯撰写
//在尼古拉斯·H·托勒维的控制台2.5的帮助下
//和来自A.L.I.C.E Bot项目的AIML基本文件
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用AIMLbot;
名称空间聊天机器人
{
爱丽丝班
{
私人Bot-myBot;
私人用户myUser;
///  
///创建ALICE对象的新实例
/// 
公众谘询委员会()
{
myBot=新Bot();
myUser=新用户(“控制台用户”,myBot);
}
///  
///这个初始化可以放在alice()方法中
///但是由于我的程序的性质,我把它分开了。
///此方法加载\AIML文件夹中的所有AIML文件
/// 
公共无效初始化()
{
myBot.loadSettings();
myBot.isAcceptingUserInput=false;
myBot.loadAIMLFromFiles();
myBot.isAcceptingUserInput=true;
}
///  
///此方法获取输入字符串,然后使用AIMLbot查找响应
///并返回它
///  
///输入文本
///回应
公共字符串getOutput(字符串输入)
{
请求=新请求(输入,myUser,myBot);
结果=myBot.Chat(请求);
返回(结果输出);
}
}
}
下面是XAML:

<Window x:Name="chatBotWindow" x:Class="Chatbot.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Chat Bot" Height="480" Width="640" Background="White">
    <Grid x:Name="chatBotMainGrid" Background="#FFE6E6E6">
        <TextBox x:Name="inputTextBox" HorizontalAlignment="Left" Height="25"
             Margin="149,83,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="353" 
             BorderBrush="Black"/>
        <Label x:Name="inputTextLabel" Content="Input Text: " HorizontalAlignment="Left"
             Height="25" Margin="53,83,0,0" VerticalAlignment="Top" Width="96" 
             FontFamily="Neuropol" FontSize="14"/>
        <TextBlock x:Name="outPutTextBlock" HorizontalAlignment="Left" Height="290"
             Margin="149,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" 
               Width="358"><InlineUIContainer>
                <Border x:Name="outputBorder" BorderBrush="Red" BorderThickness="1"
                          Height="272" Width="355" Background="White">
                <ScrollBar x:Name="outPutScrollBar" HorizontalAlignment="Left"
                                Height="272" Margin="337,-1,-1,-1" VerticalAlignment="Top"
                                Width="10" BorderBrush="Red"/>
                </Border>
            </InlineUIContainer></TextBlock>
        <Button x:Name="inputButton" Content="Enter" HorizontalAlignment="Left" Height="25"
             Margin="507,83,0,0" VerticalAlignment="Top" Width="76" 
             FontFamily="Neuropol" FontSize="16" Click="inputButtonClick">
            <Button.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="White" Offset="0"/>
                        <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                        <GradientStop Color="#FFC5BCBC" Offset="0.5"/>
                        <GradientStop Color="Red" Offset="1"/>
                    </LinearGradientBrush>
            </Button.Background>
        </Button>
        <Label x:Name="titleLabel" Content="Tony's Chat Bot" HorizontalAlignment="Left"
             Height="49" Margin="221,29,0,0" VerticalAlignment="Top" 
            Width="203" FontFamily="Arnprior" FontSize="20"/>
    </Grid>
</Window>

您好,我已经根据提供的代码运行了您的程序。您的问题与wpf无关。这与alice.Initialize()方法有关。根本不调用它。如果在“getOutput”之前调用它,则所有操作都有效。为了测试的目的,我把它放进了电脑里

    public alice()
    {
        myBot = new Bot();
        myUser = new User("consoleUser", myBot);
        Initialize();
    }

我试着像这样测试它,但现在当我运行时,我得到了一个新的异常。发生XAML解析异常。源不可用:对与指定绑定约束匹配的类型“Chatbot.MainWindow”调用构造函数时引发异常。“行号“3”和行位置“9”。“是否有“aiml”和“config”根据此示例,您的调试/发布文件夹下的文件夹:我缺少配置文件夹。你说得对。现在效果很好!