The ontology compiler

Introduction

When building queries targeted at a given ontology, you'll likely find yourself mirroring with Cubi classes the entire ontology. To solve this problem, Cubi includes a small tool called cubi-oc, the Cubi ontology-compiler. This tool will scan the available ontologies and generate a set of C++ headers defining Cubi classes corresponding to the RDF resources of the ontology, which you can include then in your source files.

Note:
The Cubi ontology-compiler only works with the Tracker database. This is due to the fact that Tracker offers some RDF extensions for ontology introspection that are needed for the compiler to work properly.
See http://www.tracker-project.org/ for more details on Tracker.

Generating the ontology headers

When run, the ontology compiler will create one folder called ontologies in the current working directory, with inside one .h file for each introspected ontology. Additionally, it will generate two files, ontologies.h which is a global header to include all the ontologies, and ontologies.pri which is a file that you can include in a .pro file if you use the qmake build system.

Overriding some of the ontology

You can override some properties defined in the ontology using a cubi-oc.overrides file.

The cubi-oc.overrides file has to be in the current working directory when running the cubi-oc command.

The syntax of the file follows the following format:

 [prefixedName]
 Property = Value

The supported properties are:

Domain Override the domain of a RDF property
Range Override the range of a RDF property

An example section of an cubi-oc.overrides file could be :

 [nie:url]
 Domain = http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject

Command line options reference

Run cubi-oc --help for more a short manual describing the various options.

Using the generated ontologies

The C++ classes describing the ontology information are generated in the namespace Cubi::Ontologies . The C++ classes describing the RDF resources in the ontology are generated in the Cubi::Resources namespace, in a nested namespace with the same name as the ontology prefix. For example, the C++ classes describing the RDF resources of the nco ontology will be in the Cubi::Resources::nco namespace.

Structure of the C++ class generated for any RDF resource

A C++ class describing an RDF resource (class, property or predefined instance) has the following methods:

 static const char * encodedIri() 
Returns the full IRI of the RDF resource, in URL encoded form, for example http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Role
 static const QString & prefixedName() 
Returns the prefixed name of the RDF resource, for example nco:Role
 static const QString & iri() 
Helper function that returns a QString out of the result of encodedIri()
 static const ResourceValue & resource() 
Helper function that returns a Cubi::ResourceValue representing the RDF class

Additionally, two types are defined inside the class:

 ResourceType 
Points to the RDF type of the resource, so for classes rdfs::Class
 Ontology 
Points to the ontology of the resource, for example Ontologies::nco

Structure of the C++ class generated for an RDF class

A C++ class describing an RDF class has the additional following types:

 Ontology 
Points to the ontology of the resource, for example Ontologies::nco

Structure of the C++ class generated for an RDF property

A C++ class describing an RDF property has the additional following methods:

 static const PredicateFunction & function() 
Returns a Cubi::PredicateFunction for that property
 static bool singleValued() 
Returns true if the nrl:maxCardinality property of that RDF property is set to 1

The following types are also defined inside the class:

 ResourceType 
Points to the RDF type of the resource, so for properties rdfs::Property
 Domain 
Points to the domain of the property
 Range 
Points to the range of the property

Structure of the C++ class generated for a predefined instance

Predefined instances have no additional methods or types defined inside the C++ class compared to normal resources.

 All Classes Functions Enumerations