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 ()
gint | tracker_resource_identifier_compare_func ()
char * | tracker_resource_print_sparql_update ()
char * | tracker_resource_print_turtle ()
char * | tracker_resource_print_jsonld ()

## Types and Values

| TrackerResource
#define | TRACKER_DATASOURCE_URN_NON_REMOVABLE_MEDIA
#define | TRACKER_OWN_GRAPH_URN
#define | TRACKER_PREFIX_DATASOURCE_URN
#define | TRACKER_PREFIX_DC
#define | TRACKER_PREFIX_MFO
#define | TRACKER_PREFIX_MLO
#define | TRACKER_PREFIX_NAO
#define | TRACKER_PREFIX_NCO
#define | TRACKER_PREFIX_NFO
#define | TRACKER_PREFIX_NID3
#define | TRACKER_PREFIX_NIE
#define | TRACKER_PREFIX_NMM
#define | TRACKER_PREFIX_NMO
#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

## 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, which must be freed by the caller.

[transfer full][element-type GValue]

Since: 1.10

### tracker_resource_identifier_compare_func ()

    gint
    tracker_resource_identifier_compare_func
                                   (TrackerResource *resource,
                                    const char *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

## Types and Values

### TrackerResource

    typedef struct _TrackerResource TrackerResource;

The TrackerResource object represents information about a given resource.

### TRACKER_DATASOURCE_URN_NON_REMOVABLE_MEDIA

    #define             TRACKER_DATASOURCE_URN_NON_REMOVABLE_MEDIA

### TRACKER_OWN_GRAPH_URN

    #define TRACKER_OWN_GRAPH_URN "urn:uuid:472ed0cc-40ff-4e37-9c0c-062d78656540"

### TRACKER_PREFIX_DATASOURCE_URN

    #define             TRACKER_PREFIX_DATASOURCE_URN

### TRACKER_PREFIX_DC

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

### TRACKER_PREFIX_MFO

    #define TRACKER_PREFIX_MFO      "http://www.tracker-project.org/temp/mfo#"

### TRACKER_PREFIX_MLO

    #define TRACKER_PREFIX_MLO      "http://www.tracker-project.org/temp/mlo#"

### TRACKER_PREFIX_NAO

    #define TRACKER_PREFIX_NAO      "http://www.semanticdesktop.org/ontologies/2007/08/15/nao#"

### TRACKER_PREFIX_NCO

    #define TRACKER_PREFIX_NCO      "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#"

### TRACKER_PREFIX_NFO

    #define TRACKER_PREFIX_NFO      "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"

### TRACKER_PREFIX_NID3

    #define TRACKER_PREFIX_NID3     "http://www.semanticdesktop.org/ontologies/2007/05/10/nid3#"

### TRACKER_PREFIX_NIE

    #define TRACKER_PREFIX_NIE      "http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"

### TRACKER_PREFIX_NMM

    #define TRACKER_PREFIX_NMM      "http://www.tracker-project.org/temp/nmm#"

### TRACKER_PREFIX_NMO

    #define TRACKER_PREFIX_NMO      "http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#"

### TRACKER_PREFIX_NRL

    #define TRACKER_PREFIX_NRL      "http://www.semanticdesktop.org/ontologies/2007/08/15/nrl#"

### TRACKER_PREFIX_OSINFO

    #define TRACKER_PREFIX_OSINFO   "http://www.tracker-project.org/ontologies/osinfo#"

### TRACKER_PREFIX_RDF

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

### TRACKER_PREFIX_RDFS

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

### TRACKER_PREFIX_SLO

    #define TRACKER_PREFIX_SLO      "http://www.tracker-project.org/temp/slo#"

### TRACKER_PREFIX_TRACKER

    #define TRACKER_PREFIX_TRACKER  "http://www.tracker-project.org/ontologies/tracker#"

### TRACKER_PREFIX_XSD

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