Tsparql.Resource¶
- Subclasses:
 None
Methods¶
- Inherited:
 - Structs:
 
class  | 
  | 
class  | 
  | 
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
Virtual Methods¶
- Inherited:
 
Properties¶
Name  | 
Type  | 
Flags  | 
Short Description  | 
|---|---|---|---|
r/w  | 
Identifier  | 
Signals¶
- Inherited:
 
Fields¶
- Inherited:
 
Name  | 
Type  | 
Access  | 
Description  | 
|---|---|---|---|
parent_instance  | 
r  | 
Class Details¶
- class Tsparql.Resource(**kwargs)¶
 - Bases:
 - Abstract:
 No
- Structure:
 
TrackerResourceis an in-memory representation of RDF data about a given resource.This object keeps track of a set of properties for a given resource, and can also link to other
TrackerResourceobjects to form trees or graphs of RDF data. See [method`Resource`.set_relation] and [method`Resource`.set_uri] on how to link aTrackerResourceto other RDF data.TrackerResourcemay also hold data about literal values, added through the specialized [method`Resource`.set_int64], [method`Resource`.set_string], etc family of functions, or the generic [method`Resource`.set_gvalue] method.Since RDF properties may be multi-valued, for every
setcall there exists anotheraddcall (e.g. [method`Resource`.add_int64], [method`Resource`.add_string] and so on). Thesetmethods do also reset any previously value the property might hold for the given resource.Resources may have an IRI set at creation through [ctor`Resource`.new], or set afterwards through [method`Resource`.set_identifier]. Resources without a name will represent a blank node, and will be dealt with as such during database insertions.
TrackerResourceperforms no validation on the data being coherent as per any ontology. Errors will be found out at the time of using theTsparql.Resourcefor e.g. database updates.Once the RDF data is built in memory, the (tree of)
TrackerResourcemay be converted to a RDF format through [method`Resource`.print_rdf], or directly inserted into a database through [method`Batch`.add_resource] or [method`SparqlConnection`.update_resource].- classmethod deserialize(variant)¶
 - Parameters:
 variant (
GLib.Variant) – a [type`GLib`.Variant]- Returns:
 A
Tsparql.Resource, orNoneif deserialization fails.- Return type:
 
Deserializes a
TrackerResourcepreviously serialized with [method`Resource`.serialize]. It is implied that both ends use a common [class`NamespaceManager`].
- classmethod new(identifier)¶
 - Parameters:
 identifier (
strorNone) – A string containing a URI, orNone.- Returns:
 a newly created
TrackerResource.- Return type:
 
Creates a
Tsparql.Resourceinstance.
- add_boolean(property_uri, value)¶
 - Parameters:
 
Adds a boolean property. Previous values for the same property are kept.
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method corresponds to xsd:boolean.
- add_datetime(property_uri, value)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to modifyvalue (
GLib.DateTime) – the property object
Adds a date property as a [type`GLib`.DateTime]. Previous values for the same property are kept.
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method corresponds to xsd:date and xsd:dateTime.
New in version 3.2.
- add_double(property_uri, value)¶
 - Parameters:
 
Adds a numeric property with double precision. Previous values for the same property are kept.
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method corresponds to xsd:double.
- add_gvalue(property_uri, value)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to setvalue (
GObject.Value) – an initialised [struct`GObject`.Value]
Add value to the list of values for given property.
You can pass any kind of [struct`GObject`.Value] for value, but serialization functions will normally only be able to serialize URIs/relationships and fundamental value types (string, int, etc.).
- add_int(property_uri, value)¶
 - Parameters:
 
Adds a numeric property with integer precision. Previous values for the same property are kept.
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method corresponds to xsd:integer.
- add_int64(property_uri, value)¶
 - Parameters:
 
Adds a numeric property with 64-bit integer precision. Previous values for the same property are kept.
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method corresponds to xsd:integer.
- add_relation(property_uri, resource)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to modifyresource (
Tsparql.Resource) – the property object
Adds a resource property as a
TrackerResource. Previous values for the same property are kept.This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method applies to properties with a rdfs:range that points to a non-literal class (i.e. a subclass of rdfs:Resource).
This method produces similar RDF to [method`Resource`.add_uri], although in this function the URI will depend on the identifier set on resource.
- add_string(property_uri, value)¶
 - Parameters:
 
Adds a string property. Previous values for the same property are kept.
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This method corresponds to xsd:string.
- add_take_relation(property_uri, resource)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to modifyresource (
Tsparql.Resource) – the property object
Adds a resource property as a
TrackerResource. Previous values for the same property are kept. Takes ownership on the given resource.This method is meant to RDF properties allowing multiple values, see nrl:maxCardinality.
This method applies to properties with a rdfs:range that points to a non-literal class (i.e. a subclass of rdfs:Resource).
This function produces similar RDF to [method`Resource`.add_uri], although in this function the URI will depend on the identifier set on resource. This function takes ownership of resource.
- add_uri(property_uri, value)¶
 - Parameters:
 
Adds a resource property as an URI string. Previous values for the same property are kept.
This method applies to properties with a rdfs:range that points to a non-literal class (i.e. a subclass of rdfs:Resource).
This method is meant for RDF properties allowing multiple values, see nrl:maxCardinality.
This function produces similar RDF to [method`Resource`.add_relation], although it requires that the URI is previously known.
- get_first_boolean(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first boolean object
- Return type:
 
Returns the first boolean object previously assigned to a property.
- get_first_datetime(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first
GLib.DateTimeobject- Return type:
 
Returns the first [type`GLib`.DateTime] previously assigned to a property.
New in version 3.2.
- get_first_double(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first double object
- Return type:
 
Returns the first double object previously assigned to a property.
- get_first_int(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first integer object
- Return type:
 
Returns the first integer object previously assigned to a property.
- get_first_int64(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first integer object
- Return type:
 
Returns the first integer object previously assigned to a property.
- get_first_relation(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first resource object
- Return type:
 
Returns the first resource object previously assigned to a property.
- get_first_string(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first string object
- Return type:
 
Returns the first string object previously assigned to a property.
- get_first_uri(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 the first resource object as an URI.
- Return type:
 
Returns the first resource object previously assigned to a property.
- get_identifier()¶
 - 
Returns the identifier of a resource.
If the identifier was set to
None, the identifier returned will be a locally unique SPARQL blank node identifier, such as_:123. 
- get_properties()¶
 - Returns:
 The list of properties.
- Return type:
 [
str]
Gets the list of properties defined in self
- get_property_overwrite(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to query- Returns:
 Trueif the property would be overwritten- Return type:
 
Returns whether the prior values for this property would be deleted in the SPARQL issued by self.
New in version 3.1.
- get_values(property_uri)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to look up- Returns:
 a [struct`GLib`.List] of [struct`GObject`.Value] instances. The list should be freed with [func`GLib`.List.free]
- Return type:
 [
GObject.Value] orNone
Returns the list of all known values of the given property.
- identifier_compare_func(identifier)¶
 - Parameters:
 identifier (
str) – a string identifying the resource- Returns:
 an integer less than, equal to, or greater than zero, if the resource identifier is <, == or > than identifier
- Return type:
 
A helper function that compares a
TrackerResourceby its identifier string.
- print_jsonld(namespaces)¶
 - Parameters:
 namespaces (
Tsparql.NamespaceManagerorNone) – a set of prefixed URLs, orNoneto use the Nepomuk set- Returns:
 a newly-allocated string containing JSON-LD data.
- Return type:
 
Serialize all the information in resource as a JSON-LD document.
See <http://www.jsonld.org/> for more information on the JSON-LD serialization format.
The namespaces object is used to expand any compact URI values. In most cases you should pass the one returned by [method`SparqlConnection`.get_namespace_manager] from the connection that is the intended recipient of this data.
Deprecated since version 3.5: Use [method`Resource`.print_rdf] instead.
- print_rdf(namespaces, format, graph)¶
 - Parameters:
 namespaces (
Tsparql.NamespaceManager) – a set of prefixed URLsformat (
Tsparql.RdfFormat) – RDF format of the printed stringgraph (
strorNone) – target graph of the resource RDF, orNonefor the default graph
- Returns:
 a newly-allocated string containing RDF data in the requested format.
- Return type:
 
Serialize all the information in resource into the selected RDF format.
The namespaces object is used to expand any compact URI values. In most cases you should pass the one returned by [method`SparqlConnection`.get_namespace_manager] from the connection that is the intended recipient of this data.
New in version 3.4.
- print_sparql_update(namespaces, graph_id)¶
 - Parameters:
 - Returns:
 a newly-allocated string containing a SPARQL update command.
- Return type:
 
Generates a SPARQL command to update a database with the information stored in resource.
The namespaces object is used to expand any compact URI values. In most cases you should pass the one returned by [method`SparqlConnection`.get_namespace_manager] from the connection that is the intended recipient of this data.
- print_turtle(namespaces)¶
 - Parameters:
 namespaces (
Tsparql.NamespaceManagerorNone) – a set of prefixed URLs, orNoneto use the Nepomuk set- Returns:
 a newly-allocated string
- Return type:
 
Serialize all the information in resource as a Turtle document.
The generated Turtle should correspond to this standard: <https://www.w3.org/TR/2014/REC-turtle-20140225/>
The namespaces object is used to expand any compact URI values. In most cases you should pass the one returned by [method`SparqlConnection`.get_namespace_manager] from the connection that is the intended recipient of this data.
Deprecated since version 3.4: Use [method`Resource`.print_rdf] instead.
- serialize()¶
 - Returns:
 A variant describing the resource, the reference is floating.
- Return type:
 GLib.VariantorNone
Serializes a
TrackerResourceto a [type`GLib`.Variant] in a lossless way. All child resources are subsequently serialized. It is implied that both ends use a common [class`NamespaceManager`].
- set_boolean(property_uri, value)¶
 - Parameters:
 
Sets a boolean property. Replaces any previous value.
This method corresponds to xsd:boolean.
- set_datetime(property_uri, value)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to modifyvalue (
GLib.DateTime) – the property object
Sets a date property as a [type`GLib`.DateTime]. Replaces any previous value.
This method corresponds to xsd:date and xsd:dateTime.
New in version 3.2.
- set_double(property_uri, value)¶
 - Parameters:
 
Sets a numeric property with double precision. Replaces any previous value.
This method corresponds to xsd:double.
- set_gvalue(property_uri, value)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to setvalue (
GObject.Value) – an initialised [struct`GObject`.Value]
Replace any previously existing value for property_uri with value.
When serialising to SPARQL, any properties that were set with this function will get a corresponding DELETE statement to remove any existing values in the database.
You can pass any kind of [struct`GObject`.Value] for value, but serialization functions will normally only be able to serialize URIs/relationships and fundamental value types (string, int, etc.).
- set_identifier(identifier)¶
 - 
Changes the identifier of a
TrackerResource. The identifier should be a URI or compact URI, but this is not necessarily enforced. Invalid identifiers may cause errors when serializing the resource or trying to insert the results in a database.If the identifier is set to
None, a SPARQL blank node identifier such as_:123is assigned to the resource. 
- set_int(property_uri, value)¶
 - Parameters:
 
Sets a numeric property with integer precision. Replaces any previous value.
This method corresponds to xsd:integer.
- set_int64(property_uri, value)¶
 - Parameters:
 
Sets a numeric property with 64-bit integer precision. Replaces any previous value.
This method corresponds to xsd:integer.
- set_relation(property_uri, resource)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to modifyresource (
Tsparql.Resource) – the property object
Sets a resource property as a
TrackerResource. Replaces any previous value.This method applies to properties with a rdfs:range that points to a non-literal class (i.e. a subclass of rdfs:Resource).
This function produces similar RDF to [method`Resource`.set_uri], although in this function the URI will depend on the identifier set on resource.
- set_string(property_uri, value)¶
 - Parameters:
 
Sets a string property. Replaces any previous value.
This method corresponds to xsd:string.
- set_take_relation(property_uri, resource)¶
 - Parameters:
 property_uri (
str) – a string identifying the property to modifyresource (
Tsparql.Resource) – the property object
Sets a resource property as a
TrackerResource. Replaces any previous value. Takes ownership on the given resource.This method applies to properties with a rdfs:range that points to a non-literal class (i.e. a subclass of rdfs:Resource).
This function produces similar RDF to [method`Resource`.set_uri], although in this function the URI will depend on the identifier set on resource.
- set_uri(property_uri, value)¶
 - Parameters:
 
Sets a resource property as an URI string. Replaces any previous value.
This method applies to properties with a rdfs:range that points to a non-literal class (i.e. a subclass of rdfs:Resource).
This function produces similar RDF to [method`Resource`.set_relation], although it requires that the URI is previously known.