【问题标题】:How do you remove one facts in CLIPS?您如何删除 CLIPS 中的一个事实?
【发布时间】:2015-08-29 22:38:10
【问题描述】:

如何删除 CLIPS 中的一个事实?事实将由一个人输入并与存在的基础进行比较,它会删除。

我试过了:

(defrule Deleting::ruleDeleteOneSynSoftgoal "This rule delete one synsoftagoal found in the basis of fact." 
   (declare (salience 42))
   (printout t "Enter below the two softgoals field that want to be deleting:" crlf crlf
             "the synonyms of the <[TYPE]QUALITY ATTRIBUTE> and the <[TOPIC]SUBJECT/OBJECT LAL> need to be entered one per line." crlf crlf)
   (bind ?dsyntype (readline))
   (bind ?dsyntopic (readline))
   ?fact3 <- (synSoftgoal 
   (ttId ?ttId3)
   (syntopic ?syntopic3)      
   (syntype ?syntype3)
   )
   (test (and (eq ?dsyntopic ?syntopic3) (eq ?dsyntype ?syntype3)))
   =>
   (retract ?fact3

)

但是,显示这个错误:

[PRNTUTIL2] Syntax Error:  Check appropriate syntax for defrule.

ERROR:
(defrule Deleting::ruleDeleteOneSynSoftgoal "This rule delete one synsoftagoal found in the basis of fact."
   (declare (salience 42))
   (printout t "Enter below the two softgoals field that want to be deleting:" crlf crlf "the synonyms of the <[TYPE]QUALITY ATTRIBUTE> and the <[TOPIC]SUBJECT/OBJECT LAL> need to be entered one per line." crlf crlf)
   (bind ?dsyntype (

你能帮帮我吗?

【问题讨论】:

    标签: clips fact


    【解决方案1】:

    规则的条件应该用于匹配事实/实例,并且规则的操作部分是您可以执行诸如打印输出和接收输入之类的操作的地方。

    您可以使用单独的规则来查询用户并删除事实,或者使用事实集查询函数从查询规则中搜索和删除事实。

    CLIPS> 
    (deftemplate synSoftgoal
       (slot ttId)
       (slot syntopic)
       (slot syntype))
    CLIPS>    
    (deffacts initial
       (synSoftgoal (ttId 1) (syntopic "A") (syntype "1"))
       (synSoftgoal (ttId 2) (syntopic "A") (syntype "2"))
       (synSoftgoal (ttId 3) (syntopic "B") (syntype "1"))
       (synSoftgoal (ttId 4) (syntopic "B") (syntype "2")))
    CLIPS>    
    (defrule QueryRule 
       => 
       (printout t "Enter below the two softgoals field that want to be deleting:" crlf crlf
                 "the synonyms of the <[TYPE]QUALITY ATTRIBUTE> and the <[TOPIC]SUBJECT/OBJECT LAL> need to be entered one per line." crlf crlf)
       (assert (dsyntype (readline)))
       (assert (dsyntopic (readline))))
    CLIPS>    
    (defrule DeleteRule
       ?fact1 <- (dsyntype ?dsyntype)
       ?fact2 <- (dsyntopic ?dsyntopic)
       ?fact3 <- (synSoftgoal 
                    (ttId ?ttId3)
                    (syntopic ?dsyntopic)      
                    (syntype ?dsyntype))
       =>
       (retract ?fact1 ?fact2 ?fact3))
    CLIPS> (reset)
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (synSoftgoal (ttId 1) (syntopic "A") (syntype "1"))
    f-2     (synSoftgoal (ttId 2) (syntopic "A") (syntype "2"))
    f-3     (synSoftgoal (ttId 3) (syntopic "B") (syntype "1"))
    f-4     (synSoftgoal (ttId 4) (syntopic "B") (syntype "2"))
    For a total of 5 facts.
    CLIPS> (run)
    Enter below the two softgoals field that want to be deleting:
    
    the synonyms of the <[TYPE]QUALITY ATTRIBUTE> and the <[TOPIC]SUBJECT/OBJECT LAL> need to be entered one per line.
    
    2
    A
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (synSoftgoal (ttId 1) (syntopic "A") (syntype "1"))
    f-3     (synSoftgoal (ttId 3) (syntopic "B") (syntype "1"))
    f-4     (synSoftgoal (ttId 4) (syntopic "B") (syntype "2"))
    For a total of 4 facts.
    CLIPS> (clear)
    CLIPS> 
    (deftemplate synSoftgoal
       (slot ttId)
       (slot syntopic)
       (slot syntype))
    CLIPS>    
    (deffacts initial
       (synSoftgoal (ttId 1) (syntopic "A") (syntype "1"))
       (synSoftgoal (ttId 2) (syntopic "A") (syntype "2"))
       (synSoftgoal (ttId 3) (syntopic "B") (syntype "1"))
       (synSoftgoal (ttId 4) (syntopic "B") (syntype "2")))
    CLIPS>    
    (defrule QueryAndDeleteRule 
       => 
       (printout t "Enter below the two softgoals field that want to be deleting:" crlf crlf
                 "the synonyms of the <[TYPE]QUALITY ATTRIBUTE> and the <[TOPIC]SUBJECT/OBJECT LAL> need to be entered one per line." crlf crlf)
       (bind ?dsyntype (readline))
       (bind ?dsyntopic (readline))
       (do-for-all-facts ((?f synSoftgoal)) (and (eq ?f:syntopic ?dsyntopic) (eq ?f:syntype ?dsyntype))
          (retract ?f)))
    CLIPS> (reset)  
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (synSoftgoal (ttId 1) (syntopic "A") (syntype "1"))
    f-2     (synSoftgoal (ttId 2) (syntopic "A") (syntype "2"))
    f-3     (synSoftgoal (ttId 3) (syntopic "B") (syntype "1"))
    f-4     (synSoftgoal (ttId 4) (syntopic "B") (syntype "2"))
    For a total of 5 facts.
    CLIPS> (run)
    Enter below the two softgoals field that want to be deleting:
    
    the synonyms of the <[TYPE]QUALITY ATTRIBUTE> and the <[TOPIC]SUBJECT/OBJECT LAL> need to be entered one per line.
    
    2
    A
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (synSoftgoal (ttId 1) (syntopic "A") (syntype "1"))
    f-3     (synSoftgoal (ttId 3) (syntopic "B") (syntype "1"))
    f-4     (synSoftgoal (ttId 4) (syntopic "B") (syntype "2"))
    For a total of 4 facts.
    CLIPS>    
    

    【讨论】:

    • 加里,感谢您的帮助。我得到了 synsoftgoals 删除。但是,当我调用删除模块时,这条规则只删除了一个 synsoftgoals。如果我更改模块然后调用删除模块,它不会打印插入数据的消息。不知道你能不能帮帮我。
    • 发布一个示例来说明您遇到的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多