Hi Jan,
Couldn't you simply write one or more rules that place matching fact
bindings into an arbitrary collection class?
I'm assuming that you are filtering only on one type of fact. For example:
(clear)
(import java.util.ArrayList)
(watch all)
(deftemplate somefact
(slot x)
(slot y)
(slot z))
(deffacts init
(somefact (x 2) (y 4) (z 6))
(somefact (x 13) (y 15) (z 29))
(somefact (x 5) (y 8) (z 11)))
(deffunction update-fact-list-display (?conditionNumber ?colFacts)
(printout t "Facts that match condition " ?conditionNumber ":" crlf)
(printout t "----------------------------" crlf)
(foreach ?fact ?colFacts
(printout t "FactID: " ?fact crlf)))
(defrule find-all-somefacts-condition-1
"Finds all somefacts having 1st set of arbitrary conditions"
?factId <-(somefact (x ?x&:(<= ?x 5)) (y ?y&:(<= ?y 5)) (z ?))
=>
(bind ?colFacts1 (fetch colFacts1))
(?colFacts1 add ?factId)
(update-fact-list-display 1 ?colFacts1))
(defrule find-all-somefacts-condition-2
"Finds all somefacts having 2nd set of arbitrary conditions"
?factId <-(somefact (x ?x&:(>= ?x 5)) (y ?y&:(>= ?y 4)) (z ?))
=>
(bind ?colFacts2 (fetch colFacts2))
(?colFacts2 add ?factId)
(update-fact-list-display 2 ?colFacts2))
;; Program
(bind ?colFacts1 (new ArrayList))
(store colFacts1 ?colFacts1)
(bind ?colFacts2 (new ArrayList))
(store colFacts2 ?colFacts2)
(reset)
(run)
// OUTPUT
==================================================
MAIN::find-all-somefacts-condition-1: +1+1+1+1+t
MAIN::find-all-somefacts-condition-2: =1+1+1+1+t
==> Focus MAIN
==> f-0 (MAIN::initial-fact)
==> f-1 (MAIN::somefact (x 2) (y 4) (z 6))
==> Activation: MAIN::find-all-somefacts-condition-1 :
==> f-2 (MAIN::somefact (x 13) (y 15) (z 29))
==> Activation: MAIN::find-all-somefacts-condition-2 :
==> f-3 (MAIN::somefact (x 5) (y 8) (z 11))
==> Activation: MAIN::find-all-somefacts-condition-2 :
FIRE 1 MAIN::find-all-somefacts-condition-2 f-3
Facts that match condtion 2:
----------------------------
FactID: <Java-Object:jess.Fact>
FIRE 2 MAIN::find-all-somefacts-condition-2 f-2
Facts that match condtion 2:
----------------------------
FactID: <Java-Object:jess.Fact>
FactID: <Java-Object:jess.Fact>
FIRE 3 MAIN::find-all-somefacts-condition-1 f-1
Facts that match condtion 1:
----------------------------
FactID: <Java-Object:jess.Fact>
<== Focus MAIN
//
Cheers,
Jason
--
-----------------------------------------------------------
Jason Morris
Morris Technical Solutions LLC
http://www.morris-technical-solutions.com
On Nov 27, 2007 7:43 AM, Jan Willem Lokin <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Consider the following situation. I have asserted quite a number of
> facts, with various values for their slots. Now I want to select a
> limited number of facts that are most suitable, according to some
> user-defined criterion.
>
> My idea was to set up a defquery and then use Java sorting to order
> the QuertResult according to my criterion. However, there seems to be
> no way to transform a QueyResult into a Collection.
>
> Note that my problems would be simple if I had fixed limits on my slot
> values, but I haven't: if i woudl have slot values of 2, 4 and 6 and I
> would like to have the smallest two, a limit of 5 would do it, but
> this would not work when the values were 13, 15 and 29.
>
> My suspicion is that I am trying to solve the problem in the wrong
> manner, or even trying to solve the wrong problem. Any suggestions are
> appreciated.
>
> Regards,
>
> JW Lokin
>
> --------------------------------------------------------------------
> 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]
--------------------------------------------------------------------