//don't mind this method for now
throw new UnsupportedOperationException("Not supported yet.");
}
private String manageMessage(String mess) {
Command c;
Trigger t = null;
Reaction r;
NaturalLanguageProcessor nlp2 = new NaturalLanguageProcessor();
// String sentenceMess[] = nlp.getSentenceDetector().sentDetect(mess);
String tokenMess[] = mess.split(" "); //nlp.getTokenizer().tokenize(sentenceMess[0]);
String triggername = "";
int conditionSep = 0;
if (tokenMess[0].equalsIgnoreCase(HELP)) {
return help(tokenMess);
}
if (tokenMess[0].equalsIgnoreCase(LIST)) {
return list(tokenMess);
}
if (tokenMess[0].equalsIgnoreCase(IF) || tokenMess[0].equalsIgnoreCase(WHEN)) {
for (int i = 1; i < tokenMess.length; i++) {
if (tokenMess[i].equalsIgnoreCase(THEN)) {
triggername = unsplit(tokenMess, 1, i - 1, " ");
conditionSep = i + 1;
break;
}
}
t = TriggerPersistence.getTrigger(triggername);
}
String commandName = unsplit(tokenMess, conditionSep, tokenMess.length - conditionSep, " ");
List<NaturalLanguageProcessor.Rank> mostSimilar = nlp2.getMostSimilarCommand(commandName, 10);
// user is asking for help
if (commandName.contains("*")) {
String response = "";
for (NaturalLanguageProcessor.Rank nlpr : mostSimilar) {
response += "? " + nlpr.getCommand().getName() + "\n";
}
return response;
}
if (!mostSimilar.isEmpty() && mostSimilar.get(0).getSimilarity() > 0) {
c = mostSimilar.get(0).getCommand();
} else {
return "No available commands similar to: " + commandName;
}
if (tokenMess[0].equalsIgnoreCase(IF)) {
Trigger NEWt = t.clone();
NEWt.setNumberOfExecutions(1);
r = new Reaction(NEWt, c);
ReactionPersistence.add(r);
} else if (tokenMess[0].equalsIgnoreCase(WHEN)) {
// do something
r = new Reaction(t, c);
ReactionPersistence.add(r);
} else {
send(c);
return c.getName() + "\n DONE.";
}
return "DONE";
}