【问题标题】:RiveScript gives an error for python object macrosRiveScript 给出了 python 对象宏的错误
【发布时间】:2020-01-18 14:44:02
【问题描述】:

是否可以在 RiveScript 内部访问对象宏?我对此有点困惑。 我已经定义了以下脚本:

> object small python
  return "4"
< object

+ small
- <call>small</call>

当我输入 small 时出现错误:

error: [ERR: Object Not Found]

【问题讨论】:

  • 我试图让这个问题更容易理解。

标签: python-3.x rivescript


【解决方案1】:

在对象名称后面留一个空格

- <call>small  </call>

【讨论】:

  • 以下是How do I write a good answer? 的一些指南。提供的这个答案可能是正确的,但它可以从解释中受益。仅代码答案不被视为“好”答案。来自review
【解决方案2】:

object 的定义似乎没问题,但您可能从 https://play.rivescript.com/https://www.rivescript.com/try 运行它,它们只允许 JavaScript 或 CoffeeScript(参见 about page)。

您可以使用rivescript-python 运行代码,您可以通过以下方式安装:

pip install rivescript

然后将您的 rivescript 放入一个文件 (.rive),例如 helloworld.rive

然后在python中:

from rivescript import RiveScript
bot = RiveScript()
bot.load_directory('.') # set your directory where the .rive file(s) is/are
bot.sort_replies()

现在您可以使用bot.reply 来获取某个输入的答案:

>>> bot.reply('localuser','small')
'4'

编辑:我已经在 Ubuntu 14.04 上使用 Python 3.4.3 和 Python 2.7.12 以及 rivescript 1.14.4 测试了这段代码。

【讨论】:

  • 我使用 pip install rivescript 来安装.. 但是它不起作用。
  • 对象宏未被调用。我收到“找不到对象”错误。
猜你喜欢
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
  • 2013-11-10
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
相关资源
最近更新 更多