model

model

Functions

int librdf_model_enumerate ()
librdf_model * librdf_new_model ()
librdf_model * librdf_new_model_with_options ()
librdf_model * librdf_new_model_from_model ()
void librdf_free_model ()
int librdf_model_size ()
int librdf_model_add ()
int librdf_model_add_string_literal_statement ()
int librdf_model_add_typed_literal_statement ()
int librdf_model_add_statement ()
int librdf_model_add_statements ()
int librdf_model_remove_statement ()
int librdf_model_contains_statement ()
int librdf_model_has_arc_in ()
int librdf_model_has_arc_out ()
librdf_stream * librdf_model_as_stream ()
librdf_stream * librdf_model_serialise ()
librdf_stream * librdf_model_find_statements ()
librdf_stream * librdf_model_find_statements_with_options ()
librdf_iterator * librdf_model_get_sources ()
librdf_iterator * librdf_model_get_arcs ()
librdf_iterator * librdf_model_get_targets ()
librdf_node * librdf_model_get_source ()
librdf_node * librdf_model_get_arc ()
librdf_node * librdf_model_get_target ()
librdf_iterator * librdf_model_get_arcs_in ()
librdf_iterator * librdf_model_get_arcs_out ()
int librdf_model_add_submodel ()
int librdf_model_remove_submodel ()
void librdf_model_print ()
int librdf_model_context_add_statement ()
int librdf_model_context_add_statements ()
int librdf_model_context_remove_statement ()
int librdf_model_context_remove_statements ()
librdf_stream * librdf_model_context_as_stream ()
librdf_stream * librdf_model_context_serialize ()
int librdf_model_contains_context ()
int librdf_model_supports_contexts ()
librdf_query_results * librdf_model_query_execute ()
int librdf_model_sync ()
librdf_storage * librdf_model_get_storage ()
int librdf_model_load ()
unsigned char * librdf_model_to_counted_string ()
unsigned char * librdf_model_to_string ()
librdf_stream * librdf_model_find_statements_in_context ()
librdf_iterator * librdf_model_get_contexts ()
librdf_node * librdf_model_get_feature ()
int librdf_model_set_feature ()
int librdf_model_transaction_commit ()
void * librdf_model_transaction_get_handle ()
int librdf_model_transaction_rollback ()
int librdf_model_transaction_start ()
int librdf_model_transaction_start_with_handle ()
int librdf_model_write ()

Types and Values

Description

Functions

librdf_model_enumerate ()

int
librdf_model_enumerate (librdf_world *world,
                        const unsigned int counter,
                        const char **name,
                        const char **label);

Get information on models.

Parameters

world

redland world object

 

counter

index into the list of models

 

name

pointer to store the name of the model (or NULL)

 

label

pointer to store syntax readable label (or NULL)

 

Returns

non 0 on failure of if counter is out of range


librdf_new_model ()

librdf_model *
librdf_new_model (librdf_world *world,
                  librdf_storage *storage,
                  const char *options_string);

Constructor - create a new storage librdf_model object.

The options are encoded as described in librdf_hash_from_string() and can be NULL if none are required.

Parameters

world

redland world object

 

storage

librdf_storage to use

 

options_string

options to initialise model

 

Returns

a new librdf_model object or NULL on failure


librdf_new_model_with_options ()

librdf_model *
librdf_new_model_with_options (librdf_world *world,
                               librdf_storage *storage,
                               librdf_hash *options);

Constructor - Create a new librdf_model with storage.

Options are presently not used.

Parameters

world

redland world object

 

storage

librdf_storage storage to use

 

options

librdf_hash of options to use

 

Returns

a new librdf_model object or NULL on failure


librdf_new_model_from_model ()

librdf_model *
librdf_new_model_from_model (librdf_model *model);

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

Creates a new model as a copy of the existing model in the same storage context.

Parameters

model

the existing librdf_model

 

Returns

a new librdf_model or NULL on failure


librdf_free_model ()

void
librdf_free_model (librdf_model *model);

Destructor - Destroy a librdf_model object.

Parameters

model

librdf_model model to destroy

 

librdf_model_size ()

int
librdf_model_size (librdf_model *model);

Get the number of statements in the model.

WARNING: Not all underlying stores can return the size of the graph In which case the return value will be negative.

Parameters

model

librdf_model object

 

Returns

the number of statements or <0 if not possible


librdf_model_add ()

int
librdf_model_add (librdf_model *model,
                  librdf_node *subject,
                  librdf_node *predicate,
                  librdf_node *object);

Create and add a new statement about a resource to the model.

After this method, the librdf_node objects become owned by the model. All of subject, predicate and object must be non-NULL.

Parameters

model

model object

 

subject

librdf_node of subject

 

predicate

librdf_node of predicate

 

object

librdf_node of object (literal or resource)

 

Returns

non 0 on failure


librdf_model_add_string_literal_statement ()

int
librdf_model_add_string_literal_statement
                               (librdf_model *model,
                                librdf_node *subject,
                                librdf_node *predicate,
                                const unsigned char *literal,
                                const char *xml_language,
                                int is_wf_xml);

Create and add a new statement about a literal to the model.

The language can be set to NULL if not used. All of subject, predicate and literal must be non-NULL.

0.9.12: xml_space argument deleted

Parameters

model

model object

 

subject

librdf_node of subject

 

predicate

librdf_node of predicate

 

literal

string literal conten

 

xml_language

language of literal

 

is_wf_xml

literal is XML

 

Returns

non 0 on failure


librdf_model_add_typed_literal_statement ()

int
librdf_model_add_typed_literal_statement
                               (librdf_model *model,
                                librdf_node *subject,
                                librdf_node *predicate,
                                const unsigned char *literal,
                                const char *xml_language,
                                librdf_uri *datatype_uri);

Create and add a new statement about a typed literal to the model.

After this method, the librdf_node subject and predicate become owned by the model.

The language can be set to NULL if not used. All of subject, predicate and literal must be non-NULL.

Parameters

model

model object

 

subject

librdf_node of subject

 

predicate

librdf_node of predicate

 

literal

string literal content

 

xml_language

language of literal

 

datatype_uri

datatype librdf_uri

 

Returns

non 0 on failure


librdf_model_add_statement ()

int
librdf_model_add_statement (librdf_model *model,
                            librdf_statement *statement);

Add a statement to the model.

The passed-in statement is copied when added to the model, not shared with the model. It must be a complete statement - all of subject, predicate, object parts must be present.

Only statements that are legal RDF can be added: URI or blank subject, URI predicate and URI or blank or literal object (i.e. anything).

If the statement already exists in the model, it is not added. Duplicate statements can be added when used with Redland Contexts such as with librdf_model_context_add_statement

Parameters

model

model object

 

statement

statement object

 

Returns

non 0 on failure


librdf_model_add_statements ()

int
librdf_model_add_statements (librdf_model *model,
                             librdf_stream *statement_stream);

Add a stream of statements to the model.

If any of the statements are illegal RDF statements they will be skipped and not added. See librdf_model_add_statement for the detail.

If any of the statements already exists in the store, they are not added unless Redland contexts are being used. See also librdf_model_context_add_statements

Parameters

model

model object

 

statement_stream

stream of statements to use

 

Returns

non 0 on failure


librdf_model_remove_statement ()

int
librdf_model_remove_statement (librdf_model *model,
                               librdf_statement *statement);

Remove a known statement from the model.

It must be a complete statement - all of subject, predicate, object parts must be present and a legal RDF triple.

Parameters

model

the model object

 

statement

the statement

 

Returns

non 0 on failure


librdf_model_contains_statement ()

int
librdf_model_contains_statement (librdf_model *model,
                                 librdf_statement *statement);

Check for a statement in the model.

It must be a complete statement - all of subject, predicate, object parts must be present and a legal RDF triple. Use librdf_model_find_statements to search for partial statement matches.

WARNING: librdf_model_contains_statement may not work correctly with stores using contexts. In this case, a search using librdf_model_find_statements for a non-empty list will return the correct result.

Parameters

model

the model object

 

statement

the statement

 

Returns

non 0 if the model contains the statement (>0 if the statement is illegal)


librdf_model_has_arc_in ()

int
librdf_model_has_arc_in (librdf_model *model,
                         librdf_node *node,
                         librdf_node *property);

Check if a node has a given property pointing to it.

Parameters

model

librdf_model object

 

node

librdf_node resource node

 

property

librdf_node property node

 

Returns

non 0 if arc property does point to the resource node


librdf_model_has_arc_out ()

int
librdf_model_has_arc_out (librdf_model *model,
                          librdf_node *node,
                          librdf_node *property);

Check if a node has a given property pointing from it.

Parameters

model

librdf_model object

 

node

librdf_node resource node

 

property

librdf_node property node

 

Returns

non 0 if arc property does point from the resource node


librdf_model_as_stream ()

librdf_stream *
librdf_model_as_stream (librdf_model *model);

List the model contents as a stream of statements.

Parameters

model

the model object

 

Returns

a librdf_stream or NULL on failure


librdf_model_serialise ()

librdf_stream *
librdf_model_serialise (librdf_model *model);

librdf_model_serialise is deprecated and should not be used in newly-written code.

Serialise the entire model as a stream (DEPRECATED).

DEPRECATED to reduce confusion with the librdf_serializer class. Please use librdf_model_as_stream.

Parameters

model

the model object

 

Returns

a librdf_stream or NULL on failure


librdf_model_find_statements ()

librdf_stream *
librdf_model_find_statements (librdf_model *model,
                              librdf_statement *statement);

Find matching statements in the model.

The partial statement is a statement where the subject, predicate and/or object can take the value NULL which indicates a match with any value in the model

Parameters

model

the model object

 

statement

the partial statement to match

 

Returns

a librdf_stream of statements (can be empty) or NULL on failure.


librdf_model_find_statements_with_options ()

librdf_stream *
librdf_model_find_statements_with_options
                               (librdf_model *model,
                                librdf_statement *statement,
                                librdf_node *context_node,
                                librdf_hash *options);

Search the model for matching statements with match options.

Searches the model for a (partial) statement as described in librdf_statement_match() and returns a librdf_stream of matching librdf_statement objects.

If options is given then the match is made according to the given options. If options is NULL, this is equivalent to librdf_model_find_statements_in_context.

Parameters

model

librdf_model object

 

statement

librdf_statement partial statement to find

 

context_node

librdf_node context node or NULL.

 

options

librdf_hash of matching options or NULL

 

Returns

librdf_stream of matching statements (may be empty) or NULL on failure


librdf_model_get_sources ()

librdf_iterator *
librdf_model_get_sources (librdf_model *model,
                          librdf_node *arc,
                          librdf_node *target);

Return the sources (subjects) of arc in an RDF graph given arc (predicate) and target (object).

Searches the model for arcs matching the given arc and target and returns a list of the source librdf_node objects as an iterator

Parameters

model

librdf_model object

 

arc

librdf_node arc

 

target

librdf_node target

 

Returns

librdf_iterator of librdf_node objects (may be empty) or NULL on failure


librdf_model_get_arcs ()

librdf_iterator *
librdf_model_get_arcs (librdf_model *model,
                       librdf_node *source,
                       librdf_node *target);

Return the arcs (predicates) of an arc in an RDF graph given source (subject) and target (object).

Searches the model for arcs matching the given source and target and returns a list of the arc librdf_node objects as an iterator

Parameters

model

librdf_model object

 

source

librdf_node source

 

target

librdf_node target

 

Returns

librdf_iterator of librdf_node objects (may be empty) or NULL on failure


librdf_model_get_targets ()

librdf_iterator *
librdf_model_get_targets (librdf_model *model,
                          librdf_node *source,
                          librdf_node *arc);

Return the targets (objects) of an arc in an RDF graph given source (subject) and arc (predicate).

Searches the model for targets matching the given source and arc and returns a list of the source librdf_node objects as an iterator

Parameters

model

librdf_model object

 

source

librdf_node source

 

arc

librdf_node arc

 

Returns

librdf_iterator of librdf_node objects (may be empty) or NULL on failure


librdf_model_get_source ()

librdf_node *
librdf_model_get_source (librdf_model *model,
                         librdf_node *arc,
                         librdf_node *target);

Return one source (subject) of arc in an RDF graph given arc (predicate) and target (object).

Searches the model for arcs matching the given arc and target and returns one librdf_node object

Parameters

model

librdf_model object

 

arc

librdf_node arc

 

target

librdf_node target

 

Returns

a new librdf_node object or NULL on failure


librdf_model_get_arc ()

librdf_node *
librdf_model_get_arc (librdf_model *model,
                      librdf_node *source,
                      librdf_node *target);

Return one arc (predicate) of an arc in an RDF graph given source (subject) and target (object).

Searches the model for arcs matching the given source and target and returns one librdf_node object

Parameters

model

librdf_model object

 

source

librdf_node source

 

target

librdf_node target

 

Returns

a new librdf_node object or NULL on failure


librdf_model_get_target ()

librdf_node *
librdf_model_get_target (librdf_model *model,
                         librdf_node *source,
                         librdf_node *arc);

Return one target (object) of an arc in an RDF graph given source (subject) and arc (predicate).

Searches the model for targets matching the given source and arc and returns one librdf_node object

Parameters

model

librdf_model object

 

source

librdf_node source

 

arc

librdf_node arc

 

Returns

a new librdf_node object or NULL on failure


librdf_model_get_arcs_in ()

librdf_iterator *
librdf_model_get_arcs_in (librdf_model *model,
                          librdf_node *node);

Return the properties pointing to the given resource.

Parameters

model

librdf_model object

 

node

librdf_node resource node

 

Returns

librdf_iterator of librdf_node objects (may be empty) or NULL on failure


librdf_model_get_arcs_out ()

librdf_iterator *
librdf_model_get_arcs_out (librdf_model *model,
                           librdf_node *node);

Return the properties pointing from the given resource.

Parameters

model

librdf_model object

 

node

librdf_node resource node

 

Returns

librdf_iterator of librdf_node objects (may be empty) or NULL on failure


librdf_model_add_submodel ()

int
librdf_model_add_submodel (librdf_model *model,
                           librdf_model *sub_model);

Add a sub-model to the model.

FIXME: Not tested

Parameters

model

the model object

 

sub_model

the sub model to add

 

Returns

non 0 on failure


librdf_model_remove_submodel ()

int
librdf_model_remove_submodel (librdf_model *model,
                              librdf_model *sub_model);

Remove a sub-model from the model.

FIXME: Not tested

Parameters

model

the model object

 

sub_model

the sub model to remove

 

Returns

non 0 on failure


librdf_model_print ()

void
librdf_model_print (librdf_model *model,
                    FILE *fh);

librdf_model_print is deprecated and should not be used in newly-written code.

Print the model.

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

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

Parameters

model

the model object

 

fh

the FILE stream to print to

 

librdf_model_context_add_statement ()

int
librdf_model_context_add_statement (librdf_model *model,
                                    librdf_node *context,
                                    librdf_statement *statement);

Add a statement to a model with a context.

It must be a complete statement - all of subject, predicate, object parts must be present.

If context is NULL, this is equivalent to librdf_model_add_statement

Parameters

model

librdf_model object

 

context

librdf_node context

 

statement

librdf_statement statement object

 

Returns

Non 0 on failure


librdf_model_context_add_statements ()

int
librdf_model_context_add_statements (librdf_model *model,
                                     librdf_node *context,
                                     librdf_stream *stream);

Add statements to a model with a context.

If context is NULL, this is equivalent to librdf_model_add_statements

Parameters

model

librdf_model object

 

context

librdf_node context

 

stream

librdf_stream stream object

 

Returns

Non 0 on failure


librdf_model_context_remove_statement ()

int
librdf_model_context_remove_statement (librdf_model *model,
                                       librdf_node *context,
                                       librdf_statement *statement);

Remove a statement from a model in a context.

It must be a complete statement - all of subject, predicate, object parts must be present.

If context is NULL, this is equivalent to librdf_model_remove_statement

Parameters

model

librdf_model object

 

context

librdf_node context

 

statement

librdf_statement statement

 

Returns

Non 0 on failure


librdf_model_context_remove_statements ()

int
librdf_model_context_remove_statements
                               (librdf_model *model,
                                librdf_node *context);

Remove statements from a model with the given context.

Parameters

model

librdf_model object

 

context

librdf_node context

 

Returns

Non 0 on failure


librdf_model_context_as_stream ()

librdf_stream *
librdf_model_context_as_stream (librdf_model *model,
                                librdf_node *context);

List all statements in a model context.

Parameters

model

librdf_model object

 

context

librdf_node context

 

Returns

librdf_stream of statements or NULL on failure


librdf_model_context_serialize ()

librdf_stream *
librdf_model_context_serialize (librdf_model *model,
                                librdf_node *context);

librdf_model_context_serialize is deprecated and should not be used in newly-written code.

List all statements in a model context.

DEPRECATED to reduce confusion with the librdf_serializer class. Please use librdf_model_context_as_stream.

Parameters

model

librdf_model object

 

context

librdf_node context

 

Returns

librdf_stream of statements or NULL on failure


librdf_model_contains_context ()

int
librdf_model_contains_context (librdf_model *model,
                               librdf_node *context);

Check for a context in the model.

Parameters

model

the model object

 

context

the contest

 

Returns

non 0 if the model contains the context node


librdf_model_supports_contexts ()

int
librdf_model_supports_contexts (librdf_model *model);

Check if this model supports contexts

Parameters

model

the model object

 

Returns

non-0 if contexts are supported


librdf_model_query_execute ()

librdf_query_results *
librdf_model_query_execute (librdf_model *model,
                            librdf_query *query);

Execute a query against the model.

Run the given query against the model and return a librdf_stream of matching librdf_statement objects

Parameters

model

librdf_model object

 

query

librdf_query object

 

Returns

librdf_query_results or NULL on failure


librdf_model_sync ()

int
librdf_model_sync (librdf_model *model);

Synchronise the model to the model implementation.

Parameters

model

librdf_model object

 

Returns

non-0 on failure


librdf_model_get_storage ()

librdf_storage *
librdf_model_get_storage (librdf_model *model);

Return the storage of this model.

Note: this can only return one storage, so model implementations that have multiple librdf_storage internally may chose not to implement this.

Parameters

model

librdf_model object

 

Returns

librdf_storage or NULL if this has no store


librdf_model_load ()

int
librdf_model_load (librdf_model *model,
                   librdf_uri *uri,
                   const char *name,
                   const char *mime_type,
                   librdf_uri *type_uri);

Load content from a URI into the model.

If the name field is NULL, the library will try to guess the parser to use from the uri, mime_type and type_uri fields. This is done via the raptor_guess_parser_name function.

Parameters

model

librdf_model object

 

uri

the URI to read the content

 

name

the name of the parser (or NULL)

 

mime_type

the MIME type of the syntax (NULL if not used)

 

type_uri

URI identifying the syntax (NULL if not used)

 

Returns

non 0 on failure


librdf_model_to_counted_string ()

unsigned char *
librdf_model_to_counted_string (librdf_model *model,
                                librdf_uri *uri,
                                const char *name,
                                const char *mime_type,
                                librdf_uri *type_uri,
                                size_t *string_length_p);

Write serialized model to a string.

If the name field is NULL, the default serializer will be used.

Note: the returned string must be freed by the caller using librdf_free_memory().

Parameters

model

librdf_model object

 

uri

base URI to use in serializing (or NULL if not used)

 

name

the name of the serializer (or NULL for default)

 

mime_type

the MIME type of the syntax (NULL if not used)

 

type_uri

URI identifying the syntax (NULL if not used)

 

string_length_p

pointer to location to store string length (or NULL)

 

Returns

new string or NULL on failure


librdf_model_to_string ()

unsigned char *
librdf_model_to_string (librdf_model *model,
                        librdf_uri *uri,
                        const char *name,
                        const char *mime_type,
                        librdf_uri *type_uri);

Write serialized model to a string.

If the name field is NULL, the default serializer will be used.

Note: the returned string must be freed by the caller.

Parameters

model

librdf_model object

 

uri

base URI to use in serializing (or NULL if not used)

 

name

the name of the serializer (or NULL for default)

 

mime_type

the MIME type of the syntax (NULL if not used)

 

type_uri

URI identifying the syntax (NULL if not used)

 

Returns

new string or NULL on failure


librdf_model_find_statements_in_context ()

librdf_stream *
librdf_model_find_statements_in_context
                               (librdf_model *model,
                                librdf_statement *statement,
                                librdf_node *context_node);

Search the model for matching statements in a given context.

Searches the model for a (partial) statement as described in librdf_statement_match() in the given context and returns a librdf_stream of matching librdf_statement objects. If context is NULL, this is equivalent to librdf_model_find_statements.

Parameters

model

librdf_model object

 

statement

librdf_statement partial statement to find

 

context_node

context librdf_node (or NULL)

 

Returns

librdf_stream of matching statements (may be empty) or NULL on failure


librdf_model_get_contexts ()

librdf_iterator *
librdf_model_get_contexts (librdf_model *model);

Return the list of contexts in the graph.

Returns an iterator of librdf_node context nodes for each context in the graph.

Parameters

model

librdf_model object

 

Returns

librdf_iterator of context nodes or NULL on failure or if contexts are not supported


librdf_model_get_feature ()

librdf_node *
librdf_model_get_feature (librdf_model *model,
                          librdf_uri *feature);

Get the value of a graph feature .

Parameters

model

librdf_model object

 

feature

librdf_uri feature property

 

Returns

new librdf_node feature value or NULL if no such feature exists or the value is empty.


librdf_model_set_feature ()

int
librdf_model_set_feature (librdf_model *model,
                          librdf_uri *feature,
                          librdf_node *value);

Set the value of a graph feature.

Parameters

model

librdf_model object

 

feature

librdf_uri feature property

 

value

librdf_node feature property value

 

Returns

non 0 on failure (negative if no such feature)


librdf_model_transaction_commit ()

int
librdf_model_transaction_commit (librdf_model *model);

Commit a transaction.

Parameters

model

the model object

 

Returns

non-0 on failure


librdf_model_transaction_get_handle ()

void *
librdf_model_transaction_get_handle (librdf_model *model);

Get the current transaction handle.

Parameters

model

the model object

 

Returns

non-0 on failure


librdf_model_transaction_rollback ()

int
librdf_model_transaction_rollback (librdf_model *model);

Rollback a transaction.

Parameters

model

the model object

 

Returns

non-0 on failure


librdf_model_transaction_start ()

int
librdf_model_transaction_start (librdf_model *model);

Start a transaction

Parameters

model

the model object

 

Returns

non-0 on failure


librdf_model_transaction_start_with_handle ()

int
librdf_model_transaction_start_with_handle
                               (librdf_model *model,
                                void *handle);

Start a transaction using an existing external transaction object.

Parameters

model

the model object

 

handle

the transaction object

 

Returns

non-0 on failure


librdf_model_write ()

int
librdf_model_write (librdf_model *model,
                    raptor_iostream *iostr);

Write a model to an iostream in a debug format.

This method is for debugging and the format of the output should not be relied on. In particular, when contexts are used the result may be 4 nodes.

Parameters

model

the model object

 

iostr

the iostream to write to

 

Returns

non-0 on failure

Types and Values

librdf_model

typedef struct librdf_model_s librdf_model;

Redland model class.


librdf_model_factory

typedef struct librdf_model_factory_s librdf_model_factory;

Redland model factory class.


LIBRDF_MODEL_FIND_OPTION_MATCH_SUBSTRING_LITERAL

#define LIBRDF_MODEL_FIND_OPTION_MATCH_SUBSTRING_LITERAL "http://feature.librdf.org/model-find-match-substring-literal"

Model find statement option.

If set, the find statement uses substring matching.


LIBRDF_MODEL_FEATURE_CONTEXTS

#define LIBRDF_MODEL_FEATURE_CONTEXTS "http://feature.librdf.org/model-contexts"

Model feature contexts.

If set, the model has redland contexts.