How to use COjDA - Complete OO jDREW API

Creating a COjDA Object in Java

     There are six different ways to create a COjDA object. For complete details about COjDA readers are refered to the JavaDoc for COjDA. One way to create a COjDA api object is to use a RDFS taxonomy and POSL knowledge base. For example you have a file called Types.rdfs that contains the following:
<rdf:RDF 
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xml:base="http://example.org/schemas/vehicles"> <rdf:Description rdf:ID="Vehicle"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> </rdf:Description> <rdf:Description rdf:ID="PassengerVehicle"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Vehicle"/> </rdf:Description> <rdf:Description rdf:ID="Van"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Vehicle"/> </rdf:Description> <rdf:Description rdf:ID="Car"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#PassengerVehicle"/> </rdf:Description> <rdf:Description rdf:ID="MiniVan"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Van"/> <rdfs:subClassOf rdf:resource="#PassengerVehicle"/> </rdf:Description> <rdf:Description rdf:ID="Sedan"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Car"/> </rdf:Description> <rdf:Description rdf:ID="SportsCoupe"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Car"/> </rdf:Description> <rdf:Description rdf:ID="ToyotaCorolla"> <rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Class"/> <rdfs:subClassOf rdf:resource="#Sedan"/> </rdf:Description> </rdf:RDF>
Also you have a file called KB.posl that contains the following:
	discount(?customer, ?product, percent5) :- premium(?customer), regular(?product).
	base_price(customer->[sex->male!?]; vehicle->? : Car; price->650 : Integer).
	base_price(customer->[sex->male!?]; vehicle->? : Van; price->725 : Integer).


You can create a COjDA api object by using the following Code:
	  
	File types = new File("Types.rdfs");
	File kb = new File("KB.posl");
	COjDA api = new COjDA(COjDA.POSL, COjDA.RDFS, kb, types);
	
Once you have created the COjDA object you can then execute KB queries and Taxonomy queries. For a full list of a methods avaible to COjDA readers are refered to the JavaDoc of COjDA. An example KB query would be the following:

base_price(customer->[sex->male; name->"John Doe"; age->28]; vehicle->vehicle:ToyotaCorolla; price->?money:Integer). To execute this query using COjDA the following code would be used:
	  
	String kbPOSLQuery = "base_price(customer->[sex->male; name->\"John Doe\"; age->28]; vehicle->vehicle:ToyotaCorolla; price->?money:Integer).";
	String result = api.issueKBQuery_POSL(kbPOSLQuery);
The resulting RuleML answer expression would look as follows:
<RuleML>
	<Answer>
		<Rulebase>
			<Equal>
				<Var type="Integer">money</Var>
				<Ind type="Integer">650</Ind>
			</Equal>
		</Rulebase>
	</Answer>
</RuleML>

To execute a Taxonomy Query the following code could be used:
	  
	String taxonomyPOSLQuery = "subsumesPlus(?X, MiniVan)";
	String resultTaxonomy = api.issueTaxonomyQuery_POSL(taxonomyPOSLQuery);
The resulting RuleML answer expression would look as follows:
<RuleML>
	<Answer>
		<Rulebase>
			<Equal>
				<Var>X</Var>
				<Ind>Van</Ind>
			</Equal>
		</Rulebase>
		<Rulebase>
			<Equal>
				<Var>X</Var>
				<Ind>PassengerVehicle</Ind>
			</Equal>
		</Rulebase>
		<Rulebase>
			<Equal>
				<Var>X</Var>
				<Ind>Vehicle</Ind>
			</Equal>
		</Rulebase>
	</Answer>
</RuleML>	
For more information about RuleML answer expressions and how to query the taxonomy, readers are referred to the documents of Taxonomy Querying and the Taxonomy Querying API.

Last Updated:
   July 30, 2008

By:
   Ben Craig