1
\$\begingroup\$

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
-> ba bla bla.
what do you think about cats
->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 >= 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.

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Apr 20, 2015 at 9:00
\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

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.

answered Jul 5, 2015 at 16:08
\$\endgroup\$
1
  • \$\begingroup\$ Hey, thanks for reply. I searched and found AIML, it's more suitable for me. (en.wikipedia.org/wiki/AIML). \$\endgroup\$ Commented Jul 5, 2015 at 16:51
1
\$\begingroup\$

A few things to point out:

["what", "do", "you", "think", "about"]

You should move this to an external array.


Rather than == matching responses in individual if-else loops: move the responses to a dictionary.

var responseDict = [
 "cats" : "I love cats"
 , "humanity": "bla bla bla"
]

Then, you can use the dictionary to build the response to fit into responseToServer().

responseToServer(responseDict[keyword])
answered Jul 6, 2015 at 1:54
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.