Search code examples
javachatbotschatbotaiml

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


I have found a code for simple chatbot using AIML and Program-ab distribution. There is a use of MagicBooleans and MagicStrings at many places. What exactly are those ? Also, I didn't understood what is a trace_mode ? The code that I found is as follows -

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();
    }
}

Solution

  • MagicBooleans is just a class wrapping static bools:

    /**
     * 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

    As they are static, it means you can access them by importing MagicBoolean and other classes will work with the same values if they read for example MagicBooleans.trace_mode.

    I'm not sure what the trace_mode is affecting, but you can search in the source code.

    The same applies for the MagicStrings - just static strings that you can access using the MagicStrings class. That's all the "Magic".