You are on page 1of 3

Jess, Java Expert System Shell

Originally

a core Clips implementation in Java Evolved into Java-influenced environment, details refer to Jess

Extendable
can be extended using Userfunction
Java program: import jess.*; public class ExMyUpcase implements { // The name method returns the

Userfunction

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 { return new Value(vv.get(1).stringValue(context).toUpperCase() , RU.STRING); } }

Every datum in Jess is represented by an object of jess.Value. The jess.Context represents an execution context for the evaluation of function calls and the resolution of variables. The jess.ValueVector class is Jess's internal representation of a list, and is used to represent multifields.
Jess commands: Jess> (load-function ExMyUpcase) Jess> (my-upcase foo)

Embeddable
can embeded in a Java program:
import jess.*; public class ExPt { public static void main(String[] unused) throws JessException

{ Rete r = new Rete(); r.executeCommand("(batch jess/scriptlib.clp)"); r.executeCommand("(deftemplate point \"A 2D point\" (slot x) (slot y))"); r.executeCommand("(assert (point (x 37) (y 49)))"); r.executeCommand("(facts)"); } }

Executing a Jess File


import jess.*; // ... // Create a Jess engine Rete rete = new Rete(); // Open the file test.clp FileReader fr = new FileReader("test.clp"); // Create a parser for the file, telling it where to take input // from and which engine to send the results to Jesp j = new Jesp(fr, rete); try { // parse and execute one construct, without printing a prompt j.parse(false); } catch (ReteException re) { // All Jess errors are reported as 'ReteException's. re.printStackTrace(rete.getErrStream()); }

Example 1: fixed rule-base file name


Java

source: Test.java Jess source: Hello1.clp Example 2: user-specified rule-base file name

Java

source: Test2.java Jess source: Hello.clp

Object Support
Create and manipulate Java objects directly from Jess,
(bind (call (call (call ?ht ?ht ?ht ?ht (new java.util.Hashtable)) put "key1" "element1") put "key2" "element2") get "key1")

Run-time Environment
1. Command Line
java jess.Main

2. Graphics Console
java jess.Console

You might also like