Projects/Nepomuk/Resources: Difference between revisions

From KDE TechBase
No edit summary
Line 6: Line 6:


In order to improve this situation we have provided a resource generator, which generates custom <code>Resource</code> classes from the ontologies. It relies on a CMake macro to accomplish that.
In order to improve this situation we have provided a resource generator, which generates custom <code>Resource</code> 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:
<syntaxhighlight lang="text">
NEPOMUK2_ADD_ONTOLOGY_CLASSES(<sources-var>
        [ONTOLOGIES] <onto-file1> [<onto-file2> ...]
        [CLASSES <classname1> [<classname2> ...]]
        [VISIBILITY <visibility-name>]
      )
</syntaxhighlight>
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.


<syntaxhighlight lang="cmake">
<syntaxhighlight lang="cmake">
include(Nepomuk2AddOntologyClasses)
nepomuk2_add_ontology_classes (SRCS
nepomuk2_add_ontology_classes (SRCS
     ONTOLOGIES
     ONTOLOGIES

Revision as of 08:56, 23 August 2012

The Nepomuk Resource class is undoubtedly the most user visible and used class. It serves as a very convenient abstraction over the statements.

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:

NEPOMUK2_ADD_ONTOLOGY_CLASSES(<sources-var>
         [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.

include(Nepomuk2AddOntologyClasses)

nepomuk2_add_ontology_classes (SRCS
    ONTOLOGIES
    ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nie.trig
    ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nco.trig
    ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/pimo/pimo.trig
)


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();