If by 'random' you mean 'any one will do' (i.e. they are all equivalent), I'd probably just grab the first one and ignore the rest. There are lots of ways to do this.
O You could define a defquery, and select randomly using the iterator. O You could assert a trigger fact (assert (process-link ?linkCount)) and then have a rule that looks for a (process-link) fact AND a (link-count) fact with a matching count and take whatever you get (then retract the (process-link) trigger fact). -Mitch -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of lai Sent: Thursday, September 30, 2004 6:20 AM To: [EMAIL PROTECTED] Subject: RE: JESS: Counting the number within facts hi Mitch Thank you for your kindly assistance. Also, I have another question. The question as follows: If some fact id have same highest number, the question is how to randomly select one of them? For example, Fact-8 is 3 Fact-6 is 3 Fact-4 is 1 Fact-1 is 3 Fact-0 is 2 The output can be Fact-8, Fact-6 or Fact-1. Lai -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Mitch Christensen Sent: Tuesday, September 28, 2004 4:10 AM To: [EMAIL PROTECTED] Subject: RE: JESS: Counting the number within facts Well, the following works. I'll leave it to others to comment on whether there is a better/easier way. for example, I was forced to declare salience. This doesn't seem necessary, but I couldn't quite get it to work without. -Mitch (deftemplate link "comment" (slot type)(slot id)) (deftemplate link-count "comment" (slot id)(slot count)) (deffacts initial-facts "comment" (MAIN::link (type similarity) (id <Fact-8>)) (MAIN::link (type contrast) (id <Fact-8>)) (MAIN::link (type contiguity) (id <Fact-8>)) (MAIN::link (type contrast) (id <Fact-6>)) (MAIN::link (type similarity) (id <Fact-6>)) (MAIN::link (type similarity) (id <Fact-4>)) (MAIN::link (type similarity) (id <Fact-1>)) (MAIN::link (type similarity) (id <Fact-0>)) (MAIN::link (type contiguity) (id <Fact-0>)) ) (reset) ;; define a query for counting (defquery count-link-assignments (declare (variables ?factId)) (MAIN::link (id ?factId))) ;; count the instances for each fact (defrule assert-type-counters (MAIN::link (type ?type)(id ?factId)) (not (MAIN::link-count (id ?factId))) => ;; count the number of link facts of this type (bind ?count (count-query-results count-link-assignments ?factId)) (assert (MAIN::link-count (id ?factId)(count ?count))) ) ;; select the largest counter (defrule print-highest-link-assignment "comment" (declare (salience -10)) (MAIN::link-count (id ?id)(count ?count)) (not (MAIN::link-count (count ?count2&:(> ?count2 ?count)))) => (printout t "Most active link found" ?id crlf)) -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of lai Sent: Monday, September 27, 2004 3:59 AM To: [EMAIL PROTECTED] Subject: JESS: Counting the number within facts Dear all I am a novice in implementing a design tool system by using JESS. Can anyone help me to solve the following questions? My questions are: If some facts are generated as following, (MAIN::link (type similarity) (id <Fact-8>)) (MAIN::link (type contrast) (id <Fact-8>)) (MAIN::link (type contiguity) (id <Fact-8>)) (MAIN::link (type contrast) (id <Fact-6>)) (MAIN::link (type similarity) (id <Fact-6>)) (MAIN::link (type similarity) (id <Fact-4>)) (MAIN::link (type similarity) (id <Fact-1>)) (MAIN::link (type similarity) (id <Fact-0>)) (MAIN::link (type contiguity) (id <Fact-0>)) 1. how to count link number within each Fact id. For examples, the link number of Fact-8 is 3, including similarity, contrast and contiguity links Fact-6 is 2 Fact-4 is 1 Fact-1 is 1 Fact-0 is 2 2. while the link number within each Fact id are compared, the Fact-8 with the highest number is selected as output. I looking forwards to your help! Lai -------------------------------------------------------------------- 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] -------------------------------------------------------------------- -------------------------------------------------------------------- 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] --------------------------------------------------------------------