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 creates a new tag. The tag can be accessed through its name which works as an identifier. Nepomuk automatically creates a new unique URI if this tag does not already exist.
Nepomuk::Tag tag( "MyTag" ); 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( Soprano::Vocabulary::NAO::decription() ).toString(); QList<Resource> tags = f.getProperty( Soprano::Vocabulary::NAO::hasTag() ).toResourceList(); QListIterator<Resource> it( tags ); while( it.hasNext() ) kdDebug() << "File tagged with tag: " << it.next().genericLabel();
Reading the information using the convenience classes:
Nepomuk::File f( "/home/foo/bar.txt" ); QString description = f.getDescription(); QList<Tag> tags = f.getTags(); QListIterator<Tag> it( tags ); while( it.hasNext() ) kdDebug() << "File tagged with tag: " << it.next().genericLabel();
Present all defined properties of an arbitrary resource to the user including internationalized labels:
Nepomuk::Resource f( "/home/foo/bar.txt" ); QHash<QUrl, Variant> properties = f.properties(); QHashIterator<QUrl, Variant> it( properties ); while( it.hasNext() ) { it.next(); kdDebug() << Nepomuk::Types::Property( it.key() ).label() << ": " << it.value().toString() << endl; }