KDE 4.5 PyKDE API Reference

- KDE's Python API

# Resource Class Reference

`from PyKDE4.nepomuk import *`

Subclasses: Nepomuk.Tag, Nepomuk.Thing
Namespace: Nepomuk

## Detailed Description

\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

Special case: file URLs

file:/ URLs are handled as a special case in Nepomuk. Starting with KDE 4.4 they are no longer used to identify the Nepomuk resource but only stored as nie:url property. All resources have nepomuk:/res/<UUID> URIs. The Resource constructors handle this automatically. Thus, one can still use file URLs to construct the objects. But be aware of the following example:

     KUrl fileUrl("file:home/foobar/example.txt");
     Nepomuk.Resource fileRes(fileUrl);
     QUrl fileResUri = fileRes.resourceUri();

Here fileUrl and fileResUri are NOT equal. The latter is the resource URI of the form nepomuk:/res/<UUID>.

Author:
  Sebastian Trueg <trueg@kde.org>

## Methods
| __init__ (self)
| __init__ (self, Nepomuk.ResourceManager manager)
| __init__ (self, Nepomuk.Resource a0)
| __init__ (self, QString pathOrIdentifier, QUrl type=QUrl())
| __init__ (self, QString pathOrIdentifier, QUrl type, Nepomuk.ResourceManager manager)
| __init__ (self, QString pathOrIdentifier, QString type)
| __init__ (self, QUrl uri, QUrl type=QUrl())
| __init__ (self, QUrl uri, QUrl type, Nepomuk.ResourceManager manager)
| addAltLabel (self, QString value)
| addAnnotation (self, Nepomuk.Resource value)
| addIdentifier (self, QString value)
| addIsRelated (self, Nepomuk.Resource value)
| addIsTopicOf (self, Nepomuk.Resource value)
| addProperty (self, QUrl uri, Nepomuk.Variant value)
| addSymbol (self, QString value)
| addTag (self, Nepomuk.Tag value)
| addTopic (self, Nepomuk.Resource value)
| addType (self, QUrl type)
{QString:Nepomuk.Variant} | allProperties (self)
QStringList | altLabels (self)
[Nepomuk.Resource] | annotationOf (self)
[Nepomuk.Resource] | annotations (self)
QString | className (self)
QString | description (self)
bool | exists (self)
QString | genericDescription (self)
QString | genericIcon (self)
QString | genericLabel (self)
bool | hasProperty (self, QUrl uri)
bool | hasProperty (self, QString uri)
bool | hasProperty (self, Nepomuk.Types.Property p, Nepomuk.Variant v)
bool | hasType (self, QUrl typeUri)
QStringList | identifiers (self)
| increaseUsageCount (self)
[Nepomuk.Resource] | isRelatedOf (self)
[Nepomuk.Resource] | isRelateds (self)
[Nepomuk.Resource] | isTopicOfs (self)
bool | isValid (self)
QString | label (self)
Nepomuk.ResourceManager | manager (self)
bool | operator != (self, Nepomuk.Resource a0)
bool | operator == (self, Nepomuk.Resource a0)
Nepomuk.Thing | pimoThing (self)
{QUrl:Nepomuk.Variant} | properties (self)
Nepomuk.Variant | property (self, QUrl uri)
Nepomuk.Variant | property (self, QString uri)
long | rating (self)
| remove (self)
| removeProperty (self, QUrl uri)
| removeProperty (self, QUrl uri, Nepomuk.Variant value)
| removeProperty (self, QString uri)
QUrl | resourceType (self)
QUrl | resourceUri (self)
| setAltLabels (self, QStringList value)
| setAnnotations (self, [Nepomuk.Resource] value)
| setDescription (self, QString value)
| setIdentifiers (self, QStringList value)
| setIsRelateds (self, [Nepomuk.Resource] value)
| setIsTopicOfs (self, [Nepomuk.Resource] value)
| setLabel (self, QString value)
| setProperty (self, QUrl uri, Nepomuk.Variant value)
| setProperty (self, QString uri, Nepomuk.Variant value)
| setRating (self, long value)
| setSymbols (self, QStringList value)
| setTags (self, [Nepomuk.Tag] value)
| setTopics (self, [Nepomuk.Resource] value)
| setTypes (self, [QUrl] types)
QStringList | symbols (self)
[Nepomuk.Tag] | tags (self)
[Nepomuk.Resource] | topics (self)
QString | type (self)
[QUrl] | types (self)
QString | uri (self)
int | usageCount (self)
## Static Methods
[Nepomuk.Resource] | allResources ()
QString | altLabelUri ()
QString | annotationUri ()
QString | descriptionUri ()
Nepomuk.Resource | fromResourceUri (KUrl uri, Nepomuk.Types.Class type=Nepomuk.Types.Class(), Nepomuk.ResourceManager manager=0)
QString | identifierUri ()
QString | isRelatedUri ()
QString | isTopicOfUri ()
QString | labelUri ()
QString | ratingUri ()
QString | symbolUri ()
QString | tagUri ()
QString | topicUri ()

## Method Documentation

__init__ | ( |  | self ) |

Constructor used internally.

__init__ | ( | self, |
|  | Nepomuk.ResourceManager | manager
| ) |  |  |

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

Parameters:

  | manager | The resource manager to use. This allows to mix resources from different managers and, thus, different models.

Since:
  4.3

__init__ | ( | self, |
|  | Nepomuk.Resource | a0
| ) |  |  |

Constructor used internally.

__init__ | ( | self, |
|  | QString | pathOrIdentifier,
|  | QUrl | type=QUrl()
| ) |  |  |

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

__init__ | ( | self, |
|  | QString | pathOrIdentifier,
|  | QUrl | type,
|  | Nepomuk.ResourceManager | manager
| ) |  |  |

Parameters:

  | manager | The resource manager to use. This allows to mix resources from different managers and, thus, different models.

Since:
  4.3

__init__ | ( | self, |
|  | QString | pathOrIdentifier,
|  | QString | type
| ) |  |  |

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

__init__ | ( | self, |
|  | QUrl | uri,
|  | QUrl | type=QUrl()
| ) |  |  |

Creates a new Resource object.

Parameters:

  | uri | The URI of the resource. If no resource with this URI exists, a new one is created. Using an empty QUrl will result in a new resource with a random URI being created on the first call to setProperty.

See the nepomuk_resource_file_uris Special file URL handling.

Parameters:

  | 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.

__init__ | ( | self, |
|  | QUrl | uri,
|  | QUrl | type,
|  | Nepomuk.ResourceManager | manager
| ) |  |  |

Parameters:

  | manager | The resource manager to use. This allows to mix resources from different managers and, thus, different models.

Since:
  4.3

addAltLabel | ( | self, |
|  | QString | value
| ) |  |  |

Add a value to property 'altLabel'.

addAnnotation | ( | self, |
|  | Nepomuk.Resource | value
| ) |  |  |

Add a value to property 'annotation'.

addIdentifier | ( | self, |
|  | QString | value
| ) |  |  |

Add a value to property 'identifier'.

addIsRelated | ( | self, |
|  | Nepomuk.Resource | value
| ) |  |  |

Add a value to property 'isRelated'.

addIsTopicOf | ( | self, |
|  | Nepomuk.Resource | value
| ) |  |  |

Add a value to property 'isTopicOf'.

addProperty | ( | self, |
|  | QUrl | uri,
|  | Nepomuk.Variant | value
| ) |  |  |

Add a property value to the existing values.

Parameters:

  | uri | The URI identifying the property.

Parameters:

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

Since:
  4.3

addSymbol | ( | self, |
|  | QString | value
| ) |  |  |

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 path to an actual pixmap file or just the name of an icon as defined by the freedesktop.org standard.

addTag | ( | self, |
|  | Nepomuk.Tag | value
| ) |  |  |

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 | ( | self, |
|  | Nepomuk.Resource | value
| ) |  |  |

Add a value to property 'Topic'.

addType | ( | self, |
|  | QUrl | type
| ) |  |  |

Add a type to the list of types.

Since:
  4.2

{QString:Nepomuk.Variant} allProperties | ( |  | self ) |

Deprecated:
  Use properties()

QStringList altLabels | ( |  | self ) |

Get property 'altLabel'.

[Nepomuk.Resource] annotationOf | ( |  | self ) |

Get all resources that have this resource set as property 'annotation'. \sa ResourceManager.allResourcesWithProperty

[Nepomuk.Resource] annotations | ( |  | self ) |

Get property 'annotation'.

QString className | ( |  | self ) |

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.

\sa type()

QString description | ( |  | self ) |

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

bool exists | ( |  | self ) |

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

QString genericDescription | ( |  | self ) |

Tries very hard to find a suitable human-readable description of the resource. This description is supposed to be longer than genericLabel() 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.

QString genericIcon | ( |  | self ) |

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.

QString genericLabel | ( |  | self ) |

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.

bool hasProperty | ( | self, |
|  | QUrl | uri
| ) |  |  |

Deprecated:
  use hasProperty( const QUrl& ) const

bool hasProperty | ( | self, |
|  | QString | uri
| ) |  |  |

Deprecated:
  use hasProperty( const QUrl& ) const

bool hasProperty | ( | self, |
|  | Nepomuk.Types.Property | p,
|  | Nepomuk.Variant | v
| ) |  |  |

Deprecated:
  use hasProperty( const QUrl& ) const

bool hasType | ( | self, |
|  | QUrl | typeUri
| ) |  |  |

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

QStringList identifiers | ( |  | self ) |

Get property 'identifier'.

increaseUsageCount | ( |  | self ) |

Increase the usage count of this resource and also update the last used date to the current date and time.

Since:
  4.5

[Nepomuk.Resource] isRelatedOf | ( |  | self ) |

Get all resources that have this resource set as property 'isRelated'. \sa ResourceManager.allResourcesWithProperty

[Nepomuk.Resource] isRelateds | ( |  | self ) |

Get property 'isRelated'.

[Nepomuk.Resource] isTopicOfs | ( |  | self ) |

Get property 'isTopicOf'.

bool isValid | ( |  | self ) |

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.

QString label | ( |  | self ) |

Get property 'label'.

Nepomuk.ResourceManager manager | ( |  | self ) |

The Resource manager that manages this resource.

Since:
  4.3

bool operator != | ( | self, |
|  | Nepomuk.Resource | a0
| ) |  |  |

Operator to compare two Resource objects.

Since:
  4.4

bool operator == | ( | self, |
|  | Nepomuk.Resource | a0
| ) |  |  |

Operator to compare two Resource objects.

Nepomuk.Thing pimoThing | ( |  | self ) |

Get or create the PIMO thing that relates to this resource. If this resource itself is a pimo:Thing, a reference to this is returned. If a pimo:Thing exists with has as occurrence this resource, the thing is returned. Otherwise a new thing is created.

Since:
  4.2

{QUrl:Nepomuk.Variant} properties | ( |  | self ) |

Returns:
  A list of all defined properties

Nepomuk.Variant property | ( | self, |
|  | QUrl | uri
| ) |  |  |

Deprecated:
  use property( const QUrl& ) const

Nepomuk.Variant property | ( | self, |
|  | QString | uri
| ) |  |  |

Deprecated:
  use property( const QUrl& ) const

long rating | ( |  | self ) |

Get property 'Rating'.

remove | ( |  | self ) |

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

removeProperty | ( | self, |
|  | QUrl | uri
| ) |  |  |

Deprecated:
  use removeProperty( const QUrl& )

removeProperty | ( | self, |
|  | QUrl | uri,
|  | Nepomuk.Variant | value
| ) |  |  |

Deprecated:
  use removeProperty( const QUrl& )

removeProperty | ( | self, |
|  | QString | uri
| ) |  |  |

Deprecated:
  use removeProperty( const QUrl& )

QUrl resourceType | ( |  | self ) |

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.

\sa name(), hasType(), types()

QUrl resourceUri | ( |  | self ) |

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.

Returns:
  The resource URI of the resource or an empty url if the resource does not exist() yet.

\sa getIdentifiers()

setAltLabels | ( | self, |
|  | QStringList | value
| ) |  |  |

Set property 'altLabel'.

setAnnotations | ( | self, |
|  | [Nepomuk.Resource] | value
| ) |  |  |

Set property 'annotation'.

setDescription | ( | self, |
|  | QString | value
| ) |  |  |

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

setIdentifiers | ( | self, |
|  | QStringList | value
| ) |  |  |

Set property 'identifier'.

setIsRelateds | ( | self, |
|  | [Nepomuk.Resource] | value
| ) |  |  |

Set property 'isRelated'.

setIsTopicOfs | ( | self, |
|  | [Nepomuk.Resource] | value
| ) |  |  |

Set property 'isTopicOf'.

setLabel | ( | self, |
|  | QString | value
| ) |  |  |

Set property 'label'.

setProperty | ( | self, |
|  | QUrl | uri,
|  | Nepomuk.Variant | value
| ) |  |  |

Deprecated:
  use setProperty( const QUrl& )

setProperty | ( | self, |
|  | QString | uri,
|  | Nepomuk.Variant | value
| ) |  |  |

Deprecated:
  use setProperty( const QUrl& )

setRating | ( | self, |
|  | long | value
| ) |  |  |

Set property 'Rating'.

setSymbols | ( | self, |
|  | QStringList | value
| ) |  |  |

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

setTags | ( | self, |
|  | [Nepomuk.Tag] | value
| ) |  |  |

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

setTopics | ( | self, |
|  | [Nepomuk.Resource] | value
| ) |  |  |

Set property 'Topic'.

setTypes | ( | self, |
|  | [QUrl] | types
| ) |  |  |

Set the types of the resource. Previous types will be overwritten.

Since:
  4.2

QStringList symbols | ( |  | self ) |

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

[Nepomuk.Tag] tags | ( |  | self ) |

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

[Nepomuk.Resource] topics | ( |  | self ) |

Get property 'Topic'.

QString type | ( |  | self ) |

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().

\sa name(), hasType(), types()

Deprecated:
  use resourceType instead

[QUrl] types | ( |  | self ) |

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

\sa type(), hasType()

QString uri | ( |  | self ) |

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 convenience.)

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

\sa resourceUri(), getIdentifiers()

Deprecated:
  use resourceUri() instead

int usageCount | ( |  | self ) |

Returns:
  The usage count stored for this resource.

\sa increaseUsageCount()

Since:
  4.5

## Static Method Documentation

[Nepomuk.Resource] allResources | ( |  | ) |

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.

\sa ResourceManager.allResources

QString altLabelUri | ( |  | ) |

Returns:
  The URI of the property 'altLabel'.

QString annotationUri | ( |  | ) |

Returns:
  The URI of the property 'annotation'.

QString descriptionUri | ( |  | ) |

Returns:
  The URI of the property 'description'.

Nepomuk.Resource fromResourceUri | ( | KUrl | uri,
|  | Nepomuk.Types.Class | type=Nepomuk.Types.Class(),
|  | Nepomuk.ResourceManager | manager=0
| ) |  |  |

Allows to quickly load a resource from its resource URI without any additional checks. This is mostly used for optimized code within Nepomuk.

In most situations the construtor Resource( QUrl, QUrl ) is better suited.

Since:
  4.5

QString identifierUri | ( |  | ) |

Returns:
  The URI of the property 'identifier'.

QString isRelatedUri | ( |  | ) |

Returns:
  The URI of the property 'isRelated'.

QString isTopicOfUri | ( |  | ) |

Returns:
  The URI of the property 'isTopicOf'.

QString labelUri | ( |  | ) |

Returns:
  The URI of the property 'label'.

QString ratingUri | ( |  | ) |

Returns:
  The URI of the property 'Rating'.

QString symbolUri | ( |  | ) |

Returns:
  The URI of the property 'Symbol'.

QString tagUri | ( |  | ) |

Returns:
  The URI of the property 'Tag'.

QString topicUri | ( |  | ) |

Returns:
  The URI of the property 'Topic'.