Can CLIPS report which pieces of an evaluation are true or false?

22 views
Skip to first unread message

Andy

unread,
Jan 26, 2012, 12:52:30 PM1/26/12
to CLIPSESG
We are looking for a way to report details of a condition evaluation
at run time so the we can provide feedback to a user about that
evaluation. So let me try to explain with an example:

(deffunction tc.ce::Fnd0SMIsCompletePercent100( ?task ?sched ?session)
(and (and (= (getTCProperty ?task "complete_percent") 100) (or (or
(= (getTCProperty
?task "task_type") 0) (= (getTCProperty ?task "task_type") 1)) (=
(getTCProperty
?task "task_type") 4))) (eq (getTCProperty ?sched "is_template")
FALSE)))

(defrule tc.ce::1
(Condition Fnd0SMIsCompletePercent100)
(task ?task)
(sched ?sched)
(session ?session)
(test (Fnd0SMIsCompletePercent100 ?task ?sched ?session))
=>
(send_to_c "True"))

Here we have a condition that is invoked to test the results of a
deffunction called Fnd0SMIsCompletePercent100. This will return True
to the user if the evaluation in that deffunction evaluates to True.
If it does not evaluate to True, we would like to be able to report to
the user the piece (or pieces) of that evaluation that made it False.
We have a user defined function (getTCProperty) that will retrieve the
value of a property from an instance in our application database given
the db object identifier tag and property name (objIdTag.property).
So in the above example we are checking the following:
IF...
(the task.complete_percent value is 100) ; #1
AND
( (task.task_type value is 0) ; #2
OR (task.task_type is 1) ; #3
OR (task.task_type is 4) ) ; #4
AND
(the sched.is_template value is FALSE) ;#5
THEN return True
ELSE return False

Is there any way we can capture the results of each (of the five
individual pieces in the example above) piece of the evaluation and
tell the user the reason for the failure?

Thanks for your insight...
Andy

CLIPS Support

unread,
Feb 5, 2012, 12:44:08 PM2/5/12
to CLIPSESG
One way to do it would be to write your own expression evaluator. You
can use the eval function to parse and execute strings, so if you
store the expressions you want to evaluate as strings or multi field
values, you could dynamically parse those values, pull out the
individual conditions to evaluate, and then evaluate them one by one
so that you could determine where the evaluation failed. Here's some
small examples of using eval.

CLIPS> (eval "(> 3 5)")
FALSE
CLIPS> (eval "(< 3 5)")
TRUE
CLIPS> (defglobal ?*task* = 4)
CLIPS> (eval "(< ?*task* 5)")
TRUE
CLIPS> (bind ?*task* 6)
6
CLIPS> (eval "(< ?*task* 5)")
FALSE
CLIPS>
(deffunction comparator (?task ?rel ?value)
(bind ?*task* ?task)
(bind ?str (str-cat "(" ?rel " ?*task* " ?value ")"))
(eval ?str))
CLIPS> (comparator 3 > 5)
FALSE
CLIPS> (comparator 3 < 5)
TRUE
CLIPS>
Reply all
Reply to author
Forward
0 new messages