Diff Inferencing
A Java program to show the result of using different reasoning levels with an ontology
This Java program loads an ontology that is in RDF/XML, N3 or Turtle format and reports the triples loaded and inferred at three reasoning levels. You may download the entire ant-based project (contains all required libraries) or just the source code file. If you download just the source, you will need Jena and Pellet to compile and run the program. See the tools section on my main semantic web page for links to those packages.
Once the ontology is loaded, the program uses three reasoners. The first does no inferencing (just uses the asserted RDF triples), the second does only RDFS reasoning and the third uses an OWL reasoner. In each case the new assertions at that level are reported.
Program Operation
The easiest way to run the program is to download the full package, unzip the archive, bring up a command prompt, switch to the base directory of the exploded archive and use ant to execute the run target. Here are a few lines that are output when running the program using the ant run target:
=====================================================================
Buildfile: build.xml
init:
[mkdir] Created dir: C:\Projects\DiffInferencing\bin
[mkdir] Created dir: C:\Projects\DiffInferencing\dist
[mkdir] Created dir: C:\Projects\DiffInferencing\generated\bin
compile:
[javac] Compiling 1 source file to C:\Projects\DiffInferencing\bin
distjar:
[jar] Building jar: C:\Projects\DiffInferencing\dist\InferenceLevel.jar
run:
[java] Using default input file: DSRDiffInferencingTestOntology.turtle
[java] Defaulting output file name to: DSRDiffInferencingTestOntology.turtle.compare.out
[java] Load model with reasoner: none
[java] Loaded model DSRDiffInferencingTestOntology.turtle using format: N3
[java] Load model with reasoner: rdfs
[java] Loaded model DSRDiffInferencingTestOntology.turtle using format: N3
[java] Load model with reasoner: owl
[java] Loaded model DSRDiffInferencingTestOntology.turtle using format: N3
[java] Jun 28, 2010 9:06:49 PM org.mindswap.pellet.jena.graph.query.GraphQueryHandler findTriple
[java] Classifying 12 elements
[java] Realizing 12 elements
[java] Wrote triples to DSRDiffInferencingTestOntology.turtle.compare.out
BUILD SUCCESSFUL
Total time: 7 seconds
=====================================================================
The main points we see in the output is that three models were loaded with the same ontology, those models were setup with different reasoners whose resulting triples were then compared and written to the output file.
The output will be written to a file with the same name as the input file but with the suffix .compare.out appended. Below is some of the generated output from the sample ontology:
=====================================================================
All Assertions at this Level (Reasoning Level: none)
Individual: CamaroPolicy
manufacturer: Chevrolet
premium: 1200
deductable: 1000
type: http://monead.com/semantic/education#AutoPolicy
All Assertions at this Level (Reasoning Level: rdfs)
Individual: CamaroPolicy
manufacturer: Chevrolet
premium: 1200
deductable: 1000
type: http://monead.com/semantic/education#AutoPolicy
type: http://monead.com/semantic/education#Policy
All Assertions at this Level (Reasoning Level: owl)
Individual: CamaroPolicy
type: http://monead.com/semantic/education#Policy
type: http://www.w3.org/2002/07/owl#Thing
type: http://monead.com/semantic/education#AutoPolicy
sameAs: http://monead.com/semantic/education#CamaroPolicy
policyCovers: http://monead.com/semantic/education#Spock
policyCovers: http://monead.com/semantic/education#KirkJT
deductable: 1000
premium: 1200
policyHolder: http://monead.com/semantic/education#KirkJT
manufacturer: Chevrolet
Assertions Unique at this Level (Reasoning Level: none)
Individual: CamaroPolicy
manufacturer: Chevrolet
premium: 1200
deductable: 1000
type: http://monead.com/semantic/education#AutoPolicy
Assertions Unique at this Level (Reasoning Level: rdfs)
Individual: CamaroPolicy
type: http://monead.com/semantic/education#Policy
Assertions Unique at this Level (Reasoning Level: owl)
Individual: CamaroPolicy
type: http://www.w3.org/2002/07/owl#Thing
sameAs: http://monead.com/semantic/education#CamaroPolicy
policyCovers: http://monead.com/semantic/education#Spock
policyCovers: http://monead.com/semantic/education#KirkJT
policyHolder: http://monead.com/semantic/education#KirkJT
=====================================================================
The sample output was greatly trimmed down from the actual output from the sample ontology. We see that the first three sections that are output contain all the triples from each model. The remaining sections then output only the unique triples that were asserted by that reasoner and not the prior one. For instance, we see that that the RDFS reasoner created a triple identifying a CamaroPolicy as a type of Policy. This makes sense since RDFS adds the concepts for subclassing. Likewise we see that the OWL reasoner added the triple relating the CamaroPolicy as a policyCovers for Spock.
Source Code
Feel free to download, use and modify this code. The intent is to help understand how to load ontologies, setup models with associated reasoners and see the impact of ontology changes.
- DiffInferencing.java: The java source code only
- DSRDiffInferencingTestOntology.turtle: A sample ontology for testing the DiffInferencing program
- Full Package: ZIP File (12.5MB)
- Source Only: ZIP File (24KB) with Java program, ant files and documentation