5.13.3 Model
-
enum SerdStatementOrder
Statement ordering.
Statements themselves always have the same fields in the same order (subject, predicate, object, graph), but a model can keep indices for different orderings to provide good performance for different kinds of queries.
-
enumerator SERD_ORDER_SPO
Subject, Predicate, Object.
-
enumerator SERD_ORDER_SOP
Subject, Object, Predicate.
-
enumerator SERD_ORDER_OPS
Object, Predicate, Subject.
-
enumerator SERD_ORDER_OSP
Object, Subject, Predicate.
-
enumerator SERD_ORDER_PSO
Predicate, Subject, Object.
-
enumerator SERD_ORDER_POS
Predicate, Object, Subject.
-
enumerator SERD_ORDER_GSPO
Graph, Subject, Predicate, Object.
-
enumerator SERD_ORDER_GSOP
Graph, Subject, Object, Predicate.
-
enumerator SERD_ORDER_GOPS
Graph, Object, Predicate, Subject.
-
enumerator SERD_ORDER_GOSP
Graph, Object, Subject, Predicate.
-
enumerator SERD_ORDER_GPSO
Graph, Predicate, Subject, Object.
-
enumerator SERD_ORDER_GPOS
Graph, Predicate, Object, Subject.
-
enumerator SERD_ORDER_SPO
-
enum SerdModelFlag
Flags that control model storage and indexing.
-
enumerator SERD_STORE_GRAPHS
Store and index the graph of statements.
-
enumerator SERD_STORE_CARETS
Store original caret of statements.
-
enumerator SERD_STORE_GRAPHS
-
typedef struct SerdModelImpl SerdModel
An indexed set of statements.
-
typedef uint32_t SerdModelFlags
Bitwise OR of SerdModelFlag values.
-
SerdModel *serd_model_new(SerdWorld *world, SerdStatementOrder default_order, SerdModelFlags flags)
Create a new model.
- Parameters
world – The world in which to make this model.
default_order – The order for the default index, which is always present and responsible for owning all the statements in the model. This should almost always be
SerdStatementOrder.SERD_ORDER_SPO
orSerdStatementOrder.SERD_ORDER_GSPO
(which support writing pretty documents), but advanced applications that do not want either of these indices can use a different order. Additional indices can be added withserd_model_add_index()
.flags – Options that control what data is stored in the model.
-
SerdModel *serd_model_copy(SerdAllocator *allocator, const SerdModel *model)
Return a deep copy of
model
-
bool serd_model_equals(const SerdModel *a, const SerdModel *b)
Return true iff
a
is equal tob
, ignoring statement cursor metadata.
-
void serd_model_free(SerdModel *model)
Close and free
model
-
SerdStatus serd_model_add_index(SerdModel *model, SerdStatementOrder order)
Add an index for a particular statement order to the model.
- Returns
Failure if this index already exists.
-
SerdStatus serd_model_drop_index(SerdModel *model, SerdStatementOrder order)
Add an index for a particular statement order to the model.
- Returns
Failure if this index does not exist.
-
SerdStatementOrder serd_model_default_order(const SerdModel *model)
Get the default statement order of
model
-
SerdModelFlags serd_model_flags(const SerdModel *model)
Get the flags enabled on
model
-
size_t serd_model_size(const SerdModel *model)
Return the number of statements stored in
model
-
bool serd_model_empty(const SerdModel *model)
Return true iff there are no statements stored in
model
-
SerdCursor *serd_model_begin(const SerdModel *model)
Return a cursor at the start of every statement in the model.
The returned cursor will advance over every statement in the model’s default order.
-
const SerdCursor *serd_model_end(const SerdModel *model)
Return a cursor past the end of the model.
This returns the “universal” end cursor, which is equivalent to any cursor for this model that has reached its end.
-
SerdCursor *serd_model_begin_ordered(const SerdModel *model, SerdStatementOrder order)
Return a cursor over all statements in the model in a specific order.
-
SerdCursor *serd_model_find(const SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *g)
Search for statements that match a pattern.
- Returns
An iterator to the first match, or NULL if no matches found.
-
const SerdNode *serd_model_get(const SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *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.- Returns
The first matching node, or NULL if no matches are found.
-
const SerdStatement *serd_model_get_statement(const SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *g)
Search for a single statement that matches a pattern.
This function is mainly useful for predicates that only have one value.
- Returns
The first matching statement, or NULL if none are found.
-
bool serd_model_ask(const SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *g)
Return true iff a statement exists.
-
size_t serd_model_count(const SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *g)
Return the number of matching statements.
-
SerdStatus serd_model_add(SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *g)
Add a statement to a model from nodes.
This function fails if there are any active iterators on
model
.
-
SerdStatus serd_model_add_with_caret(SerdModel *model, const SerdNode *s, const SerdNode *p, const SerdNode *o, const SerdNode *g, const SerdCaret *caret)
Add a statement to a model from nodes with a caret.
This function fails if there are any active iterators on
model
.
-
SerdStatus serd_model_insert(SerdModel *model, const SerdStatement *statement)
Add a statement to a model.
This function fails if there are any active iterators on
model
. If statement is null, then SERD_FAILURE is returned.
-
SerdStatus serd_model_insert_statements(SerdModel *model, SerdCursor *range)
Add a range of statements to a model.
This function fails if there are any active iterators on
model
.
-
SerdStatus serd_model_erase(SerdModel *model, SerdCursor *cursor)
Remove a statement from a model via an iterator.
Calling this function invalidates all other iterators on this model.
- Parameters
model – The model which
iter
points to.cursor – Cursor pointing to the element to erase. This cursor is advanced to the next statement on return.
-
SerdStatus serd_model_erase_statements(SerdModel *model, SerdCursor *range)
Remove a range of statements from a model.
This can be used with
serd_model_find()
to erase all statements in a model that match a pattern.Calling this function invalidates all iterators on
model
.- Parameters
model – The model which
range
points to.range – Range to erase, which will be empty on return.
-
SerdStatus serd_model_clear(SerdModel *model)
Remove everything from a model.
Calling this function invalidates all iterators on
model
.- Parameters
model – The model to clear.