RDF Graph (librdf_model)

RDF Graph (librdf_model) — RDF graph (set of triples) API.

Synopsis




typedef     librdf_model;
typedef     librdf_model_factory;
int         librdf_model_enumerate          (librdf_world *world,
                                             unsigned int counter,
                                             const char **name,
                                             const char **label);
librdf_model* librdf_new_model              (librdf_world *world,
                                             librdf_storage *storage,
                                             const char *options_string);
librdf_model* librdf_new_model_with_options (librdf_world *world,
                                             librdf_storage *storage,
                                             librdf_hash *options);
librdf_model* librdf_new_model_from_model   (librdf_model *model);
void        librdf_free_model               (librdf_model *model);
int         librdf_model_size               (librdf_model *model);
int         librdf_model_add                (librdf_model *model,
                                             librdf_node *subject,
                                             librdf_node *predicate,
                                             librdf_node *object);
int         librdf_model_add_string_literal_statement
                                            (librdf_model *model,
                                             librdf_node *subject,
                                             librdf_node *predicate,
                                             unsigned char *literal,
                                             const char *xml_language,
                                             int is_wf_xml);
int         librdf_model_add_typed_literal_statement
                                            (librdf_model *model,
                                             librdf_node *subject,
                                             librdf_node *predicate,
                                             unsigned char *literal,
                                             const char *xml_language,
                                             librdf_uri *datatype_uri);
int         librdf_model_add_statement      (librdf_model *model,
                                             librdf_statement *statement);
int         librdf_model_add_statements     (librdf_model *model,
                                             librdf_stream *statement_stream);
int         librdf_model_remove_statement   (librdf_model *model,
                                             librdf_statement *statement);
int         librdf_model_contains_statement (librdf_model *model,
                                             librdf_statement *statement);
int         librdf_model_has_arc_in         (librdf_model *model,
                                             librdf_node *node,
                                             librdf_node *property);
int         librdf_model_has_arc_out        (librdf_model *model,
                                             librdf_node *node,
                                             librdf_node *property);
librdf_stream* librdf_model_as_stream       (librdf_model *model);
librdf_stream* librdf_model_serialise       (librdf_model *model);
librdf_stream* librdf_model_find_statements (librdf_model *model,
                                             librdf_statement *statement);
#define     LIBRDF_MODEL_FIND_OPTION_MATCH_SUBSTRING_LITERAL
librdf_stream* librdf_model_find_statements_with_options
                                            (librdf_model *model,
                                             librdf_statement *statement,
                                             librdf_node *context_node,
                                             librdf_hash *options);
librdf_iterator* librdf_model_get_sources   (librdf_model *model,
                                             librdf_node *arc,
                                             librdf_node *target);
librdf_iterator* librdf_model_get_arcs      (librdf_model *model,
                                             librdf_node *source,
                                             librdf_node *target);
librdf_iterator* librdf_model_get_targets   (librdf_model *model,
                                             librdf_node *source,
                                             librdf_node *arc);
librdf_node* librdf_model_get_source        (librdf_model *model,
                                             librdf_node *arc,
                                             librdf_node *target);
librdf_node* librdf_model_get_arc           (librdf_model *model,
                                             librdf_node *source,
                                             librdf_node *target);
librdf_node* librdf_model_get_target        (librdf_model *model,
                                             librdf_node *source,
                                             librdf_node *arc);
librdf_iterator* librdf_model_get_arcs_in   (librdf_model *model,
                                             librdf_node *node);
librdf_iterator* librdf_model_get_arcs_out  (librdf_model *model,
                                             librdf_node *node);
int         librdf_model_add_submodel       (librdf_model *model,
                                             librdf_model *sub_model);
int         librdf_model_remove_submodel    (librdf_model *model,
                                             librdf_model *sub_model);
void        librdf_model_print              (librdf_model *model,
                                             FILE *fh);
int         librdf_model_context_add_statement
                                            (librdf_model *model,
                                             librdf_node *context,
                                             librdf_statement *statement);
int         librdf_model_context_add_statements
                                            (librdf_model *model,
                                             librdf_node *context,
                                             librdf_stream *stream);
int         librdf_model_context_remove_statement
                                            (librdf_model *model,
                                             librdf_node *context,
                                             librdf_statement *statement);
int         librdf_model_context_remove_statements
                                            (librdf_model *model,
                                             librdf_node *context);
librdf_stream* librdf_model_context_as_stream
                                            (librdf_model *model,
                                             librdf_node *context);
librdf_stream* librdf_model_context_serialize
                                            (librdf_model *model,
                                             librdf_node *context);
int         librdf_model_contains_context   (librdf_model *model,
                                             librdf_node *context);
librdf_query_results* librdf_model_query_execute
                                            (librdf_model *model,
                                             librdf_query *query);
int         librdf_model_sync               (librdf_model *model);
librdf_storage* librdf_model_get_storage    (librdf_model *model);
int         librdf_model_load               (librdf_model *model,
                                             librdf_uri *uri,
                                             const char *name,
                                             const char *mime_type,
                                             librdf_uri *type_uri);
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);
unsigned char* librdf_model_to_string       (librdf_model *model,
                                             librdf_uri *uri,
                                             const char *name,
                                             const char *mime_type,
                                             librdf_uri *type_uri);
librdf_stream* librdf_model_find_statements_in_context
                                            (librdf_model *model,
                                             librdf_statement *statement,
                                             librdf_node *context_node);
librdf_iterator* librdf_model_get_contexts  (librdf_model *model);
#define     LIBRDF_MODEL_FEATURE_CONTEXTS
librdf_node* librdf_model_get_feature       (librdf_model *model,
                                             librdf_uri *feature);
int         librdf_model_set_feature        (librdf_model *model,
                                             librdf_uri *feature,
                                             librdf_node *value);

Description

The main user API class for Redland, providing access to the RDF graph and the triples in it (librdf_statement), storage, parsing, serializing and querying.

Details

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_enumerate ()

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

Get information on models.

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.

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.

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.

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.

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.

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.

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,
                                             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

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,
                                             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.

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

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

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.

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.

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.

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.

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.

model : the model object
Returns : a librdf_stream or NULL on failure

librdf_model_serialise ()

librdf_stream* librdf_model_serialise       (librdf_model *model);

Serialise the entire model as a stream (DEPRECATED).

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

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

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_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_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.

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

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

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

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

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

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

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.

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.

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

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

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);

Print the model.

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

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

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

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

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.

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.

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);

List all statements in a model context.

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

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.

model : the model object
context : the contest
Returns : non 0 if the model contains the context node

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

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.

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.

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.

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.

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.

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.

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.

model : librdf_model object
Returns : librdf_iterator of context nodes or NULL on failure or if contexts are not supported

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.


librdf_model_get_feature ()

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

Get the value of a graph feature .

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.

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)