• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Nepomuk

Nepomuk Examples

Overview | Using | Examples | Desktop Ontologies | Resource Generator

Add an annotation (a comment) to a file.

Nepomuk::File f( "/home/foo/bar.txt" );
f.setAnnotation( "This is just a test file that contains nothing of interest." );

The following example is a little more complicated since it contains creating a new tag and thus, coming up with a unique URI for this tag (future versions of Nepomuk should provide a way to create a unique URI automatically.)

Nepomuk::Tag tag( "someURI/that/is.unique" );
tag.setName( "Important" );
Nepomuk::File f( "/home/foo/bar.txt" );
f.addTag( tag );

Reading the information using plain Resource methods:

Nepomuk::Resource f( "/home/foo/bar.txt" );
QString annotation = f.getProperty( "http://nepomuk-kde.semanticdesktop.org/ontology/nkde-0.1#hasAnnotation" ).toString();
QList<Resource> tags = f.getProperty( "http://nepomuk-kde.semanticdesktop.org/ontology/nkde-0.1#hasTag" ).toResourceList();
QListIterator<Resource> it( tags );
while( it.hasNext() )
  kdDebug() << "File tagged with tag: "
            << it.next().getProperty( "http://nepomuk-kde.semanticdesktop.org/ontology/nkde-0.1#hasName" ).toString();

Reading the information using the convenience classes:

Nepomuk::File f( "/home/foo/bar.txt" );
QString annotation = f.getAnnotation();
QList<Tag> tags = f.getTags();
QListIterator<Tag> it( tags );
while( it.hasNext() )
  kdDebug() << "File tagged with tag: " << it.next().getName();

Present all defined properties of an arbitrary resource to the user:

Nepomuk::Ontology* ont = Nepomuk::ResourceManager::instance()->ontology();
Nepomuk::Resource f( "/home/foo/bar.txt" );
QHash<QString, Variant> properties = f.allProperties();
QHashIterator<QString, Variant> it( properties );
while( it.hasNext() ) {
  it.next();
  kdDebug() << ont->propertyName( it.key() ) << ": " << it.value().toString() << endl;
}

Nepomuk

Skip menu "Nepomuk"
  • Main Page
  • File List
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   WTF
  • KJSEmbed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  •   core
  • Phonon
  •   Backend
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal