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

Reply via email to