Sorry, I guess this is one of those cases when simplifying the question
also simplified the answer. In reality, my template has 4 slots rather
than just two, and I need to check for facts that contain a unique slot
value in any of the 4 slots.
I currently have a working solution (exactly the one you proposed), but
it requires four separate rules (one per slot) with four patterns each.
I guess I'm just wondering if there isn't a simpler solution.
My specific implementation looks like this:
;; watch for distinct slot values and assert 'distinct' facts when found
(defrule find-distinct-firstname
?p <- (tuple (firstname ?fn)(lastname ?ln)(item ?i)(store ?s))
(not (or (tuple (firstname ?fn)(lastname ~?ln))
(tuple (firstname ?fn)(item ~?i))
(tuple (firstname ?fn)(store ~?s))
)
)
=>
(assert (distinct ?p))
)
I have three others just like this one for 'lastname', 'item' and
'store'.
I guess I was hoping to leverage the unique fact id somehow to
identify/eliminate identical facts matching both patterns as in the
following (contrived) example:
(defrule find-distinct-firstname
(tuple (firstname ?fn)(fact-id ?id))
(not (tuple (firstname ?fn)(fact-id ~?id)))
=>
...)
Thanks for your help.
-Mitch
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, December 29, 2004 7:08 PM
To: [email protected]
Subject: Re: JESS: Finding distinct slot values
I think Mitch Christensen wrote:
> I want a rule that will only match the assignment fact with key=child.
(defrule find-singletons
;; There's an assignment with key k and value v
?a <- (assignment (key ?k) (value ?v))
;; and no other assignment has the same
;; key but a different value
(not (assignment (key ?k) (value ~?v)))
=>
;; ?a is a singleton assignment
)
---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov
--------------------------------------------------------------------
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]
--------------------------------------------------------------------