Well I was interested in walking the deftemplate inheritance path. For the
record
here's the implementation I cam up with:


; determines if the given fact is an instance of or derived from
; the given template name. Note the templateName must include the
; module, e.g (instance-of (fact-id 0) MAIN::foo)
(deffunction instance-of (?fact ?templateName)
     (bind ?templateName (str-cat ?templateName)) ; force templateName to
be an RU.STRING
     (bind ?__deftemplate (call ?fact getDeftemplate))
     (while (neq ?__deftemplate nil)
          (if (eq* (call ?__deftemplate getName) ?templateName) then
(return TRUE))
          (bind ?__deftemplate (call ?__deftemplate getParent))
     ) ; while
     (return FALSE)
)


Simon Hamilton
Senior Principal Engineer
Orincon Information Assurance
[EMAIL PROTECTED]
858-455-5530x224


                                                                                       
                        
                    [EMAIL PROTECTED]                                                  
                        
                    .gov                     To:     [EMAIL PROTECTED]             
                        
                    Sent by:                 cc:                                       
                        
                    owner-jess-users@        Subject:     Re: JESS: equiv of 
instanceof for facts?             
                    sandia.gov                                                         
                        
                                                                                       
                        
                                                                                       
                        
                    09/26/2002 03:23                                                   
                        
                    PM                                                                 
                        
                    Please respond to                                                  
                        
                    jess-users                                                         
                        
                                                                                       
                        
                                                                                       
                        




I think [EMAIL PROTECTED] wrote:
>
> I'f attempting to construct a query that will iterate over all facts that
> aren't
> associated with a specific deftemplate. It seem to do so I need something
> like the
> Java instanceof operator. I was thinking of something like this:
>
> (defquery all-facts-that-arent-foos
>      ?f <- (__fact)
>      (test (not (instance-of ?f MAIN::foo)))
> )
>
> where "foo" is the deftemplate of the classes of facts I wish to ignore.
>
> Is there some other way of acheiving this that I might have missed?
>


This seems like a good approach -- I can't think of a better way to do
it.

If no templates extend "foo", then instance-of could just look like

(deffunction instance-of (?fact ?name)
        (return (eq (str-compare (?fact getName) ?name))))

If you want to allow for foo and any template that extends foo, then
you can use Fact.getDeftemplate to get the Fact's template, then use
Deftemplate.getName() to check the name, and getParent() to get the
parent template, and walk up the tree until getParent() returns
null. Look at the Java code in jess.Node1TECT.callNodeRight(), which
has to do precisely this.





---------------------------------------------------------
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]
--------------------------------------------------------------------

--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to