< Projects‎ | Nepomuk
Revision as of 13:21, 23 August 2012 by Vishesh (talk | contribs)


The Nepomuk Resource class provides a convenient wrapper over the Nepomuk data. It does so by keeping a cache of the relevant data and using the Resource Watcher to keep it up to date.

Saving Resources

Resources are a real-time view of the data in the virtuoso database. They are automatically saved after each change, and all other resources across the different applications are updated.

Saving New Resources

A new resource will automatically be saved the first time it is used.

    Nepomuk2::Resource res;
    res.exists(); // Will return false
    res.uri(); // Will be blank

    res.setRating( 5 ); // Will be created and saved
    res.exists(); // Will return true
    res.uri(); // Will return its unique identifier

Managing Properties

Nepomuk Resource Generator

While it is fairly convenient to use the setProperty and getProperty methods. It requires you to explicitly define the property which you need modify. This can get quite cumbersome and destroys readability of the code.

In order to improve this situation we have provided a resource generator, which generates custom Resource classes from the ontologies. It relies on a CMake macro to accomplish that.

Usage in CMake

The resource generator is best used through the CMake macro provided by Nepomuk. The syntax is fairly simple and similar to the macro for adding ui files to a list of sources:

         [ONTOLOGIES] <onto-file1> [<onto-file2> ...]
         [CLASSES <classname1> [<classname2> ...]]
         [VISIBILITY <visibility-name>]

The optional CLASSES parameter allows to specify the classes to be generated (RDF class names) in case one does not want all classes in the ontologies to be generated. If omitted all classes in the ontology files will be generated.

The optional VISIBILITY parameter can only be used in non-fast mode and allows to set the gcc visibility to make the generated classes usable in a publically exported API. The <visibility-name> is used to create the name of the export macro and the export include file. Thus, when using "VISIBILITY foobar" include file "foobar_export.h" needs to define FOOBAR_EXPORT.



nepomuk2_add_ontology_classes (SRCS

This will generate a C++ class for each type defined in the mentioned ontologies.

#include "personcontact.h"

Nepomuk2::PersonContact spiderman;
spiderman.setFullName( QLatin1String("Peter Parker") );
QString name = spiderman.fullname();

This page was last edited on 9 February 2018, at 12:35. Content is available under Creative Commons License SA 4.0 unless otherwise noted.