【问题标题】:What pattern should I use for making a listen bot in Node/JavaScript?我应该使用什么模式在 Node/JavaScript 中制作监听机器人?
【发布时间】:2012-06-28 17:04:15
【问题描述】:

我目前正在使用 Node 来制作我的第一个机器人,但我对如何将其变为现实感到有些困惑。问题是,我应该为这类东西使用的最佳模式和模式名称是什么?

基本上,一个人可以听一个主题和说话者。

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!"
  }
}

对不起,没有完成代码,但这是我能走的最远的地方。

【问题讨论】:

标签: javascript node.js design-patterns


【解决方案1】:

如果您在谈论对话逻辑,责任链似乎是要走的路。话虽如此,这仅适用于实现响应树。您可能有不同的需求。

可行的方法是: 逻辑树中的所有节点都会有这个方法;

bool consider(utterence, history);

如果节点或其子节点之一已处理该情况,此方法将返回 true。

我会实现几个主题检测器和一个通用的“我想不出一个好的答案”,以及一群专门的响应者。

逻辑是这样的:

(weatherDetector 考虑话语、历史) (确定主题是天气) (传递到处理天气对话的对象链)

(weatherDetector 考虑话语、历史) (确定该主题不是天气) (传递到主题检测器链中的下一个) (genericFunnyResponder 考虑话语、历史) (随机选择一个古怪的答案)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-19
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多