真的需要一些帮助。我用javascript和Node.js完成了AI。我已经训练了很多问题和答案,如果他愿意,也可以让用户改变IA的答案。
大多数javascript代码都是在服务器端制作的。
我需要让AI重复一个特定的单词。例如:
如果用户写道 - “你住在哪里?”,由于aray列表,ai将返回“In middle earth my precious”:
var Question4 = { Question: "Where do you live?", Response: "In Middle Earth my precious" };
我必须这样做以便用户写“现场”它将重复“直播”。我在考虑使用匹配变量,但我不确定。 Som输入将不胜感激!
BestAnswer 会返回新的答案如果用户已更改,否则会返回默认答案。这是数组和发送到客户端/ html端的代码:
var Question1 = { Question: "Hello", Response: "Hello precious" };
var Question2 = { Question: "What is your name?", Response: "My name is " + aHobbit.name + " " + "precious" };
var Question3 = { Question: "How old are you?", Response: "I'm " + aHobbit.age + " " + "my love" };
var Question4 = { Question: "Where do you live?", Response: "In Middle Earth my precious" };
var Question5 = { Question: "What do you like?", Response: "We love the precious. Yummy food we like, raw fish, rabbits, all of them.<br> I like them raw and raddeling. Yes precious raw we like them" };
var Question6 = { Question: "What don't you like?", Response: "Filthy orcsisses, stupid fat hobbitsses.<br> Yes precious.. but juicy and tender they are.." };
var Question7 = { Question: "How are you?", Response: "We are so happy precious oh yees..<br> Up and down down and up.. up up up we go.. Smeagoooool!!" };
var AllQueries = [Question1, Question2, Question3, Question4, Question5, Question6];
app.post("/creature", function (req, res) {
var aQuestion = req.param("question");
//var BestQuestion = req.param("bestQuestion");
var BestAnswer = req.param("bestAnswer");
var length = AllQueries.length;
Answer = "What does it ask us?? Gollum! Gollum!!...";
for (var i = 0; i < length; i++) {
if (AllQueries[i].Question === aQuestion) {
if (BestAnswer != undefined && BestAnswer.trim().length > 0) {
AllQueries[i].Response = BestAnswer;
}
Answer = AllQueries[i].Response;
}
}
res.sendfile("public/index.html");
这是一个关于它的外观的屏幕:
http://postimg.org/image/nbf3w6wr7/full/
此致
克里斯
答案 0 :(得分:0)
如果我正确理解了这个问题,这可能有用:
var Question1 = { Question: "Hello", Response: "Hello precious" };
var Question2 = { Question: "What is your name?", Response: "My name is " + aHobbit.name + " " + "precious" };
var Question3 = { Question: "How old are you?", Response: "I'm " + aHobbit.age + " " + "my love" };
var Question4 = { Question: "Where do you live?", Response: "In Middle Earth my precious" };
var Question5 = { Question: "What do you like?", Response: "We love the precious. Yummy food we like, raw fish, rabbits, all of them.<br> I like them raw and raddeling. Yes precious raw we like them" };
var Question6 = { Question: "What don't you like?", Response: "Filthy orcsisses, stupid fat hobbitsses.<br> Yes precious.. but juicy and tender they are.." };
var Question7 = { Question: "How are you?", Response: "We are so happy precious oh yees..<br> Up and down down and up.. up up up we go.. Smeagoooool!!" };
var AllQueries = [Question1, Question2, Question3, Question4, Question5, Question6];
app.post("/creature", function (req, res) {
var aQuestion = req.param("question");
//var BestQuestion = req.param("bestQuestion");
var BestAnswer = req.param("bestAnswer");
var length = AllQueries.length;
Answer = "What does it ask us?? Gollum! Gollum!!...";
for (var i = 0; i < length; i++) {
if (AllQueries[i].Question === aQuestion) {
if (BestAnswer != undefined && BestAnswer.trim().length > 0) {
AllQueries[i].Response = BestAnswer;
}
Answer = AllQueries[i].Response;
}
}
//check if answer was found, if it's default echo user's question:
if(aQuestion != '' && Answer == "What does it ask us?? Gollum! Gollum!!...") {
Answer = aQuestion;
}
res.sendfile("public/index.html");