cannam@130
|
1 /*
|
cannam@130
|
2 Copyright 2011-2016 David Robillard <http://drobilla.net>
|
cannam@130
|
3
|
cannam@130
|
4 Permission to use, copy, modify, and/or distribute this software for any
|
cannam@130
|
5 purpose with or without fee is hereby granted, provided that the above
|
cannam@130
|
6 copyright notice and this permission notice appear in all copies.
|
cannam@130
|
7
|
cannam@130
|
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
cannam@130
|
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
cannam@130
|
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
cannam@130
|
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
cannam@130
|
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
cannam@130
|
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
cannam@130
|
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
cannam@130
|
15 */
|
cannam@130
|
16
|
cannam@130
|
17 /**
|
cannam@130
|
18 @file sord.h API for Sord, a lightweight RDF model library.
|
cannam@130
|
19 */
|
cannam@130
|
20
|
cannam@130
|
21 #ifndef SORD_SORD_H
|
cannam@130
|
22 #define SORD_SORD_H
|
cannam@130
|
23
|
cannam@130
|
24 #include <stddef.h>
|
cannam@130
|
25 #include <stdint.h>
|
cannam@130
|
26 #include <stdio.h>
|
cannam@130
|
27
|
cannam@130
|
28 #include "serd/serd.h"
|
cannam@130
|
29
|
cannam@130
|
30 #ifdef SORD_SHARED
|
cannam@130
|
31 # ifdef _WIN32
|
cannam@130
|
32 # define SORD_LIB_IMPORT __declspec(dllimport)
|
cannam@130
|
33 # define SORD_LIB_EXPORT __declspec(dllexport)
|
cannam@130
|
34 # else
|
cannam@130
|
35 # define SORD_LIB_IMPORT __attribute__((visibility("default")))
|
cannam@130
|
36 # define SORD_LIB_EXPORT __attribute__((visibility("default")))
|
cannam@130
|
37 # endif
|
cannam@130
|
38 # ifdef SORD_INTERNAL
|
cannam@130
|
39 # define SORD_API SORD_LIB_EXPORT
|
cannam@130
|
40 # else
|
cannam@130
|
41 # define SORD_API SORD_LIB_IMPORT
|
cannam@130
|
42 # endif
|
cannam@130
|
43 #else
|
cannam@130
|
44 # define SORD_API
|
cannam@130
|
45 #endif
|
cannam@130
|
46
|
cannam@130
|
47 #ifdef __cplusplus
|
cannam@130
|
48 extern "C" {
|
cannam@130
|
49 #else
|
cannam@130
|
50 # include <stdbool.h>
|
cannam@130
|
51 #endif
|
cannam@130
|
52
|
cannam@130
|
53 /**
|
cannam@130
|
54 @defgroup sord Sord
|
cannam@130
|
55 A lightweight RDF model library.
|
cannam@130
|
56
|
cannam@130
|
57 Sord stores RDF (subject object predicate context) quads, where the context
|
cannam@130
|
58 may be omitted (to represent triples in the default graph).
|
cannam@130
|
59 @{
|
cannam@130
|
60 */
|
cannam@130
|
61
|
cannam@130
|
62 /**
|
cannam@130
|
63 Sord World.
|
cannam@130
|
64 The World represents all library state, including interned strings.
|
cannam@130
|
65 */
|
cannam@130
|
66 typedef struct SordWorldImpl SordWorld;
|
cannam@130
|
67
|
cannam@130
|
68 /**
|
cannam@130
|
69 Sord Model.
|
cannam@130
|
70
|
cannam@130
|
71 A model is an indexed set of Quads (i.e. it can contain several RDF
|
cannam@130
|
72 graphs). It may be searched using various patterns depending on which
|
cannam@130
|
73 indices are enabled.
|
cannam@130
|
74 */
|
cannam@130
|
75 typedef struct SordModelImpl SordModel;
|
cannam@130
|
76
|
cannam@130
|
77 /**
|
cannam@130
|
78 Model Inserter.
|
cannam@130
|
79
|
cannam@130
|
80 An inserter is used for writing statements to a model using the Serd sink
|
cannam@130
|
81 interface. This makes it simple to write to a model directly using a
|
cannam@130
|
82 SerdReader, or any other code that writes statements to a SerdStatementSink.
|
cannam@130
|
83 */
|
cannam@130
|
84 typedef struct SordInserterImpl SordInserter;
|
cannam@130
|
85
|
cannam@130
|
86 /**
|
cannam@130
|
87 Model Iterator.
|
cannam@130
|
88 */
|
cannam@130
|
89 typedef struct SordIterImpl SordIter;
|
cannam@130
|
90
|
cannam@130
|
91 /**
|
cannam@130
|
92 RDF Node.
|
cannam@130
|
93 A Node is a component of a Quad. Nodes may be URIs, blank nodes, or
|
cannam@130
|
94 (in the case of quad objects only) string literals. Literal nodes may
|
cannam@130
|
95 have an associate language or datatype (but not both).
|
cannam@130
|
96 */
|
cannam@130
|
97 typedef struct SordNodeImpl SordNode;
|
cannam@130
|
98
|
cannam@130
|
99 /**
|
cannam@130
|
100 Quad of nodes (a statement), or a quad pattern.
|
cannam@130
|
101
|
cannam@130
|
102 Nodes are ordered (S P O G). The ID of the default graph is 0.
|
cannam@130
|
103 */
|
cannam@130
|
104 typedef const SordNode* SordQuad[4];
|
cannam@130
|
105
|
cannam@130
|
106 /**
|
cannam@130
|
107 Index into a SordQuad.
|
cannam@130
|
108 */
|
cannam@130
|
109 typedef enum {
|
cannam@130
|
110 SORD_SUBJECT = 0, /**< Subject */
|
cannam@130
|
111 SORD_PREDICATE = 1, /**< Predicate ("key") */
|
cannam@130
|
112 SORD_OBJECT = 2, /**< Object ("value") */
|
cannam@130
|
113 SORD_GRAPH = 3 /**< Graph ("context") */
|
cannam@130
|
114 } SordQuadIndex;
|
cannam@130
|
115
|
cannam@130
|
116 /**
|
cannam@130
|
117 Type of a node.
|
cannam@130
|
118 */
|
cannam@130
|
119 typedef enum {
|
cannam@130
|
120 SORD_URI = 1, /**< URI */
|
cannam@130
|
121 SORD_BLANK = 2, /**< Blank node identifier */
|
cannam@130
|
122 SORD_LITERAL = 3 /**< Literal (string with optional lang or datatype) */
|
cannam@130
|
123 } SordNodeType;
|
cannam@130
|
124
|
cannam@130
|
125 /**
|
cannam@130
|
126 Indexing option.
|
cannam@130
|
127 */
|
cannam@130
|
128 typedef enum {
|
cannam@130
|
129 SORD_SPO = 1, /**< Subject, Predicate, Object */
|
cannam@130
|
130 SORD_SOP = 1 << 1, /**< Subject, Object, Predicate */
|
cannam@130
|
131 SORD_OPS = 1 << 2, /**< Object, Predicate, Subject */
|
cannam@130
|
132 SORD_OSP = 1 << 3, /**< Object, Subject, Predicate */
|
cannam@130
|
133 SORD_PSO = 1 << 4, /**< Predicate, Subject, Object */
|
cannam@130
|
134 SORD_POS = 1 << 5 /**< Predicate, Object, Subject */
|
cannam@130
|
135 } SordIndexOption;
|
cannam@130
|
136
|
cannam@130
|
137 /**
|
cannam@130
|
138 @name World
|
cannam@130
|
139 @{
|
cannam@130
|
140 */
|
cannam@130
|
141
|
cannam@130
|
142 /**
|
cannam@130
|
143 Create a new Sord World.
|
cannam@130
|
144 It is safe to use multiple worlds in one process, though no data
|
cannam@130
|
145 (e.g. nodes) can be shared between worlds, and this should be avoided if
|
cannam@130
|
146 possible for performance reasons.
|
cannam@130
|
147 */
|
cannam@130
|
148 SORD_API
|
cannam@130
|
149 SordWorld*
|
cannam@130
|
150 sord_world_new(void);
|
cannam@130
|
151
|
cannam@130
|
152 /**
|
cannam@130
|
153 Free `world`.
|
cannam@130
|
154 */
|
cannam@130
|
155 SORD_API
|
cannam@130
|
156 void
|
cannam@130
|
157 sord_world_free(SordWorld* world);
|
cannam@130
|
158
|
cannam@130
|
159 /**
|
cannam@130
|
160 Set a function to be called when errors occur.
|
cannam@130
|
161
|
cannam@130
|
162 The `error_sink` will be called with `handle` as its first argument. If
|
cannam@130
|
163 no error function is set, errors are printed to stderr.
|
cannam@130
|
164 */
|
cannam@130
|
165 SORD_API
|
cannam@130
|
166 void
|
cannam@130
|
167 sord_world_set_error_sink(SordWorld* world,
|
cannam@130
|
168 SerdErrorSink error_sink,
|
cannam@130
|
169 void* handle);
|
cannam@130
|
170
|
cannam@130
|
171 /**
|
cannam@130
|
172 @}
|
cannam@130
|
173 @name Node
|
cannam@130
|
174 @{
|
cannam@130
|
175 */
|
cannam@130
|
176
|
cannam@130
|
177 /**
|
cannam@130
|
178 Get a URI node from a string.
|
cannam@130
|
179
|
cannam@130
|
180 Note this function measures `str`, which is a common bottleneck.
|
cannam@130
|
181 Use sord_node_from_serd_node() instead if `str` is already measured.
|
cannam@130
|
182 */
|
cannam@130
|
183 SORD_API
|
cannam@130
|
184 SordNode*
|
cannam@130
|
185 sord_new_uri(SordWorld* world, const uint8_t* uri);
|
cannam@130
|
186
|
cannam@130
|
187 /**
|
cannam@130
|
188 Get a URI node from a relative URI string.
|
cannam@130
|
189 */
|
cannam@130
|
190 SORD_API
|
cannam@130
|
191 SordNode*
|
cannam@130
|
192 sord_new_relative_uri(SordWorld* world,
|
cannam@130
|
193 const uint8_t* str,
|
cannam@130
|
194 const uint8_t* base_uri);
|
cannam@130
|
195
|
cannam@130
|
196 /**
|
cannam@130
|
197 Get a blank node from a string.
|
cannam@130
|
198
|
cannam@130
|
199 Note this function measures `str`, which is a common bottleneck.
|
cannam@130
|
200 Use sord_node_from_serd_node() instead if `str` is already measured.
|
cannam@130
|
201 */
|
cannam@130
|
202 SORD_API
|
cannam@130
|
203 SordNode*
|
cannam@130
|
204 sord_new_blank(SordWorld* world, const uint8_t* str);
|
cannam@130
|
205
|
cannam@130
|
206 /**
|
cannam@130
|
207 Get a literal node from a string.
|
cannam@130
|
208
|
cannam@130
|
209 Note this function measures `str`, which is a common bottleneck.
|
cannam@130
|
210 Use sord_node_from_serd_node() instead if `str` is already measured.
|
cannam@130
|
211 */
|
cannam@130
|
212 SORD_API
|
cannam@130
|
213 SordNode*
|
cannam@130
|
214 sord_new_literal(SordWorld* world,
|
cannam@130
|
215 SordNode* datatype,
|
cannam@130
|
216 const uint8_t* str,
|
cannam@130
|
217 const char* lang);
|
cannam@130
|
218
|
cannam@130
|
219 /**
|
cannam@130
|
220 Copy a node (obtain a reference).
|
cannam@130
|
221
|
cannam@130
|
222 Node that since nodes are interned and reference counted, this does not
|
cannam@130
|
223 actually create a deep copy of `node`.
|
cannam@130
|
224 */
|
cannam@130
|
225 SORD_API
|
cannam@130
|
226 SordNode*
|
cannam@130
|
227 sord_node_copy(const SordNode* node);
|
cannam@130
|
228
|
cannam@130
|
229 /**
|
cannam@130
|
230 Free a node (drop a reference).
|
cannam@130
|
231 */
|
cannam@130
|
232 SORD_API
|
cannam@130
|
233 void
|
cannam@130
|
234 sord_node_free(SordWorld* world, SordNode* node);
|
cannam@130
|
235
|
cannam@130
|
236 /**
|
cannam@130
|
237 Return the type of a node (SORD_URI, SORD_BLANK, or SORD_LITERAL).
|
cannam@130
|
238 */
|
cannam@130
|
239 SORD_API
|
cannam@130
|
240 SordNodeType
|
cannam@130
|
241 sord_node_get_type(const SordNode* node);
|
cannam@130
|
242
|
cannam@130
|
243 /**
|
cannam@130
|
244 Return the string value of a node.
|
cannam@130
|
245 */
|
cannam@130
|
246 SORD_API
|
cannam@130
|
247 const uint8_t*
|
cannam@130
|
248 sord_node_get_string(const SordNode* node);
|
cannam@130
|
249
|
cannam@130
|
250 /**
|
cannam@130
|
251 Return the string value of a node, and set `bytes` to its length in bytes.
|
cannam@130
|
252 */
|
cannam@130
|
253 SORD_API
|
cannam@130
|
254 const uint8_t*
|
cannam@130
|
255 sord_node_get_string_counted(const SordNode* node, size_t* bytes);
|
cannam@130
|
256
|
cannam@130
|
257 /**
|
cannam@130
|
258 Return the string value of a node, and set `bytes` to its length in bytes,
|
cannam@130
|
259 and `count` to its length in characters.
|
cannam@130
|
260 */
|
cannam@130
|
261 SORD_API
|
cannam@130
|
262 const uint8_t*
|
cannam@130
|
263 sord_node_get_string_measured(const SordNode* node,
|
cannam@130
|
264 size_t* bytes,
|
cannam@130
|
265 size_t* chars);
|
cannam@130
|
266
|
cannam@130
|
267 /**
|
cannam@130
|
268 Return the language of a literal node (or NULL).
|
cannam@130
|
269 */
|
cannam@130
|
270 SORD_API
|
cannam@130
|
271 const char*
|
cannam@130
|
272 sord_node_get_language(const SordNode* node);
|
cannam@130
|
273
|
cannam@130
|
274 /**
|
cannam@130
|
275 Return the datatype URI of a literal node (or NULL).
|
cannam@130
|
276 */
|
cannam@130
|
277 SORD_API
|
cannam@130
|
278 SordNode*
|
cannam@130
|
279 sord_node_get_datatype(const SordNode* node);
|
cannam@130
|
280
|
cannam@130
|
281 /**
|
cannam@130
|
282 Return the flags (string attributes) of a node.
|
cannam@130
|
283 */
|
cannam@130
|
284 SORD_API
|
cannam@130
|
285 SerdNodeFlags
|
cannam@130
|
286 sord_node_get_flags(const SordNode* node);
|
cannam@130
|
287
|
cannam@130
|
288 /**
|
cannam@130
|
289 Return true iff node can be serialised as an inline object.
|
cannam@130
|
290
|
cannam@130
|
291 More specifically, this returns true iff the node is the object field
|
cannam@130
|
292 of exactly one statement, and therefore can be inlined since it needn't
|
cannam@130
|
293 be referred to by name.
|
cannam@130
|
294 */
|
cannam@130
|
295 SORD_API
|
cannam@130
|
296 bool
|
cannam@130
|
297 sord_node_is_inline_object(const SordNode* node);
|
cannam@130
|
298
|
cannam@130
|
299 /**
|
cannam@130
|
300 Return true iff `a` is equal to `b`.
|
cannam@130
|
301
|
cannam@130
|
302 Note this is much faster than comparing the node's strings.
|
cannam@130
|
303 */
|
cannam@130
|
304 SORD_API
|
cannam@130
|
305 bool
|
cannam@130
|
306 sord_node_equals(const SordNode* a,
|
cannam@130
|
307 const SordNode* b);
|
cannam@130
|
308
|
cannam@130
|
309 /**
|
cannam@130
|
310 Return a SordNode as a SerdNode.
|
cannam@130
|
311
|
cannam@130
|
312 The returned node is shared and must not be freed or modified.
|
cannam@130
|
313 */
|
cannam@130
|
314 SORD_API
|
cannam@130
|
315 const SerdNode*
|
cannam@130
|
316 sord_node_to_serd_node(const SordNode* node);
|
cannam@130
|
317
|
cannam@130
|
318 /**
|
cannam@130
|
319 Create a new SordNode from a SerdNode.
|
cannam@130
|
320
|
cannam@130
|
321 The returned node must be freed using sord_node_free().
|
cannam@130
|
322 */
|
cannam@130
|
323 SORD_API
|
cannam@130
|
324 SordNode*
|
cannam@130
|
325 sord_node_from_serd_node(SordWorld* world,
|
cannam@130
|
326 SerdEnv* env,
|
cannam@130
|
327 const SerdNode* node,
|
cannam@130
|
328 const SerdNode* datatype,
|
cannam@130
|
329 const SerdNode* lang);
|
cannam@130
|
330
|
cannam@130
|
331 /**
|
cannam@130
|
332 @}
|
cannam@130
|
333 @name Model
|
cannam@130
|
334 @{
|
cannam@130
|
335 */
|
cannam@130
|
336
|
cannam@130
|
337 /**
|
cannam@130
|
338 Create a new model.
|
cannam@130
|
339
|
cannam@130
|
340 @param world The world in which to make this model.
|
cannam@130
|
341
|
cannam@130
|
342 @param indices SordIndexOption flags (e.g. SORD_SPO|SORD_OPS). Be sure to
|
cannam@130
|
343 enable an index where the most significant node(s) are not variables in your
|
cannam@130
|
344 queries (e.g. to make (? P O) queries, enable either SORD_OPS or SORD_POS).
|
cannam@130
|
345
|
cannam@130
|
346 @param graphs If true, store (and index) graph contexts.
|
cannam@130
|
347 */
|
cannam@130
|
348 SORD_API
|
cannam@130
|
349 SordModel*
|
cannam@130
|
350 sord_new(SordWorld* world,
|
cannam@130
|
351 unsigned indices,
|
cannam@130
|
352 bool graphs);
|
cannam@130
|
353
|
cannam@130
|
354 /**
|
cannam@130
|
355 Close and free `model`.
|
cannam@130
|
356 */
|
cannam@130
|
357 SORD_API
|
cannam@130
|
358 void
|
cannam@130
|
359 sord_free(SordModel* model);
|
cannam@130
|
360
|
cannam@130
|
361 /**
|
cannam@130
|
362 Get the world associated with `model`.
|
cannam@130
|
363 */
|
cannam@130
|
364 SORD_API
|
cannam@130
|
365 SordWorld*
|
cannam@130
|
366 sord_get_world(SordModel* model);
|
cannam@130
|
367
|
cannam@130
|
368 /**
|
cannam@130
|
369 Return the number of nodes stored in `world`.
|
cannam@130
|
370
|
cannam@130
|
371 Nodes are included in this count iff they are a part of a quad in `world`.
|
cannam@130
|
372 */
|
cannam@130
|
373 SORD_API
|
cannam@130
|
374 size_t
|
cannam@130
|
375 sord_num_nodes(const SordWorld* world);
|
cannam@130
|
376
|
cannam@130
|
377 /**
|
cannam@130
|
378 Return the number of quads stored in `model`.
|
cannam@130
|
379 */
|
cannam@130
|
380 SORD_API
|
cannam@130
|
381 size_t
|
cannam@130
|
382 sord_num_quads(const SordModel* model);
|
cannam@130
|
383
|
cannam@130
|
384 /**
|
cannam@130
|
385 Return an iterator to the start of `model`.
|
cannam@130
|
386 */
|
cannam@130
|
387 SORD_API
|
cannam@130
|
388 SordIter*
|
cannam@130
|
389 sord_begin(const SordModel* model);
|
cannam@130
|
390
|
cannam@130
|
391 /**
|
cannam@130
|
392 Search for statements by a quad pattern.
|
cannam@130
|
393 @return an iterator to the first match, or NULL if no matches found.
|
cannam@130
|
394 */
|
cannam@130
|
395 SORD_API
|
cannam@130
|
396 SordIter*
|
cannam@130
|
397 sord_find(SordModel* model, const SordQuad pat);
|
cannam@130
|
398
|
cannam@130
|
399 /**
|
cannam@130
|
400 Search for statements by nodes.
|
cannam@130
|
401 @return an iterator to the first match, or NULL if no matches found.
|
cannam@130
|
402 */
|
cannam@130
|
403 SORD_API
|
cannam@130
|
404 SordIter*
|
cannam@130
|
405 sord_search(SordModel* model,
|
cannam@130
|
406 const SordNode* s,
|
cannam@130
|
407 const SordNode* p,
|
cannam@130
|
408 const SordNode* o,
|
cannam@130
|
409 const SordNode* g);
|
cannam@130
|
410 /**
|
cannam@130
|
411 Search for a single node that matches a pattern.
|
cannam@130
|
412 Exactly one of `s`, `p`, `o` must be NULL.
|
cannam@130
|
413 This function is mainly useful for predicates that only have one value.
|
cannam@130
|
414 The returned node must be freed using sord_node_free().
|
cannam@130
|
415 @return the first matching node, or NULL if no matches are found.
|
cannam@130
|
416 */
|
cannam@130
|
417 SORD_API
|
cannam@130
|
418 SordNode*
|
cannam@130
|
419 sord_get(SordModel* model,
|
cannam@130
|
420 const SordNode* s,
|
cannam@130
|
421 const SordNode* p,
|
cannam@130
|
422 const SordNode* o,
|
cannam@130
|
423 const SordNode* g);
|
cannam@130
|
424
|
cannam@130
|
425 /**
|
cannam@130
|
426 Return true iff a statement exists.
|
cannam@130
|
427 */
|
cannam@130
|
428 SORD_API
|
cannam@130
|
429 bool
|
cannam@130
|
430 sord_ask(SordModel* model,
|
cannam@130
|
431 const SordNode* s,
|
cannam@130
|
432 const SordNode* p,
|
cannam@130
|
433 const SordNode* o,
|
cannam@130
|
434 const SordNode* g);
|
cannam@130
|
435
|
cannam@130
|
436 /**
|
cannam@130
|
437 Return the number of matching statements.
|
cannam@130
|
438 */
|
cannam@130
|
439 SORD_API
|
cannam@130
|
440 uint64_t
|
cannam@130
|
441 sord_count(SordModel* model,
|
cannam@130
|
442 const SordNode* s,
|
cannam@130
|
443 const SordNode* p,
|
cannam@130
|
444 const SordNode* o,
|
cannam@130
|
445 const SordNode* g);
|
cannam@130
|
446
|
cannam@130
|
447 /**
|
cannam@130
|
448 Check if `model` contains a triple pattern.
|
cannam@130
|
449
|
cannam@130
|
450 @return true if `model` contains a match for `pat`, otherwise false.
|
cannam@130
|
451 */
|
cannam@130
|
452 SORD_API
|
cannam@130
|
453 bool
|
cannam@130
|
454 sord_contains(SordModel* model, const SordQuad pat);
|
cannam@130
|
455
|
cannam@130
|
456 /**
|
cannam@130
|
457 Add a quad to a model.
|
cannam@130
|
458
|
cannam@130
|
459 Calling this function invalidates all iterators on `model`.
|
cannam@130
|
460
|
cannam@130
|
461 @return true on success, false, on error.
|
cannam@130
|
462 */
|
cannam@130
|
463 SORD_API
|
cannam@130
|
464 bool
|
cannam@130
|
465 sord_add(SordModel* model, const SordQuad quad);
|
cannam@130
|
466
|
cannam@130
|
467 /**
|
cannam@130
|
468 Remove a quad from a model.
|
cannam@130
|
469
|
cannam@130
|
470 Calling this function invalidates all iterators on `model`. To remove quads
|
cannam@130
|
471 while iterating, use sord_erase() instead.
|
cannam@130
|
472 */
|
cannam@130
|
473 SORD_API
|
cannam@130
|
474 void
|
cannam@130
|
475 sord_remove(SordModel* model, const SordQuad quad);
|
cannam@130
|
476
|
cannam@130
|
477 /**
|
cannam@130
|
478 Remove a quad from a model via an iterator.
|
cannam@130
|
479
|
cannam@130
|
480 Calling this function invalidates all iterators on `model` except `iter`.
|
cannam@130
|
481
|
cannam@130
|
482 @param model The model which `iter` points to.
|
cannam@130
|
483 @param iter Iterator to the element to erase, which is incremented to the
|
cannam@130
|
484 next value on return.
|
cannam@130
|
485 */
|
cannam@130
|
486 SORD_API
|
cannam@130
|
487 SerdStatus
|
cannam@130
|
488 sord_erase(SordModel* model, SordIter* iter);
|
cannam@130
|
489
|
cannam@130
|
490 /**
|
cannam@130
|
491 @}
|
cannam@130
|
492 @name Inserter
|
cannam@130
|
493 @{
|
cannam@130
|
494 */
|
cannam@130
|
495
|
cannam@130
|
496 /**
|
cannam@130
|
497 Create an inserter for writing statements to a model.
|
cannam@130
|
498 */
|
cannam@130
|
499 SORD_API
|
cannam@130
|
500 SordInserter*
|
cannam@130
|
501 sord_inserter_new(SordModel* model,
|
cannam@130
|
502 SerdEnv* env);
|
cannam@130
|
503
|
cannam@130
|
504 /**
|
cannam@130
|
505 Free an inserter.
|
cannam@130
|
506 */
|
cannam@130
|
507 SORD_API
|
cannam@130
|
508 void
|
cannam@130
|
509 sord_inserter_free(SordInserter* inserter);
|
cannam@130
|
510
|
cannam@130
|
511 /**
|
cannam@130
|
512 Set the current base URI for writing to the model.
|
cannam@130
|
513
|
cannam@130
|
514 Note this function can be safely casted to SerdBaseSink.
|
cannam@130
|
515 */
|
cannam@130
|
516 SORD_API
|
cannam@130
|
517 SerdStatus
|
cannam@130
|
518 sord_inserter_set_base_uri(SordInserter* inserter,
|
cannam@130
|
519 const SerdNode* uri);
|
cannam@130
|
520
|
cannam@130
|
521 /**
|
cannam@130
|
522 Set a namespace prefix for writing to the model.
|
cannam@130
|
523
|
cannam@130
|
524 Note this function can be safely casted to SerdPrefixSink.
|
cannam@130
|
525 */
|
cannam@130
|
526 SORD_API
|
cannam@130
|
527 SerdStatus
|
cannam@130
|
528 sord_inserter_set_prefix(SordInserter* inserter,
|
cannam@130
|
529 const SerdNode* name,
|
cannam@130
|
530 const SerdNode* uri);
|
cannam@130
|
531
|
cannam@130
|
532 /**
|
cannam@130
|
533 Write a statement to the model.
|
cannam@130
|
534
|
cannam@130
|
535 Note this function can be safely casted to SerdStatementSink.
|
cannam@130
|
536 */
|
cannam@130
|
537 SORD_API
|
cannam@130
|
538 SerdStatus
|
cannam@130
|
539 sord_inserter_write_statement(SordInserter* inserter,
|
cannam@130
|
540 SerdStatementFlags flags,
|
cannam@130
|
541 const SerdNode* graph,
|
cannam@130
|
542 const SerdNode* subject,
|
cannam@130
|
543 const SerdNode* predicate,
|
cannam@130
|
544 const SerdNode* object,
|
cannam@130
|
545 const SerdNode* object_datatype,
|
cannam@130
|
546 const SerdNode* object_lang);
|
cannam@130
|
547
|
cannam@130
|
548 /**
|
cannam@130
|
549 @}
|
cannam@130
|
550 @name Iteration
|
cannam@130
|
551 @{
|
cannam@130
|
552 */
|
cannam@130
|
553
|
cannam@130
|
554 /**
|
cannam@130
|
555 Set `quad` to the quad pointed to by `iter`.
|
cannam@130
|
556 */
|
cannam@130
|
557 SORD_API
|
cannam@130
|
558 void
|
cannam@130
|
559 sord_iter_get(const SordIter* iter, SordQuad quad);
|
cannam@130
|
560
|
cannam@130
|
561 /**
|
cannam@130
|
562 Return a field of the quad pointed to by `iter`.
|
cannam@130
|
563
|
cannam@130
|
564 Returns NULL if `iter` is NULL or is at the end.
|
cannam@130
|
565 */
|
cannam@130
|
566 SORD_API
|
cannam@130
|
567 const SordNode*
|
cannam@130
|
568 sord_iter_get_node(const SordIter* iter, SordQuadIndex index);
|
cannam@130
|
569
|
cannam@130
|
570 /**
|
cannam@130
|
571 Return the store pointed to by `iter`.
|
cannam@130
|
572 */
|
cannam@130
|
573 SORD_API
|
cannam@130
|
574 const SordModel*
|
cannam@130
|
575 sord_iter_get_model(SordIter* iter);
|
cannam@130
|
576
|
cannam@130
|
577 /**
|
cannam@130
|
578 Increment `iter` to point to the next statement.
|
cannam@130
|
579 */
|
cannam@130
|
580 SORD_API
|
cannam@130
|
581 bool
|
cannam@130
|
582 sord_iter_next(SordIter* iter);
|
cannam@130
|
583
|
cannam@130
|
584 /**
|
cannam@130
|
585 Return true iff `iter` is at the end of its range.
|
cannam@130
|
586 */
|
cannam@130
|
587 SORD_API
|
cannam@130
|
588 bool
|
cannam@130
|
589 sord_iter_end(const SordIter* iter);
|
cannam@130
|
590
|
cannam@130
|
591 /**
|
cannam@130
|
592 Free `iter`.
|
cannam@130
|
593 */
|
cannam@130
|
594 SORD_API
|
cannam@130
|
595 void
|
cannam@130
|
596 sord_iter_free(SordIter* iter);
|
cannam@130
|
597
|
cannam@130
|
598 /**
|
cannam@130
|
599 @}
|
cannam@130
|
600 @name Utilities
|
cannam@130
|
601 @{
|
cannam@130
|
602 */
|
cannam@130
|
603
|
cannam@130
|
604 /**
|
cannam@130
|
605 Match two quads (using ID comparison only).
|
cannam@130
|
606
|
cannam@130
|
607 This function is a straightforward and fast equivalence match with wildcard
|
cannam@130
|
608 support (ID 0 is a wildcard). It does not actually read node data.
|
cannam@130
|
609 @return true iff `x` and `y` match.
|
cannam@130
|
610 */
|
cannam@130
|
611 SORD_API
|
cannam@130
|
612 bool
|
cannam@130
|
613 sord_quad_match(const SordQuad x, const SordQuad y);
|
cannam@130
|
614
|
cannam@130
|
615 /**
|
cannam@130
|
616 @}
|
cannam@130
|
617 @name Serialisation
|
cannam@130
|
618 @{
|
cannam@130
|
619 */
|
cannam@130
|
620
|
cannam@130
|
621 /**
|
cannam@130
|
622 Return a reader that will read into `model`.
|
cannam@130
|
623 */
|
cannam@130
|
624 SORD_API
|
cannam@130
|
625 SerdReader*
|
cannam@130
|
626 sord_new_reader(SordModel* model,
|
cannam@130
|
627 SerdEnv* env,
|
cannam@130
|
628 SerdSyntax syntax,
|
cannam@130
|
629 SordNode* graph);
|
cannam@130
|
630
|
cannam@130
|
631 /**
|
cannam@130
|
632 Write a model to a writer.
|
cannam@130
|
633 */
|
cannam@130
|
634 SORD_API
|
cannam@130
|
635 bool
|
cannam@130
|
636 sord_write(SordModel* model,
|
cannam@130
|
637 SerdWriter* writer,
|
cannam@130
|
638 SordNode* graph);
|
cannam@130
|
639
|
cannam@130
|
640 /**
|
cannam@130
|
641 Write a range to a writer.
|
cannam@130
|
642
|
cannam@130
|
643 This increments `iter` to its end, then frees it.
|
cannam@130
|
644 */
|
cannam@130
|
645 SORD_API
|
cannam@130
|
646 bool
|
cannam@130
|
647 sord_write_iter(SordIter* iter,
|
cannam@130
|
648 SerdWriter* writer);
|
cannam@130
|
649
|
cannam@130
|
650 /**
|
cannam@130
|
651 @}
|
cannam@130
|
652 @}
|
cannam@130
|
653 */
|
cannam@130
|
654
|
cannam@130
|
655 #ifdef __cplusplus
|
cannam@130
|
656 } /* extern "C" */
|
cannam@130
|
657 #endif
|
cannam@130
|
658
|
cannam@130
|
659 #endif /* SORD_SORD_H */
|