Clips.BuildRule 中出现错误
我正在使用 pyClips (这是嵌入在 python 中的 Clips)来构建知识 根据。我想通过调用函数向知识库文件添加新规则 实现此函数中显示的规则:
def normalRule(clips, i, path):
rule_name = 'rule_' + str(i)
rule_prec = '(phase ?phase)'
rule_prec += '?address1 <-(Organ (name ?organ))'
rule_prec += '?address2 <-(Surgical-Action (action ?action))'
rule_prec += '?address3 <-(Medical-Devices (tool-name ?tool))'
rule_body = '(if(=(str-compare ?*pickupEvent* "no")0) then'
rule_body += '(bind ?predicted-action ?action)'
rule_body += '(bind ?*current-action* ?predicted-action)'
rule_body += '(bind ?ex-tool ?tool)'
rule_body += 'else'
rule_body += '(bind ?actual-action ?action)'
rule_body += '(bind ?s-tool ?tool)'
rule_body += '(retract ?address1 ?address2 ?address3)'
rule_body += '(if (and (=(str-compare ?predicted-action ?actual-action)0)\
(=(str-compare ?ex-tool ?s-tool) 0)) then'
rule_body += '(updateAction ?*current-action* ?actual-action)'
rule_body += 'else'
rule_body += '( if (not(=(str-compare ?predicted-action ?actual-action)0)) then'
rule_body += '(updateAction ?*current-action* ?actual-action)'
rule_body += '(assert (You have mistake: incorrect action))'
rule_body += '(bind ?*number-of-mistakes* (+ ?*number-of-mistakes* 1)))'
rule_body += '(if (not(=(str-compare ?ex-tool ?s-tool) 0)) then'
rule_body += '(updateAction ?*current-action* ?actual-action)'
rule_body += '(assert (You have mistake: incorrect surgical device))'
rule_body += '(bind ?*number-of-mistakes* (+ ?*number-of-mistakes* 1))'
rule_body += ')))'
rule = clips.BuildRule(rule_name, rule_prec, rule_body)
当我使用 Clips 应用它时,此函数内的规则工作正常,但现在我想 每次调用该函数时都会构建一个新规则。
但是当我调用这个函数时,我得到了一个错误:
Traceback (most recent call last):
File "C:\Users\DELL\My Documents\Aptana Studio 3 Workspace\
Interface\src\ruleModel\ruleTypes.py", line 305,
in <module> normalRule(clips, 1, "C:\Users\DELL\Desktop\bjareb\tt.py")
File "C:\Users\DELL\My Documents\Aptana Studio 3 Workspace\
Interface\src\ruleModel\ruleTypes.py", line 39,
in normalRule rule = clips.BuildRule(rule_name, rule_prec, rule_body)
File "C:\Python26\lib\clips\_clips_wrap.py", line 149, in _WRAPPER return f(*args)
File "C:\Python26\lib\clips\_clips_wrap.py", line 238, in _WRAPPER return f(*newargs)
File "C:\Python26\lib\clips\_clips_wrap.py", line 3317, in BuildRule _c.build(construct)
_clips.ClipsError: C08: syntax error, or unable to parse expression
所以请,我修改了很多次,规则没有任何问题 构造,当我使用 Clips 时它也有效,那么我该如何解决这个问题?
I am using pyClips (which is Clips embedded in python) for building a knowledge
base. I want to add a new rule to a knowledge base file by calling a function
that implements the rule shown in this function:
def normalRule(clips, i, path):
rule_name = 'rule_' + str(i)
rule_prec = '(phase ?phase)'
rule_prec += '?address1 <-(Organ (name ?organ))'
rule_prec += '?address2 <-(Surgical-Action (action ?action))'
rule_prec += '?address3 <-(Medical-Devices (tool-name ?tool))'
rule_body = '(if(=(str-compare ?*pickupEvent* "no")0) then'
rule_body += '(bind ?predicted-action ?action)'
rule_body += '(bind ?*current-action* ?predicted-action)'
rule_body += '(bind ?ex-tool ?tool)'
rule_body += 'else'
rule_body += '(bind ?actual-action ?action)'
rule_body += '(bind ?s-tool ?tool)'
rule_body += '(retract ?address1 ?address2 ?address3)'
rule_body += '(if (and (=(str-compare ?predicted-action ?actual-action)0)\
(=(str-compare ?ex-tool ?s-tool) 0)) then'
rule_body += '(updateAction ?*current-action* ?actual-action)'
rule_body += 'else'
rule_body += '( if (not(=(str-compare ?predicted-action ?actual-action)0)) then'
rule_body += '(updateAction ?*current-action* ?actual-action)'
rule_body += '(assert (You have mistake: incorrect action))'
rule_body += '(bind ?*number-of-mistakes* (+ ?*number-of-mistakes* 1)))'
rule_body += '(if (not(=(str-compare ?ex-tool ?s-tool) 0)) then'
rule_body += '(updateAction ?*current-action* ?actual-action)'
rule_body += '(assert (You have mistake: incorrect surgical device))'
rule_body += '(bind ?*number-of-mistakes* (+ ?*number-of-mistakes* 1))'
rule_body += ')))'
rule = clips.BuildRule(rule_name, rule_prec, rule_body)
The rule inside this function works fine when i apply it using Clips, but now I want to
build a new rule every time the function is being called.
But when I called this function, I got an error:
Traceback (most recent call last):
File "C:\Users\DELL\My Documents\Aptana Studio 3 Workspace\
Interface\src\ruleModel\ruleTypes.py", line 305,
in <module> normalRule(clips, 1, "C:\Users\DELL\Desktop\bjareb\tt.py")
File "C:\Users\DELL\My Documents\Aptana Studio 3 Workspace\
Interface\src\ruleModel\ruleTypes.py", line 39,
in normalRule rule = clips.BuildRule(rule_name, rule_prec, rule_body)
File "C:\Python26\lib\clips\_clips_wrap.py", line 149, in _WRAPPER return f(*args)
File "C:\Python26\lib\clips\_clips_wrap.py", line 238, in _WRAPPER return f(*newargs)
File "C:\Python26\lib\clips\_clips_wrap.py", line 3317, in BuildRule _c.build(construct)
_clips.ClipsError: C08: syntax error, or unable to parse expression
So please, I revised it many times and there is nothing wrong in the rule
construction, also it works when I use Clips, so how do I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须小心程序中缺少的空格。需要 Eoln 以及比较语句的空格。因此,您的程序应如下所示:
其次,如果您正在使用 PyClips 并且对 CLIPS 感到满意,请使用以下行以获得您的规则的真正 CLIPS 错误消息。我尝试解决您的问题,但您的规则模式和操作部分存在几个问题。
First of all you have to be careful with whitespaces that you are missing in your program. Eoln's are needed as well as spaces for your comparison statements. So, your program should look like this:
Second, if you are using PyClips and feel comfortable with CLIPS, use the following lines in order to get the real CLIPS error message for your rule. I tried solving your problem but there are several problems in your rule's pattern and action parts.