Triples
3
RASQAL Library

# Triples

Triple pattern or RDF triple.

## Synopsis

                        rasqal_triple;
    enum                rasqal_triple_flags;
    rasqal_triple*      rasqal_new_triple                   (rasqal_literal *subject,
                                                             rasqal_literal *predicate,
                                                             rasqal_literal *object);
    rasqal_triple*      rasqal_new_triple_from_triple       (rasqal_triple *t);
    void                rasqal_free_triple                  (rasqal_triple *t);
    rasqal_literal*     rasqal_triple_get_origin            (rasqal_triple *t);
    enum                rasqal_triple_parts;
    void                rasqal_triple_print                 (rasqal_triple *t,
                                                             FILE *fh);
    void                rasqal_triple_set_origin            (rasqal_triple *t,
                                                             rasqal_literal *l);

## Description

An object for a triple pattern or an RDF triple in a query. It contains the three parts of an RDF triple - subject, predicate, object as well as origin for matching triples in some graph (such as with the SPARQL `GRAPH`).

## Details

### rasqal_triple

    typedef struct {
      rasqal_literal* subject;
      rasqal_literal* predicate;
      rasqal_literal* object;
      rasqal_literal* origin;
      unsigned int flags;
    } rasqal_triple;

A triple pattern or RDF triple.

This is used as a triple pattern in queries and an RDF triple when generating RDF triples such as with SPARQL CONSTRUCT.

rasqal_literal *subject;

  Triple subject.

rasqal_literal *predicate;

  Triple predicate.

rasqal_literal *object;

  Triple object.

rasqal_literal *origin;

  Triple origin.

unsigned int flags;

  Or of enum rasqal_triple_flags bits.

### enum rasqal_triple_flags

    typedef enum {

      /* Not used - was only used internally in the execution engine */
      RASQAL_TRIPLE_FLAGS_EXACT=1,

      /* Not used - this is now a property of a graph pattern */
      RASQAL_TRIPLE_FLAGS_OPTIONAL=2,

      RASQAL_TRIPLE_FLAGS_LAST=RASQAL_TRIPLE_FLAGS_OPTIONAL
    } rasqal_triple_flags;

Flags for triple patterns.

`RASQAL_TRIPLE_FLAGS_EXACT`

  Not used.

`RASQAL_TRIPLE_FLAGS_OPTIONAL`

  Not used.

`RASQAL_TRIPLE_FLAGS_LAST`

  Internal.

### rasqal_new_triple ()

    rasqal_triple*      rasqal_new_triple                   (rasqal_literal *subject,
                                                             rasqal_literal *predicate,
                                                             rasqal_literal *object);

Constructor - create a new rasqal_triple triple or triple pattern. Takes ownership of the literals passed in.

The triple origin can be set with `rasqal_triple_set_origin()`.

`subject` :

  Triple subject.

`predicate` :

  Triple predicate.

`object` :

  Triple object.

Returns :

  a new rasqal_triple or NULL on failure.

### rasqal_new_triple_from_triple ()

    rasqal_triple*      rasqal_new_triple_from_triple       (rasqal_triple *t);

Copy constructor - create a new rasqal_triple from an existing one.

`t` :

  Triple to copy.

Returns :

  a new rasqal_triple or NULL on failure.

### rasqal_free_triple ()

    void                rasqal_free_triple                  (rasqal_triple *t);

Destructor - destroy a rasqal_triple object.

`t` :

  rasqal_triple object.

### rasqal_triple_get_origin ()

    rasqal_literal*     rasqal_triple_get_origin            (rasqal_triple *t);

Get the origin field of a rasqal_triple.

`t` :

  The triple object.

Returns :

  The triple origin or NULL.

### enum rasqal_triple_parts

    typedef enum {
      RASQAL_TRIPLE_SUBJECT  = 1,
      RASQAL_TRIPLE_PREDICATE= 2,
      RASQAL_TRIPLE_OBJECT   = 4,
      RASQAL_TRIPLE_ORIGIN   = 8,
      RASQAL_TRIPLE_GRAPH    = RASQAL_TRIPLE_ORIGIN,
      RASQAL_TRIPLE_SPO      = RASQAL_TRIPLE_SUBJECT | RASQAL_TRIPLE_PREDICATE | RASQAL_TRIPLE_OBJECT,
      RASQAL_TRIPLE_SPOG     = RASQAL_TRIPLE_SPO | RASQAL_TRIPLE_GRAPH
    } rasqal_triple_parts;

Flags for parts of a triple.

`RASQAL_TRIPLE_SUBJECT`

  Subject present in a triple.

`RASQAL_TRIPLE_PREDICATE`

  Predicate present in a triple.

`RASQAL_TRIPLE_OBJECT`

  Object present in a triple.

`RASQAL_TRIPLE_ORIGIN`

  Origin/graph present in a triple.

`RASQAL_TRIPLE_GRAPH`

  Alias for RASQAL_TRIPLE_ORIGIN

`RASQAL_TRIPLE_SPO`

  Subject, Predicate and Object present in a triple.

`RASQAL_TRIPLE_SPOG`

  Subject, Predicate, Object, Graph present in a triple.

### rasqal_triple_print ()

    void                rasqal_triple_print                 (rasqal_triple *t,
                                                             FILE *fh);

Print a Rasqal triple in a debug format.

The print debug format may change in any release.

`t` :

  rasqal_triple object.

`fh` :

  The FILE* handle to print to.

### rasqal_triple_set_origin ()

    void                rasqal_triple_set_origin            (rasqal_triple *t,
                                                             rasqal_literal *l);

Set the origin field of a rasqal_triple.

`t` :

  The triple object.

`l` :

  The rasqal_literal object to set as origin.