1

How do you remove one facts in CLIPS? The fact would be entered by a person and compared with the base was present, it deletes.

I tried so:

(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

)

But, it is show this erro:

[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 (

Can you help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3174846
  • 13
  • 1
  • 5

1 Answers1

0

The condition of a rule should be used for matching facts/instances and the action portion of the rule is where you would perform actions such as printing output and receiving input.

You can either use a separate rule to query the user and another to delete the fact, or use the fact set query functions to search and delete the fact from the query rule.

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>    
Gary Riley
  • 10,130
  • 2
  • 19
  • 34
  • Gary, Thanks for helping. I get synsoftgoals delete. However, when I call the delete module, this rule delete only one synsoftgoals. If I change the module and then call the delete module, it does not print the message to insert the data. I wonder if you can help me. – user3174846 Apr 08 '14 at 19:51
  • Post an example illustrating the issue you're having. – Gary Riley Apr 09 '14 at 15:01