Parsing sentences to create a chat bot I am developing a chat bot with Node.Js. I am trying to find efficient way to parsing sentence.




what do you think about humanity
-&gt; ba bla bla.

what do you think about cats
-&gt;I love cats



Right now I am using the intersection technique, but I don't think it's efficient:



var sentence = sentence.split(",")
var inters = intersectionOfArrays(sentence, ["what", "do", "you", "think", "about"])
if(inters.length &gt;= 3) { //we have common words 
    keyword = extractionOfarrays(sentence,["what", "do", "you", "think", "about"]) // get question word (humanity, cats etc)
    if(keyword == "cats") 
       responseToServer("I love cats")
    if(keyword == "humanity") 
       responseToServer("bla bla bla")
}


Is this technique bad? I want to answer thousands of questions so I need to know what is the best method for doing some "AI" magic.
From a personal standpoint, I think this method is fine. You might want to re-work it a little. I'd recommend creating an array with possible intersections, and looping through that array and checking user input against those. For example:

var intersections = [
    ["what", "do", "you", "think", "about"],
    ["what", "is", "your"],
    ...
];


Finally, I'd recommend having something that allows for multiple keywords, rather than one. In addition to this, you may not want to be checking the length of intersections based on a constant, in this case, three.

Anyways, if there's anything else that you want me to cover, just mention it in the comments, and I'll see what I can do.