本文整理汇总了Java中org.alicebot.ab.Chat类的典型用法代码示例。如果您正苦于以下问题:Java Chat类的具体用法?Java Chat怎么用?Java Chat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Chat类属于org.alicebot.ab包,在下文中一共展示了Chat类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: savePredicates
import org.alicebot.ab.Chat; //导入依赖的package包/类
/**
* Persist the predicates for all known sessions in the robot.
*
* @throws IOException
*
*/
public void savePredicates() throws IOException {
for (String session : sessions.keySet()) {
String sessionPredicateFilename = createSessionPredicateFilename(session);
File sessionPredFile = new File(sessionPredicateFilename);
Chat chat = sessions.get(session);
// overwrite the original file , this should always be a full set.
log.info("Writing predicate file for session {}", session);
FileWriter predWriter = new FileWriter(sessionPredFile, false);
for (String predicate : chat.predicates.keySet()) {
String value = chat.predicates.get(predicate);
predWriter.write(predicate + ":" + value + "\n");
}
predWriter.close();
}
log.info("Done saving predicates.");
}
示例2: savePredicates
import org.alicebot.ab.Chat; //导入依赖的package包/类
/**
* Persist the predicates for all known sessions in the robot.
*
*/
public void savePredicates() throws IOException {
for (String session : sessions.keySet()) {
// TODO: better parsing of this.
String[] parts = session.split("-");
String username = parts[0];
String botname = session.substring(username.length() + 1);
String sessionPredicateFilename = createSessionPredicateFilename(username, botname);
File sessionPredFile = new File(sessionPredicateFilename);
Chat chat = getChat(username, botname);
// overwrite the original file , this should always be a full set.
log.info("Writing predicate file for session {}", session);
FileWriter predWriter = new FileWriter(sessionPredFile, false);
for (String predicate : chat.predicates.keySet()) {
String value = chat.predicates.get(predicate);
predWriter.write(predicate + ":" + value + "\n");
}
predWriter.close();
}
log.info("Done saving predicates.");
}
示例3: getResponse
import org.alicebot.ab.Chat; //导入依赖的package包/类
public static BotResponseInfo getResponse(Bot bot, String question){
Chat chat = new Chat(bot);
BotResponseInfo response = new BotResponseInfo();
String answer = chat.multisentenceRespond(question);
History hist = chat.thatHistory.get(0);
String that = "";
if (hist == null) that = MagicStrings.default_that;
else that = hist.getString(0);
String topic = chat.predicates.get("topic");
Nodemapper leaf = chat.bot.brain.match(question, that, topic);
response.setAnswer(answer);
response.setCategory(leaf.category);
return response;
}
示例4: ChatRoom
import org.alicebot.ab.Chat; //导入依赖的package包/类
public ChatRoom(ChatBot bot, Room room, int startBatchNumber, List<Class<? extends BotCommand>> allowedCommands,int dupNotifyStrategy, boolean enableAi){
this.bot = bot;
this.room = room;
this.currentBatchNumber = startBatchNumber;
this.allowedCommands = allowedCommands;
this.dupNotifyStrategy = dupNotifyStrategy;
if (enableAi){
chatSession = new Chat(bot.getAiBot());
}
}
示例5: updateLocation
import org.alicebot.ab.Chat; //导入依赖的package包/类
private void updateLocation() {
Location updatedLocation = bestLastKnownLocation(MIN_LAST_READ_ACCURACY, TEN_MIN);
if (updatedLocation != null) {
location = updatedLocation;
Chat.locationKnown = true;
Chat.longitude = Double.toString(location.getLongitude());
Chat.latitude = Double.toString(location.getLatitude());
}
}
示例6: initChatbot
import org.alicebot.ab.Chat; //导入依赖的package包/类
private void initChatbot() {
try {
String botDir = "bots";
String botName = "alice2";
AssetUtils.copyFileOrDir(botDir, this);
File botPath = getExternalFilesDir(null);
Bot bot = new Bot(botName, botPath.getAbsolutePath());
chatSession = new Chat(bot);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
示例7: getChat
import org.alicebot.ab.Chat; //导入依赖的package包/类
public Chat getChat(String userName, String botName) {
String sessionKey = resolveSessionKey(userName, botName);
if (!sessions.containsKey(sessionKey)) {
error("%s session does not exist", sessionKey);
return null;
} else {
return sessions.get(sessionKey).chat;
}
}
示例8: getAnswer
import org.alicebot.ab.Chat; //导入依赖的package包/类
public static String getAnswer(Bot bot,String question) {
// bot.preProcessor.normalizeFile("c:/ab/bots/super/aiml/thats.txt",
// "c:/ab/bots/super/aiml/normalthats.txt");
Chat chatSession = new Chat(bot);
bot.brain.nodeStats();
String answer = chatSession.multisentenceRespond(question);
while (answer.contains("<"))
answer = answer.replace("<", "<");
while (answer.contains(">"))
answer = answer.replace(">", ">");
System.out.println("Question: " + question);
System.out.println("Answer: " + answer);
return answer;
}
示例9: trainBot
import org.alicebot.ab.Chat; //导入依赖的package包/类
public static void trainBot(BotInfo botInfo, String question, String newAnswer) {
// TODO Auto-generated method stub
Bot bot = getRunningBot(botInfo).getBot();
Chat chat = new Chat(bot);
chat.multisentenceRespond(question);
History hist = chat.thatHistory.get(0);
String that = "";
if (hist == null) that = MagicStrings.default_that;
else that = hist.getString(0);
String topic = chat.predicates.get("topic");
Nodemapper leaf = chat.bot.brain.match(question, that, topic);
leaf.category.setTemplate(newAnswer);
bot.writeAIMLFiles();
bot.writeAIMLIFFiles();
}
示例10: onHandleIntent
import org.alicebot.ab.Chat; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Log.i(TAG, "onHandleIntent()");
String query = intent.getStringExtra(KEY_QUERY);
query = query.toLowerCase(Locale.getDefault()).replace("\'", "");
DoubleMetaphone encoder = new DoubleMetaphone();
Set<String> ngrams = StringUtils.extractNgrams(query, NGRAM_SIZE);
for (String segment : ngrams) {
String hash = encoder.encode(segment);
if (KEYWORD_HASHES.containsKey(hash)) {
query = query.replace(segment, KEYWORD_HASHES.get(hash));
break;
}
}
final Daytripper daytripper = (Daytripper) getApplicationContext();
final Chat chatSession = daytripper.getChatSession();
String response = chatSession.multisentenceRespond(query);
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(RESPONSE_ACTION);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
String url = chatSession.predicates.get("url");
if (!TextUtils.isEmpty(url) && !url.equalsIgnoreCase("unknown")) {
chatSession.predicates.remove("url");
broadcastIntent.putExtra(EXTRA_URL_MESSAGE, url);
} else {
broadcastIntent.putExtra(EXTRA_CONTENT_MESSAGE, response);
}
String voice = chatSession.predicates.get(VOICE_FLAG);
if (!TextUtils.isEmpty(voice) && !voice.equalsIgnoreCase("unknown")) {
chatSession.predicates.remove(VOICE_FLAG);
broadcastIntent.putExtra(VOICE_FLAG, voice);
}
broadcastIntent.putExtra(EXTRA_TEXT_MESSAGE, Jsoup.parse(response).text());
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
}
示例11: ChatData
import org.alicebot.ab.Chat; //导入依赖的package包/类
public ChatData(Chat chat) {
this.chat = chat;
}
示例12: getChatSession
import org.alicebot.ab.Chat; //导入依赖的package包/类
public final static Chat getChatSession() { return Daytripper.chatSession; }