Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/Node AI-如何使用match从一组单词中重复一个单词_Javascript_Arrays_Node.js_Artificial Intelligence - Fatal编程技术网

Javascript/Node AI-如何使用match从一组单词中重复一个单词

Javascript/Node AI-如何使用match从一组单词中重复一个单词,javascript,arrays,node.js,artificial-intelligence,Javascript,Arrays,Node.js,Artificial Intelligence,我真的需要一些帮助。Iv'e使用javascript和Node.js完成了一个AI。我已经编写了一系列问题和答案,iv'e还可以让用户在需要时更改IA的答案 大多数javascript代码都是在服务器端编写的 我需要让人工智能能够重复特定单词。例如: 如果用户写下“你住在哪里?”,ai将返回“中土我的宝贝”,因为aray列表: var Question4 = { Question: "Where do you live?", Response: "In Middle Earth my preci

我真的需要一些帮助。Iv'e使用javascript和Node.js完成了一个AI。我已经编写了一系列问题和答案,iv'e还可以让用户在需要时更改IA的答案

大多数javascript代码都是在服务器端编写的

我需要让人工智能能够重复特定单词。例如:

如果用户写下“你住在哪里?”,ai将返回“中土我的宝贝”,因为aray列表:

var Question4 = { Question: "Where do you live?", Response: "In Middle Earth my precious" };
我必须让用户写下“live”,然后重复“live”。我想用match variabel,但我不确定。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");
var Question1={问题:“你好”,回答:“你好,宝贝”};
var Question2={问题:“你叫什么名字?”,回答:“我的名字是”+aHobbit.name++++“珍贵”};
变量问题3={问题:“你多大了?”,回答:“我是”+aHobbit.age++++“我的爱人”};
var问题4={问题:“你住在哪里?”,回答:“在中土我的宝贝”};
var问题5={问题:“你喜欢什么?”,回答:“我们喜欢珍贵的、美味的食物,生鱼、兔子,所有这些。
我喜欢生的和烤的。是的,珍贵的生的,我们喜欢它们”}; var问题6={问题:“你不喜欢什么?”回答:“肮脏的兽人,愚蠢的胖哈比人。
是的,很珍贵……但它们又多汁又嫩……”; var问题7={问题:“你好吗?”,回答:“我们很高兴,宝贝哦,是的..
上下上; var AllQueries=[问题1、问题2、问题3、问题4、问题5、问题6]; 应用程序post(“/生物”,功能(请求,恢复){ var aQuestion=需求参数(“问题”); //var BestQuestion=请求参数(“BestQuestion”); var BestAnswer=请求参数(“BestAnswer”); var length=allquerys.length; 回答=“它问我们什么?咕噜!咕噜!!…”; 对于(变量i=0;i0){ 所有查询[i]。响应=最佳答案; } 答案=所有查询[i]。响应; } } res.sendfile(“public/index.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;
        }

   }

   //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");
var Question1={问题:“你好”,回答:“你好,宝贝”};
var Question2={问题:“你叫什么名字?”,回答:“我的名字是”+aHobbit.name++++“珍贵”};
变量问题3={问题:“你多大了?”,回答:“我是”+aHobbit.age++++“我的爱人”};
var问题4={问题:“你住在哪里?”,回答:“在中土我的宝贝”};
var问题5={问题:“你喜欢什么?”,回答:“我们喜欢珍贵的、美味的食物,生鱼、兔子,所有这些。
我喜欢生的和烤的。是的,珍贵的生的,我们喜欢它们”}; var问题6={问题:“你不喜欢什么?”回答:“肮脏的兽人,愚蠢的胖哈比人。
是的,很珍贵……但它们又多汁又嫩……”; var问题7={问题:“你好吗?”,回答:“我们很高兴,宝贝哦,是的..
上下上; var AllQueries=[问题1、问题2、问题3、问题4、问题5、问题6]; 应用程序post(“/生物”,功能(请求,恢复){ var aQuestion=需求参数(“问题”); //var BestQuestion=请求参数(“BestQuestion”); var BestAnswer=请求参数(“BestAnswer”); var length=allquerys.length; 回答=“它问我们什么?咕噜!咕噜!!…”; 对于(变量i=0;i0){ 所有查询[i]。响应=最佳答案; } 答案=所有查询[i]。响应; } } //检查是否找到答案,如果是默认的echo用户问题: 如果(问!=''&&Answer==“它问我们什么?咕噜!咕噜!!…”){ 答案=提问; } res.sendfile(“public/index.html”);