(facts) f-0 (MAIN::Account (balance 0.0) (class Download presentation Presentation is loading. Please wait. Published byOctavia Paul
Modified over 6 years ago
1
Integration Part 2 csandru@info.uvt.ro
2
Shadow facts Unordered facts that serve as "bridges" to Java objects
3
Ensuring shadow facts consistency
4
Automatic updating public class Person {
5
Querying WM Allows for retrieving working memory objects/facts based on filters Iterator<Object> it = expertEngine.getObjects(new Filter() { public boolean accept(Object o) { return o instanceof Person; } }); while(it.hasNext()) { System.out.println("Person object in WM: " + ((Person) it.next()).getName());
6
Queries Defining queries Collect the result (defquery search-by-name
7
Marks in the working memory
8
Java from Jess Source: awtdraw.clp (import java.awt.event.WindowEvent)
9
Adding commands to Jess
10
Blood Groups Sample Adapted
11
JESS side elements (defrule transfusion =>
12
JAVA side elements //create a person object and make it available in the expertise Person personNeedingBlood = new Person(name, bg); expertEngine.add(personNeedingBlood); //create the needed transfusion fact and assert it String factStr = "(need-transfusion (who \"" + name + "\"))"; expertEngine.assertString(factStr); //collect the result QueryResult result = expertEngine.runQueryStar("search-by-name", new ValueVector().add(new Value(name, RU.STRING))); while (result.next()) { System.out.println(name + " is compatible with: " + result.getString("with")); }
Similar presentations © 2025 SlidePlayer.com. Inc. Log in
Integration Part 2 csandru@info.uvt.ro Intelligent Systems Integration Part 2 csandru@info.uvt.ro.
Similar presentations
Presentation on theme: "Integration Part 2 csandru@info.uvt.ro Intelligent Systems Integration Part 2 csandru@info.uvt.ro."— Presentation transcript:
Intelligent Systems Integration Part 2
Serve to put any Java object into Jess's working memory. (deftemplate account (declare (from-class Account))) - construct (defclass account Account) – function (definstance account (new Account “Name”) [static | dynamic | auto] ) (assert (Account (name “Test”))): no object created (add new Account “Other”): automatically creates a template called “Account”, a shadow fact and the account object (bind ?a (new Account “Third”)) (add ?a) Jess> (facts) f-0 (MAIN::Account (balance 0.0) (class <Java-Object:java.lang.Class>) (OBJECT <Java-Object:Account>))
(bind ?pObject (new Person “John” “B”)) (bind ?person (add ?pObject)) (modify ?person (name “Jack”)): pObject automatically updated (?pObject setName “Jack”): fact is not updated; need special update (update ?pObject)
PropertyChangeSupport pcs = new PropertyChangeSupport(this); public void setName(String name) { String temp = name; this.name = name; pcs.firePropertyChange("name", temp, name); } public void setBlood(String blood) { String temp = blood; this.blood = blood; pcs.firePropertyChange("blood", temp, blood); }; public void addPropertyChangeListener(PropertyChangeListener pcl) { pcs.addPropertyChangeListener(pcl); public void removePropertyChangeListener(PropertyChangeListener pcl) { pcs.removePropertyChangeListener(pcl);
"Finds compatibilities for a given name" (declare (variables ?name)) (compatibility (who ?name) (with ?with&~”John”)) ) Collect the result QueryResult result = expertEngine.runQueryStar("search-by-name", new ValueVector().add(new Value(“Mathew”, RU.STRING))); while (result.next()) { System.out.println(name + " is compatible with: " + result.getString("with")); }
Save a working memory status expertEngine.batch("bgExpert.clp"); expertEngine.reset(); expertEngine.addAll(getDonors()); //save this engine status for future resets WorkingMemoryMarker initialStatus = expertEngine.mark(); Reset to saved status expertEngine.resetToMark(initialStatus);
(import java.awt.event.WindowListener) (import java.awt.Frame) (import java.awt.Color) (deffunction create-components () (bind ?f (new Frame "Drawing Demo")) (?f addWindowListener (implement WindowListener using (lambda (?name?event) (if (eq ?name windowClosing) then (System.exit 0))))) (bind ?c (new jess.awt.Canvas painter (engine))) (?f add "Center" ?c) (?f setSize ) (?f setVisible TRUE))
public class ExMyUpcase implements Userfunction { // The name method returns the name by which // the function will appear in Jess code. public String getName() { return "my-upcase"; } public Value call(ValueVector vv, Context context) throws JessException { String result = vv.get(1).stringValue(context).toUpperCase(); return new Value(result, RU.STRING); r.addUserfunction(new ExMyUpcase());
Loading persons from JAVA while keeping blood rules in JESS (deftemplate Person (declare (from-class Person)) ) private List<Person> getDonors(){ List<Person> donors = new ArrayList<Person>(); donors.add(new Person("John", "O")); donors.add(new Person("Stan", "O")); donors.add(new Person("Peter", "A")); donors.add(new Person("Bruce", "B")); donors.add(new Person("Dan", "AB")); donors.add(new Person("Mathew", "A")); donors.add(new Person("Andrew", "B")); return donors; } expertEngine.addAll(getDonors());
(need-transfusion (who ?who)) (Person (name ?who) (blood ?required)) (Person (name ?source&~?who) (blood ?bg)) (blood-acceptance (acceptor ?required) (donators $? ?bg $?)) => (assert (compatibility (who ?who) (with ?source))) ) (defquery search-by-name "Finds compatibilities for a given name" (declare (variables ?name)) (compatibility (who ?name) (with ?with))
Similar presentations
All rights reserved.