Javascript/Node AI-如何使用match从单词数组中重复单词
Javascript/Node AI - How to use match to repeat a word from an array of words
真的需要一些帮助。Iv'e用javascript和Node.js做了一个AI。我已经编写了一堆问题和答案,如果用户愿意,Iv'e还可以更改IA的答案。
大多数javascript代码都是在服务器端生成的。
我需要让AI能够重复一个特定的单词。例如:
如果用户写下"你住在哪里?",ai将返回"在中土世界我的宝贝",因为aray列表:
var Question4 = { Question: "Where do you live?", Response: "In Middle Earth my precious" };
我必须让用户写"live",它会重复"live(直播)"。我想使用匹配变量,但我不确定。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/
问候
Chris
如果我正确理解问题,这可能会起作用:
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");
相关文章:
- Javascript-从随机的单词数组中创建段落
- 将组成单词的字符添加到数组的开头
- undercore返回数组中对象的indes,其中单词存在于对象中的句子中
- Javascript-在一个数组中搜索整个单词,并创建一个符合条件的新数组
- 在两个位置显示数组中的随机单词
- 如果输入包含数组中的任何单词
- 单词数组到字符串
- Javascript/Node AI-如何使用match从单词数组中重复单词
- 在单词数组中查找相似的单词
- 在单词数组中搜索单词
- 将句子字符串拆分为单词数组,然后将单词数组拆分为单词数组中的字符数组
- underscore.js基于单词数组从字符串中删除文本
- 从JavaScript中的单词数组中查找第n个字符
- Coffeescription在页面上的单词数组中进行迭代
- 我们如何用单词数组填充一组
- 用正则表达式连续收集单词数组中的任意单词
- 试图响应从node.js http服务器中分割成单词数组的文本
- 在mark.js中为单独的单词数组设置样式
- 将字符串拆分为单词数组以查找“最长”
- 王牌编辑器查找全部不起作用.需要所有带有 dif 的单词.数组中的值