我正在使用 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 时也可以,那么我该如何解决这个问题?