Volksdata 1.0b12
RDF library and triple store
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
141 void *txn, const VOLK_Graph *src, VOLK_Graph *dest,
142 const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o);
143
144/* @brief Copy all triples from a graph (non-transactional).
145 *
146 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
147 * specify a transaction handle for the copy, use that.
148 *
149 * @param[in] src Source graph.
150 *
151 * @param[in] dest Destination graph.
152 *
153 * @param[in] s, p, o Terms to look up for filtering. Any and all terms can be
154 * NULL, which indicate unbound terms.
155 *
156 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
157 * if an error occurred.
158 */
159#define VOLK_graph_copy_contents(...) \
160 VOLK_graph_copy_contents_txn (NULL, __VA_ARGS__)
161
162
163/* @brief Copy all triples from a graph.
164 *
165 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
166 * specify a transaction handle and/or a filter for the copy, use that.
167 *
168 * @param[in] src Source graph.
169 *
170 * @param[in] dest Destination graph.
171 *
172 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
173 * if an error occurred.
174 */
175#define VOLK_graph_copy(src, dest) \
176 VOLK_graph_copy_contents_txn (NULL, src, dest, NULL, NULL, NULL)
177
178
206 void *txn, const VOLK_bool_op op,
207 const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res);
208
210#define VOLK_graph_bool_op(...) VOLK_graph_bool_op_txn (NULL, __VA_ARGS__)
211
212
215void
216VOLK_graph_free (VOLK_Graph *gr);
217
218
232bool
233VOLK_graph_equals_txn (void *txn, const VOLK_Graph *gr1, const VOLK_Graph *gr2);
234
236#define VOLK_graph_equals(...) VOLK_graph_equals_txn (NULL, __VA_ARGS__)
237
238
246const VOLK_Term *
247VOLK_graph_uri (const VOLK_Graph *gr);
248
249
253VOLK_graph_store (const VOLK_Graph *gr);
254
255
275VOLK_graph_set_uri_txn (void *txn, VOLK_Graph *gr, const char *uri_str);
276
278#define VOLK_graph_set_uri(...) VOLK_graph_set_uri_txn (NULL, __VA_ARGS__)
279
280
289size_t
290VOLK_graph_size_txn (void *txn, const VOLK_Graph *gr);
291
293#define VOLK_graph_size(...) VOLK_graph_size_txn (NULL, __VA_ARGS__)
294
295
306bool
308 void *txn, const VOLK_Graph *gr, const VOLK_Triple *spo);
309
311#define VOLK_graph_contains(...) VOLK_graph_contains_txn (NULL, __VA_ARGS__)
312
313
326VOLK_GraphIterator *
327VOLK_graph_add_init_txn (void *txn, VOLK_Graph *gr);
328
330#define VOLK_graph_add_init(...) VOLK_graph_add_init_txn (NULL, __VA_ARGS__)
331
332
344VOLK_graph_add_iter (VOLK_GraphIterator *it, const VOLK_Triple *spo);
345
346
364 void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct);
365
367#define VOLK_graph_add(...) VOLK_graph_add_txn (NULL, __VA_ARGS__)
368
369
383 void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p,
384 const VOLK_Term *o, size_t *ct);
385
387#define VOLK_graph_remove(...) VOLK_graph_remove_txn (NULL, __VA_ARGS__)
388
389
411VOLK_GraphIterator *
412VOLK_graph_lookup_txn (void *txn, const VOLK_Graph *gr, const VOLK_Term *s,
413 const VOLK_Term *p, const VOLK_Term *o, size_t *ct);
414
416#define VOLK_graph_lookup(...) VOLK_graph_lookup_txn (NULL, __VA_ARGS__)
417
418
431VOLK_graph_iter_next (VOLK_GraphIterator *it, VOLK_Triple **spo);
432
433
436const VOLK_Graph *
437VOLK_graph_iter_graph (VOLK_GraphIterator *it);
438
439
447void
448VOLK_graph_iter_free (VOLK_GraphIterator *it);
449
450
455void
456VOLK_graph_print (const VOLK_Graph *gr);
457
458
480 void *txn, const VOLK_Graph *gr, const VOLK_Term *t,
481 const VOLK_LinkType type
482);
483
485#define VOLK_graph_connections(...) \
486 VOLK_graph_connections_txn (NULL, __VA_ARGS__)
487
488
507 void *txn, const VOLK_Graph *gr,
508 const VOLK_Term *t1, const VOLK_TriplePos t1_pos,
509 const VOLK_Term *t2, const VOLK_TriplePos t2_pos);
510
512#define VOLK_graph_term_set(...) VOLK_graph_term_set_txn (NULL, __VA_ARGS__)
513
514
525 void *txn, const VOLK_Graph *gr, VOLK_TriplePos pos);
526
528#define VOLK_graph_unique_terms(...) \
529 VOLK_graph_unique_terms_txn (NULL, __VA_ARGS__)
530
531
544size_t
545VOLK_graph_add_link_map ( VOLK_GraphIterator *it, VOLK_LinkMap *lm);
546
547
559VOLK_Term *
560VOLK_bnode_add_collection (VOLK_GraphIterator *it, VOLK_TermSet *ts);
561
563
564#endif // VOLK_GRAPH_H
#define RCNL(exp)
Return NULL if exp returns a nonzero value.
Definition core.h:405
int VOLK_rc
Return code.
Definition core.h:117
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:729
const VOLK_Graph * VOLK_graph_iter_graph(VOLK_GraphIterator *it)
Return the graph related to an iterator.
Definition graph.c:690
void VOLK_graph_print(const VOLK_Graph *gr)
Print graph information and triples to stdout.
Definition graph.c:745
size_t VOLK_graph_size_txn(void *txn, const VOLK_Graph *gr)
Number of triples in a graph.
Definition graph.c:331
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:775
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:897
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:523
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:554
void VOLK_graph_free(VOLK_Graph *gr)
Free a graph.
Definition graph.c:266
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:489
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:610
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:290
VOLK_Store * VOLK_graph_store(const VOLK_Graph *gr)
Underlying graph store handle.
Definition graph.c:285
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:876
VOLK_GraphIterator * VOLK_graph_add_init_txn(void *txn, VOLK_Graph *gr)
Initialize an iterator to add triples.
Definition graph.c:415
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:670
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:841
VOLK_Term * VOLK_bnode_add_collection(VOLK_GraphIterator *it, VOLK_TermSet *ts)
Add triples for an anonymous collection to a graph.
Definition graph.c:916
bool VOLK_graph_equals_txn(void *txn, const VOLK_Graph *gr1, const VOLK_Graph *gr2)
Compare two graphs.
Definition graph.c:359
VOLK_rc VOLK_graph_add_iter(VOLK_GraphIterator *it, const VOLK_Triple *spo)
Add a single triple to the store.
Definition graph.c:432
void VOLK_graph_iter_free(VOLK_GraphIterator *it)
Free a graph iterator.
Definition graph.c:700
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:281
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:261
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