Development/Tutorials/Metadata/Nepomuk/OntologyLoaderService: Difference between revisions

From KDE TechBase
No edit summary
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(2 intermediate revisions by 2 users not shown)
Line 16: Line 16:
===Installed ontologies===
===Installed ontologies===


Nepomuk comes with a set of pre-installed ontologies which are automatically read into the storage by this service.
Nepomuk uses a set of pre-installed ontologies from the [http://sourceforge.net/apps/trac/oscaf/ 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 [http://www4.wiwiss.fu-berlin.de/bizer/TriG/ trig] file) and a desktop 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.
The ontologies are stored in ''KDEDIR/share/apps/nepomuk/ontologies''. Each ontology consists of two files: the ontology itself (in most cases a [http://www4.wiwiss.fu-berlin.de/bizer/TriG/ 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 desktop file which contains at least the following fields:
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
* Name - A name for the ontology
* Comment - A short comment describing the ontology
* Comment - A short comment describing the ontology
* URL - The namespace of the ontology (if possible the ontology should be available under that URL)
* Namespace - The namespace of the ontology
* Path - The path to the ontology file (which will be parsed by the service)
* 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)
* 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)
* Type - Always needs to be set to "Data"


For examples and ideas on how to install using cmake see Nepomuk source at ''kdebase/runtime/nepomuk/ontologies''.
For examples and ideas on how to install using cmake see the shared-desktop-ontology sources.




Line 38: Line 37:
For this task the service provides a DBus interface named ''org.kde.nepomuk.OntologyManager'' which is exported at ''nepomukontologyloader'':
For this task the service provides a DBus interface named ''org.kde.nepomuk.OntologyManager'' which is exported at ''nepomukontologyloader'':


<code>QString findOntologyContext(QString uri)</code>
<syntaxhighlight lang="text">QString findOntologyContext(QString uri)</syntaxhighlight>
Searches for the ontology with the provided namespace. If found the context (named graph) the ontology is stored in is returned.
Searches for the ontology with the provided namespace. If found the context (named graph) the ontology is stored in is returned.


<code>void importOntology(QString url)</code>
<syntaxhighlight lang="text">void importOntology(QString url)</syntaxhighlight>
Import an ontology from the provided URL. All URLs suported by KIO can be used.
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.
This is an async method that will report its success through the following signals.


<code>void ontologyUpdateFailed(QString uri, QString errorString)</code>
<syntaxhighlight lang="text">void ontologyUpdateFailed(QString uri, QString errorString)</syntaxhighlight>
Emitted if updating en ontology failed.
Emitted if updating en ontology failed.


<code>void ontologyUpdated(QString uri)</code>
<syntaxhighlight lang="text">void ontologyUpdated(QString uri)</syntaxhighlight>
Emitted if updating an ontology was successful.
Emitted if updating an ontology was successful.


<code>void updateAllLocalOntologies()</code>
<syntaxhighlight lang="text">void updateAllLocalOntologies()</syntaxhighlight>
Forces the service to update all installed ontologies, even if they did not change.
Forces the service to update all installed ontologies, even if they did not change.


<code>void updateLocalOntologies()</code>
<syntaxhighlight lang="text">void updateLocalOntologies()</syntaxhighlight>
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.
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.

Latest revision as of 20:53, 29 June 2011

Nepomuk Ontology Loader Service
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.