Ich möchte zwei der bedingten Testelemente aus der folgenden Regel entfernen und die Lesbarkeit verbessern. CLIPS Clause Interdependence
(defrule compare-things
(logical ?thing0 <- (object (is-a TYPED_THING)
(type-results $? ?t0 $?)))
(logical ?thing1 <- (object (is-a TYPED_THING)
(type-results $? ?t1 $?)))
(thing-comparable ?type)
?type0 <- (object (is-a TYPING)
(qualified-type ?type ?model ?mode ?comp0))
?type1 <- (object (is-a TYPING)
(qualified-type ?type ?model ?mode ?comp1))
; This test exists to restrict the number of rule firings
(test (> (str-compare (instance-name ?thing0) (instance-name ?thing1)) 0))
; Ideally, the following two tests can be removed
(test (= (str-compare (instance-name ?type0) (instance-name ?t0)) 0))
(test (= (str-compare (instance-name ?type1) (instance-name ?t1)) 0))
=>
(make-instance of COMPARISON
(compares ?thing0 ?thing1)
(score nil)
)
(printout t "comparing: " (instance-name ?thing0) (instance-name ?thing1) crlf)
)
Die Multi-Slot-Feldwerte ?t0
und ?t1
auf die gleichen Instanzen wie ?type0
und ?type1
entsprechen. Wenn ich ?t0
und ?t1
mit ?type0
ersetzen und ?type1
(dem intuitiven ersten Versuch ist), dann erhalte ich folgende Fehler während der Regeln Laden:
Defining defrule: compare-things
[ANALYSIS2] Pattern-address ?type0 used in CE #4 was previously bound within a pattern CE.
[ANALYSIS2] Pattern-address ?type1 used in CE #5 was previously bound within a pattern CE.
ERROR:
(defrule MAIN::compare-things
(logical
?thing0 <- (object (is-a TYPED_THING)
(type-results $? ?type0 $?)))
(logical
?thing1 <- (object (is-a TYPED_THING)
(type-results $? ?type1 $?)))
(thing-comparable ?type)
?type0 <- (object (is-a TYPING)
(qualified-type ?type ?model ?mode ?comp0))
?type1 <- (object (is-a TYPING)
(qualified-type ?type ?model ?mode ?comp1))
(test (> (str-compare (instance-name ?thing0) (instance-name ?thing1)) 0))
=>
(make-instance of COMPARISON
(compares ?thing0 ?thing1)
(score nil))
(printout t "comparing: " (instance-name ?thing0) (instance-name ?thing1) crlf))
FALSE
Die folgenden Daten verwendet werden, um die Regel in der Entwicklung zu stimulieren:
(defclass TYPING (is-a USER)
(role concrete)
(multislot qualified-type (access initialize-only)
(type STRING)
(cardinality 4 4))
(slot score (access initialize-only)
(type FLOAT))
)
(defclass TYPED_THING (is-a USER)
(slot id (access initialize-only)
(type INTEGER))
(multislot type-results (access initialize-only)
(type INSTANCE)) ; of TYPING
)
(defclass COMPARISON (is-a USER)
(multislot compares (access initialize-only)
(type INSTANCE) ; of TYPED_THING
(cardinality 2 2))
(slot score (access read-write)
(type FLOAT))
)
; These facts tag top-level types that are comparable
(deffacts KNOWN_COMPARABLE_TYPES
(thing-comparable "cat-a")
(thing-comparable "cat-c")
)
(definstances KNOWN_THINGS
(thing0 of TYPED_THING
(id 0)
(type-results (make-instance of TYPING (qualified-type "cat-a" "x0" "y0" "z0")(score 0.9))
(make-instance of TYPING (qualified-type "cat-b" "x0" "y0" "z0")(score 0.9))))
(thing1 of TYPED_THING
(id 1)
(type-results (make-instance of TYPING (qualified-type "cat-a" "x0" "y0" "z1")(score 0.9))
(make-instance of TYPING (qualified-type "cat-a" "x1" "y1" "z0")(score 0.9))))
(thing2 of TYPED_THING
(id 2)
(type-results (make-instance of TYPING (qualified-type "cat-b" "x0" "y0" "z1")(score 0.9))))
)
, die die folgende Ausgabe (wie es gegenwärtig der Fall ist) produzieren sollte:
CLIPS> (reset)
CLIPS> (run)
comparing: [thing1][thing0]
Dies ist genau das, was ich suchte. Ich wusste nicht, dass der Name-Slot für Instanzen vorhanden ist. –