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