本文整理匯總了Java中org.alicebot.ab.utils.JapaneseUtils類的典型用法代碼示例。如果您正苦於以下問題:Java JapaneseUtils類的具體用法?Java JapaneseUtils怎麽用?Java JapaneseUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JapaneseUtils類屬於org.alicebot.ab.utils包,在下文中一共展示了JapaneseUtils類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: put
import org.alicebot.ab.utils.JapaneseUtils; //導入依賴的package包/類
/**
* save a predicate value
*
* @param key predicate name
* @param value predicate value
* @return predicate value
*/
public String put(String key, String value) {
//MagicBooleans.trace("predicates.put(key: " + key + ", value: " + value + ")");
if (MagicBooleans.jp_tokenize) {
if (key.equals("topic")) value = JapaneseUtils.tokenizeSentence(value);
}
if (key.equals("topic") && value.length()==0) value = MagicStrings.default_get;
if (value.equals(MagicStrings.too_much_recursion)) value = MagicStrings.default_list_item;
// MagicBooleans.trace("Setting predicate key: " + key + " to value: " + value);
String result = super.put(key, value);
//MagicBooleans.trace("in predicates.put, returning: " + result);
return result;
}
示例2: respond
import org.alicebot.ab.utils.JapaneseUtils; //導入依賴的package包/類
/**
* Return bot response to a single sentence input given conversation context
*
* @param input client input
* @param that bot's last sentence
* @param topic current topic
* @param contextThatHistory history of "that" values for this request/response interaction
* @return bot's reply
*/
String respond(String input, String that, String topic, History contextThatHistory) {
//MagicBooleans.trace("chat.respond(input: " + input + ", that: " + that + ", topic: " + topic + ", contextThatHistory: " + contextThatHistory + ")");
boolean repetition = true;
//inputHistory.printHistory();
for (int i = 0; i < MagicNumbers.repetition_count; i++) {
//System.out.println(request.toUpperCase()+"=="+inputHistory.get(i)+"? "+request.toUpperCase().equals(inputHistory.get(i)));
if (inputHistory.get(i) == null || !input.toUpperCase().equals(inputHistory.get(i).toUpperCase()))
repetition = false;
}
if (input.equals(MagicStrings.null_input)) repetition = false;
inputHistory.add(input);
if (repetition) {input = MagicStrings.repetition_detected;}
String response;
response = AIMLProcessor.respond(input, that, topic, this);
//MagicBooleans.trace("in chat.respond(), response: " + response);
String normResponse = bot.preProcessor.normalize(response);
//MagicBooleans.trace("in chat.respond(), normResponse: " + normResponse);
if (MagicBooleans.jp_tokenize) normResponse = JapaneseUtils.tokenizeSentence(normResponse);
String sentences[] = bot.preProcessor.sentenceSplit(normResponse);
for (int i = 0; i < sentences.length; i++) {
that = sentences[i];
//System.out.println("That "+i+" '"+that+"'");
if (that.trim().equals("")) that = MagicStrings.default_that;
contextThatHistory.add(that);
}
String result = response.trim()+" ";
//MagicBooleans.trace("in chat.respond(), returning: " + result);
return result;
}
示例3: multisentenceRespond
import org.alicebot.ab.utils.JapaneseUtils; //導入依賴的package包/類
/**
* return a compound response to a multiple-sentence request. "Multiple" means one or more.
*
* @param request client's multiple-sentence input
* @return
*/
public String multisentenceRespond(String request) {
//MagicBooleans.trace("chat.multisentenceRespond(request: " + request + ")");
String response="";
matchTrace="";
try {
String normalized = bot.preProcessor.normalize(request);
normalized = JapaneseUtils.tokenizeSentence(normalized);
//MagicBooleans.trace("in chat.multisentenceRespond(), normalized: " + normalized);
String sentences[] = bot.preProcessor.sentenceSplit(normalized);
History<String> contextThatHistory = new History<String>("contextThat");
for (int i = 0; i < sentences.length; i++) {
//System.out.println("Human: "+sentences[i]);
AIMLProcessor.trace_count = 0;
String reply = respond(sentences[i], contextThatHistory);
response += " "+reply;
//System.out.println("Robot: "+reply);
}
requestHistory.add(request);
responseHistory.add(response);
thatHistory.add(contextThatHistory);
response = response.replaceAll("[\n]+", "\n");
response = response.trim();
} catch (Exception ex) {
ex.printStackTrace();
return MagicStrings.error_bot_response;
}
if (doWrites) {
bot.writeLearnfIFCategories();
}
//MagicBooleans.trace("in chat.multisentenceRespond(), returning: " + response);
return response;
}