RSBot.java
Go to the documentation of this file.
00001 
00009 package com.rosalfred.core.ia.rivescript;
00010 
00011 import java.io.BufferedReader;
00012 import java.io.IOException;
00013 import java.io.InputStreamReader;
00014 
00015 import com.rosalfred.core.ia.rivescript.lang.Echo;
00016 import com.rosalfred.core.ia.rivescript.lang.Java;
00017 
00023 public class RSBot {
00024         public static void main (String[] args) {
00025                 // Let the user specify debug mode!
00026                 boolean debug = false;
00027                 for (int i = 0; i < args.length; i++) {
00028                         if (args[i].equals("--debug") || args[i].equals("-d")) {
00029                                 debug = true;
00030                         }
00031                 }
00032                 debug = true;
00033 
00034                 // Create a new RiveScript interpreter.
00035                 System.out.println(":: Creating RS Object");
00036                 RiveScript rs = new RiveScript(debug);
00037 
00038                 // Create a handler for X objects.
00039                 rs.setHandler("perl", new Echo(rs)); //new com.rivescript.lang.Perl(rs, "./lang/rsp4j.pl"));
00040                 rs.setHandler("python", new Echo(rs));
00041                 rs.setHandler("java", new Java(rs, "/home/micky/ros-workspace/tact_medialfred/media_common/src/media_ia/res/src" ));
00042 
00043                 // Load and sort replies
00044                 System.out.println(":: Loading replies");
00045                 rs.loadDirectory("/home/micky/ros-workspace/tact_medialfred/media_common/src/media_ia/res"); //"./Aiden");
00046                 rs.sortReplies();
00047 
00048                 // Enter the main loop.
00049                 InputStreamReader converter = new InputStreamReader(System.in);
00050                 BufferedReader stdin = new BufferedReader(converter);
00051                 while (true) {
00052                         System.out.print("You> ");
00053                         String message = "";
00054                         try {
00055                                 message = stdin.readLine();
00056                         }
00057                         catch (IOException e) {
00058                                 System.err.println("Read error!");
00059                         }
00060 
00061                         // Quitting?
00062                         if (message.equals("/quit")) {
00063                                 System.exit(0);
00064                         }
00065                         else if (message.equals("/dump topics")) {
00066                                 rs.dumpTopics();
00067                         }
00068                         else if (message.equals("/dump sorted")) {
00069                                 rs.dumpSorted();
00070                         }
00071                         else {
00072                             String escapeString = message.replaceAll("-:", " "); // ignore
00073                 String[] res = escapeString.split("[.,!?:;]+\\s*");
00074 
00075                 String reply = "ERR : NOOOOOOO !";
00076                 for (String sentence : res) {
00077                     reply = rs.reply("localuser", sentence).getReply();
00078                 }
00079 
00080                                 System.out.println("Bot> " + reply);
00081                         }
00082                 }
00083         }
00084 }


alfred_bot
Author(s): Mickael Gaillard , Erwan Le Huitouze
autogenerated on Tue Jun 14 2016 01:34:50