Development/Tutorials/Metadata/Nepomuk/OntologyLoaderService
Tutorial Series | Nepomuk |
Previous | Storage Service |
What's Next | File Watch Service |
Further Reading | Nepomuk Services, Nepomuk Server,Data Layout in Nepomuk |
Nepomuk Ontology Loader Service
The ontology loader service maintains the ontologies in Nepomuk and allows to fetch ontologies from the internet. Normally applications should work with ontologies through the Nepomuk::Types API provided by libnepomuk which is part of the kdelibs.
See the Nepomuk Data Layout for details on how ontologies are stored in Nepomuk.
Installed ontologies
Nepomuk uses a set of pre-installed ontologies from the shared-desktop-ontologies project which are automatically read into the storage by this service.
The ontologies are stored in KDEDIR/share/apps/nepomuk/ontologies. Each ontology consists of two files: the ontology itself (in most cases a trig file) and a .ontology file describing the ontology. The latter is read by the service and used to find the ontology file which is then parsed, validated and updated in the Nepomuk Storage.
Installing new ontologies (in case an application needs them) is rather simple: write a .ontology file which contains at least the following fields:
- Name - A name for the ontology
- Comment - A short comment describing the ontology
- Namespace - The namespace of the ontology
- Path - The path to the ontology file (which will be parsed by the service)
- MimeType - The mimetype used to encode the RDF data in the file (for example "application/x-trig" for trig data or "application/rdf+xml" for RDF+XML data)
For examples and ideas on how to install using cmake see the shared-desktop-ontology sources.
Further Ontologies
The Ontology service also allows to fetch new ontologies from the internet. The advantage of using the service in comparison to simply downloading and parsing is that the service performs some checks, makes sure the data is compatible with the Nepomuk system, and performs updates rather than just storing it in addition to old versions.
For this task the service provides a DBus interface named org.kde.nepomuk.OntologyManager which is exported at nepomukontologyloader:
QString findOntologyContext(QString uri)
Searches for the ontology with the provided namespace. If found the context (named graph) the ontology is stored in is returned.
void importOntology(QString url)
Import an ontology from the provided URL. All URLs suported by KIO can be used. This is an async method that will report its success through the following signals.
void ontologyUpdateFailed(QString uri, QString errorString)
Emitted if updating en ontology failed.
void ontologyUpdated(QString uri)
Emitted if updating an ontology was successful.
void updateAllLocalOntologies()
Forces the service to update all installed ontologies, even if they did not change.
void updateLocalOntologies()
Make the service update all installed ontologies that have changed. Normally there is no need to call this method as the service monitors all installed ontologies.