Jena OWL Syntax Checker HowTo

Contents

Conformance and Status

The OWL syntax checker shipping with Jena2.0 is alpha quality (mostly) conforming with the Last Call of the OWL design.

Two known conformance errors are:

Further conformance issues concern changes made between the OWL Last Call and Candidate Recommendation. The most significant of these is that the _:b rdf:type rdf:List triples are no longer required. However, the Jena2.0 syntax checker code has not been updated reflecting this. Since the Jena2.0 version of ARP has been updated and does not generate these triples, it means that the syntax checker is difficult to use in practice.

The three main aspects that are expected to change on the next revision of this software (from alpha to beta quality) are:

Overview of Usage

The OWL Syntax Checker takes a graph and sees whether it conforms with OWL Lite or OWL DL syntax.

The basic usage returns a single word being one of "Lite" "DL" or "Full".

Error messages can indicate why it is not in a lower level.

No rationale is offered as to why it is in this level rather than a higher level; such a rationale can be found from a different tool that provides the abstract syntax form corresponding to the graph. This functionality is not planned within Jena.

It is generally desirous to compute an imports closure before doing a syntax check, the code sample below shows how to do this. A future revision is likely to simplify this.

If it is desired to have error messages indicating why a graph is in OWL DL rather than OWL Lite then appropriate constructor arguments must be given.

Sample code

    // set this boolean to true if error msgs should
    // indicate why the graph is not in Lite.
    boolean expectingLite = false;
    Model baseModel;
    Writer w; // for error messages.
    
    ...
    // construct imports closure 
    OntModel m = ModelFactory.createOntologyModel(
                   OntModelSpec.OWL_MEM,
                   baseModel);

   // Get a snytax checker
   Checker chk = new Checker(expectingLite);

   // Add one or more graphs.
   chk.add(m.getGraph());
   // get result.
   String subLang = chk.getSubLanguage();
   ...

   ...
   // If we do not like the answer we can 
   // get error messages.

   if (!(subLang.equals("Lite"))) {
     // There is no explaination offered why something
     // is in a lower level than expected, only why it 
     // is in a higher level than expected.
     Iterator it = chk.getProblems();
     while (it.hasNext()) {
       SyntaxProblem sp = (SyntaxProblem) it.next();
       String s = sp.longDescription();

       w.write(s);
       w.write("\n");
     }
   }

In Lieu of Javadoc

The Javadoc has not been finished since the API has not been fully designed. This section sketches the current interface.

Checker

com.hp.hpl.jena.ontology.tidy.Checker

Constructor

Checker(boolean expectingLite)
If expectingLite is true then the checker will use an OWL Lite grammar and error messages will be generated for constructs that are in OWL DL but not OWL Lite. However, if this is true then the checker cannot distinguish OWL DL from OWL Full. If false the checker can distinguish OWL Lite from OWL DL, but cannot justify itself.

Methods

void add(Graph g)
Check this graph (and any others that are added)
void load(String url)
Add the imports closure of the RDF/XML document found at URL
String getSubLanguage()
Returns one of "Lite", "DL", "Full" or "DL or Full". The latter is only returned when the checker was constructed with the expectingLite flag as true. This should work incrementally (not tested). i.e. calls to add(Graph) and getSubLanguage() can be interleaved.
Iterator getErrors()
Iterator getProblems()
Both these methods return an Iterator over SyntaxProblem's. The second returns errors and warnings, the first just the errors.

SyntaxProblem

Typically, use either the shortDescription or the longDescription method, and none of the others.

com.hp.hpl.jena.ontology.tidy.SyntaxProblem

Methods

String shortDescription()
String longDescription()
A description of the problem detected, often somewhat cryptic.
RDFWriter setWriter(RDFWriter)
Sets the RDFWriter used for creation of the longDescription(). Returns the previous value.
EnhNode problemNode()
Graph problemSubGraph()
Helps identify the problem. At least one of these two is non-null.