Hi Rob,
You can use template inheritance: define a template has-a-and-b, then
let foo and baz extend it. Then write the pattern as
(deftemplate has-a-and-b (slot A) (slot B))
(deftemplate foo extends has-a-and-b (slot C) ...)
(deftemplate baz extends has-a-and-b (slot E) ...)
(defrule findB
(has-a-and-b (A ?id) (B value))
=>
(do something))
You only get single inheritance, but you can have multiple levels of
inheritance. There could be a (has-a) template that both
(has-a-and-b) and (bar) extend.
I'm thinking about having meta-templates in Jess 7, which might let
you write something like
(defrule findB
(?head (A ?id) (B value))
=>
(do something))
with your original set of templates, without using inheritance.
> (defrule findB
> (or
> (foo (A ?id) (B ?b))
> (baz (A ?id) (B ?b))
> )
> (test (eq ?b value))
> =>
> (do something)
> )
I think Rob Wheeler wrote:
> Hi All,
>
> Suppose I have the following deftemplates:
>
> (deftemplate foo (slot A) (slot B) (slot C) ...)
> (deftemplate bar (slot A) (slot D) ...)
> (deftemplate baz (slot A) (slot B) (slot E) ...)
>
> I want to get the A value for all facts with specific B value.
>
> I know I can use this:
>
> (defrule findB
> (or
> (foo (A ?id) (B ?b))
> (baz (A ?id) (B ?b))
> )
> (test (eq ?b value))
> =>
> (do something)
> )
>
> but this gets rather unwieldy with the dozen or so templates I've currently
> got to search.
>
> Is there any way I can search across multiple templates?
>
> cheers
> Rob.
> --
> British Maritime Technology
> Tel: +44 (0)20 8943 5544
> Fax: +44 (0)20 8977 9304
> WWW: http://www.bmtech.co.uk
>
> IMPORTANT: Any views or opinions expressed are solely those of the author
> and do not necessarily represent those of British Maritime Technology.
>
>
>
>
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
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]
---------------------------------------------------------------------