コード例 #1
0
ファイル: Bot.java プロジェクト: dims12/program-ab
  /** Write all AIML files. Adds categories for BUILD and DEVELOPMENT ENVIRONMENT */
  public void writeAIMLFiles() {
    if (MagicBooleans.trace_mode) System.out.println("writeAIMLFiles");
    HashMap<String, BufferedWriter> fileMap = new HashMap<String, BufferedWriter>();
    Category b = new Category(0, "BRAIN BUILD", "*", "*", new Date().toString(), "update.aiml");
    brain.addCategory(b);
    // b = new Category(0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version,
    // "update.aiml");
    // brain.addCategory(b);
    ArrayList<Category> brainCategories = brain.getCategories();
    Collections.sort(brainCategories, Category.CATEGORY_NUMBER_COMPARATOR);
    for (Category c : brainCategories) {

      if (!c.getFilename().equals(MagicStrings.null_aiml_file))
        try {
          // System.out.println("Writing "+c.getCategoryNumber()+" "+c.inputThatTopic());
          BufferedWriter bw;
          String fileName = c.getFilename();
          if (fileMap.containsKey(fileName)) bw = fileMap.get(fileName);
          else {
            String copyright = Utilities.getCopyright(this, fileName);
            bw = new BufferedWriter(new FileWriter(aiml_path + "/" + fileName));
            fileMap.put(fileName, bw);
            bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<aiml>\n");
            bw.write(copyright);
            // bw.newLine();
          }
          bw.write(Category.categoryToAIML(c) + "\n");
          // bw.newLine();
        } catch (Exception ex) {
          ex.printStackTrace();
        }
    }
    Set set = fileMap.keySet();
    for (Object aSet : set) {
      BufferedWriter bw = fileMap.get(aSet);
      // Close the bw
      try {
        if (bw != null) {
          bw.write("</aiml>\n");
          bw.flush();
          bw.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    File dir = new File(aiml_path);
    dir.setLastModified(new Date().getTime());
  }
コード例 #2
0
ファイル: Bot.java プロジェクト: dims12/program-ab
 /** Write all AIMLIF files from bot brain */
 public void writeAIMLIFFiles() {
   if (MagicBooleans.trace_mode) System.out.println("writeAIMLIFFiles");
   HashMap<String, BufferedWriter> fileMap = new HashMap<String, BufferedWriter>();
   Category b = new Category(0, "BRAIN BUILD", "*", "*", new Date().toString(), "update.aiml");
   brain.addCategory(b);
   ArrayList<Category> brainCategories = brain.getCategories();
   Collections.sort(brainCategories, Category.CATEGORY_NUMBER_COMPARATOR);
   for (Category c : brainCategories) {
     try {
       BufferedWriter bw;
       File aimlifFile;
       String fileName = c.getFilename();
       if (fileMap.containsKey(fileName)) bw = fileMap.get(fileName);
       else {
         aimlifFile = new File(aimlif_path + "/" + fileName + MagicStrings.aimlif_file_suffix);
         aimlifFile.getParentFile().mkdirs();
         bw = new BufferedWriter(new FileWriter(aimlifFile));
         fileMap.put(fileName, bw);
       }
       bw.write(Category.categoryToIF(c));
       bw.newLine();
     } catch (Exception ex) {
       ex.printStackTrace();
     }
   }
   Set set = fileMap.keySet();
   for (Object aSet : set) {
     BufferedWriter bw = fileMap.get(aSet);
     // Close the bw
     try {
       if (bw != null) {
         bw.flush();
         bw.close();
       }
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
   File dir = new File(aimlif_path);
   dir.setLastModified(new Date().getTime());
 }