<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://techbase.kde.org/skins/common/feed.css?0.2"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://techbase.kde.org/index.php?title=Projects/Nepomuk/Resources/en&amp;feed=atom&amp;action=history</id>
		<title>Projects/Nepomuk/Resources/en - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://techbase.kde.org/index.php?title=Projects/Nepomuk/Resources/en&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Projects/Nepomuk/Resources/en&amp;action=history"/>
		<updated>2013-05-19T20:07:39Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.2</generator>

	<entry>
		<id>http://techbase.kde.org/index.php?title=Projects/Nepomuk/Resources/en&amp;diff=77204&amp;oldid=prev</id>
		<title>FuzzyBot: Updating to match new version of source page</title>
		<link rel="alternate" type="text/html" href="http://techbase.kde.org/index.php?title=Projects/Nepomuk/Resources/en&amp;diff=77204&amp;oldid=prev"/>
				<updated>2012-12-11T14:00:02Z</updated>
		
		<summary type="html">&lt;p&gt;Updating to match new version of source page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;languages /&amp;gt;&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Saving Resources ==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
=== Saving New Resources ===&lt;br /&gt;
&lt;br /&gt;
A new resource will automatically be saved the first time it is used.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
    Nepomuk2::Resource res;&lt;br /&gt;
    res.exists(); // Will return false&lt;br /&gt;
    res.uri(); // Will be blank&lt;br /&gt;
&lt;br /&gt;
    res.setRating( 5 ); // Will be created and saved&lt;br /&gt;
    res.exists(); // Will return true&lt;br /&gt;
    res.uri(); // Will return its unique identifier&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Managing Properties ==&lt;br /&gt;
&lt;br /&gt;
When using the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Resource.html &amp;lt;tt&amp;gt;Resource&amp;lt;/tt&amp;gt;] class, one can easily access certain properties such as ratings and tags via convenience functions. However, if one wishes to access more properties then that is performed via the [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Resource.html#a9a59f482f21c6150bc9cb39dd47a7d77 &amp;lt;tt&amp;gt;property&amp;lt;/tt&amp;gt;], [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Resource.html#a8ffb9cb55cb641e022479e80b9fc0dcf &amp;lt;tt&amp;gt;setProperty&amp;lt;/tt&amp;gt;] and [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Resource.html#a7dcb083459a2e967a4ddfbf5f6fbcf9e &amp;lt;tt&amp;gt;addProperty&amp;lt;/tt&amp;gt;] functions.&lt;br /&gt;
&lt;br /&gt;
It's important to know which properties are available in each resource. The simplest way would be to check they keys in [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk-core/html/classNepomuk2_1_1Resource.html#ac26aeaa49c264ce6e3778e028aa4dc85 &amp;lt;tt&amp;gt;properties&amp;lt;/tt&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
=== Accessing the Vocabularies ===&lt;br /&gt;
&lt;br /&gt;
In order to modify any of the properties in '''Nepomuk''', one must access the ontologies. The recommended way of doing that is by using the pre-generated ontologies headers which are shipped with '''Soprano''' and '''NepomukCore'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;Soprano/Vocabulary/RDF&amp;gt;&lt;br /&gt;
#include &amp;lt;Soprano/Vocabulary/RDFS&amp;gt;&lt;br /&gt;
#include &amp;lt;Soprano/Vocabulary/NRL&amp;gt;&lt;br /&gt;
#include &amp;lt;Soprano/Vocabulary/NAO&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;Nepomuk2/Vocabulary/NIE&amp;gt;&lt;br /&gt;
#include &amp;lt;Nepomuk2/Vocabulary/NFO&amp;gt;&lt;br /&gt;
#include &amp;lt;Nepomuk2/Vocabulary/NMM&amp;gt;&lt;br /&gt;
#include &amp;lt;Nepomuk2/Vocabulary/NCO&amp;gt;&lt;br /&gt;
#include &amp;lt;Nepomuk2/Vocabulary/PIMO&amp;gt;&lt;br /&gt;
#include &amp;lt;Nepomuk2/Vocabulary/NCAL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
using namespace Neppomuk2::Vocabulary;&lt;br /&gt;
using namespace Soprano::Vocabulary;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Setting Properties ===&lt;br /&gt;
&lt;br /&gt;
When setting a property of a resource. It is imperative that the domain, range and cardinality of the property be correct. Otherwise the &amp;lt;tt&amp;gt;setProperty&amp;lt;/tt&amp;gt; call will silently fail and output an error as a debug message. In future releases we will provide other ways to get notified of the errors.&lt;br /&gt;
&lt;br /&gt;
Example - &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
    Nepomuk2::Resource res;&lt;br /&gt;
    res.addType( NCO::Contact() );&lt;br /&gt;
&lt;br /&gt;
    res.setProperty( NFO::fileName(), &amp;quot;Fire&amp;quot; ); // Will silently fail&lt;br /&gt;
    res.property( NFO::fileName() ).toString(); // Will be empty&lt;br /&gt;
&lt;br /&gt;
    res.addProperty( NCO::fullname(), QLatin1String(&amp;quot;Tom Marvolo Riddle&amp;quot;) ); // Will work&lt;br /&gt;
    res.addProperty( NCO::fullname(), QLatin1String(&amp;quot;Lord Voldemort&amp;quot;) ); // Will fail - nco:fullname has a max cardinality of 1&lt;br /&gt;
&lt;br /&gt;
    QString origName = res.property( NCO::fullname() ).toString(); // will return &amp;quot;Tom Marvolo Riddle&amp;quot;&lt;br /&gt;
    res.setProperty( NCO::fullname(), QLatin1String(&amp;quot;Lord Voldemort&amp;quot;) ); // will work this time - we're using setProperty&lt;br /&gt;
&lt;br /&gt;
    QString newName = res.property( NCO::fullname() ).toString(); // Will return You-know-who&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Nepomuk Resource Generator ==&lt;br /&gt;
&lt;br /&gt;
While it is fairly convenient to use the &amp;lt;tt&amp;gt;setProperty&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;getProperty&amp;lt;/tt&amp;gt; methods. It requires you to explicitly define the property which you need modify. This can get quite cumbersome and destroys readability of the code.&lt;br /&gt;
&lt;br /&gt;
In order to improve this situation we have provided a resource generator, which generates custom &amp;lt;code&amp;gt;Resource&amp;lt;/code&amp;gt; classes from the ontologies. It relies on a CMake macro to accomplish that.&lt;br /&gt;
&lt;br /&gt;
===Usage in CMake===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
NEPOMUK2_ADD_ONTOLOGY_CLASSES(&amp;lt;sources-var&amp;gt;&lt;br /&gt;
         [ONTOLOGIES] &amp;lt;onto-file1&amp;gt; [&amp;lt;onto-file2&amp;gt; ...]&lt;br /&gt;
         [CLASSES &amp;lt;classname1&amp;gt; [&amp;lt;classname2&amp;gt; ...]]&lt;br /&gt;
         [VISIBILITY &amp;lt;visibility-name&amp;gt;]&lt;br /&gt;
       )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;visibility-name&amp;gt; is used to create the name of the export macro and the export include file. Thus, when using &amp;quot;VISIBILITY foobar&amp;quot; include&lt;br /&gt;
file &amp;quot;foobar_export.h&amp;quot; needs to define FOOBAR_EXPORT.&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
include(Nepomuk2AddOntologyClasses)&lt;br /&gt;
&lt;br /&gt;
nepomuk2_add_ontology_classes (SRCS&lt;br /&gt;
    ONTOLOGIES&lt;br /&gt;
    ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nie.trig&lt;br /&gt;
    ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/nie/nco.trig&lt;br /&gt;
    ${SHAREDDESKTOPONTOLOGIES_ROOT_DIR}/pimo/pimo.trig&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This will generate a C++ class for each type defined in the mentioned ontologies. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp-qt&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;personcontact.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Nepomuk2::PersonContact spiderman;&lt;br /&gt;
spiderman.setFullName( QLatin1String(&amp;quot;Peter Parker&amp;quot;) );&lt;br /&gt;
QString name = spiderman.fullname();&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>FuzzyBot</name></author>	</entry>

	</feed>