TrackerResource: Tracker SPARQL Library Reference Manual

## TrackerResource TrackerResource — Represents a single Tracker resource |

## Stability Level

Stable, unless otherwise indicated

## Functions

TrackerResource * | tracker_resource_new ()
void | tracker_resource_set_boolean ()
void | tracker_resource_set_double ()
void | tracker_resource_set_gvalue ()
void | tracker_resource_set_identifier ()
void | tracker_resource_set_int ()
void | tracker_resource_set_int64 ()
void | tracker_resource_set_relation ()
void | tracker_resource_set_take_relation ()
void | tracker_resource_set_string ()
void | tracker_resource_set_uri ()
void | tracker_resource_add_boolean ()
void | tracker_resource_add_double ()
void | tracker_resource_add_gvalue ()
void | tracker_resource_add_int ()
void | tracker_resource_add_int64 ()
void | tracker_resource_add_relation ()
void | tracker_resource_add_take_relation ()
void | tracker_resource_add_string ()
void | tracker_resource_add_uri ()
gboolean | tracker_resource_get_first_boolean ()
double | tracker_resource_get_first_double ()
int | tracker_resource_get_first_int ()
gint64 | tracker_resource_get_first_int64 ()
TrackerResource * | tracker_resource_get_first_relation ()
const char * | tracker_resource_get_first_string ()
const char * | tracker_resource_get_first_uri ()
const char * | tracker_resource_get_identifier ()
GList * | tracker_resource_get_values ()
GList * | tracker_resource_get_properties ()
gint | tracker_resource_identifier_compare_func ()
char * | tracker_resource_print_sparql_update ()
char * | tracker_resource_print_turtle ()
char * | tracker_resource_print_jsonld ()
GVariant * | tracker_resource_serialize ()
TrackerResource * | tracker_resource_deserialize ()

## Properties

gchar * | identifier | Read / Write

## Types and Values

| TrackerResource
#define | TRACKER_PREFIX_DC
#define | TRACKER_PREFIX_MFO
#define | TRACKER_PREFIX_NAO
#define | TRACKER_PREFIX_NCO
#define | TRACKER_PREFIX_NFO
#define | TRACKER_PREFIX_NIE
#define | TRACKER_PREFIX_NMM
#define | TRACKER_PREFIX_NRL
#define | TRACKER_PREFIX_OSINFO
#define | TRACKER_PREFIX_RDF
#define | TRACKER_PREFIX_RDFS
#define | TRACKER_PREFIX_SLO
#define | TRACKER_PREFIX_TRACKER
#define | TRACKER_PREFIX_XSD

## Object Hierarchy

        GObject
        ╰── TrackerResource

## Includes

    #include <tracker-resource.h>

## Description

TrackerResource keeps track of a set of properties for a given resource. The resulting data can be serialized in several ways.

## Functions

### tracker_resource_new ()

    TrackerResource *
    tracker_resource_new (const char *identifier);

Creates a TrackerResource instance.

#### Parameters

identifier | A string containing a URI |

#### Returns

a newly created TrackerResource. Free with `g_object_unref()` when done

Since: 1.10

### tracker_resource_set_boolean ()

    void
    tracker_resource_set_boolean (TrackerResource *self,
                                  const char *property_uri,
                                  gboolean value);

Sets a single-valued boolean object.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_set_double ()

    void
    tracker_resource_set_double (TrackerResource *self,
                                 const char *property_uri,
                                 double value);

Sets a single-valued double object.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_set_gvalue ()

    void
    tracker_resource_set_gvalue (TrackerResource *self,
                                 const char *property_uri,
                                 const GValue *value);

State that the only value for the given property is 'value'. Any existing values for 'property' will be removed.

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 GValue for `value` , but serialization functions will normally only be able to serialize URIs/relationships and fundamental value types (string, int, etc.).

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to set |
value | an initialised GValue |

Since: 1.10

### tracker_resource_set_identifier ()

    void
    tracker_resource_set_identifier (TrackerResource *self,
                                     const char *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 NULL, a SPARQL blank node identifier such as "_:123" is assigned to the resource.

#### Parameters

self | a TrackerResource |
identifier | a string identifying the resource. | [allow-none]

Since: 1.10

### tracker_resource_set_int ()

    void
    tracker_resource_set_int (TrackerResource *self,
                              const char *property_uri,
                              int value);

Sets a single-valued integer object.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_set_int64 ()

    void
    tracker_resource_set_int64 (TrackerResource *self,
                                const char *property_uri,
                                gint64 value);

Sets a single-valued integer object.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_set_relation ()

    void
    tracker_resource_set_relation (TrackerResource *self,
                                   const char *property_uri,
                                   TrackerResource *resource);

Sets a single-valued resource object as a TrackerResource. This function produces similar RDF to `tracker_resource_set_uri()`, although in this function the URI will depend on the identifier set on `resource` .

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
resource | the property object |

Since: 1.10

### tracker_resource_set_take_relation ()

    void
    tracker_resource_set_take_relation (TrackerResource *self,
                                        const char *property_uri,
                                        TrackerResource *resource);

Sets a single-valued resource object as a TrackerResource. This function produces similar RDF to `tracker_resource_set_uri()`, although in this function the URI will depend on the identifier set on `resource` . This function takes ownership of `resource` .

[skip]

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
resource | the property object |

Since: 2.0

### tracker_resource_set_string ()

    void
    tracker_resource_set_string (TrackerResource *self,
                                 const char *property_uri,
                                 const char *value);

Sets a single-valued string object.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_set_uri ()

    void
    tracker_resource_set_uri (TrackerResource *self,
                              const char *property_uri,
                              const char *value);

Sets a single-valued resource object as a string URI. This function produces similar RDF to `tracker_resource_set_relation()`, although it requires that the URI is previously known.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_add_boolean ()

    void
    tracker_resource_add_boolean (TrackerResource *self,
                                  const char *property_uri,
                                  gboolean value);

Adds a boolean object to a multi-valued property.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_add_double ()

    void
    tracker_resource_add_double (TrackerResource *self,
                                 const char *property_uri,
                                 double value);

Adds a double object to a multi-valued property.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_add_gvalue ()

    void
    tracker_resource_add_gvalue (TrackerResource *self,
                                 const char *property_uri,
                                 const GValue *value);

Add 'value' to the list of values for given property.

You can pass any kind of GValue for `value` , but serialization functions will normally only be able to serialize URIs/relationships and fundamental value types (string, int, etc.).

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to set |
value | an initialised GValue |

Since: 1.10

### tracker_resource_add_int ()

    void
    tracker_resource_add_int (TrackerResource *self,
                              const char *property_uri,
                              int value);

Adds an integer object to a multi-valued property.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_add_int64 ()

    void
    tracker_resource_add_int64 (TrackerResource *self,
                                const char *property_uri,
                                gint64 value);

Adds an integer object to a multi-valued property.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_add_relation ()

    void
    tracker_resource_add_relation (TrackerResource *self,
                                   const char *property_uri,
                                   TrackerResource *resource);

Adds a resource object to a multi-valued property. This function produces similar RDF to `tracker_resource_add_uri()`, although in this function the URI will depend on the identifier set on `resource` .

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
resource | the property object |

Since: 1.10

### tracker_resource_add_take_relation ()

    void
    tracker_resource_add_take_relation (TrackerResource *self,
                                        const char *property_uri,
                                        TrackerResource *resource);

Adds a resource object to a multi-valued property. This function produces similar RDF to `tracker_resource_add_uri()`, although in this function the URI will depend on the identifier set on `resource` . This function takes ownership of `resource` .

[skip]

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
resource | the property object |

Since: 2.0

### tracker_resource_add_string ()

    void
    tracker_resource_add_string (TrackerResource *self,
                                 const char *property_uri,
                                 const char *value);

Adds a string object to a multi-valued property.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_add_uri ()

    void
    tracker_resource_add_uri (TrackerResource *self,
                              const char *property_uri,
                              const char *value);

Adds a resource object to a multi-valued property. This function produces similar RDF to `tracker_resource_add_relation()`, although it requires that the URI is previously known.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to modify |
value | the property object |

Since: 1.10

### tracker_resource_get_first_boolean ()

    gboolean
    tracker_resource_get_first_boolean (TrackerResource *self,
                                        const char *property_uri);

Returns the first boolean object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first boolean object

Since: 1.10

### tracker_resource_get_first_double ()

    double
    tracker_resource_get_first_double (TrackerResource *self,
                                       const char *property_uri);

Returns the first double object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first double object

Since: 1.10

### tracker_resource_get_first_int ()

    int
    tracker_resource_get_first_int (TrackerResource *self,
                                    const char *property_uri);

Returns the first integer object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first integer object

Since: 1.10

### tracker_resource_get_first_int64 ()

    gint64
    tracker_resource_get_first_int64 (TrackerResource *self,
                                      const char *property_uri);

Returns the first integer object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first integer object

Since: 1.10

### tracker_resource_get_first_relation ()

    TrackerResource *
    tracker_resource_get_first_relation (TrackerResource *self,
                                         const char *property_uri);

Returns the first resource object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first resource object.

[transfer none]

Since: 1.10

### tracker_resource_get_first_string ()

    const char *
    tracker_resource_get_first_string (TrackerResource *self,
                                       const char *property_uri);

Returns the first string object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first string object

Since: 1.10

### tracker_resource_get_first_uri ()

    const char *
    tracker_resource_get_first_uri (TrackerResource *self,
                                    const char *property_uri);

Returns the first resource object previously assigned to a property.

#### Parameters

self | A TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

the first resource object as an URI.

Since: 1.10

### tracker_resource_get_identifier ()

    const char *
    tracker_resource_get_identifier (TrackerResource *self);

Returns the identifier of a resource.

If the identifier was set to NULL, the identifier returned will be a unique SPARQL blank node identifier, such as "_:123".

#### Parameters

self | A TrackerResource |

#### Returns

a string owned by the resource

Since: 1.10

### tracker_resource_get_values ()

    GList *
    tracker_resource_get_values (TrackerResource *self,
                                 const char *property_uri);

Returns the list of all known values of the given property.

#### Parameters

self | the TrackerResource |
property_uri | a string identifying the property to look up |

#### Returns

a GList of GValue instances. The list should be freed with `g_list_free()`.

[transfer container][element-type GValue]

Since: 1.10

### tracker_resource_get_properties ()

    GList *
    tracker_resource_get_properties (TrackerResource *resource);

Gets the list of properties defined in `resource`

#### Parameters

resource | a TrackerResource |

#### Returns

The list of properties. The list should be freed with `g_list_free()`.

[transfer container][element-type utf8]

Since: 3.0

### tracker_resource_identifier_compare_func ()

    gint
    tracker_resource_identifier_compare_func
                                   (TrackerResource *resource,
                                    const char *identifier);

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

#### Parameters

resource | a TrackerResource |
identifier | a string identifying the resource |

#### Returns

an integer less than, equal to, or greater than zero, if the resource identifier is <, == or > than `identifier`

### tracker_resource_print_sparql_update ()

    char *
    tracker_resource_print_sparql_update (TrackerResource *self,
                                          TrackerNamespaceManager *namespaces,
                                          const char *graph_id);

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 `NULL`, which means the set of namespaces returned by `tracker_namespace_manager_get_default()` will be used. This defines the usual prefixes for all of the ontologies that Tracker ships with by default.

#### Parameters

self | a TrackerResource |
namespaces | a set of prefixed URLs, or `NULL` to use the default set. | [allow-none]
graph_id | the URN of the graph the data should be added to, or `NULL`. | [allow-none]

#### Returns

a newly-allocated string containing a SPARQL update command.

Since: 1.10

### tracker_resource_print_turtle ()

    char *
    tracker_resource_print_turtle (TrackerResource *self,
                                   TrackerNamespaceManager *namespaces);

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 `NULL`, which means the set of namespaces returned by `tracker_namespace_manager_get_default()` will be used. This defines the usual prefixes for all of the ontologies that Tracker ships with by default.

#### Parameters

self | a TrackerResource |
namespaces | a set of prefixed URLs, or `NULL` to use the default set. | [allow-none]

#### Returns

a newly-allocated string

Since: 1.10

### tracker_resource_print_jsonld ()

    char *
    tracker_resource_print_jsonld (TrackerResource *self,
                                   TrackerNamespaceManager *namespaces);

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 `NULL`, which means the set of namespaces returned by `tracker_namespace_manager_get_default()` will be used. This defines the usual prefixes for all of the ontologies that Tracker ships with by default.

#### Parameters

self | a TrackerResource |
namespaces | a set of prefixed URLs, or `NULL` to use the default set. | [allow-none]

#### Returns

a newly-allocated string containing JSON-LD data.

Since: 2.0.5

### tracker_resource_serialize ()

    GVariant *
    tracker_resource_serialize (TrackerResource *resource);

Serializes a TrackerResource to a GVariant in a lossless way. All child resources are subsequently serialized. It is implied that both ends use a common TrackerNamespaceManager.

#### Parameters

resource | A TrackerResource |

#### Returns

A variant describing the resource, the reference is floating.

[transfer full]

Since: 3.0

### tracker_resource_deserialize ()

    TrackerResource *
    tracker_resource_deserialize (GVariant *variant);

Deserializes a TrackerResource previously serialized with `tracker_resource_serialize()`. It is implied that both ends use a common TrackerNamespaceManager.

#### Parameters

variant | a GVariant |

#### Returns

A TrackerResource, or `NULL` if deserialization fails.

[transfer full]

Since: 3.0

## Types and Values

### TrackerResource

    typedef struct _TrackerResource TrackerResource;

The TrackerResource object represents information about a given resource.

### TRACKER_PREFIX_DC

    #define TRACKER_PREFIX_DC       "http://purl.org/dc/elements/1.1/"

The Prefix of the DC (Dublin Core) namespace

### TRACKER_PREFIX_MFO

    #define TRACKER_PREFIX_MFO      "http://tracker.api.gnome.org/ontology/v3/mfo#"

The Prefix of the MFO namespace

### TRACKER_PREFIX_NAO

    #define TRACKER_PREFIX_NAO      "http://tracker.api.gnome.org/ontology/v3/nao#"

The Prefix of the NAO namespace

### TRACKER_PREFIX_NCO

    #define TRACKER_PREFIX_NCO      "http://tracker.api.gnome.org/ontology/v3/nco#"

The Prefix of the NCO namespace

### TRACKER_PREFIX_NFO

    #define TRACKER_PREFIX_NFO      "http://tracker.api.gnome.org/ontology/v3/nfo#"

The Prefix of the NFO namespace

### TRACKER_PREFIX_NIE

    #define TRACKER_PREFIX_NIE      "http://tracker.api.gnome.org/ontology/v3/nie#"

The Prefix of the NIE namespace

### TRACKER_PREFIX_NMM

    #define TRACKER_PREFIX_NMM      "http://tracker.api.gnome.org/ontology/v3/nmm#"

The Prefix of the RDF namespace

### TRACKER_PREFIX_NRL

    #define TRACKER_PREFIX_NRL      "http://tracker.api.gnome.org/ontology/v3/nrl#"

The Prefix of the NRL namespace

### TRACKER_PREFIX_OSINFO

    #define TRACKER_PREFIX_OSINFO   "http://tracker.api.gnome.org/ontology/v3/osinfo#"

The Prefix of the Osinfo namespace

### TRACKER_PREFIX_RDF

    #define TRACKER_PREFIX_RDF      "http://www.w3.org/1999/02/22-rdf-syntax-ns#"

The Prefix of the RDF namespace

### TRACKER_PREFIX_RDFS

    #define TRACKER_PREFIX_RDFS     "http://www.w3.org/2000/01/rdf-schema#"

The Prefix of the RDFS namespace

### TRACKER_PREFIX_SLO

    #define TRACKER_PREFIX_SLO      "http://tracker.api.gnome.org/ontology/v3/slo#"

The Prefix of the SLO namespace

### TRACKER_PREFIX_TRACKER

    #define TRACKER_PREFIX_TRACKER  "http://tracker.api.gnome.org/ontology/v3/tracker#"

The Prefix of the Tracker namespace

### TRACKER_PREFIX_XSD

    #define TRACKER_PREFIX_XSD      "http://www.w3.org/2001/XMLSchema#"

The Prefix of the XSD namespace

## Property Details

### The `“identifier”` property

      “identifier”               gchar *

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

Owner: TrackerResource

Flags: Read / Write

Default value: NULL