RDF Triple (librdf_statement)

RDF Triple (librdf_statement) — RDF Triple.

Synopsis

typedef             librdf_statement;
enum                librdf_statement_part;
librdf_statement *  librdf_new_statement                (librdf_world *world);
librdf_statement *  librdf_new_statement_from_statement (librdf_statement *statement);
librdf_statement *  librdf_new_statement_from_statement2
                                                        (librdf_statement *statement);
librdf_statement *  librdf_new_statement_from_nodes     (librdf_world *world,
                                                         librdf_node *subject,
                                                         librdf_node *predicate,
                                                         librdf_node *object);
void                librdf_statement_init               (librdf_world *world,
                                                         librdf_statement *statement);
void                librdf_statement_clear              (librdf_statement *statement);
void                librdf_free_statement               (librdf_statement *statement);
librdf_node *       librdf_statement_get_subject        (librdf_statement *statement);
void                librdf_statement_set_subject        (librdf_statement *statement,
                                                         librdf_node *node);
librdf_node *       librdf_statement_get_predicate      (librdf_statement *statement);
void                librdf_statement_set_predicate      (librdf_statement *statement,
                                                         librdf_node *node);
librdf_node *       librdf_statement_get_object         (librdf_statement *statement);
void                librdf_statement_set_object         (librdf_statement *statement,
                                                         librdf_node *node);
int                 librdf_statement_is_complete        (librdf_statement *statement);
unsigned char *     librdf_statement_to_string          (librdf_statement *statement);
void                librdf_statement_print              (librdf_statement *statement,
                                                         FILE *fh);
int                 librdf_statement_equals             (librdf_statement *statement1,
                                                         librdf_statement *statement2);
int                 librdf_statement_match              (librdf_statement *statement,
                                                         librdf_statement *partial_statement);
size_t              librdf_statement_encode             (librdf_statement *statement,
                                                         unsigned char *buffer,
                                                         size_t length);
size_t              librdf_statement_encode2            (librdf_world *world,
                                                         librdf_statement *statement,
                                                         unsigned char *buffer,
                                                         size_t length);
size_t              librdf_statement_encode_parts       (librdf_statement *statement,
                                                         librdf_node *context_node,
                                                         unsigned char *buffer,
                                                         size_t length,
                                                         librdf_statement_part fields);
size_t              librdf_statement_encode_parts2      (librdf_world *world,
                                                         librdf_statement *statement,
                                                         librdf_node *context_node,
                                                         unsigned char *buffer,
                                                         size_t length,
                                                         librdf_statement_part fields);
size_t              librdf_statement_decode             (librdf_statement *statement,
                                                         unsigned char *buffer,
                                                         size_t length);
size_t              librdf_statement_decode2            (librdf_world *world,
                                                         librdf_statement *statement,
                                                         librdf_node **context_node,
                                                         unsigned char *buffer,
                                                         size_t length);
size_t              librdf_statement_decode_parts       (librdf_statement *statement,
                                                         librdf_node **context_node,
                                                         unsigned char *buffer,
                                                         size_t length);
int                 librdf_statement_write              (librdf_statement *statement,
                                                         raptor_iostream *iostr);

Description

An object representing an RDF Triple of three RDF terms (librdf_node). Triples can be created, accessed, destroyed and en/decoded into a binary form for use in storage.

Details

librdf_statement

typedef raptor_statement librdf_statement;

Redland statement class.


enum librdf_statement_part

typedef enum {
  LIBRDF_STATEMENT_SUBJECT   = 1 << 0,
  LIBRDF_STATEMENT_PREDICATE = 1 << 1,
  LIBRDF_STATEMENT_OBJECT    = 1 << 2,

  /* must be a combination of all of the above */
  LIBRDF_STATEMENT_ALL       = (LIBRDF_STATEMENT_SUBJECT|
                                LIBRDF_STATEMENT_PREDICATE|
                                LIBRDF_STATEMENT_OBJECT)
} librdf_statement_part;

Flags that are or-ed to indicate statement parts.

Used in fields arguments to methods such as the public librdf_statement_encode_parts() librdf_statement_decode_parts() librdf_new_stream_from_node_iterator().

LIBRDF_STATEMENT_SUBJECT

Subject of a statement.

LIBRDF_STATEMENT_PREDICATE

Predicate of a statement.

LIBRDF_STATEMENT_OBJECT

Object of a statement.

LIBRDF_STATEMENT_ALL

All parts of a statement.

librdf_new_statement ()

librdf_statement *  librdf_new_statement                (librdf_world *world);

Constructor - create a new empty librdf_statement.

world :

redland world object

Returns :

a new librdf_statement or NULL on failure

librdf_new_statement_from_statement ()

librdf_statement *  librdf_new_statement_from_statement (librdf_statement *statement);

Copy constructor - create a new librdf_statement from an existing librdf_statement. Creates a deep copy - changes to original statement nodes are not reflected in the copy.

statement :

librdf_statement to copy

Returns :

a new librdf_statement with copy or NULL on failure

librdf_new_statement_from_statement2 ()

librdf_statement *  librdf_new_statement_from_statement2
                                                        (librdf_statement *statement);

Copy constructor - create a new librdf_statement from an existing librdf_statement. Creates a shallow copy - changes to original statement nodes are reflected in the copy.

statement :

librdf_statement to copy

Returns :

a new librdf_statement with copy or NULL on failure

librdf_new_statement_from_nodes ()

librdf_statement *  librdf_new_statement_from_nodes     (librdf_world *world,
                                                         librdf_node *subject,
                                                         librdf_node *predicate,
                                                         librdf_node *object);

Constructor - create a new librdf_statement from existing librdf_node objects.

The node objects become owned by the new statement (or freed on error).

world :

redland world object

subject :

librdf_node

predicate :

librdf_node

object :

librdf_node

Returns :

a new librdf_statement with copy or NULL on failure

librdf_statement_init ()

void                librdf_statement_init               (librdf_world *world,
                                                         librdf_statement *statement);

Initialise a statically declared librdf_statement.

This MUST be called on a statically declared librdf_statement to initialise it properly. It is the responsibility of the user of the statically allocated librdf_statement to deal with deallocation of any statement parts (subject, predicate, object).

world :

redland world object

statement :

librdf_statement object

librdf_statement_clear ()

void                librdf_statement_clear              (librdf_statement *statement);

Empty a librdf_statement of nodes.

statement :

librdf_statement object

librdf_free_statement ()

void                librdf_free_statement               (librdf_statement *statement);

Destructor - destroy a librdf_statement.

statement :

librdf_statement object

librdf_statement_get_subject ()

librdf_node *       librdf_statement_get_subject        (librdf_statement *statement);

Get the statement subject.

This method returns a SHARED pointer to the subject which must be copied by the caller if needed.

statement :

librdf_statement object

Returns :

a pointer to the librdf_node of the statement subject -

librdf_statement_set_subject ()

void                librdf_statement_set_subject        (librdf_statement *statement,
                                                         librdf_node *node);

Set the statement subject.

The subject passed in becomes owned by the statement object and must not be used by the caller after this call.

statement :

librdf_statement object

node :

librdf_node of subject

librdf_statement_get_predicate ()

librdf_node *       librdf_statement_get_predicate      (librdf_statement *statement);

Get the statement predicate.

This method returns a SHARED pointer to the predicate which must be copied by the caller if needed.

statement :

librdf_statement object

Returns :

a pointer to the librdf_node of the statement predicate -

librdf_statement_set_predicate ()

void                librdf_statement_set_predicate      (librdf_statement *statement,
                                                         librdf_node *node);

Set the statement predicate.

The predicate passed in becomes owned by the statement object and must not be used by the caller after this call.

statement :

librdf_statement object

node :

librdf_node of predicate

librdf_statement_get_object ()

librdf_node *       librdf_statement_get_object         (librdf_statement *statement);

Get the statement object.

This method returns a SHARED pointer to the object which must be copied by the caller if needed.

statement :

librdf_statement object

Returns :

a pointer to the librdf_node of the statement object -

librdf_statement_set_object ()

void                librdf_statement_set_object         (librdf_statement *statement,
                                                         librdf_node *node);

Set the statement object.

The object passed in becomes owned by the statement object and must not be used by the caller after this call.

statement :

librdf_statement object

node :

librdf_node of object

librdf_statement_is_complete ()

int                 librdf_statement_is_complete        (librdf_statement *statement);

Check if statement is a complete and legal RDF triple.

Checks that all subject, predicate, object fields are present and they have the allowed node types.

statement :

librdf_statement object

Returns :

non 0 if the statement is complete and legal

librdf_statement_to_string ()

unsigned char *     librdf_statement_to_string          (librdf_statement *statement);

Format the librdf_statement as a string.

Formats the statement as a newly allocate string that must be freed by the caller.

Deprecated: Use librdf_statement_write() to write to raptor_iostream which can be made to write to a string. Use a librdf_serializer to write proper syntax formats.

statement :

the statement

Returns :

the string or NULL on failure.

librdf_statement_print ()

void                librdf_statement_print              (librdf_statement *statement,
                                                         FILE *fh);

Pretty print the statement to a file descriptor.

This method is for debugging and the format of the output should not be relied on.

statement :

the statement

fh :

file handle

librdf_statement_equals ()

int                 librdf_statement_equals             (librdf_statement *statement1,
                                                         librdf_statement *statement2);

Check if two statements are equal.

statement1 :

first librdf_statement

statement2 :

second librdf_statement

Returns :

non 0 if statements are equal

librdf_statement_match ()

int                 librdf_statement_match              (librdf_statement *statement,
                                                         librdf_statement *partial_statement);

Match a statement against a 'partial' statement.

A partial statement is where some parts of the statement - subject, predicate or object can be empty (NULL). Empty parts match against any value, parts with values must match exactly. Node matching is done via librdf_node_equals()

statement :

statement

partial_statement :

statement with possible empty parts

Returns :

non 0 on match

librdf_statement_encode ()

size_t              librdf_statement_encode             (librdf_statement *statement,
                                                         unsigned char *buffer,
                                                         size_t length);

Serialise a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

Deprecated: Use librdf_statement_encode2()

statement :

the statement to serialise

buffer :

the buffer to use

length :

buffer size

Returns :

the number of bytes written or 0 on failure.

librdf_statement_encode2 ()

size_t              librdf_statement_encode2            (librdf_world *world,
                                                         librdf_statement *statement,
                                                         unsigned char *buffer,
                                                         size_t length);

Serialise a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

world :

redland world

statement :

the statement to serialise

buffer :

the buffer to use

length :

buffer size

Returns :

the number of bytes written or 0 on failure.

librdf_statement_encode_parts ()

size_t              librdf_statement_encode_parts       (librdf_statement *statement,
                                                         librdf_node *context_node,
                                                         unsigned char *buffer,
                                                         size_t length,
                                                         librdf_statement_part fields);

Serialise parts of a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

The fields values are or-ed combinations of: LIBRDF_STATEMENT_SUBJECT LIBRDF_STATEMENT_PREDICATE LIBRDF_STATEMENT_OBJECT or LIBRDF_STATEMENT_ALL for subject,prdicate,object fields

If context_node is given, it is encoded also

Deprecated: This will no longer be a public API

statement :

statement to serialise

context_node :

librdf_node context node (can be NULL)

buffer :

the buffer to use

length :

buffer size

fields :

fields to encode

Returns :

the number of bytes written or 0 on failure.

librdf_statement_encode_parts2 ()

size_t              librdf_statement_encode_parts2      (librdf_world *world,
                                                         librdf_statement *statement,
                                                         librdf_node *context_node,
                                                         unsigned char *buffer,
                                                         size_t length,
                                                         librdf_statement_part fields);

Serialise parts of a statement into a buffer.

Encodes the given statement in the buffer, which must be of sufficient size. If buffer is NULL, no work is done but the size of buffer required is returned.

The fields values are or-ed combinations of: LIBRDF_STATEMENT_SUBJECT LIBRDF_STATEMENT_PREDICATE LIBRDF_STATEMENT_OBJECT or LIBRDF_STATEMENT_ALL for subject,prdicate,object fields

If context_node is given, it is encoded also

world :

redland world object

statement :

statement to serialise

context_node :

librdf_node context node (can be NULL)

buffer :

the buffer to use

length :

buffer size

fields :

fields to encode

Returns :

the number of bytes written or 0 on failure.

librdf_statement_decode ()

size_t              librdf_statement_decode             (librdf_statement *statement,
                                                         unsigned char *buffer,
                                                         size_t length);

Decodes a statement from a buffer. (ALWAYS FAILS)

Used to decode the serialised statement as created by librdf_statement_encode() from the given buffer.

Deprecated: Replaced by librdf_statement_decode2() which works.

statement :

the statement to deserialise into

buffer :

the buffer to use

length :

buffer size

Returns :

0 signifying failure

librdf_statement_decode2 ()

size_t              librdf_statement_decode2            (librdf_world *world,
                                                         librdf_statement *statement,
                                                         librdf_node **context_node,
                                                         unsigned char *buffer,
                                                         size_t length);

Decodes a statement + context node from a buffer.

Decodes the serialised statement (as created by librdf_statement_encode() ) from the given buffer. If a context node is found and context_node is not NULL, a pointer to the new librdf_node is stored in *context_node.

world :

redland world

statement :

the statement to deserialise into

context_node :

pointer to librdf_node context_node to deserialise into

buffer :

the buffer to use

length :

buffer size

Returns :

number of bytes used or 0 on failure (bad encoding, allocation failure)

librdf_statement_decode_parts ()

size_t              librdf_statement_decode_parts       (librdf_statement *statement,
                                                         librdf_node **context_node,
                                                         unsigned char *buffer,
                                                         size_t length);

Decodes a statement + context node from a buffer. (ALWAYS FAILS)

Used to decode the serialised statement as created by librdf_statement_encode() from the given buffer.

Deprecated: Replaced by librdf_statement_decode2() which works.

statement :

the statement to deserialise into

context_node :

pointer to librdf_node context_node to deserialise into

buffer :

the buffer to use

length :

buffer size

Returns :

0 signifying failure

librdf_statement_write ()

int                 librdf_statement_write              (librdf_statement *statement,
                                                         raptor_iostream *iostr);

Write the statement to an iostream

This method is for debugging and the format of the output should not be relied on.

statement :

the statement

iostr :

raptor iostream to write to

Returns :

non-0 on failure


Navigation: Redland Home Page

Copyright 2000-2023 Dave Beckett