-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 12:27 PM -0400 8/3/99, <[EMAIL PROTECTED]> wrote:
>Hello Jess Users:
> If I have to execute more than one clp file, how to combine and call these
>files in Jess.
>The requirement is that the Rules present in one clp file are related to
>another clp file.
Well, the easy answer is to put a (batch file1.clp) in the beginning=20
of file2.clp. This will load the stuff from file1.clp before you=20
load the stuff from file2.clp.
Alternatively, I have written a very small jess extension called=20
require that works kind of like an include guard. You call require=20
with a path string (require "file1.clp"). Require will check if it=20
loaded anything by that name before, and if not will batch the file.=20
If it was already loaded, it will return immediately.
I use require because I have a largeish collection of files that all=20
sort of depend on each other (it's a bunch of ontologies, and you=20
need global.clp to understand inference.clp etc...). This way I can=20
list the dependencies of each file at the beginning of that file and=20
not worry about loading a file multiple times by accident.
I posted this a little while ago, and have since improved it based on=20
feedback from Ernest regarding the call mechanism.
Eric Eslinger
/**
*
* A userfunction extension to jess.=A0
* The jess function (require) will take a string as argument, and if
* that string corresponds to a file that has already been loaded=20
through require, it will
* do nothing, otherwise it will use the batch facility to load the file.
*
* @author Eric M Eslinger
* @see <a href=3Dhttp://herzberg1.ca.sandia.gov/jess>Jess</a>
*/
import jess.*;
import java.util.Hashtable;
public class Require implements Userfunction {
/**
* Returns the name of the userfunction (require) for use by jess.
* @return a string equal to "require", the name of this userfunction=A0
*/
public String name() {
return "require";
}
/**
* Calls the require function, called from jess
* @return true or false, based on the sucess of the file loading.
* @exception ReteException If the call was malformed.
*/
public Value call(ValueVector vv, Context context) throws=20
ReteException {
if ((vv.size() !=3D 2) || ((vv.get(1).type() !=3D=20
RU.STRING) && (vv.get(1).type()!=3DRU.ATOM))) {
throw new ReteException("require", "usage:=20
require <filename>","");
}
String filename =3D vv.get(1).stringValue(); //get the filename
synchronized (context.engine()) {
Value rlist =3D context.engine().fetch("require-list");
if (rlist =3D=3D null) {
rlist =3D new Value(new=20
Hashtable(),RU.EXTERNAL_ADDRESS);
context.engine().store("require-list",rlist);
}
Hashtable rtable =3D (Hashtable)=20
rlist.externalAddressValue();
if (rtable.get(filename) =3D=3D null) {
rtable.put(filename,"loaded");
return=20
context.engine().findUserfunction("batch").call(vv,context);
} else {
return Funcall.TRUE();
}
}
}
}
(o_ Eric Eslinger
(o_ (o_ //\ [EMAIL PROTECTED]
(/)_ (/)_ V_/_ artificial intelligence masquerading as a graduate stud=
ent
Get eric's public key at http://socrates.berkeley.edu/~erice/pubkey.asc
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.1 for non-commercial use <http://www.pgp.com>
iQA/AwUBN6dlFmcs0GtuY6HtEQLS+gCgjjiv+CFt7zHGK2XFBlqi733DFDgAoLfb
q1xKNq0O4p3M8X02JBf9mn8I
=CWEz
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------