public static String interpretInput(String user_said) { String newMemory = ""; // will be the resulting memory-command String orgIn = user_said; // save original input just in case String param1, param2; // temporary strings // normally one would start with tweaking the input by removing special characters and simplify // as much as possible user_said = ILA_decisions.tweakString( user_said); // this will automatically call language_tweakString(...) first (see below) // examples - feel free to implement this in a completely different manner, whatever works ... if (ILA.language.matches("en|oz|ca|in|uk")) { // don't forget to set "inUse=true" to activate this branch (see top of this class) // a) simple command - "hey ILA I wonder if you know who I am" if (stringContains( user_said, new String[] {"who am I", "who I am", "what's my name", "do you know me"})) { newMemory = ("who am I;conversation;sayusername"); } // b) more complex command - "please search pictures of Bonobo apes" else if (stringContains(user_said, "search pictures")) { param1 = whatsAfter("pictures", user_said); param1 = param1.replaceAll("\\b(^of the|^of|^the)\\b", "").trim(); newMemory = ("search pictures;search;pictures;" + param1); } // c) even more complex command - "can you please get directions from here to work else if (stringContains(user_said, new String[] {"get directions", "show me the way"})) { user_said = user_said.replaceAll("\\b(get directions|show me the way)\\b", ""); param1 = whatsAfter("from", user_said).replaceAll("\\b(to).*", "").trim(); param2 = whatsAfter("to", user_said).trim(); newMemory = ("get directions;search;direction;" + param1 + ";" + param2); } } // System.out.println("ILA - original input: "+orgIn); //debug // System.out.println("ILA - custom interpretation result: "+newMemory); //debug return newMemory; }
private static String whatsBetween(String before, String after, String full) { return ILA_decisions.whatsBetween(before, after, full); }
private static String whatsAfter(String before, String full) { return ILA_decisions.whatsAfter(before, full); }
// check strings for words before "key", after "key" and between "key-A" and "key-B" private static String whatsBefore(String after, String full) { return ILA_decisions.whatsBefore(after, full); }
private static boolean stringContains(String userIn, String[] containsOneOf) { return ILA_decisions.stringContains(userIn, containsOneOf); }
// check strings for matching words private static boolean stringContains(String userIn, String matchStr) { return ILA_decisions.stringContains(userIn, matchStr); }