Volksdata 1.0b7
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
15typedef struct graph_t VOLK_Graph;
16
23typedef struct graph_iter_t VOLK_GraphIterator;
24
25
38VOLK_Graph *
39VOLK_graph_new (VOLK_Store *store, const char *uri_str);
40
41
53inline VOLK_Graph *
54VOLK_graph_new_ns (VOLK_Store *store, const char *ns_str) {
55 char *uri_str;
56 RCNL (VOLK_nsmap_normalize_uri (ns_str, &uri_str));
57
58 VOLK_Graph *gr = VOLK_graph_new (store, uri_str);
59 free (uri_str);
60
61 return gr;
62};
63
64
84VOLK_Graph *
86 void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct);
87
88
90#define VOLK_graph_get(...) VOLK_graph_get_txn (NULL, __VA_ARGS__)
91
92
115 void *txn, const VOLK_Graph *src, VOLK_Graph *dest,
116 const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o);
117
118
119/* @brief Copy all triples from a graph (non-transactional).
120 *
121 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
122 * specify a transaction handle for the copy, use that.
123 *
124 * @param[in] src Source graph.
125 *
126 * @param[in] dest Destination graph.
127 *
128 * @param[in] s, p, o Terms to look up for filtering. Any and all terms can be
129 * NULL, which indicate unbound terms.
130 *
131 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
132 * if an error occurred.
133 */
134#define VOLK_graph_copy_contents(...) \
135 VOLK_graph_copy_contents_txn (NULL, __VA_ARGS__)
136
137
138/* @brief Copy all triples from a graph.
139 *
140 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
141 * specify a transaction handle and/or a filter for the copy, use that.
142 *
143 * @param[in] src Source graph.
144 *
145 * @param[in] dest Destination graph.
146 *
147 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
148 * if an error occurred.
149 */
150#define VOLK_graph_copy(src, dest) \
151 VOLK_graph_copy_contents_txn (NULL, src, dest, NULL, NULL, NULL)
152
153
179 void *txn, const VOLK_bool_op op,
180 const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res);
181
182
184#define VOLK_graph_bool_op(...) VOLK_graph_bool_op_txn (NULL, __VA_ARGS__)
185
186
189void
190VOLK_graph_free (VOLK_Graph *gr);
191
192
204bool
205VOLK_graph_equals (const VOLK_Graph *gr1, const VOLK_Graph *gr2);
206
207
215const VOLK_Term *
216VOLK_graph_uri (const VOLK_Graph *gr);
217
218
222VOLK_graph_store (const VOLK_Graph *gr);
223
224
242VOLK_graph_set_uri (VOLK_Graph *gr, const char *uri_str);
243
244
251size_t
252VOLK_graph_size (const VOLK_Graph *gr);
253
254
263bool
264VOLK_graph_contains (const VOLK_Graph *gr, const VOLK_Triple *spo);
265
266
277VOLK_GraphIterator *
278VOLK_graph_add_init_txn (void *txn, VOLK_Graph *gr);
279
280
282#define VOLK_graph_add_init(...) VOLK_graph_add_init_txn (NULL, __VA_ARGS__)
283
284
293VOLK_graph_add_iter (VOLK_GraphIterator *it, const VOLK_Triple *spo);
294
295
309 void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct);
310
311
313#define VOLK_graph_add(...) VOLK_graph_add_txn (NULL, __VA_ARGS__)
314
315
329 void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p,
330 const VOLK_Term *o, size_t *ct);
331
332
334#define VOLK_graph_remove(...) VOLK_graph_remove_txn (NULL, __VA_ARGS__)
335
336
358VOLK_GraphIterator *
359VOLK_graph_lookup_txn (void *txn, const VOLK_Graph *gr, const VOLK_Term *s,
360 const VOLK_Term *p, const VOLK_Term *o, size_t *ct);
361
362
364#define VOLK_graph_lookup(...) VOLK_graph_lookup_txn (NULL, __VA_ARGS__)
365
366
379VOLK_graph_iter_next (VOLK_GraphIterator *it, VOLK_Triple **spo);
380
381
384const VOLK_Graph *
385VOLK_graph_iter_graph (VOLK_GraphIterator *it);
386
387
395void
396VOLK_graph_iter_free (VOLK_GraphIterator *it);
397
398
403void
404VOLK_graph_print (const VOLK_Graph *gr);
405
406
426 const VOLK_Graph *gr, const VOLK_Term *t, const VOLK_LinkType type);
427
428
445 const VOLK_Graph *gr, const VOLK_Term *t1, const VOLK_TriplePos t1_pos,
446 const VOLK_Term *t2, const VOLK_TriplePos t2_pos);
447
448
456VOLK_graph_unique_terms (const VOLK_Graph *gr, VOLK_TriplePos pos);
457
458
468VOLK_graph_list_txn (void *txn, VOLK_Store *store);
469
470
472#define VOLK_graph_list(...) VOLK_graph_list_txn (NULL, __VA_ARGS__)
473
474
487size_t
488VOLK_graph_add_link_map ( VOLK_GraphIterator *it, VOLK_LinkMap *lm);
489
490
502VOLK_Term *
503VOLK_bnode_add_collection (VOLK_GraphIterator *it, VOLK_TermSet *ts);
504
506
507#endif // VOLK_GRAPH_H
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:54
const VOLK_Graph * VOLK_graph_iter_graph(VOLK_GraphIterator *it)
Return the graph related to an iterator.
Definition graph.c:588
VOLK_TermSet * VOLK_graph_list_txn(void *txn, VOLK_Store *store)
List all graph URIs in a store.
Definition graph.c:627
void VOLK_graph_print(const VOLK_Graph *gr)
Print graph information and triples to stdout.
Definition graph.c:669
VOLK_LinkMap * VOLK_graph_connections(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:697
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:63
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:812
bool VOLK_graph_contains(const VOLK_Graph *gr, const VOLK_Triple *spo)
Whether a graph contains a triple.
Definition graph.c:654
bool VOLK_graph_equals(const VOLK_Graph *gr1, const VOLK_Graph *gr2)
Compare two graphs.
Definition graph.c:330
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:456
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:480
void VOLK_graph_free(VOLK_Graph *gr)
Free a graph.
Definition graph.c:246
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:422
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:508
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:100
VOLK_TermSet * VOLK_graph_unique_terms(const VOLK_Graph *gr, VOLK_TriplePos pos)
Get all unique subjcts, predicates, or objects in a graph.
Definition graph.c:791
VOLK_Store * VOLK_graph_store(const VOLK_Graph *gr)
Underlying graph store handle.
Definition graph.c:267
VOLK_GraphIterator * VOLK_graph_add_init_txn(void *txn, VOLK_Graph *gr)
Initialize an iterator to add triples.
Definition graph.c:343
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:568
VOLK_rc VOLK_graph_set_uri(VOLK_Graph *gr, const char *uri_str)
Definition graph.c:272
VOLK_Term * VOLK_bnode_add_collection(VOLK_GraphIterator *it, VOLK_TermSet *ts)
Add triples for an anonymous collection to a graph.
Definition graph.c:831
VOLK_rc VOLK_graph_add_iter(VOLK_GraphIterator *it, const VOLK_Triple *spo)
Add a single triple to the store.
Definition graph.c:360
void VOLK_graph_iter_free(VOLK_GraphIterator *it)
Free a graph iterator.
Definition graph.c:598
VOLK_TermSet * VOLK_graph_term_set(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:757
VOLK_Graph * VOLK_graph_new(VOLK_Store *store, const char *uri_str)
Create new graph.
Definition graph.c:44
const VOLK_Term * VOLK_graph_uri(const VOLK_Graph *gr)
Read-only graph URI.
Definition graph.c:263
size_t VOLK_graph_size(const VOLK_Graph *gr)
Number of triples in a graph.
Definition graph.c:311
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
#define RCNL(exp)
Return NULL if exp returns a nonzero value.
Definition core.h:345
VOLK_bool_op
Boolean operations that can be performed on a graph.
Definition core.h:221
int VOLK_rc
Definition core.h:79
struct hashmap VOLK_TermSet
a set of unique terms.
Definition term.h:124
VOLK_LinkType
Link type.
Definition term.h:94
Generic store dependency.
Store structure.
Definition store.h:59
RDF term.
Definition term.h:62
RDF triple.
Definition term.h:86
Graph iterator.
Definition graph.c:12
size_t ct
Total lookup matches.
Definition graph.c:15
Graph object.
Definition graph.c:7