Beispiel #1
0
  /** Load all AIML Maps */
  int addAIMLMaps() {
    int cnt = 0;
    Timer timer = new Timer();
    timer.start();

    try {
      String[] listOfFiles = Alice.getContext().getAssets().list(maps_path);
      if (MagicBooleans.trace_mode) {
        System.out.println("Loading AIML Map files from " + maps_path);
        BrainLogger.getInstance().info("Loading AIML Map files from " + maps_path);
      }

      for (String file : listOfFiles) {

        if (file.endsWith(".txt") || file.endsWith(".TXT")) {
          if (MagicBooleans.trace_mode) System.out.println(file);
          String mapName = file.substring(0, file.length() - ".txt".length());
          if (MagicBooleans.trace_mode) System.out.println("Read AIML Map " + mapName);
          AIMLMap aimlMap = new AIMLMap(mapName, this);
          cnt += aimlMap.readAIMLMap(this);
          mapMap.put(mapName, aimlMap);
        }
      }
    } catch (IOException e) {
      System.out.println("addAIMLMaps: " + maps_path + " does not exist.");
      e.printStackTrace();
    }

    return cnt;
  }
Beispiel #2
0
  /** Load all brain categories from AIML directory */
  int addCategoriesFromAIML() {
    Timer timer = new Timer();
    timer.start();
    int cnt = 0;

    try {
      String[] listOfFiles = Alice.getContext().getAssets().list(aiml_path);
      if (MagicBooleans.trace_mode) {
        System.out.println("Loading AIML files from " + aiml_path);
        BrainLogger.getInstance().info("Loading AIML files from " + aiml_path);
      }
      for (String file : listOfFiles) {
        if (file.endsWith(".aiml") || file.endsWith(".AIML")) {
          if (MagicBooleans.trace_mode) {
            System.out.println(file);
            BrainLogger.getInstance().info("Reading AIML category " + file);
          }
          try {
            ArrayList<Category> moreCategories = AIMLProcessor.AIMLToCategories(aiml_path, file);
            addMoreCategories(file, moreCategories);
            cnt += moreCategories.size();
          } catch (Exception iex) {
            System.out.println("Problem loading " + file);
            iex.printStackTrace();
          }
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    }

    if (MagicBooleans.trace_mode) {
      System.out.println("Loaded " + cnt + " categories in " + timer.elapsedTimeSecs() + " sec");
      BrainLogger.getInstance()
          .info("Loaded " + cnt + " categories in " + timer.elapsedTimeSecs() + " sec");
    }
    return cnt;
  }