Tracker.Resource

g GObject.Object GObject.Object Tracker.Resource Tracker.Resource GObject.Object->Tracker.Resource

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

deserialize (variant)

class

new (identifier)

add_boolean (property_uri, value)

add_datetime (property_uri, value)

add_double (property_uri, value)

add_gvalue (property_uri, value)

add_int (property_uri, value)

add_int64 (property_uri, value)

add_relation (property_uri, resource)

add_string (property_uri, value)

add_take_relation (property_uri, resource)

add_uri (property_uri, value)

get_first_boolean (property_uri)

get_first_datetime (property_uri)

get_first_double (property_uri)

get_first_int (property_uri)

get_first_int64 (property_uri)

get_first_relation (property_uri)

get_first_string (property_uri)

get_first_uri (property_uri)

get_identifier ()

get_properties ()

get_property_overwrite (property_uri)

get_values (property_uri)

identifier_compare_func (identifier)

print_jsonld (namespaces)

print_rdf (namespaces, format, graph)

print_sparql_update (namespaces, graph_id)

print_turtle (namespaces)

serialize ()

set_boolean (property_uri, value)

set_datetime (property_uri, value)

set_double (property_uri, value)

set_gvalue (property_uri, value)

set_identifier (identifier)

set_int (property_uri, value)

set_int64 (property_uri, value)

set_relation (property_uri, resource)

set_string (property_uri, value)

set_take_relation (property_uri, resource)

set_uri (property_uri, value)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

identifier

str

r/w

Identifier

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Tracker.Resource(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Tracker.ResourceClass

TrackerResource is 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 TrackerResource objects to form trees or graphs of RDF data. See [method`Tracker`.Resource.set_relation] and [method`Tracker`.Resource.set_uri] on how to link a TrackerResource to other RDF data.

TrackerResource may also hold data about literal values, added through the specialized [method`Tracker`.Resource.set_int64], [method`Tracker`.Resource.set_string], etc family of functions, or the generic [method`Tracker`.Resource.set_gvalue] method.

Since RDF properties may be multi-valued, for every set call there exists another add call (e.g. [method`Tracker`.Resource.add_int64], [method`Tracker`.Resource.add_string] and so on). The set methods do also reset any previously value the property might hold for the given resource.

Resources may have an IRI set at creation through [ctor`Tracker`.Resource.new], or set afterwards through [method`Tracker`.Resource.set_identifier]. Resources without a name will represent a blank node, and will be dealt with as such during database insertions.

TrackerResource performs no validation on the data being coherent as per any ontology. Errors will be found out at the time of using the Tracker.Resource for e.g. database updates.

Once the RDF data is built in memory, the (tree of) TrackerResource may be converted to a RDF format through [method`Tracker`.Resource.print_rdf], or directly inserted into a database through [method`Tracker`.Batch.add_resource] or [method`Tracker`.SparqlConnection.update_resource].

classmethod deserialize(variant)
Parameters:

variant (GLib.Variant) – a [type`GLib`.Variant]

Returns:

A Tracker.Resource, or None if deserialization fails.

Return type:

Tracker.Resource or None

Deserializes a TrackerResource previously serialized with [method`Tracker`.Resource.serialize]. It is implied that both ends use a common [class`Tracker`.NamespaceManager].

classmethod new(identifier)
Parameters:

identifier (str or None) – A string containing a URI, or None.

Returns:

a newly created TrackerResource.

Return type:

Tracker.Resource

Creates a Tracker.Resource instance.

add_boolean(property_uri, value)
Parameters:
  • property_uri (str) – A string identifying the property to modify

  • value (bool) – The property boolean value

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 modify

  • value (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:
  • property_uri (str) – a string identifying the property to modify

  • value (float) – the property object

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 set

  • value (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:
  • property_uri (str) – a string identifying the property to modify

  • value (int) – the property object

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:
  • property_uri (str) – a string identifying the property to modify

  • value (int) – the property object

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 modify

  • resource (Tracker.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`Tracker`.Resource.add_uri], although in this function the URI will depend on the identifier set on resource.

add_string(property_uri, value)
Parameters:
  • property_uri (str) – a string identifying the property to modify

  • value (str) – the property object

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 modify

  • resource (Tracker.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`Tracker`.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:
  • property_uri (str) – a string identifying the property to modify

  • value (str) – the property object

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`Tracker`.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:

bool

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

Return type:

GLib.DateTime or None

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:

float

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:

int

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:

int

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:

Tracker.Resource or None

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:

str or None

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:

str or None

Returns the first resource object previously assigned to a property.

get_identifier()
Returns:

a string owned by the resource

Return type:

str or None

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:

True if the property would be overwritten

Return type:

bool

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] or None

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:

int

A helper function that compares a TrackerResource by its identifier string.

print_jsonld(namespaces)
Parameters:

namespaces (Tracker.NamespaceManager or None) – a set of prefixed URLs, or None to use the Nepomuk set

Returns:

a newly-allocated string containing JSON-LD data.

Return type:

str

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`Tracker`.SparqlConnection.get_namespace_manager] from the connection that is the intended recipient of this data.

Deprecated since version 3.5: Use [method`Tracker`.Resource.print_rdf] instead.

print_rdf(namespaces, format, graph)
Parameters:
Returns:

a newly-allocated string containing RDF data in the requested format.

Return type:

str

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`Tracker`.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:

str

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`Tracker`.SparqlConnection.get_namespace_manager] from the connection that is the intended recipient of this data.

print_turtle(namespaces)
Parameters:

namespaces (Tracker.NamespaceManager or None) – a set of prefixed URLs, or None to use the Nepomuk set

Returns:

a newly-allocated string

Return type:

str

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`Tracker`.SparqlConnection.get_namespace_manager] from the connection that is the intended recipient of this data.

Deprecated since version 3.4: Use [method`Tracker`.Resource.print_rdf] instead.

serialize()
Returns:

A variant describing the resource, the reference is floating.

Return type:

GLib.Variant or None

Serializes a TrackerResource to a [type`GLib`.Variant] in a lossless way. All child resources are subsequently serialized. It is implied that both ends use a common [class`Tracker`.NamespaceManager].

set_boolean(property_uri, value)
Parameters:
  • property_uri (str) – A string identifying the property to modify

  • value (bool) – The property boolean value

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 modify

  • value (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:
  • property_uri (str) – A string identifying the property to modify

  • value (float) – The property object

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 set

  • value (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)
Parameters:

identifier (str or None) – a string identifying the resource

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 _:123 is assigned to the resource.

set_int(property_uri, value)
Parameters:
  • property_uri (str) – A string identifying the property to modify

  • value (int) – The property object

Sets a numeric property with integer precision. Replaces any previous value.

This method corresponds to xsd:integer.

set_int64(property_uri, value)
Parameters:
  • property_uri (str) – a string identifying the property to modify

  • value (int) – the property object

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 modify

  • resource (Tracker.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`Tracker`.Resource.set_uri], although in this function the URI will depend on the identifier set on resource.

set_string(property_uri, value)
Parameters:
  • property_uri (str) – a string identifying the property to modify

  • value (str) – the property object

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 modify

  • resource (Tracker.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`Tracker`.Resource.set_uri], although in this function the URI will depend on the identifier set on resource.

set_uri(property_uri, value)
Parameters:
  • property_uri (str) – a string identifying the property to modify

  • value (str) – the property object

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`Tracker`.Resource.set_relation], although it requires that the URI is previously known.

Property Details

Tracker.Resource.props.identifier
Name:

identifier

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE

The URI identifier for this class, or None for a blank node.