sord - Sord
Contents
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
SORD_API SordWorld * sord_world_new (void)
SORD_API void sord_world_free (SordWorld *world)
SORD_API void sord_world_set_error_sink (SordWorld *world, SerdErrorSink error_sink, void *handle)
Node
SORD_API SordNode * sord_new_uri (SordWorld *world, const uint8_t *uri)
SORD_API SordNode * sord_new_relative_uri (SordWorld *world, const uint8_t *uri, const uint8_t *base_uri)
SORD_API SordNode * sord_new_blank (SordWorld *world, const uint8_t *str)
SORD_API SordNode * sord_new_literal (SordWorld *world, SordNode *datatype, const uint8_t *str, const
char *lang)
SORD_API SordNode * sord_node_copy (const SordNode *node)
SORD_API void sord_node_free (SordWorld *world, SordNode *node)
SORD_API SordNodeTypesord_node_get_type (const SordNode *node)
SORD_API const uint8_t * sord_node_get_string (const SordNode *node)
SORD_API const uint8_t * sord_node_get_string_counted (const SordNode *node, size_t *bytes)
SORD_API const uint8_t * sord_node_get_string_measured (const SordNode *node, size_t *bytes, size_t
*chars)
SORD_API const char * sord_node_get_language (const SordNode *node)
SORD_API SordNode * sord_node_get_datatype (const SordNode *node)
SORD_API SerdNodeFlags sord_node_get_flags (const SordNode *node)
SORD_API bool sord_node_is_inline_object (const SordNode *node)
SORD_API bool sord_node_equals (const SordNode *a, const SordNode *b)
SORD_API const SerdNode * sord_node_to_serd_node (const SordNode *node)
SORD_API SordNode * sord_node_from_serd_node (SordWorld *world, SerdEnv *env, const SerdNode *node, const
SerdNode *datatype, const SerdNode *lang)
Model
SORD_API SordModel * sord_new (SordWorld *world, unsigned indices, bool graphs)
SORD_API void sord_free (SordModel *model)
SORD_API SordWorld * sord_get_world (SordModel *model)
SORD_API size_t sord_num_nodes (const SordWorld *world)
SORD_API size_t sord_num_quads (const SordModel *model)
SORD_API SordIter * sord_begin (const SordModel *model)
SORD_API SordIter * sord_find (SordModel *model, const SordQuad pat)
SORD_API SordIter * sord_search (SordModel *model, const SordNode *s, const SordNode *p, const SordNode
*o, const SordNode *g)
SORD_API SordNode * sord_get (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o,
const SordNode *g)
SORD_API bool sord_ask (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o, const
SordNode *g)
SORD_API uint64_t sord_count (SordModel *model, const SordNode *s, const SordNode *p, const SordNode *o,
const SordNode *g)
SORD_API bool sord_contains (SordModel *model, const SordQuad pat)
SORD_API bool sord_add (SordModel *model, const SordQuad tup)
SORD_API void sord_remove (SordModel *model, const SordQuad tup)
SORD_API SerdStatus sord_erase (SordModel *model, SordIter *iter)
Inserter
SORD_API SordInserter * sord_inserter_new (SordModel *model, SerdEnv *env)
SORD_API void sord_inserter_free (SordInserter *inserter)
SORD_API SerdStatus sord_inserter_set_base_uri (SordInserter *inserter, const SerdNode *uri)
SORD_API SerdStatus sord_inserter_set_prefix (SordInserter *inserter, const SerdNode *name, const
SerdNode *uri)
SORD_API 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
SORD_API void sord_iter_get (const SordIter *iter, SordQuad tup)
SORD_API const SordNode * sord_iter_get_node (const SordIter *iter, SordQuadIndex index)
SORD_API const SordModel * sord_iter_get_model (SordIter *iter)
SORD_API bool sord_iter_next (SordIter *iter)
SORD_API bool sord_iter_end (const SordIter *iter)
SORD_API void sord_iter_free (SordIter *iter)
Utilities
SORD_API bool sord_quad_match (const SordQuad x, const SordQuad y)
Serialisation
SORD_API SerdReader * sord_new_reader (SordModel *model, SerdEnv *env, SerdSyntax syntax, SordNode
*graph)
SORD_API bool sord_write (SordModel *model, SerdWriter *writer, SordNode *graph)
SORD_API bool sord_write_iter (SordIter *iter, SerdWriter *writer)
Enumeration Type Documentation
enumSordQuadIndex
Index into a SordQuad.
EnumeratorSORD_SUBJECT
Subject.
SORD_PREDICATE
Predicate ('key')
SORD_OBJECT
Object ('value')
SORD_GRAPH
Graph ('context')
enumSordNodeType
Type of a node.
EnumeratorSORD_URI
URI.
SORD_BLANK
Blank node identifier.
SORD_LITERAL
Literal (string with optional lang or datatype)
enumSordIndexOption
Indexing option.
EnumeratorSORD_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
SORD_APISordWorld*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.
SORD_APIvoidsord_world_free(SordWorld*world)
Free world.
SORD_APIvoidsord_world_set_error_sink(SordWorld*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.
SORD_APISordNode*sord_new_uri(SordWorld*world,constuint8_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.
SORD_APISordNode*sord_new_relative_uri(SordWorld*world,constuint8_t*uri,constuint8_t*base_uri)
Get a URI node from a relative URI string.
SORD_APISordNode*sord_new_blank(SordWorld*world,constuint8_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.
SORD_APISordNode*sord_new_literal(SordWorld*world,SordNode*datatype,constuint8_t*str,constchar*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.
SORD_APISordNode*sord_node_copy(constSordNode*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.
SORD_APIvoidsord_node_free(SordWorld*world,SordNode*node)
Free a node (drop a reference).
SORD_APISordNodeTypesord_node_get_type(constSordNode*node)
Return the type of a node (SORD_URI, SORD_BLANK, or SORD_LITERAL).
SORD_APIconstuint8_t*sord_node_get_string(constSordNode*node)
Return the string value of a node.
SORD_APIconstuint8_t*sord_node_get_string_counted(constSordNode*node,size_t*bytes)
Return the string value of a node, and set bytes to its length in bytes.
SORD_APIconstuint8_t*sord_node_get_string_measured(constSordNode*node,size_t*bytes,size_t*chars)
Return the string value of a node, and set bytes to its length in bytes, and count to its length in
characters.
SORD_APIconstchar*sord_node_get_language(constSordNode*node)
Return the language of a literal node (or NULL).
SORD_APISordNode*sord_node_get_datatype(constSordNode*node)
Return the datatype URI of a literal node (or NULL).
SORD_APISerdNodeFlagssord_node_get_flags(constSordNode*node)
Return the flags (string attributes) of a node.
SORD_APIboolsord_node_is_inline_object(constSordNode*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.
SORD_APIboolsord_node_equals(constSordNode*a,constSordNode*b)
Return true iff a is equal to b. Note this is much faster than comparing the node's strings.
SORD_APIconstSerdNode*sord_node_to_serd_node(constSordNode*node)
Return a SordNode as a SerdNode. The returned node is shared and must not be freed or modified.
SORD_APISordNode*sord_node_from_serd_node(SordWorld*world,SerdEnv*env,constSerdNode*node,constSerdNode*datatype,constSerdNode*lang)
Create a new SordNode from a SerdNode. The returned node must be freed using sord_node_free().
SORD_APISordModel*sord_new(SordWorld*world,unsignedindices,boolgraphs)
Create a new model.
Parametersworld 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.
SORD_APIvoidsord_free(SordModel*model)
Close and free model.
SORD_APISordWorld*sord_get_world(SordModel*model)
Get the world associated with model.
SORD_APIsize_tsord_num_nodes(constSordWorld*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.
SORD_APIsize_tsord_num_quads(constSordModel*model)
Return the number of quads stored in model.
SORD_APISordIter*sord_begin(constSordModel*model)
Return an iterator to the start of model.
SORD_APISordIter*sord_find(SordModel*model,constSordQuadpat)
Search for statements by a quad pattern.
Returns
an iterator to the first match, or NULL if no matches found.
SORD_APISordIter*sord_search(SordModel*model,constSordNode*s,constSordNode*p,constSordNode*o,constSordNode*g)
Search for statements by nodes.
Returns
an iterator to the first match, or NULL if no matches found.
SORD_APISordNode*sord_get(SordModel*model,constSordNode*s,constSordNode*p,constSordNode*o,constSordNode*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.
SORD_APIboolsord_ask(SordModel*model,constSordNode*s,constSordNode*p,constSordNode*o,constSordNode*g)
Return true iff a statement exists.
SORD_APIuint64_tsord_count(SordModel*model,constSordNode*s,constSordNode*p,constSordNode*o,constSordNode*g)
Return the number of matching statements.
SORD_APIboolsord_contains(SordModel*model,constSordQuadpat)
Check if model contains a triple pattern.
Returns
true if model contains a match for pat, otherwise false.
SORD_APIboolsord_add(SordModel*model,constSordQuadtup)
Add a quad to a model. Calling this function invalidates all iterators on model.
Returns
true on success, false, on error.
SORD_APIvoidsord_remove(SordModel*model,constSordQuadtup)
Remove a quad from a model. Calling this function invalidates all iterators on model. To remove quads
while iterating, use sord_erase() instead.
SORD_APISerdStatussord_erase(SordModel*model,SordIter*iter)
Remove a quad from a model via an iterator. Calling this function invalidates all iterators on model
except iter.
Parametersmodel The model which iter points to.
iter Iterator to the element to erase, which is incremented to the next value on return.
SORD_APISordInserter*sord_inserter_new(SordModel*model,SerdEnv*env)
Create an inserter for writing statements to a model.
SORD_APIvoidsord_inserter_free(SordInserter*inserter)
Free an inserter.
SORD_APISerdStatussord_inserter_set_base_uri(SordInserter*inserter,constSerdNode*uri)
Set the current base URI for writing to the model. Note this function can be safely casted to
SerdBaseSink.
SORD_APISerdStatussord_inserter_set_prefix(SordInserter*inserter,constSerdNode*name,constSerdNode*uri)
Set a namespace prefix for writing to the model. Note this function can be safely casted to
SerdPrefixSink.
SORD_APISerdStatussord_inserter_write_statement(SordInserter*inserter,SerdStatementFlagsflags,constSerdNode*graph,constSerdNode*subject,constSerdNode*predicate,constSerdNode*object,constSerdNode*object_datatype,constSerdNode*object_lang)
Write a statement to the model. Note this function can be safely casted to SerdStatementSink.
SORD_APIvoidsord_iter_get(constSordIter*iter,SordQuadtup)
Set quad to the quad pointed to by iter.
SORD_APIconstSordNode*sord_iter_get_node(constSordIter*iter,SordQuadIndexindex)
Return a field of the quad pointed to by iter. Returns NULL if iter is NULL or is at the end.
SORD_APIconstSordModel*sord_iter_get_model(SordIter*iter)
Return the store pointed to by iter.
SORD_APIboolsord_iter_next(SordIter*iter)
Increment iter to point to the next statement.
SORD_APIboolsord_iter_end(constSordIter*iter)
Return true iff iter is at the end of its range.
SORD_APIvoidsord_iter_free(SordIter*iter)
Free iter.
SORD_APIboolsord_quad_match(constSordQuadx,constSordQuady)
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.
SORD_APISerdReader*sord_new_reader(SordModel*model,SerdEnv*env,SerdSyntaxsyntax,SordNode*graph)
Return a reader that will read into model.
SORD_APIboolsord_write(SordModel*model,SerdWriter*writer,SordNode*graph)
Write a model to a writer.
SORD_APIboolsord_write_iter(SordIter*iter,SerdWriter*writer)
Write a range to a writer. This increments iter to its end, then frees it.
Name
sord - Sord
Typedef Documentation
typedefstructSordWorldImplSordWorld
Sord World. The World represents all library state, including interned strings.
typedefstructSordModelImplSordModel
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.
typedefstructSordInserterImplSordInserter
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.
typedefstructSordIterImplSordIter
Model Iterator.
typedefstructSordNodeImplSordNode
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).
typedefconstSordNode*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.
