0

So I'm trying to self-learn CLIPS and clipspy for a class assignment and I'm a bit stuck. The code below compiles and runs just fine but the output is a bit strange. I am trying to expand on examples I found in the manual.

import clips
import logging
env = clips.Environment()
logging.basicConfig(level=10, format='%(message)s')
router = clips.LoggingRouter()
router.add_to_environment(env)
env.build("""
(defrule whodunit
 (shoot ?hunter ?who)
 =>
 (printout t ?hunter " shot " ?who crlf)
)""")
env.build("""
(defrule animalGame
 (animal ?ani)
 (shoot $? ?ani)
 =>
 (assert (game ?ani))
)""")
env.build("""
(defrule gameAnimal
 (game ?ani)
 =>
 (assert (animal ?ani))
)""")
env.build("""
(defrule isIllegal
 (shoot ?a ?b)
 (not(game ?b))
 =>
 (assert (criminal ?a))
)""")
env.assert_string("(animal duck)")
env.assert_string("(animal dog)")
env.assert_string("(shoot Brian duck)")
env.assert_string("(shoot Bob rhino)")
env.assert_string("(game deer)")
env.run()
for fact in env.facts():
 print(fact)

This outputs:

(initial-fact)
(animal duck)
(animal dog)
(shoot Brian duck)
(shoot Bob rhino)
(game deer)
(animal deer)
(criminal Bob)
(criminal Brian)
(game duck)

It seems that Brian is labeled a criminal for shooting an animal that is not game despite the animal he is shooting being declared game in the next step. Is there anyway to re-evaluate rules to fix this contradiction?

asked Nov 14, 2020 at 3:12

1 Answer 1

0

I figured it out. The answer is salience. I also realized there's some logical flaws/inconsistencies declaring all animals hunted as game and charging shooting animals that are not game as criminal. Anyways:

env.build("""
(defrule animalGame
 (declare (salience 100))
 (animal ?ani)
 (shoot $? ?ani)
 =>
 (assert (game ?ani))
)""")
answered Nov 14, 2020 at 3:24
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.