CLIPS Error:Template xxx does not exist for assert

半腔热情 提交于 2020-01-06 05:46:09

问题


  • CLIPS version: 6.31
  • language: c++ clips C API

Why am I getting this error? How should I fix this error?

[FACTRHS1] Template be-contact-model.riskLevel does not exist for assert.
Function load-facts encountered an error

The process is as follows: Firstly, I create a CLIPS environment from the full clips rule code using the ClipsEnvLoadFromString function, I will get a normal result in this CLIPS environment using the EnvLoadFactsFromString function.Next I want to copy more than one CLIPS environment, so I save the rules in a binary image file using the EnvBsave function and then I load a new environment from a binary file using EnvBload function, and then I use the EnvLoadFactsFromString function to load the user facts.But the EnvLoadFactsFromString function return false, and the cli stdout get the error string:

[FACTRHS1] Template be-contact-model.riskLevel does not exist for assert.
Function load-facts encountered an error

The facts parameter of the EnvLoadFactsFromString function as following:

(appId "TEST")
(be-contact-model.riskLevel "PASS")
(be-contact-model.score 0)
(channel "POST_TEXT.RlokQwRlVjUrTUlkIqOg.COMMENT")
(constantKey "constantKey")
(contact.model "contact_detector(GO)")
(contact.nicknameResult.has_contact FALSE)
(contact.nicknameResult.has_qq FALSE)
(contact.nicknameResult.has_tel FALSE)
(contact.nicknameResult.has_url FALSE)
(contact.nicknameResult.has_wechat FALSE)
(contact.riskLevel "PASS")
(contact.score 0)
(contact.textResult.baidusearch.REJECT_LEVEL 0)
(contact.textResult.has_contact FALSE)
(contact.textResult.has_qq FALSE)
(contact.textResult.has_tel FALSE)
(contact.textResult.has_url FALSE)
(contact.textResult.has_wechat FALSE)

回答1:


Once you load a binary image, you can't create any new constructs. Ordered facts and patterns (those that don't have a corresponding deftemplate construct) automatically create a deftemplate. If your rules haven't already created this automatic deftemplate, it can't be created after you've already loaded a binary image:

         CLIPS (6.31 6/12/19)
CLIPS> (bsave example.bin)
TRUE
CLIPS> (bload example.bin)
TRUE
CLIPS> (assert (be-contact-model.riskLevel "PASS"))
[FACTRHS1] Template be-contact-model.riskLevel does not exist for assert.
CLIPS> 

If you have a rule that matches the ordered fact, you can assert this type of fact after you've loaded the binary image.

CLIPS> (clear)
CLIPS> 
(defrule r1
   (be-contact-model.riskLevel ?)
   =>)
CLIPS> (bsave example.bin)
TRUE
CLIPS> (clear)
CLIPS> (bload example.bin)
TRUE
CLIPS> (assert (be-contact-model.riskLevel "PASS"))
<Fact-0>
CLIPS> 

So the fact that you're getting an error message would indicate that you're attempting to assert a fact that none of your rules can match.

It looks like your facts are attribute/value pairs, so one thing you can do if you're asserting facts that no rule can match is to create a generic deftemplate for representing all of them:

CLIPS> (clear)
CLIPS> (deftemplate av (slot a) (slot v))
CLIPS> (assert (av (a be-contact-model.riskLevel) (v "PASS")))
<Fact-1>
CLIPS> 


来源:https://stackoverflow.com/questions/58450773/clips-error-template-xxx-does-not-exist-for-assert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!