# class Resource

###

Module | nepomuk
Namespace | Nepomuk
Class | Resource
Inherits |

\class Resource resource.h Nepomuk/Resource

Resource is the central object type in Nepomuk. It represents a piece of information of any kind.

Resources are identified by their unique URI (which correlates directly with the URI in the local NEPOMUK RDF storage.

Resource objects with the same URI share their data.

All methods in Resource are thread-safe.

See hacking for details on how to use Resource.

See also ResourceManager

Author Sebastian Trueg <trueg@kde.org>

### methods

- Resource ( )

  returns ctor

  Creates an empty invalid Resource. An invalid resource will become valid (i.e. get a new random URI) once setProperty is called.

- Resource (a0)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  a0 | Nepomuk.Resource |

- Resource (uriOrIdentifier, type)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  uriOrIdentifier | QString |
  type | QUrl | QUrl()

  Creates a new Resource object.

  The actual resource data is loaded on demand. Thus, it is possible to work with Resources as if they were in memory all the time.

  uriOrIdentifier - The unique URI or an arbitrary identifier of the resource. If it exists as a resource URI in the RDF store it is used to load the related properties. If not the passed string is treated as an identifier. If a resource exists in the store which has this identifier set this resource's properties are loaded. Otherwise the resource is created in the store with a new random URI which can be accessed through uri after the resource has been synced. The resource can later again be found through the same identifier. In Nepomuk there are two ways of identifying a resource uniquely:

- The URI of the resource which is generated randomly
by the framework and can only be accessed in a read-only fashion.
- An identifier in combination with the resource type (Be
aware that this identification can only be guranteed if identifiers are never set manually via addIdentifier but only through the constructor.

type - The URI identifying the type of the resource. If it is empty Resource falls back to http://www.w3.org/2000/01/rdf-schema\#Resource or in case the resource already exists the type will be read from the store. (This is a QString instead of a QUrl for historical reasons)

Example:

The best way to understand the URI and identifier system is through file resources. When a Resource object is created with the local path of the file as an identifier:

    Resource myfile( "/tmp/testfile.txt" );

Now the URI of the resource in the store representing metadata for the file /tmp/testfile.txt is referred to by myfile.uri() which differs from the path of the file. However, the path of the file is saved as a hasIdentifier relation which means that it can be used to easily find the related resource.

- Resource (uriOrIdentifier, type)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  uriOrIdentifier | QString |
  type | QString |

  Deprecated use Resource( const QString&, const QUrl& )

- Resource (uri, type)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  uri | QUrl |
  type | QUrl | QUrl()

  Creates a new Resource object.

  url - The URI of the resource. If no resource with this URI exists, a new one is created.

  type - The URI identifying the type of the resource. If it is empty Resource falls back to http://www.w3.org/2000/01/rdf-schema\#Resource or in case the resource already exists the type will be read from the store.

- Resource (a0)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  a0 | ResourceData |

  Constructor used internally.

- addAltLabel (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QString |

  Add a value to property 'altLabel'.

- addAnnotation (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | Nepomuk.Resource |

  Add a value to property 'annotation'.

- addIdentifier (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QString |

  Add a value to property 'identifier'.

- addIsRelated (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | Nepomuk.Resource |

  Add a value to property 'isRelated'.

- addIsTopicOf (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | Nepomuk.Resource |

  Add a value to property 'isTopicOf'.

- addSymbol (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QString |

  Add a value to property 'Symbol'. Each resource can have a symbol assigned. For now this is a simple string which can either be the patch to an actual pixmap file or just the name of an icon as defined by the freedesktop.org standard.

- addTag (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | Nepomuk.Tag |

  Add a value to property 'Tag'. Each Resource can be tagged with an arbitrary number of Tags. This allows a simple grouping of resources.

- addTopic (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | Nepomuk.Resource |

  Add a value to property 'Topic'.

- allProperties ( )

  returns QHash<QString,Nepomuk::Variant>

  Deprecated Use properties()

- allResources ( )

  returns QList<Nepomuk::Resource>
  static

  Retrieve a list of all available Resource resources. This list consists of all resource of type Resource that are stored in the local Nepomuk meta data storage and any changes made locally. Be aware that in some cases this list can get very big. Then it might be better to use libKNep directly.

- altLabelUri ( )

  returns QString
  static

  Returns The URI of the property 'altLabel'.

- altLabels ( )

  returns QStringList

  Get property 'altLabel'.

- annotationOf ( )

  returns QList<Nepomuk::Resource>

  Get all resources that have this resource set as property 'annotation'.

  See also ResourceManager.allResourcesWithProperty

- annotationUri ( )

  returns QString
  static

  Returns The URI of the property 'annotation'.

- annotations ( )

  returns QList<Nepomuk::Resource>

  Get property 'annotation'.

- className ( )

  returns QString

  The name of the class this Resource represents an object of. The classname is derived from the type URI (see Resource.uri). For a translated user readable name of the resource see Ontology.typeName.

  See also type()

- description ( )

  returns QString

  Get property 'description'. Everything can be annotated with a simple string comment.

- descriptionUri ( )

  returns QString
  static

  Returns The URI of the property 'description'.

- exists ( )

  returns bool

  Returns true if this resource (i.e. the uri of this resource) exists in the local NEPOMUK RDF store.

- genericDescription ( )

  returns QString

  Tries very hard to find a suitable human-readable description of the resource. This description is supposed to be longer than text() and includes such properties as nao:description, xesam:comment, rdfs:comment

  Returns A human readable description of the resource or an empty string if none could be found.

- genericIcon ( )

  returns QString

  Tries very hard to find an icon suitable for this resource.

  Returns An icon name to be used with KIcon or an empty string if none was found.

- genericLabel ( )

  returns QString

  Tries very hard to find a suitable human-readable label for this resource. It looks for properties such as nao:prefLabel, rdfs:label, or nao:identifier, or even the fileName of File resources.

  Returns A human readable label or if all fails the URI of the resource.

- hasProperty (uri)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  uri | QUrl |

  Check if property identified by uri is defined for this resource.

  uri - The URI identifying the property.

  Returns true if property uri has a value set.

- hasProperty (uri)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  uri | QString |

  Deprecated use hasProperty( const QUrl& ) const

- hasType (typeUri)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  typeUri | QUrl |

  Check if the resource is of a certain type. The type hierarchy is checked including subclass relations.

- identifierUri ( )

  returns QString
  static

  Returns The URI of the property 'identifier'.

- identifiers ( )

  returns QStringList

  Get property 'identifier'.

- isRelatedOf ( )

  returns QList<Nepomuk::Resource>

  Get all resources that have this resource set as property 'isRelated'.

  See also ResourceManager.allResourcesWithProperty

- isRelatedUri ( )

  returns QString
  static

  Returns The URI of the property 'isRelated'.

- isRelateds ( )

  returns QList<Nepomuk::Resource>

  Get property 'isRelated'.

- isTopicOfUri ( )

  returns QString
  static

  Returns The URI of the property 'isTopicOf'.

- isTopicOfs ( )

  returns QList<Nepomuk::Resource>

  Get property 'isTopicOf'.

- isValid ( )

  returns bool

  Returns true if this Resource object is valid, i.e. has a proper URI and type and can be synced with the local NEPOMUK RDF store.

  An invalid resource will become valid (i.e. get a new random URI) once setProperty is called.

- label ( )

  returns QString

  Get property 'label'.

- labelUri ( )

  returns QString
  static

  Returns The URI of the property 'label'.

- operator == (a0)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  a0 | Nepomuk.Resource |

  Operator to compare two Resource objects. Normally one does not need this. It is mainly intended for testing and debugging purposes.

- properties ( )

  returns QHash<QUrl,Nepomuk::Variant>

  Returns A list of all defined properties

- property (uri)

  returns Nepomuk.Variant

  Argument | Type | Default
  --- | --- | ---
  uri | QUrl |

  Retrieve the value of property uri. If the property is not defined for this resource an invalid, empty Variant object is returned.

  uri - The URI identifying the property.

- property (uri)

  returns Nepomuk.Variant

  Argument | Type | Default
  --- | --- | ---
  uri | QString |

  Deprecated use property( const QUrl& ) const

- rating ( )

  returns quint32

  Get property 'Rating'.

- ratingUri ( )

  returns QString
  static

  Returns The URI of the property 'Rating'.

- remove ( )

  returns Nothing

  Remove this resource completely. CAUTION: After calling this method the resource will have been removed from the store without any trace.

- removeProperty (uri)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  uri | QUrl |

  Remove property uri from this resource object.

  uri - The URI identifying the property.

- removeProperty (uri)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  uri | QString |

  Deprecated use removeProperty( const QUrl& )

- resourceType ( )

  returns QUrl

  The main type of the resource. Nepomuk tries hard to make this the type furthest down the hierarchy. In case the resource has only one type, this is no problem. However, if the resource has multiple types from different type hierarchies, there is no guarantee which one will be used here.

  See also name(), hasType(), types()

- resourceUri ( )

  returns QUrl

  The URI of the resource, uniquely identifying it. This URI in most cases is a virtual one which has been created from a generic base namespace and some identifier.

  the most important thing to remember is that the URI of for example a file does not necessarily have a relation to its local path. (Although Nepomuk tries to keep the URI of file resources in sync with the file URL for convinience.)

  See also uri, getIdentifiers

- setAltLabels (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QStringList |

  Set property 'altLabel'.

- setAnnotations (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QList<Nepomuk::Resource> |

  Set property 'annotation'.

- setDescription (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QString |

  Set property 'description'. Everything can be annotated with a simple string comment.

- setIdentifiers (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QStringList |

  Set property 'identifier'.

- setIsRelateds (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QList<Nepomuk::Resource> |

  Set property 'isRelated'.

- setIsTopicOfs (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QList<Nepomuk::Resource> |

  Set property 'isTopicOf'.

- setLabel (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QString |

  Set property 'label'.

- setProperty (uri, value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  uri | QUrl |
  value | Nepomuk.Variant |

  Set a property of the resource.

  uri - The URI identifying the property.

  value - The value of the property (i.e. the object of the RDF triple(s))

- setProperty (uri, value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  uri | QString |
  value | Nepomuk.Variant |

  Deprecated use setProperty( const QUrl& )

- setRating (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | quint32 |

  Set property 'Rating'.

- setSymbols (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QStringList |

  Set property 'Symbol'. Each resource can have a symbol assigned. For now this is a simple string which can either be the patch to an actual pixmap file or just the name of an icon as defined by the freedesktop.org standard.

- setTags (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QList<Nepomuk::Tag> |

  Set property 'Tag'. Each Resource can be tagged with an arbitrary number of Tags. This allows a simple grouping of resources.

- setTopics (value)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  value | QList<Nepomuk::Resource> |

  Set property 'Topic'.

- symbolUri ( )

  returns QString
  static

  Returns The URI of the property 'Symbol'.

- symbols ( )

  returns QStringList

  Get property 'Symbol'. Each resource can have a symbol assigned. For now this is a simple string which can either be the patch to an actual pixmap file or just the name of an icon as defined by the freedesktop.org standard.

- tagUri ( )

  returns QString
  static

  Returns The URI of the property 'Tag'.

- tags ( )

  returns QList<Nepomuk::Tag>

  Get property 'Tag'. Each Resource can be tagged with an arbitrary number of Tags. This allows a simple grouping of resources.

- topicUri ( )

  returns QString
  static

  Returns The URI of the property 'Topic'.

- topics ( )

  returns QList<Nepomuk::Resource>

  Get property 'Topic'.

- type ( )

  returns QString

  The main type of the resource. Nepomuk tries hard to make this the type furthest down the hierarchy. In case the resource has only one type, this is no problem. However, if the resource has multiple types from different type hierarchies, there is no guarantee which one will be used here.

  For historical reasons the method does return a URI as QString instead of QUrl. The value equals resourceType().toString().

  See also name(), hasType(), types()

  Deprecated use resourceType instead

- types ( )

  returns QList<QUrl>

  Returns The list of all stored types for this resource. This may also include types that lie in the same hierachy.

  See also type(), hasType()

- uri ( )

  returns QString

  The URI of the resource, uniquely identifying it. This URI in most cases is a virtual one which has been created from a generic base namespace and some identifier.

  the most important thing to remember is that the URI of for example a file does not necessarily have a relation to its local path. (Although Nepomuk tries to keep the URI of file resources in sync with the file URL for convinience.)

  For historical reasons the method does return a URI as QString instead of QUrl. The value equals resourceUri().toString().

  See also resourceUri, getIdentifiers

  Deprecated use resourceUri instead