Dear Sirs or Madams:
I am trying to make a general off-the-shelf email reply system using a chatbot backend. So far I have had good results with Program D and AAA AIML.
http://aitools.org/Program_D
http://www.alicebot.org/aiml/aaa/
Some troubles with Chomsky AIML set
http://alicebot.wikidot.com/forum/t-80187/chomsky-aiml-set
http://www.aimlpad.com/chomskyaiml.zip
about which I posted here
http://www.vrconsulting.it/vhf/topic.asp?TOPIC_ID=1102
I was wondering, is there a good way to design an automated email response system like this? Specifically, I am concerned about _KEEPING TRACK OF THE PAST CONVERSATION_ rather than having _ONE SENTENCE AT A TIME RESPONSES_ without _COHERENCY/CONSISTENCY_.
Thank you!
Sincerely yours
Misha Koshelev
p.s. Here is my quick attempt so far:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.List;
import java.util.LinkedList;
import java.io.FileNotFoundException;
import java.net.URL;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import org.aitools.programd.Core;
import org.aitools.programd.util.URLTools;
public class test
{
// http://joust.kano.net/weblog/archives/000060.html
private static final Pattern wrapRE=Pattern.compile(".{0,79}(?:\S(?:-| |$)|$)");
private static String[] wordWrap(String str) {
List list = new LinkedList();
Matcher m = wrapRE.matcher(str);
while (m.find()) list.add(m.group());
return (String[]) list.toArray(new String[list.size()]);
}
private static void outputWrapped(String str, String prefix) {
String[] wrapped=wordWrap(str);
for (int j=0;j<wrapped.length;j++) {
System.out.println(prefix+wrapped[j]);
}
}
private static void outputWrapped(String str) {
outputWrapped(str, "");
}
public static void main(String[] argv) throws FileNotFoundException,IOException {
URL baseURL = URLTools.createValidURL(System.getProperty("user.dir"));
Core core = new Core(baseURL, URLTools.createValidURL("/home/misha/personal/ProgramD/conf/core.xml"));
// Send the connect string.
core.processResponse(core.getSettings().getConnectString());
byte[] buffer = new byte[(int) new File("message").length()];
BufferedInputStream f = new BufferedInputStream(new FileInputStream("message"));
f.read(buffer);
String message=new String(buffer);
String botid=core.getBots().getABot().getID();
String userid="misha";
String patternStr = "(?<=(\r\n|\r|\n))([ \t]*$)+"; // http://www.exampledepot.com/egs/java.util.regex/parsepara.html
String[] paragraph = Pattern.compile(patternStr, Pattern.MULTILINE).split(message);
for (int i=0;i<paragraph.length;i++) {
String[] sentence=paragraph[i].split("[?!.]\s*");
String response="";
for (int j=0;j<sentence.length;j++) {
String r=core.getResponse(sentence[j],userid,botid).replaceAll("\s+"," ");
if (r!=null&r.length()>0) {
if (response.length()==0) {
response=r.trim();
} else {
response=response+" "+r.trim();
}
}
}
outputWrapped(paragraph[i],"> ");
outputWrapped(response);
}
}
}