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
Method Documentation
__init__ | ( | self ) |
Creates an empty invalid Resource. An invalid resource will become valid (i.e. get a new random URI) once setProperty is called.
__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 | |||
) |
Copy constructor
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.
- Parameters:
-
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:
- 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. (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.
__init__ | ( | self, | ||
QString | uriOrIdentifier, | |||
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
- Deprecated:
- use Resource( const QString&, const 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.
- 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
__init__ | ( | self, | ||
ResourceData | a0 | |||
) |
Constructor used internally.
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 patch 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
QHash |
( | self ) |
- Deprecated:
- Use properties()
[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'.
QStringList altLabels | ( | self ) |
Get property 'altLabel'.
[Nepomuk.Resource] annotationOf | ( | self ) |
Get all resources that have this resource set as property 'annotation'. \sa ResourceManager.allResourcesWithProperty
QString annotationUri | ( | ) |
- Returns:
- The URI of the property 'annotation'.
[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.
QString descriptionUri | ( | ) |
- Returns:
- The URI of the property 'description'.
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 | |||
) |
Check if property identified by uri is defined for this resource.
- Parameters:
-
uri The URI identifying the property.
- Returns:
- true if property uri has a value set.
bool hasProperty | ( | self, | ||
QString | uri | |||
) |
- 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.
QString identifierUri | ( | ) |
- Returns:
- The URI of the property 'identifier'.
QStringList identifiers | ( | self ) |
Get property 'identifier'.
[Nepomuk.Resource] isRelatedOf | ( | self ) |
Get all resources that have this resource set as property 'isRelated'. \sa ResourceManager.allResourcesWithProperty
QString isRelatedUri | ( | ) |
- Returns:
- The URI of the property 'isRelated'.
[Nepomuk.Resource] isRelateds | ( | self ) |
Get property 'isRelated'.
QString isTopicOfUri | ( | ) |
- Returns:
- The URI of the property 'isTopicOf'.
[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'.
QString labelUri | ( | ) |
- Returns:
- The URI of the 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. Normally one does not need this. It is mainly intended for testing and debugging purposes.
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
QHash |
( | self ) |
- Returns:
- A list of all defined properties
Nepomuk.Variant property | ( | self, | ||
QUrl | uri | |||
) |
Retrieve the value of property uri. If the property is not defined for this resource an invalid, empty Variant object is returned.
- Parameters:
-
uri The URI identifying the property.
Nepomuk.Variant property | ( | self, | ||
QString | uri | |||
) |
- Deprecated:
- use property( const QUrl& ) const
long rating | ( | self ) |
Get property 'Rating'.
QString ratingUri | ( | ) |
- Returns:
- The URI of the 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 | |||
) |
Remove property uri from this resource object.
- Parameters:
-
uri The URI identifying the property.
removeProperty | ( | self, | ||
QUrl | uri, | |||
Nepomuk.Variant | value | |||
) |
Remove value from property uri of this resource object.
- Parameters:
-
uri The URI identifying the property.
- Parameters:
-
value The value to remove
- Since:
- 4.3
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. (Although Nepomuk tries to keep the URI of file resources in sync with the file URL for convenience.)
\sa uri, 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 | |||
) |
Set a property of the resource.
- Parameters:
-
uri The URI identifying the property.
- Parameters:
-
value The value of the property (i.e. the object of the RDF triple(s))
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 patch 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
QString symbolUri | ( | ) |
- Returns:
- The URI of the property 'Symbol'.
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 patch to an actual pixmap file or just the name of an icon as defined by the freedesktop.org standard.
QString tagUri | ( | ) |
- Returns:
- The URI of the property 'Tag'.
[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.
QString topicUri | ( | ) |
- Returns:
- The URI of the property 'Topic'.
[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