Author: Paola Turci (University of Parma)
Date: October 18, 2001
Java platform: Sun JDK 1.2 Windows
JADE version 2.4
SAX parser (e.g. Xerces)
RDF parser: http://www-db.stanford.edu/~melnik/rdf/api.html
This tutorial describes how to install and use the RDF support with JADE; the RDF support permits to use a concrete syntax, for ACLmessage content, based on RDF/RDFS. The RDFCodec.java class implements the Codec interface of JADE (jade.content.lang.Codec) and allows converting back and forth between arrays of byte in RDF format and AbsContentElement (abstract descriptor of the message content). Since RDFCodec package uses the package jade.content and its sub-packages, it requires JADE 2.4.
Installation
In order to install RDF support the following steps must be performed:
- The RDFCodec must be downloaded from the JADE download page.
- After downloading you must unzip the RDFCodec package under the root of the jade distribution tree. You should end having a hierarchy like jade/add-ons/RDFCodec.
- A SAX parser (e.g. Xerces) and the RDF parser (http://www-db.stanford.edu/~melnik/rdf/api.html) must be downloaded and installed into the system.
- The xml parser jar file (e.g. xerces.jar) and the RDF parser jar file (rdf-api-2001-01-19.jar) must be added to the CLASSPATH or specified in the -classpath argument when starting the virtual machine
Compiling
The default JADE Makefile rules don’t take the RDFCodec into account. For handling the compilation process of the RDFCodec you have to use the ‘build.xml’ ant-file located in the RDFCodec directory. The following rules are available:
- ant – compiles the RDFCodec classes (if you want to recompile the package you must put rdf-api-2001-01-19.jar archives in the jade/lib directory or change the ‘build.xml’ makefile)
- ant lib – creates the rdf.jar archive in the lib directory
- ant clean – removes the compiled classes and the rdf.jar archive
- ant examples – compiles the example classes
Configuration and Usage
The current configuration uses Xerces as the default SAX parser. So if you don’t want to make any changes you just have to download Xerces from the link provided above and make sure it is added to the classpath when starting (either by including it into the $CLASSPATH environment variable – %CLASSPATH% under windows or by specifing it on the command line). Moreover this package uses Stanford API (rdf-api-2001-01-19.jar) as rdf parser, so you must download and added it to the classpath too.
Here is an example of how you would start the platform assuming that you copied xerces.jar and rdf-api-2001-01-19.jar from the initial distribution to the RDFCodec/lib directory:
java -classpath ./lib/jade.jar:./lib/iiop.jar:./add-ons/RDFCodec/lib/xerces.jar:./add-ons/RDFCodec/lib/rdf-api-2001-01-19.jar:./add-ons/RDFCodec/lib/rdf.jar jade.Boot ( for Unix )
or
java -classpath .\lib\jade.jar;.\lib\iiop.jar;.\add-ons\RDFCodec\lib\xerces.jar;.\add-ons\RDFCodec\lib\rdf-api-2001-01-19.jar;.\add-ons\RDFCodec\lib\rdf.jar jade.Boot ( for Windows )
If you want to use another xml parser you have to specify in the command line the system property org.xml.sax.parser.
When an agent wants to send an RDF encoded message, it must register the language with the registerLanguage() method of the ContentManager class. For example (assuming manager is theContentManager):
manager.registerLanguage(new RDFCodec());
Moreover it is recommended to set the language of the message. For example (assuming ACLmsg is the ACL message):
ACLmsg.setLanguage(RDFCodec.NAME);
Using RDFCodec, the messages are arrays of byte in RDF format; the tags used are those defined in the subsequent RDF schema.
<?xml version=\"1.0\"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/TR/1999/PR-rdf-schema-19990303#"> <!--- resources ---> <rdfs:Class rdf:about="Object"> <!--- superclass ---> <rdfs:subClassOf rdf:resource="rdfs:Resource"/> </rdfs:Class> <rdfs:Class rdf:about="AttributeDescription"> <rdfs:subClassOf rdf:resource="#Object"/> </rdfs:Class> <rdfs:Class rdf:about="Term"> <rdfs:subClassOf rdf:resource="#Object"/> </rdfs:Class> <rdfs:Class rdf:about="Aggregate"> <rdfs:subClassOf rdf:resource="#Term"/> </rdfs:Class> <rdfs:Class rdf:about="Primitive"> <rdfs:subClassOf rdf:resource="#Term"/> </rdfs:Class> <rdfs:Class rdf:about="ContentElement"> <rdfs:subClassOf rdf:resource="#Object"/> </rdfs:Class> <rdfs:Class rdf:about="ContentElementList"> <rdfs:subClassOf rdf:resource="#ContentElement"/> </rdfs:Class> <!--- properties ---> <rdf:Property rdf:about="type"> <rdfs:domain rdf:resource="#Object"/> <rdfs:range rdf:resource="rdfs:Literal"/> </rdf:Property> <rdf:Property rdf:about="Attributes"> <rdfs:domain rdf:resource="#Object"/> <rdfs:range rdf:resource="#AttributeDescription"/> </rdf:Property> <rdf:Property rdf:about="attributeValue"> <rdfs:domain rdf:resource="#AttributeDescription"/> <rdfs:range rdf:resource="#Object"/> </rdf:Property> <rdf:Property rdf:about="aggregateElements"> <rdfs:domain rdf:resource="Aggregate"/> <rdfs:range rdf:resource="Term"/> </rdf:Property> <rdf:Property rdf:about="primitiveValue"> <rdfs:domain rdf:resource="#Primitive"/> <rdfs:range rdf:resource="rdfs:Literal"/> </rdf:Property> <rdf:Property rdf:about="contentElementListElements"> <rdfs:domain rdf:resource="#ContentElementList"/> <rdfs:range rdf:resource="#ContentElement"/> </rdf:Property> </rdf:RDF>
RDFCodec package refers to this RDF schema to verify the validity of the message content.
Examples
After setting properly the CLASSPATH, execute the following command to start Sender and Receiver agents:
java jade.Boot
receiver:examples.rdfcontent.Receiver sender:examples.rdfcontent.Sender
To see the messages RDF format, execute the following command:
java jade.Boot –gui
after, utilize the gui to run receiver and sender agents; utilize the sniffer agent to see the messages.