Volksdata 1.0b10
RDF library
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1#ifndef VOLK_GRAPH_H
2#define VOLK_GRAPH_H
3
4#include "volksdata/store.h"
5#include "volksdata/term.h"
6
7
12
32typedef struct graph_t VOLK_Graph;
33
40typedef struct graph_iter_t VOLK_GraphIterator;
41
42
59VOLK_Graph *
60VOLK_graph_new (VOLK_Store *store, const char *uri_str);
61
62
74inline VOLK_Graph *
75VOLK_graph_new_ns (VOLK_Store *store, const char *ns_str) {
76 if (!ns_str) {
77 log_error ("Cannot pass NULL as namespace-prefixed URI.");
78 return NULL;
79 }
80 char *uri_str;
81 RCNL (VOLK_nsmap_normalize_uri (ns_str, &uri_str));
82
83 VOLK_Graph *gr = VOLK_graph_new (store, uri_str);
84 free (uri_str);
85
86 return gr;
87};
88
89
109VOLK_Graph *
111 void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct);
112
114#define VOLK_graph_get(...) VOLK_graph_get_txn (NULL, __VA_ARGS__)
115
116
139 void *txn, const VOLK_Graph *src, VOLK_Graph *dest,
140 const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o);
141
142/* @brief Copy all triples from a graph (non-transactional).
143 *
144 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
145 * specify a transaction handle for the copy, use that.
146 *
147 * @param[in] src Source graph.
148 *
149 * @param[in] dest Destination graph.
150 *
151 * @param[in] s, p, o Terms to look up for filtering. Any and all terms can be
152 * NULL, which indicate unbound terms.
153 *
154 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
155 * if an error occurred.
156 */
157#define VOLK_graph_copy_contents(...) \
158 VOLK_graph_copy_contents_txn (NULL, __VA_ARGS__)
159
160
161/* @brief Copy all triples from a graph.
162 *
163 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
164 * specify a transaction handle and/or a filter for the copy, use that.
165 *
166 * @param[in] src Source graph.
167 *
168 * @param[in] dest Destination graph.
169 *
170 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
171 * if an error occurred.
172 */
173#define VOLK_graph_copy(src, dest) \
174 VOLK_graph_copy_contents_txn (NULL, src, dest, NULL, NULL, NULL)
175
176
204 void *txn, const VOLK_bool_op op,
205 const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res);
206
208#define VOLK_graph_bool_op(...) VOLK_graph_bool_op_txn (NULL, __VA_ARGS__)
209
210
213void
214VOLK_graph_free (VOLK_Graph *gr);
215
216
230bool
231VOLK_graph_equals_txn (void *txn, const VOLK_Graph *gr1, const VOLK_Graph *gr2);
232
234#define VOLK_graph_equals(...) VOLK_graph_equals_txn (NULL, __VA_ARGS__)
235
236
244const VOLK_Term *
245VOLK_graph_uri (const VOLK_Graph *gr);
246
247
251VOLK_graph_store (const VOLK_Graph *gr);
252
253
273VOLK_graph_set_uri_txn (void *txn, VOLK_Graph *gr, const char *uri_str);
274
276#define VOLK_graph_set_uri(...) VOLK_graph_set_uri_txn (NULL, __VA_ARGS__)
277
278
287size_t
288VOLK_graph_size_txn (void *txn, const VOLK_Graph *gr);
289
291#define VOLK_graph_size(...) VOLK_graph_size_txn (NULL, __VA_ARGS__)
292
293
304bool
306 void *txn, const VOLK_Graph *gr, const VOLK_Triple *spo);
307
309#define VOLK_graph_contains(...) VOLK_graph_contains_txn (NULL, __VA_ARGS__)
310
311
324VOLK_GraphIterator *
325VOLK_graph_add_init_txn (void *txn, VOLK_Graph *gr);
326
328#define VOLK_graph_add_init(...) VOLK_graph_add_init_txn (NULL, __VA_ARGS__)
329
330
342VOLK_graph_add_iter (VOLK_GraphIterator *it, const VOLK_Triple *spo);
343
344
362 void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct);
363
365#define VOLK_graph_add(...) VOLK_graph_add_txn (NULL, __VA_ARGS__)
366
367
381 void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p,
382 const VOLK_Term *o, size_t *ct);
383
385#define VOLK_graph_remove(...) VOLK_graph_remove_txn (NULL, __VA_ARGS__)
386
387
409VOLK_GraphIterator *
410VOLK_graph_lookup_txn (void *txn, const VOLK_Graph *gr, const VOLK_Term *s,
411 const VOLK_Term *p, const VOLK_Term *o, size_t *ct);
412
414#define VOLK_graph_lookup(...) VOLK_graph_lookup_txn (NULL, __VA_ARGS__)
415
416
429VOLK_graph_iter_next (VOLK_GraphIterator *it, VOLK_Triple **spo);
430
431
434const VOLK_Graph *
435VOLK_graph_iter_graph (VOLK_GraphIterator *it);
436
437
445void
446VOLK_graph_iter_free (VOLK_GraphIterator *it);
447
448
453void
454VOLK_graph_print (const VOLK_Graph *gr);
455
456
478 void *txn, const VOLK_Graph *gr, const VOLK_Term *t,
479 const VOLK_LinkType type
480);
481
483#define VOLK_graph_connections(...) \
484 VOLK_graph_connections_txn (NULL, __VA_ARGS__)
485
486
505 void *txn, const VOLK_Graph *gr,
506 const VOLK_Term *t1, const VOLK_TriplePos t1_pos,
507 const VOLK_Term *t2, const VOLK_TriplePos t2_pos);
508
510#define VOLK_graph_term_set(...) VOLK_graph_term_set_txn (NULL, __VA_ARGS__)
511
512
523 void *txn, const VOLK_Graph *gr, VOLK_TriplePos pos);
524
526#define VOLK_graph_unique_terms(...) \
527 VOLK_graph_unique_terms_txn (NULL, __VA_ARGS__)
528
529
542size_t
543VOLK_graph_add_link_map ( VOLK_GraphIterator *it, VOLK_LinkMap *lm);
544
545
557VOLK_Term *
558VOLK_bnode_add_collection (VOLK_GraphIterator *it, VOLK_TermSet *ts);
559
561
562#endif // VOLK_GRAPH_H
#define RCNL(exp)
Return NULL if exp returns a nonzero value.
Definition core.h:379
int VOLK_rc
Return code.
Definition core.h:91
struct hashmap VOLK_TermSet
a set of unique terms.
Definition term.h:123
VOLK_LinkType
Link type.
Definition term.h:93
VOLK_TriplePos
Triple position of s, p, o.
Definition buffer.h:19
VOLK_Graph * VOLK_graph_new_ns(VOLK_Store *store, const char *ns_str)
Create an empty graph using a namespace-prefixed string for its URI.
Definition graph.h:75
bool VOLK_graph_contains_txn(void *txn, const VOLK_Graph *gr, const VOLK_Triple *spo)
Whether a graph contains a triple.
Definition graph.c:717
const VOLK_Graph * VOLK_graph_iter_graph(VOLK_GraphIterator *it)
Return the graph related to an iterator.
Definition graph.c:678
void VOLK_graph_print(const VOLK_Graph *gr)
Print graph information and triples to stdout.
Definition graph.c:733
size_t VOLK_graph_size_txn(void *txn, const VOLK_Graph *gr)
Number of triples in a graph.
Definition graph.c:328
VOLK_Graph * VOLK_graph_get_txn(void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct)
Create a temp graph from stored triples.
Definition graph.c:67
VOLK_LinkMap * VOLK_graph_connections_txn(void *txn, const VOLK_Graph *gr, const VOLK_Term *t, const VOLK_LinkType type)
Get term pairs connected to a term in a graph.
Definition graph.c:763
size_t VOLK_graph_add_link_map(VOLK_GraphIterator *it, VOLK_LinkMap *lm)
Add triples for a term and related link map to a graph.
Definition graph.c:885
VOLK_rc VOLK_graph_remove_txn(void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
Delete triples by a matching pattern.
Definition graph.c:518
VOLK_rc VOLK_graph_copy_contents_txn(void *txn, const VOLK_Graph *src, VOLK_Graph *dest, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o)
Copy triples from a source graph into a destination one.
Definition graph.c:549
void VOLK_graph_free(VOLK_Graph *gr)
Free a graph.
Definition graph.c:263
VOLK_rc VOLK_graph_add_txn(void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct)
Add triples to a graph.
Definition graph.c:484
VOLK_GraphIterator * VOLK_graph_lookup_txn(void *txn, const VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o, size_t *ct)
Look up triples by a matching pattern and yield an iterator.
Definition graph.c:599
VOLK_rc VOLK_graph_bool_op_txn(void *txn, const VOLK_bool_op op, const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res)
Definition graph.c:111
VOLK_rc VOLK_graph_set_uri_txn(void *txn, VOLK_Graph *gr, const char *uri_str)
Definition graph.c:287
VOLK_Store * VOLK_graph_store(const VOLK_Graph *gr)
Underlying graph store handle.
Definition graph.c:282
VOLK_TermSet * VOLK_graph_unique_terms_txn(void *txn, const VOLK_Graph *gr, VOLK_TriplePos pos)
Get all unique subjcts, predicates, or objects in a graph.
Definition graph.c:864
VOLK_GraphIterator * VOLK_graph_add_init_txn(void *txn, VOLK_Graph *gr)
Initialize an iterator to add triples.
Definition graph.c:410
VOLK_rc VOLK_graph_iter_next(VOLK_GraphIterator *it, VOLK_Triple **spo)
Advance a cursor obtained by a lookup and return a matching triple.
Definition graph.c:658
VOLK_TermSet * VOLK_graph_term_set_txn(void *txn, const VOLK_Graph *gr, const VOLK_Term *t1, const VOLK_TriplePos t1_pos, const VOLK_Term *t2, const VOLK_TriplePos t2_pos)
Get a list of terms related to a term pair in a graph.
Definition graph.c:829
VOLK_Term * VOLK_bnode_add_collection(VOLK_GraphIterator *it, VOLK_TermSet *ts)
Add triples for an anonymous collection to a graph.
Definition graph.c:904
bool VOLK_graph_equals_txn(void *txn, const VOLK_Graph *gr1, const VOLK_Graph *gr2)
Compare two graphs.
Definition graph.c:354
VOLK_rc VOLK_graph_add_iter(VOLK_GraphIterator *it, const VOLK_Triple *spo)
Add a single triple to the store.
Definition graph.c:427
void VOLK_graph_iter_free(VOLK_GraphIterator *it)
Free a graph iterator.
Definition graph.c:688
VOLK_Graph * VOLK_graph_new(VOLK_Store *store, const char *uri_str)
Create new graph.
Definition graph.c:45
const VOLK_Term * VOLK_graph_uri(const VOLK_Graph *gr)
Read-only graph URI.
Definition graph.c:278
VOLK_rc VOLK_nsmap_normalize_uri(const char *pfx_uri, char **fq_uri_p)
Convert a namespace-prefixed string to a FQ URI sring if mapped.
Definition namespace.c:110
VOLK_bool_op
Boolean operations that can be performed on a graph.
Definition core.h:235
Generic store dependency.
Store structure.
Definition store.h:59
RDF term.
Definition term.h:61
RDF triple.
Definition term.h:85
Graph iterator.
Definition graph.c:12
size_t ct
Total lookup matches.
Definition graph.c:15
Graph object.
Definition graph.c:7