0% found this document useful (0 votes)
29 views

Jess Con Java

Jess is an expert system shell written in Java that allows rules to be defined using a Lisp-like syntax. Jess can be extended with custom Java functions and objects, and embedded within Java programs. Rules and facts can be loaded from files or programmatically. Jess represents all data as Value objects and provides an execution context for evaluating functions and resolving variables.

Uploaded by

Ivan Fernandez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Jess Con Java

Jess is an expert system shell written in Java that allows rules to be defined using a Lisp-like syntax. Jess can be extended with custom Java functions and objects, and embedded within Java programs. Rules and facts can be loaded from files or programmatically. Jess represents all data as Value objects and provides an execution context for evaluating functions and resolving variables.

Uploaded by

Ivan Fernandez
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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