예제 #1
0
파일: Bot.java 프로젝트: dims12/program-ab
 /**
  * write categories to AIMLIF file
  *
  * @param cats array list of categories
  * @param filename AIMLIF filename
  */
 public void writeIFCategories(ArrayList<Category> cats, String filename) {
   // System.out.println("writeIFCategories "+filename);
   BufferedWriter bw = null;
   File existsPath = new File(aimlif_path);
   if (existsPath.exists())
     try {
       // Construct the bw object
       bw = new BufferedWriter(new FileWriter(aimlif_path + "/" + filename));
       for (Category category : cats) {
         bw.write(Category.categoryToIF(category));
         bw.newLine();
       }
     } catch (FileNotFoundException ex) {
       ex.printStackTrace();
     } catch (IOException ex) {
       ex.printStackTrace();
     } finally {
       // Close the bw
       try {
         if (bw != null) {
           bw.flush();
           bw.close();
         }
       } catch (IOException ex) {
         ex.printStackTrace();
       }
     }
 }
예제 #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());
 }