I have a few, rare rules that need to count a number of matching facts
in order to determine whether to fire or not. I guess one solution would
be to keep the counts stored explicitely, but keeping them up to date
seems rather complicated. The following seems to work:

(defquery find-statements
  (declare (variables ?subject ?predicate))
  (statement (subject ?subject) (predicate ?predicate)))

(defrule too-many-features
  (logical (statement (subject ?subject) (predicate v:feature))
  (statement (subject ?subject) (predicate rdf:type) (object
v:Protein)))
  (test(< 2 (count-query-results find-statements ?subject v:feature)))
  =>
  (printout t "Too many features for " ?subject))

...but I'd like to replace the call to count query-results with a more
generic count(?templateFact) function. Any suggestions how to approach
this? Perhaps this would be useful to have as a built-in fanction?

(deffunction count (?fact)
  (return ?))

(defrule too-many-features
  (logical (statement (subject ?subject) (predicate v:feature))
  (statement (subject ?subject) (predicate rdf:type) (object
v:Protein)))
  (test(< 2 (count (statement (subject ?subject) (predicate
v:feature)))))
  =>
  (printout t "Too many features for " ?subject))

--
Eric Jain

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