alicebot 包中的 'MagicBooleans'、'MagicStrings' 是什么?

What is 'MagicBooleans', 'MagicStrings' in alicebot package?

我找到了使用 AIML 和 Program-ab 分发的简单聊天机器人的代码。许多地方都使用了 MagicBooleans 和 MagicStrings。那些到底是什么?另外,我不明白什么是 trace_mode ? 我找到的代码如下-

import java.io.File;
import org.alicebot.ab.Bot;
import org.alicebot.ab.Chat;
import org.alicebot.ab.History;
import org.alicebot.ab.MagicBooleans;
import org.alicebot.ab.MagicStrings;
import org.alicebot.ab.utils.IOUtils;

public class ChatBot {
private static final boolean TRACE_MODE = false;
static String botName = "super";

public static void main(String[] args) {
    try {

       String resourcesPath = "/home/user/eclipse-workspace/myProject/src/main/resources";
       System.out.println(resourcesPath);

        MagicBooleans.trace_mode = TRACE_MODE;
        Bot bot = new Bot("super", resourcesPath);
        Chat chatSession = new Chat(bot);
        bot.brain.nodeStats();
        String textLine = "";

        while(true) {
            System.out.print("Human : ");
            textLine = IOUtils.readInputTextLine();
            if ((textLine == null) || (textLine.length() < 1))
                textLine = MagicStrings.null_input;
            if (textLine.equals("q")) {
                System.exit(0);
            } else if (textLine.equals("wq")) {
                bot.writeQuit();
                System.exit(0);
            } else {
                String request = textLine;
                if (MagicBooleans.trace_mode)
                    System.out.println("STATE=" + request + ":THAT=" + ((History) chatSession.thatHistory.get(0)).get(0) + ":TOPIC=" + chatSession.predicates.get("topic"));
                String response = chatSession.multisentenceRespond(request);
                while (response.contains("&lt;"))
                    response = response.replace("&lt;", "<");
                while (response.contains("&gt;"))
                    response = response.replace("&gt;", ">");
                System.out.println("Robot : " + response);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

MagicBooleans 只是一个 class 包装静态布尔值:

/**
 * Global boolean values that control various actions in Program AB
 */
public class MagicBooleans {
    public static boolean trace_mode = true;
    public static boolean enable_external_sets = true;
    public static boolean enable_external_maps = true;
    public static boolean jp_morphological_analysis = false;
    public static boolean fix_excel_csv = true;
}

source on github

因为它们是静态的,这意味着您可以通过导入 MagicBoolean 来访问它们,而其他 classes 将使用相同的值,例如 MagicBooleans.trace_mode。

我不确定 trace_mode 有什么影响,但您可以在源代码中搜索。

这同样适用于 MagicStrings - 只是您可以使用 MagicStrings class 访问的静态字符串。这就是所有 "Magic"。