0

刚从 AIML 开始,似乎无法让<srai>命令用于链接同义词。我正在使用 Ruby on Rails 和 Programr gem。例如,下面是我的代码:

<?xml version="1.0" encoding="UTF-8"?>

<aiml version="1.0">

<category>
    <pattern>HELLO</pattern>
    <template>Hi there!</template>
</category>
<category>
    <pattern>HI</pattern>
    <template><srai>HELLO</srai></template>
</category>

</aiml>

当我输入 Hi 时,我的聊天机器人不明白我在说什么。在命令日志中,您可以看到它正在查询“Hi”,而不是“Hello”。知道我可能在哪里转向错误吗?

为了增加参考,这是我的控制器:

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  def ask_warwick
    reaction = WARWICK.get_reaction(params[:query])
    render json: { response: reaction.present? ? reaction : 'I do not understand' }
  end
end

还有我的初始化程序:

require 'programr'

brains = Dir.glob("lib/warwick/*")

WARWICK = ProgramR::Facade.new
WARWICK.learn(brains)
4

1 回答 1

1

这是gem代码中的错误

进入 gem 并找到文件 lib/programr/aiml_parser.rb

然后注释掉 193 附近的行,它说 currentSrai = Srai.new

  @parser.listen(:characters, %w{ srai }){|text|
    # currentSrai = Srai.new 
    currentSrai.add(text)
  }   
于 2016-01-07T02:36:29.067 回答