【问题标题】:how to make an virtual chat bot in java? [closed]如何在java中制作一个虚拟聊天机器人? [关闭]
【发布时间】:2016-05-15 19:05:32
【问题描述】:

我想用 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..");
        }
    }
}

【问题讨论】:

    标签: java chat bots chatbot aiml


    【解决方案1】:

    如果你想用一个窗口来做这个,你可以使用一个 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

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 2019-11-23
      • 2020-04-09
      • 1970-01-01
      相关资源
      最近更新 更多