---
name: "sord"
section: "3"
platform: "linux"
package: "libsord-doc"
version: "0.16.8-2"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/sord"
---

# sord(3)

Sord

## NAME

sord - Sord

## 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 **SordNodeType** **sord\_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)\

## Typedef Documentation

### typedef struct SordWorldImpl SordWorld

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

### typedef struct SordModelImpl SordModel

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 SordInserter

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 SordIter

Model Iterator.

### typedef struct SordNodeImpl SordNode

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 SordNode\* 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 SordQuadIndex

Index into a SordQuad.

**Enumerator**

- *SORD\_SUBJECT*

  *Subject.*

- *SORD\_PREDICATE*

  *Predicate ('key')*

- *SORD\_OBJECT*

  *Object ('value')*

- *SORD\_GRAPH*

  *Graph ('context')*

### enum SordNodeType

*Type of a node.*

**Enumerator**

- *SORD\_URI*

  *URI.*

- *SORD\_BLANK*

  *Blank node identifier.*

- *SORD\_LITERAL*

  *Literal (string with optional lang or datatype)*

### enum SordIndexOption

*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

### SORD\_API SordWorld\* 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\_API void sord\_world\_free (SordWorld \* world)

*Free* `world`*.*

### SORD\_API void sord\_world\_set\_error\_sink (SordWorld \* world, SerdErrorSink error\_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\_API SordNode\* sord\_new\_uri (SordWorld \* 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.*

### SORD\_API SordNode\* sord\_new\_relative\_uri (SordWorld \* world, const uint8\_t \* uri, const uint8\_t \* base\_uri)

*Get a URI node from a relative URI string.*

### SORD\_API SordNode\* sord\_new\_blank (SordWorld \* 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.*

### SORD\_API SordNode\* sord\_new\_literal (SordWorld \* world, SordNode \* 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.*

### SORD\_API SordNode\* sord\_node\_copy (const SordNode \* 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\_API void sord\_node\_free (SordWorld \* world, SordNode \* node)

*Free a node (drop a reference).*

### SORD\_API SordNodeType sord\_node\_get\_type (const SordNode \* node)

*Return the type of a node (SORD\_URI, SORD\_BLANK, or SORD\_LITERAL).*

### SORD\_API const uint8\_t\* sord\_node\_get\_string (const SordNode \* node)

*Return the string value of a node.*

### SORD\_API const uint8\_t\* sord\_node\_get\_string\_counted (const SordNode \* node, size\_t \* bytes)

*Return the string value of a node, and set* `bytes` *to its length in bytes.*

### SORD\_API const uint8\_t\* sord\_node\_get\_string\_measured (const SordNode \* 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\_API const char\* sord\_node\_get\_language (const SordNode \* node)

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

### SORD\_API SordNode\* sord\_node\_get\_datatype (const SordNode \* node)

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

### SORD\_API SerdNodeFlags sord\_node\_get\_flags (const SordNode \* node)

*Return the flags (string attributes) of a node.*

### SORD\_API bool sord\_node\_is\_inline\_object (const SordNode \* 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\_API bool sord\_node\_equals (const SordNode \* a, const SordNode \* b)

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

### SORD\_API const SerdNode\* sord\_node\_to\_serd\_node (const SordNode \* node)

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

### SORD\_API SordNode\* sord\_node\_from\_serd\_node (SordWorld \* 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()***.*

### SORD\_API SordModel\* sord\_new (SordWorld \* world, unsigned indices, bool graphs)

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

### SORD\_API void sord\_free (SordModel \* model)

*Close and free* `model`*.*

### SORD\_API SordWorld\* sord\_get\_world (SordModel \* model)

*Get the world associated with* `model`*.*

### SORD\_API size\_t sord\_num\_nodes (const SordWorld \* 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\_API size\_t sord\_num\_quads (const SordModel \* model)

*Return the number of quads stored in* `model`*.*

### SORD\_API SordIter\* sord\_begin (const SordModel \* model)

*Return an iterator to the start of* `model`*.*

### SORD\_API SordIter\* sord\_find (SordModel \* model, const SordQuad pat)

*Search for statements by a quad pattern.*

**Returns**

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

### SORD\_API SordIter\* sord\_search (SordModel \* model, const SordNode \* s, const SordNode \* p, const SordNode \* o, const SordNode \* g)

*Search for statements by nodes.*

**Returns**

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

### SORD\_API SordNode\* sord\_get (SordModel \* model, const SordNode \* s, const SordNode \* p, const SordNode \* o, const SordNode \* 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\_API bool sord\_ask (SordModel \* model, const SordNode \* s, const SordNode \* p, const SordNode \* o, const SordNode \* g)

*Return true iff a statement exists.*

### SORD\_API uint64\_t sord\_count (SordModel \* model, const SordNode \* s, const SordNode \* p, const SordNode \* o, const SordNode \* g)

*Return the number of matching statements.*

### SORD\_API bool sord\_contains (SordModel \* model, const SordQuad pat)

*Check if* `model` *contains a triple pattern.*

**Returns**

*true if* `model` *contains a match for* `pat`*, otherwise false.*

### SORD\_API bool sord\_add (SordModel \* model, const SordQuad tup)

*Add a quad to a model. Calling this function invalidates all iterators on* `model`*.*

**Returns**

*true on success, false, on error.*

### SORD\_API void sord\_remove (SordModel \* model, const SordQuad tup)

*Remove a quad from a model. Calling this function invalidates all iterators on* `model`*. To remove quads while iterating, use* **sord\_erase()** *instead.*

### SORD\_API SerdStatus sord\_erase (SordModel \* model, SordIter \* iter)

*Remove a quad from a model via an iterator. Calling this function invalidates all iterators on* `model` *except* `iter`*.*

**Parameters**

*model The model which* `iter` *points to.* \
 *iter Iterator to the element to erase, which is incremented to the next value on return.*

### SORD\_API SordInserter\* sord\_inserter\_new (SordModel \* model, SerdEnv \* env)

*Create an inserter for writing statements to a model.*

### SORD\_API void sord\_inserter\_free (SordInserter \* inserter)

*Free an inserter.*

### SORD\_API SerdStatus sord\_inserter\_set\_base\_uri (SordInserter \* inserter, const SerdNode \* uri)

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

### SORD\_API SerdStatus sord\_inserter\_set\_prefix (SordInserter \* 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.*

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

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

### SORD\_API void sord\_iter\_get (const SordIter \* iter, SordQuad tup)

*Set* `quad` *to the quad pointed to by* `iter`*.*

### SORD\_API const SordNode\* sord\_iter\_get\_node (const SordIter \* iter, SordQuadIndex index)

*Return a field of the quad pointed to by* `iter`*. Returns NULL if* `iter` *is NULL or is at the end.*

### SORD\_API const SordModel\* sord\_iter\_get\_model (SordIter \* iter)

*Return the store pointed to by* `iter`*.*

### SORD\_API bool sord\_iter\_next (SordIter \* iter)

*Increment* `iter` *to point to the next statement.*

### SORD\_API bool sord\_iter\_end (const SordIter \* iter)

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

### SORD\_API void sord\_iter\_free (SordIter \* iter)

*Free* `iter`*.*

### SORD\_API bool sord\_quad\_match (const SordQuad x, const SordQuad y)

*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\_API SerdReader\* sord\_new\_reader (SordModel \* model, SerdEnv \* env, SerdSyntax syntax, SordNode \* graph)

*Return a reader that will read into* `model`*.*

### SORD\_API bool sord\_write (SordModel \* model, SerdWriter \* writer, SordNode \* graph)

*Write a model to a writer.*

### SORD\_API bool sord\_write\_iter (SordIter \* 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.*
