Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,34 @@
<version>1.1.1</version>
</dependency>
<!-- Binding for System.out -->

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>


<!--
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.0</version>
</dependency>
-->
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>


-->
<!-- Lucene based analyzers -->
<!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-analyzers-common -->
<dependency>
Expand Down
25 changes: 25 additions & 0 deletions src/org/alicebot/ab/AIMLProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
Expand Down Expand Up @@ -1226,6 +1231,26 @@ private static String learn(Node node, ParseState ps, Locale locale) { // learn,
// log.info("node is <learnf>");
c = new Category(0, pattern, that, "*", template, MagicStrings.learnf_aiml_file);
ps.chatSession.bot.learnfGraph.addCategory(c);

try {
File newCatFile = new File(ps.chatSession.bot.aiml_path + File.separator + MagicStrings.learnf_aiml_file);
FileOutputStream fos = null;
if (newCatFile.exists()) {
fos = new FileOutputStream(newCatFile, true);
} else {
fos = new FileOutputStream(newCatFile);
String header = new String("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes(), StandardCharsets.UTF_8);
fos.write(header.getBytes());
}

fos.write((Category.categoryToAIML(c) + "\n").getBytes());
fos.close();
// bw.newLine();
} catch (Exception ex) {
ex.printStackTrace();
}


}
ps.chatSession.bot.brain.addCategory(c);
// ps.chatSession.bot.brain.printgraph();
Expand Down
12 changes: 9 additions & 3 deletions src/org/alicebot/ab/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class Bot {
public HashMap<String, AIMLSet> setMap = new HashMap<String, AIMLSet>();
public HashMap<String, AIMLMap> mapMap = new HashMap<String, AIMLMap>();
public HashSet<String> pronounSet = new HashSet<String>();
public String root_path = "c:/ab";
// public String root_path = "c:/ab"; // REALLY ? ARE YOU SERIOUS ?
public String root_path = "."; // if your not going to set it to null - at least do this
public String bot_path = root_path + "/bots";
public String bot_name_path = bot_path + "/super";
public String aimlif_path = bot_path + "/aimlif";
Expand Down Expand Up @@ -366,7 +367,7 @@ public int addCategoriesFromAIMLIF() {
* write all AIML and AIMLIF categories
*/
public void writeQuit() {
writeAIMLIFFiles();
// writeAIMLIFFiles();
// log.info("Wrote AIMLIF Files");
writeAIMLFiles();
// log.info("Wrote AIML Files");
Expand Down Expand Up @@ -557,7 +558,7 @@ public void writeAIMLFiles() {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fn), StandardCharsets.UTF_8));
fileMap.put(fileName, bw);
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n" + "<aiml>\n");
bw.write(copyright);
// bw.write(copyright);
// bw.newLine();
}
bw.write(Category.categoryToAIML(c) + "\n");
Expand Down Expand Up @@ -789,4 +790,9 @@ public void setSraixHandler(SraixHandler sraixHandler) {
public SraixHandler getSraixHandler() {
return sraixHandler;
}

public String toString() {
return String.format("%s - %s", name, root_path);
}

}