I think Scott O Farrar wrote:
> Hi All,
>
> Does anyone no if it's possible to inspect each assertion to see what type
> of slot it contains?
>
Absolutely. The Jess manual has a whole chapter on Jess's Java
interfaces, which you'd need to use; see below.
> I would guess the following rule, but it seems you can't have a variable
> in the first position:
>
> (defrule find-template-with-age
> (?X (slot age)
> =>
> (printout t ?X " has an age slot" crlf))
>
>
> You can do this w. Java's Reflection tools so I assume it must be possible
> in Jess.
>
Jess rules are compiled, just as Java code is, so fact heads and slot
names can't be variables for much the same reason that class names and
member names can't be variables in Java code. Indeed, the reflection
analogy is a good one, for in Jess just as in Java, you have to jump
out of the "normal" way of doing things to get this information.
Let's see, what do you need to know... First of all, all facts
ultimately inherit from a deftemplate named "__fact", so a pattern
(__fact)
matches every fact. __fact has no slots, so this is the only pattern
that can legally use __fact. Once you've gotten this random fact,
you have to jump back and use the Java interface. So (untested code,
but you get the idea)
(defrule find-template-with-age
?f <- (__fact)
(test (neq -1 ((?f getDeftemplate) getSlotIndex age)))
=>
(printout t (?f getName) " has an age slot" crlf))
The (test) CE calls Fact.getDeftemplate, then calls getSlotIndex on
the Deftemplate; getSlotIndex returns -1 if there's no such slot.
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------