this is a half baked code I made on the fly. what it does is:
get data (as key value pair) {item, price} for example
the data is saved
the data is also saved in the format of {question, value}
this means I can get the item value as a response to a question,
for example: how much does bread cost?
use in main:
its also possible to decorate the value in the getAnswer method
so instead of just 2, it can say: that would cost you 2$
get data (as key value pair) {item, price} for example
the data is saved
the data is also saved in the format of {question, value}
this means I can get the item value as a response to a question,
for example: how much does bread cost?
Code:
package AXJava;
import LivinGrimoire.RegexUtil;
import java.util.Hashtable;
public class AXInfo {
private Hashtable<String,String> kv = new Hashtable<>(); // key value
private Hashtable<String,String> qv = new Hashtable<>(); // question as key to value
public void insert(String key, String value){
// override me
kv.put(key, value);
ChatBot cBot = new ChatBot(5);
cBot.addSentence("how much does item # cost");
cBot.addParam("item",key);
qv.put(cBot.talk(), value);
}
public String getAnswer(String question){
// override me
ChatBot cBot = new ChatBot(5);
cBot.addSentence("that would cost you price #");
cBot.addSentence("the price is price #");
cBot.addSentence("only price # $");
cBot.addParam("price",qv.getOrDefault(question, "hmm"));
return cBot.talk();
}
public String gevalue(String key){
return kv.getOrDefault(key, "i do not know");
}
}
use in main:
Code:
AXInfo prices = new AXInfo();
prices.insert("bread", "2");
System.out.println(prices.getAnswer("how much does bread cost"));
its also possible to decorate the value in the getAnswer method
so instead of just 2, it can say: that would cost you 2$