RE: JESS: Accessing Java objects fields from a defrule

View: New views
1 Messages — Rating Filter:   Alert me  

RE: JESS: Accessing Java objects fields from a defrule

by Nguyen, Son :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

RE: JESS: Accessing Java objects fields from a defrule

Hi,

I am wondering whether the following would accomplish what you wanted.

Here is the complete clp file. You can change the weight of the door at the bottom of the clp file.

(import House)
(import Door)

(deftemplate House
    (declare (from-class House)
                 (include-variables TRUE)))

(deftemplate Door
    (declare (from-class Door)
                 (include-variables TRUE)))

(defrule rule
    (House (door ?door&:(> (?door getWeight) 25)))
    =>
    (printout t "weight: " (?door getWeight) crlf)
)
;
; create a House
(bind ?house (new House))

; create Door and add it to the House
(bind ?door (new Door))
(?house setDoor ?door)
(set-member ?door weight 22)

; add the house to the working memory
(add ?house)

(run)


I hope this helps.

Son