com.google.code.chatterbotapi.Pandorabots Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chatter-bot-api Show documentation
Show all versions of chatter-bot-api Show documentation
A JAVA (also Mono/.NET, Python and PHP) chatter bot API
that supports Cleverbot, JabberWacky and Pandorabots.
package com.google.code.chatterbotapi;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
/*
chatter-bot-api
Copyright (C) 2011 [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
class Pandorabots implements ChatterBot {
private final String botid;
public Pandorabots(String botid) {
this.botid = botid;
}
@Override
public ChatterBotSession createSession(Locale... locales) {
return new Session();
}
private class Session implements ChatterBotSession {
private final Map vars;
public Session() {
vars = new LinkedHashMap();
vars.put("botid", botid);
vars.put("custid", UUID.randomUUID().toString());
}
public ChatterBotThought think(ChatterBotThought thought) throws Exception {
vars.put("input", thought.getText());
String response = Utils.request("http://www.pandorabots.com/pandora/talk-xml", null, null, vars);
ChatterBotThought responseThought = new ChatterBotThought();
responseThought.setText(Utils.xPathSearch(response, "//result/that/text()"));
return responseThought;
}
public String think(String text) throws Exception {
ChatterBotThought thought = new ChatterBotThought();
thought.setText(text);
return think(thought).getText();
}
}
}