Detailed Description

A lightweight RDF model library.

Sord stores RDF (subject object predicate context) quads, where the context may be omitted (to represent triples in the default graph).

Typedefs

typedef struct SordWorldImpl SordWorld

typedef struct SordModelImpl SordModel

typedef struct SordInserterImpl SordInserter

typedef struct SordIterImpl SordIter

typedef struct SordNodeImpl SordNode

typedef const SordNode * SordQuad [4]

Enumerations

enum SordQuadIndex { SORD_SUBJECT = 0, SORD_PREDICATE = 1, SORD_OBJECT = 2, SORD_GRAPH = 3 }

enum SordNodeType { SORD_URI = 1, SORD_BLANK = 2, SORD_LITERAL = 3 }

enum SordIndexOption { SORD_SPO = 1, SORD_SOP = 1 << 1, SORD_OPS = 1 << 2, SORD_OSP = 1 << 3, SORD_PSO = 1 << 4, SORD_POS = 1 << 5 }

World

SordWorld * sord_world_new (void)

void sord_world_free (SordWorld *world)

void sord_world_set_error_sink (SordWorld *world, SerdErrorSink error_sink, void *handle)

Node

SordNode * sord_new_uri (SordWorld *world, const uint8_t *uri)

SordNode * sord_new_relative_uri (SordWorld *world, const uint8_t *str, const uint8_t *base_uri)

SordNode * sord_new_blank (SordWorld *world, const uint8_t *str)

SordNode * sord_new_literal (SordWorld *world, SordNode *datatype, const uint8_t *str, const char *lang)

SordNode * sord_node_copy (const SordNode *node)

void sord_node_free (SordWorld *world, SordNode *node)

SordNodeType sord_node_get_type (const SordNode *node)

const uint8_t * sord_node_get_string (const SordNode *node)

const uint8_t * sord_node_get_string_counted (const SordNode *node, size_t *len)

const char * sord_node_get_language (const SordNode *node)

SordNode * sord_node_get_datatype (const SordNode *node)

SerdNodeFlags sord_node_get_flags (const SordNode *node)

bool sord_node_is_inline_object (const SordNode *node)

bool sord_node_equals (const SordNode *a, const SordNode *b)

const SerdNode * sord_node_to_serd_node (const SordNode *node)

SordNode * sord_node_from_serd_node (SordWorld *world, SerdEnv *env, const SerdNode *node, const SerdNode *datatype, const SerdNode *lang)

Model

SordModel * sord_new (SordWorld *world, unsigned indices, bool graphs)

void sord_free (SordModel *model)

SordWorld * sord_get_world (SordModel *model)

size_t sord_num_nodes (const SordWorld *world)

size_t sord_num_quads (const SordModel *model)

SordIter * sord_begin (const SordModel *model)

SordIter * sord_find (SordModel *model, const SordQuad pat)

SordIter * sord_search (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)

SordNode * sord_get (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)

bool sord_ask (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)

uint64_t sord_count (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const SordNode *g)

bool sord_contains (SordModel *model, const SordQuad pat)

bool sord_add (SordModel *model, const SordQuad quad)

void sord_remove (SordModel *model, const SordQuad quad)

Inserter

SordInserter * sord_inserter_new (SordModel *model, SerdEnv *env)

void sord_inserter_free (SordInserter *inserter)

SerdStatus sord_inserter_set_base_uri (SordInserter *inserter, const SerdNode *uri)

SerdStatus sord_inserter_set_prefix (SordInserter *inserter, const SerdNode *name, const SerdNode *uri)

SerdStatus sord_inserter_write_statement (SordInserter *inserter, SerdStatementFlags flags, const SerdNode *graph, const SerdNode *subject, const SerdNode *predicate, const SerdNode *object, const SerdNode *object_datatype, const SerdNode *object_lang)

Iteration

void sord_iter_get (const SordIter *iter, SordQuad quad)

const SordNode * sord_iter_get_node (const SordIter *iter, SordQuadIndex index)

const SordModel * sord_iter_get_model (SordIter *iter)

bool sord_iter_next (SordIter *iter)

bool sord_iter_end (const SordIter *iter)

void sord_iter_free (SordIter *iter)

Utilities

bool sord_quad_match (const SordQuad x, const SordQuad y)

Serialisation

SerdReader * sord_new_reader (SordModel *model, SerdEnv *env, SerdSyntax syntax, SordNode *graph)

bool sord_write (SordModel *model, SerdWriter *writer, SordNode *graph)

bool sord_write_iter (SordIter *iter, SerdWriter *writer)

Typedef Documentation

typedef struct SordWorldImpl \fBSordWorld\fP

Sord World. The World represents all library state, including interned strings.

typedef struct SordModelImpl \fBSordModel\fP

Sord Model. A model is an indexed set of Quads (i.e. it can contain several RDF graphs). It may be searched using various patterns depending on which indices are enabled.

typedef struct SordInserterImpl \fBSordInserter\fP

Model Inserter. An inserter is used for writing statements to a model using the Serd sink interface. This makes it simple to write to a model directly using a SerdReader, or any other code that writes statements to a SerdStatementSink.

typedef struct SordIterImpl \fBSordIter\fP

Model Iterator.

typedef struct SordNodeImpl \fBSordNode\fP

RDF Node. A Node is a component of a Quad. Nodes may be URIs, blank nodes, or (in the case of quad objects only) string literals. Literal nodes may have an associate language or datatype (but not both).

typedef const \fBSordNode\fP* SordQuad[4]

Quad of nodes (a statement), or a quad pattern. Nodes are ordered (S P O G). The ID of the default graph is 0.

Enumeration Type Documentation

enum \fBSordQuadIndex\fP

Index into a SordQuad.

Enumerator

SORD_SUBJECT

Subject.

SORD_PREDICATE

Predicate (a.k.a. 'key')

SORD_OBJECT

Object (a.k.a. 'value')

SORD_GRAPH

Graph (a.k.a. 'context')

enum \fBSordNodeType\fP

Type of a node.

Enumerator

SORD_URI

URI.

SORD_BLANK

Blank node identifier.

SORD_LITERAL

Literal (string with optional lang or datatype)

enum \fBSordIndexOption\fP

Indexing option.

Enumerator

SORD_SPO

Subject, Predicate, Object.

SORD_SOP

Subject, Object, Predicate.

SORD_OPS

Object, Predicate, Subject.

SORD_OSP

Object, Subject, Predicate.

SORD_PSO

Predicate, Subject, Object.

SORD_POS

Predicate, Object, Subject.

Function Documentation

\fBSordWorld\fP* sord_world_new (void)

Create a new Sord World. It is safe to use multiple worlds in one process, though no data (e.g. nodes) can be shared between worlds, and this should be avoided if possible for performance reasons.

void sord_world_free (\fBSordWorld\fP *world)

Free world.

void sord_world_set_error_sink (\fBSordWorld\fP *world, SerdErrorSinkerror_sink, void *handle)

Set a function to be called when errors occur. The error_sink will be called with handle as its first argument. If no error function is set, errors are printed to stderr.

\fBSordNode\fP* sord_new_uri (\fBSordWorld\fP *world, const uint8_t *uri)

Get a URI node from a string. Note this function measures str, which is a common bottleneck. Use sord_node_from_serd_node instead if str is already measured.

\fBSordNode\fP* sord_new_relative_uri (\fBSordWorld\fP *world, const uint8_t *str, const uint8_t *base_uri)

Get a URI node from a relative URI string.

\fBSordNode\fP* sord_new_blank (\fBSordWorld\fP *world, const uint8_t *str)

Get a blank node from a string. Note this function measures str, which is a common bottleneck. Use sord_node_from_serd_node instead if str is already measured.

\fBSordNode\fP* sord_new_literal (\fBSordWorld\fP *world, \fBSordNode\fP *datatype, const uint8_t *str, const char *lang)

Get a literal node from a string. Note this function measures str, which is a common bottleneck. Use sord_node_from_serd_node instead if str is already measured.

\fBSordNode\fP* sord_node_copy (const \fBSordNode\fP *node)

Copy a node (obtain a reference). Node that since nodes are interned and reference counted, this does not actually create a deep copy of node.

void sord_node_free (\fBSordWorld\fP *world, \fBSordNode\fP *node)

Free a node (drop a reference).

\fBSordNodeType\fP sord_node_get_type (const \fBSordNode\fP *node)

Return the type of a node (SORD_URI, SORD_BLANK, or SORD_LITERAL).

const uint8_t* sord_node_get_string (const \fBSordNode\fP *node)

Return the string value of a node.

const uint8_t* sord_node_get_string_counted (const \fBSordNode\fP *node, size_t *len)

Return the string value of a node, and set len to its length.

const char* sord_node_get_language (const \fBSordNode\fP *node)

Return the language of a literal node (or NULL).

\fBSordNode\fP* sord_node_get_datatype (const \fBSordNode\fP *node)

Return the datatype URI of a literal node (or NULL).

SerdNodeFlags sord_node_get_flags (const \fBSordNode\fP *node)

Return the flags (string attributes) of a node.

bool sord_node_is_inline_object (const \fBSordNode\fP *node)

Return true iff node can be serialised as an inline object. More specifically, this returns true iff the node is the object field of exactly one statement, and therefore can be inlined since it needn't be referred to by name.

bool sord_node_equals (const \fBSordNode\fP *a, const \fBSordNode\fP *b)

Return true iff a is equal to b. Note this is much faster than comparing the node's strings.

const SerdNode* sord_node_to_serd_node (const \fBSordNode\fP *node)

Return a SordNode as a SerdNode. The returned node is shared and must not be freed or modified.

\fBSordNode\fP* sord_node_from_serd_node (\fBSordWorld\fP *world, SerdEnv *env, const SerdNode *node, const SerdNode *datatype, const SerdNode *lang)

Create a new SordNode from a SerdNode. The returned node must be freed using sord_node_free.

\fBSordModel\fP* sord_new (\fBSordWorld\fP *world, unsignedindices, boolgraphs)

Create a new model.

Parameters:

world The world in which to make this model.

indices SordIndexOption flags (e.g. SORD_SPO|SORD_OPS). Be sure to enable an index where the most significant node(s) are not variables in your queries (e.g. to make (? P O) queries, enable either SORD_OPS or SORD_POS).

graphs If true, store (and index) graph contexts.

void sord_free (\fBSordModel\fP *model)

Close and free model.

\fBSordWorld\fP* sord_get_world (\fBSordModel\fP *model)

Get the world associated with model.

size_t sord_num_nodes (const \fBSordWorld\fP *world)

Return the number of nodes stored in world. Nodes are included in this count iff they are a part of a quad in world.

size_t sord_num_quads (const \fBSordModel\fP *model)

Return the number of quads stored in model.

\fBSordIter\fP* sord_begin (const \fBSordModel\fP *model)

Return an iterator to the start of model.

\fBSordIter\fP* sord_find (\fBSordModel\fP *model, const \fBSordQuad\fPpat)

Search for statements by a quad pattern.

Returns:

an iterator to the first match, or NULL if no matches found.

\fBSordIter\fP* sord_search (\fBSordModel\fP *model, const \fBSordNode\fP *s, const \fBSordNode\fP *p, const \fBSordNode\fP *o, const \fBSordNode\fP *g)

Search for statements by nodes.

Returns:

an iterator to the first match, or NULL if no matches found.

\fBSordNode\fP* sord_get (\fBSordModel\fP *model, const \fBSordNode\fP *s, const \fBSordNode\fP *p, const \fBSordNode\fP *o, const \fBSordNode\fP *g)

Search for a single node that matches a pattern. Exactly one of s, p, o must be NULL. This function is mainly useful for predicates that only have one value. The returned node must be freed using sord_node_free.

Returns:

the first matching node, or NULL if no matches are found.

bool sord_ask (\fBSordModel\fP *model, const \fBSordNode\fP *s, const \fBSordNode\fP *p, const \fBSordNode\fP *o, const \fBSordNode\fP *g)

Return true iff a statement exists.

uint64_t sord_count (\fBSordModel\fP *model, const \fBSordNode\fP *s, const \fBSordNode\fP *p, const \fBSordNode\fP *o, const \fBSordNode\fP *g)

Return the number of matching statements.

bool sord_contains (\fBSordModel\fP *model, const \fBSordQuad\fPpat)

Check if model contains a triple pattern.

bool sord_add (\fBSordModel\fP *model, const \fBSordQuad\fPquad)

Add a quad to a model.

void sord_remove (\fBSordModel\fP *model, const \fBSordQuad\fPquad)

Remove a quad from a model. Note that is it illegal to remove while iterating over model.

\fBSordInserter\fP* sord_inserter_new (\fBSordModel\fP *model, SerdEnv *env)

Create an inserter for writing statements to a model.

void sord_inserter_free (\fBSordInserter\fP *inserter)

Free an inserter.

SerdStatus sord_inserter_set_base_uri (\fBSordInserter\fP *inserter, const SerdNode *uri)

Set the current base URI for writing to the model. Note this function can be safely casted to SerdBaseSink.

SerdStatus sord_inserter_set_prefix (\fBSordInserter\fP *inserter, const SerdNode *name, const SerdNode *uri)

Set a namespace prefix for writing to the model. Note this function can be safely casted to SerdPrefixSink.

SerdStatus sord_inserter_write_statement (\fBSordInserter\fP *inserter, SerdStatementFlagsflags, const SerdNode *graph, const SerdNode *subject, const SerdNode *predicate, const SerdNode *object, const SerdNode *object_datatype, const SerdNode *object_lang)

Write a statement to the model. Note this function can be safely casted to SerdStatementSink.

void sord_iter_get (const \fBSordIter\fP *iter, \fBSordQuad\fPquad)

Set quad to the quad pointed to by iter.

const \fBSordNode\fP* sord_iter_get_node (const \fBSordIter\fP *iter, \fBSordQuadIndex\fPindex)

Return a field of the quad pointed to by iter.

const \fBSordModel\fP* sord_iter_get_model (\fBSordIter\fP *iter)

Return the store pointed to by iter.

bool sord_iter_next (\fBSordIter\fP *iter)

Increment iter to point to the next statement.

bool sord_iter_end (const \fBSordIter\fP *iter)

Return true iff iter is at the end of its range.

void sord_iter_free (\fBSordIter\fP *iter)

Free iter.

bool sord_quad_match (const \fBSordQuad\fPx, const \fBSordQuad\fPy)

Match two quads (using ID comparison only). This function is a straightforward and fast equivalence match with wildcard support (ID 0 is a wildcard). It does not actually read node data.

Returns:

true iff x and y match.

SerdReader* sord_new_reader (\fBSordModel\fP *model, SerdEnv *env, SerdSyntaxsyntax, \fBSordNode\fP *graph)

Return a reader that will read into model.

bool sord_write (\fBSordModel\fP *model, SerdWriter *writer, \fBSordNode\fP *graph)

Write a model to a writer.

bool sord_write_iter (\fBSordIter\fP *iter, SerdWriter *writer)

Write a range to a writer. This increments iter to its end, then frees it.

Author

Generated automatically by Doxygen for Sord from the source code.