如何在 java 中制作虚拟聊天机器人?

how to make an virtual chat bot in java?

我想在Java中制作一个聊天机器人,但我不知道如何开始? 我已经尝试了以下代码,但没有得到我真正需要的。 在这个程序中,我必须写下所有可能的问题。 如果有人有解决办法请帮助我。

import java.io.*;

public class Chatbot 
{
public static void main(String[]args) throws IOException
{
    String hel = new String("Hello");
    String hel1 = new String("HELLO");
    String hel2 = new String("hello");
    String hel3 = new String("Hii");
    String hel4 = new String("Hiii");
    String hel5 = new String("hii");
    String hel6 = new String("hiii");

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("What is Your Name?");
        String name = br.readLine();
        System.out.println("Hello "+name+"..");
        String hellorep = br.readLine();
        if(hellorep .equals(hel))
        {
            System.out.println("Hello there...");
        }
        else if(hellorep .equals(hel1))
        {
            System.out.println("Hello there...");
        }
        else if(hellorep .equals(hel2))
        {
            System.out.println("Hello there...");
        }
        else if(hellorep .equals(hel3))
        {
            System.out.println("Hii");
        }
        else if(hellorep .equals(hel4))
        {
            System.out.println("Hiii");
        }
        else if(hellorep .equals(hel5))
        {
            System.out.println("Hii");
        }
        else if(hellorep .equals(hel6))
        {
            System.out.println("Hiii");
        }
        else
        {
            System.out.println("Please type Again I Didn't get you..");
        }
    }
}

如果你想用 window 做这个,你可以使用 jtextfield 并向它添加一个动作监听器,如果你想用控制台做这个,那么使用输入

然后获取消息,也就是将其存储在变量中,然后在您的响应方法中执行此操作

if(STRINGVARIABLENAME.contains("Your word that you want it to check if it contains")) { then make the bot respond by Console or just do JTEXTFIELDNAME.setText("ANSWER HERE") }

并通过像这样在 if 之后执行 else if 来添加尽可能多的响应可能性

if(){ } else if(STRINGVARIABLENAME.contains("")){ }

您可以多次执行此操作,这样您就有了聊天机器人 :D