Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7493405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:56:38+00:00 2026-05-29T16:56:38+00:00

Using Jess as the rule engine, we can assert a fact that some witness

  • 0

Using Jess as the rule engine, we can assert a fact that some witness has seen a person, at some place, and with time associated:

(deffacts witnesses
    (witness Batman Gotham 18)
    (witness Hulk NYC 19)
    (witness Batman Gotham 2)
    (witness Superman Chicago 22)
    (witness Batman Gotham 10)
)

With a rule, I want to know if several witnesses have seen the same person at the same place, not considering time.

In Jess documentation we got this example for counting employees making salraries of 100K and more:

(defrule count-highly-paid-employees
    ?c <- (accumulate (bind ?count 0)                        ;; initializer
    (bind ?count (+ ?count 1))                    ;; action
    ?count                                        ;; result
    (employee (salary ?s&:(> ?s 100000)))) ;; CE
    =>
    (printout t ?c " employees make more than $100000/year." crlf))

So I based my code on previous example:

(defrule count-witnesses
    (is-lost ?plost)
    (witness ?pseen ?place ?time)
    ?c <- (accumulate (bind ?count 0)
    (bind ?count (+ ?count 1))
    ?count
    (test ())  ; conditional element of accumulate
    (test (= ?plost ?pseen))
    (test (>= ?count 3))
    =>
    (assert (place-seen ?place))
)

With the ‘(deffacts)’ instruction provided above and the rule, the engine should assert the fact

(place-seen Gotham)

because we have Batman seen three times in Gotham.

I have no idea how to use the conditional element (CE) part of ‘accumulate’. Can I use a ‘test’ to retain facts with same person and place?

Any idea how to achieve this?

Thank you!


Note : synthax of ‘accumulate’ is

(accumulate <initializer> <action> <result> <conditional element>)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:56:44+00:00Added an answer on May 29, 2026 at 4:56 pm

    I’m going to leave out the stuff about ?plost, as you don’t explain what that is, exactly; you can add it back in yourself if you need to.

    A basic rule that (almost) does what you want is as follows. The CE part you weren’t getting is just a pattern that we want to accumulate over; here, it matches facts with the same person witnessed at the same place as the fact matched by the first person:

    (defrule count-witnesses
      ;; Given that some person ?person was seen in place ?place
      (witness ?person ?place ?)  
      ;; Count all the sightings of that person in that place  
      ?c <- (accumulate (bind ?count 0)
                        (bind ?count (+ ?count 1))
                        ?count
                        (witness ?person ?place ?))
      ;; Don't fire unless the count is at least 3
      (test (>= ?c 3))
      =>
      (assert (place-seen ?person ?place))
    )
    

    Now, the only problem with this rule is that it’ll fire three times for your deffacts, once for every one of the Batman/Gotham facts. We can stop this by changing the first pattern to match only the earliest sighting of a person at a given place:

    (defrule count-witnesses
      ;; Given that some person ?person was seen in place ?place, and there is no other 
      ;; sighting of the same person at the same place at an earlier time
      (witness ?person ?place ?t1)    
      (not (witness ?person ?place ?t2&:(< ?t2 ?t1)))
      ;; Count all the sightings of that person in that place  
      ?c <- (accumulate (bind ?count 0)
                        (bind ?count (+ ?count 1))
                        ?count
                        (witness ?person ?place ?))
      ;; Don't fire unless the count is at least 3
      (test (>= ?c 3))
      =>
      (assert (place-seen ?person ?place))
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using C#, I need a class called User that has a username, password, active
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button
I am developing an expert system using Jess shell. I would like a program
I'm running a java code using Apache Avro. Some code gets deprecated in the
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using jQuery, one can easily find out whether a particular element is visible using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.