I have facts such as
(claim (name Employee) (field 'EmpName' 'Company') (value 'Bob' 'ABC'))
(claim (name Event) (field 'EventName' 'Company') (value 'Conference' 'ABC'))
(drule (id gen1)(name1 'Employee') (field1 'EmpName' 'Company') (value1 'Bob' 'ABC') (name2 'Event')
(field2 'EventName') (value2 'Conference'))
I have tried a rule such as following. But it does not work as intended.
(defrule drule-rule
(drule
(id ?id))
(forall
(drule
(id ?id)
(name1 ?name1)
(field1 $?f11 ?field1 $?)
(value1 $?v11&:(= (length$ ?f11) (length$ ?v11)) ?value1 $?))
(name2 ?name2)
(field2 $?f22 ?field2 $?)
(value2 $?v22&:(= (length$ ?f22) (length$ ?v22)) ?value2 $?))
(claim
(name ?name1)
(field $?f1 ?field1 $?)
(value $?v1&:(= (length$ ?f1) (length$ ?v1)) ?value1 $?))
(claim (name ?name2)
(field $?f2 ?field2 $?)
(value $?v2&:(= (length$ ?f2) (length$ ?v2)) ?value2 $?)))
(forall
(claim
(field $?f3 ?field3 $?)
(value $?v4&:(= (length$ ?f3) (length$ ?v3)) ?value3 $?))
(claim
(field $?f4 ?field4 $?)
(value $?v4&:(= (length$ ?f4) (length$ ?v4)) ?value3 $?)))
=>
(assert (Action allowed)))
I want the above rule to check each field in matched claim
in the first forall
with other matched claims. If same field
name is found, then check the value of
that field in other claims.
For the above facts, the assertion should work. While for the below, the assertion should fail because Company
field
does not match other claim.
(claim (name Employee) (field 'EmpName' 'Company') (value 'Bob' 'xyz'))
(claim (name Event) (field 'EventName' 'Company') (value 'Conference' 'ABC'))
(drule (id gen1)(name1 'Employee') (field1 'EmpName' 'Company') (value1 'Bob' 'ABC') (name2 'Event')
(field2 'EventName') (value2 'Conference'))
Is this possible with a single rule? Or any other alternatives?
Thank you.