Hi,
My goal is to have logical expressions in rule LHS involving multiple
templates derived from hierarchical Java models:
public class PO {
public Customer customer;
// setter, getter not shown.
}
public class Customer {
public String name;
public Address address;
// setters, getters not shown.
}
public class Address {
public int streetNumber;
public String street;
public String city;
// setters, getters not shown.
}
Templates:
(deftemplate Customer
(declare (from-class Customer)
(include-variables TRUE)))
(deftemplate PO
(declare (from-class PO)
(include-variables TRUE)))
The following rule can handle an expression such as:
If (purchaseOrder.customer.address.street == customer.address.street)
(defrule rule
(Customer (address ?address))
(PO (customer ?customer))
(test (= 0 (str-compare ((?customer getAddress) getStreet) (?address
getStreet))))
=>
(bind ?name (?customer getName))
(bind ?addr (?address getStreet))
(printout t ?addr ": customer: " ?name crlf)
)
Are there better, more elegant ways to accomplish the same?
I tried:
?po <- (PO (customer ?customer))
?customer <- (Customer (address ?address))
(test (= (((?po getCustomer) getAddress) getStreet) ((?customer
getAddress) getStreet)))
But ?po and ?customer are facts (Jess.Fact) that have no getCustomer and
getAddress methods.
Son