These exercises and examples use the newspaper project included in the examples folder of your Protege installation.
;; this line is unnecessary if you are working inside Protege
;; and you have the newspaper example loaded.
(tell ((:USE-KB :KB-1 Protege "/Applications/Protege-2000/examples/newspaper/newspaper.pprj")))
;; It is a booming economy, so assign every Editor to the Business section.
;; instance_00048 is the Business section.
(tell ((:ADD-RULE Editor
((date_hired ?editor ?date)
->
(sections ?editor instance_00048)))))
;; Test the rule --------------------------------------
;; Should fail.
;; instance_00068 is "Ms Gardiner"
(ask ((sections instance_00068 ?section)))
;; This should trigger the rule.
(tell ((date_hired instance_00068 "08-Feb-2003")))
;; This should now succeed.
(ask ((sections instance_00068 ?section)))
When laying out a newspaper, every rectangle must be
between 3 and 15 square inches.
(tell ((:ADD-RULE Rectangle
((width ?rectangle ?width)
->
(height ?rectangle ?height)
(:bind ?area (:LISP (* ?width ?height)))
(:fail (:test (:LISP (<= 3 ?area 15))))
(name ?rectangle ?name)
(:PRINTLN "Warning: rectangle " ?name " has an out of limits area of " ?area)))))
(tell (;;(:trace :verbose)
(:add-instance (?r1 Rectangle) (:name ?r1 "Rect1") (name ?r1 "Rect1") (width ?r1 1.0) (height ?r1 5.0))
(:add-instance (?r2 Rectangle) (:name ?r2 "Rect2") (name ?r2 "Rect2") (width ?r2 2.0) (height ?r2 1.0))
(:add-instance (?r3 Rectangle) (:name ?r3 "Rect3") (name ?r3 "Rect3") (width ?r3 3.0) (height ?r3 5.0))
(:add-instance (?r4 Rectangle) (:name ?r4 "Rect4") (name ?r4 "Rect4") (width ?r4 4.0) (height ?r4 3.0))
(:add-instance (?r5 Rectangle) (:name ?r5 "Rect5") (name ?r5 "Rect5") (width ?r5 6.3) (height ?r5 1.6))
(:add-instance (?r6 Rectangle) (:name ?r6 "Rect6") (name ?r6 "Rect6") (width ?r6 6.0) (height ?r6 3.8))
))
Notes: