[英]What pattern should I use for making a listen bot in Node/JavaScript?
I'm currently using Node to make my first bot, but I'm a little bit confused as to how I can make this into reality. 我目前正在使用Node制作我的第一台机器人,但我对如何将其变为现实感到有些困惑。 The question is, what is the best pattern and name of the pattern I should use for this kind of stuff?
问题是, 我应该为这种东西使用的模式的最佳模式和名称是什么?
Basically, a person can listen to a subject and the speaker. 基本上,一个人可以听主题和发言者。
var test = person("ask_name","hallo person you are special");
console.log(test); // should return thanks!
var test = person("ask_name","hallo person you are dumb as the bird");
console.log(test); // should return i hate you!
function person(ability, body) {
console.log(ability,body);
var ability_name = "ability_" + ability;
console.log(ability_name,typeof ability_name); // ignore all of this, trying something
if (typeof ability_name) {};
// ability list array
var ability = [];
// Search for ability
// not done
var say_bad = function() {
this.listen_subject = 'ask_name';
this.listen_body = 'you are dumb';
return "i hate you!"
}
var say_good = function() {
this.listen_subject = 'ask_name';
this.listen_body = 'you are special';
return "thanks!"
}
}
Sorry, for not completing the code but this is the furthest I can go. 对不起,因为没有完成代码,但这是我能走得最远的。
If you're talking about the conversation logic, chain of responsibility seems like the way to go. 如果你在谈论对话逻辑,责任链似乎是要走的路。 That being said, that's only suitable for implementing a response tree.
话虽这么说,这只适用于实现响应树。 You may have different needs.
您可能有不同的需求。
The way that could work is: All nodes in the logic tree would have this method; 可行的方法是:逻辑树中的所有节点都有这种方法;
bool consider(utterence, history);
This method would return true if the node, or one of its subnodes has handled the situation. 如果节点或其子节点之一已处理该情况,则此方法将返回true。
I would implement a couple of topic detectors and a generic "I can't come up with a good answer", as well as a bunch of specialized responders. 我会实现一些主题检测器和一个通用的“我无法想出一个好的答案”,以及一堆专业的响应者。
The logic would be something like: 逻辑将类似于:
(weatherDetector considers utterence, history) (determines that topic is weather) (passes on to chain of objects that handle weather conversations) (weatherDetector考虑历史,历史)(确定主题是天气)(传递给处理天气对话的对象链)
or 要么
(weatherDetector considers utterence, history) (determines that topic is NOT weather) (passes on to next in chain of topic detectors) (genericFunnyResponder considers utterence, history) (picks a random quirky answer) (weatherDetector考虑历史,历史)(确定主题不是天气)(传递到主题探测器链中的下一个)(genericFunnyResponder考虑话语,历史)(选择一个随机的古怪答案)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.