Nepomuk
Nepomuk Examples
Overview | Using | Examples | Desktop Ontologies | Resource GeneratorAdd 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; }
KDE 4.0 API Reference