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
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 char *uri_str;
77 RCNL (VOLK_nsmap_normalize_uri (ns_str, &uri_str));
78
79 VOLK_Graph *gr = VOLK_graph_new (store, uri_str);
80 free (uri_str);
81
82 return gr;
83};
84
85
105VOLK_Graph *
107 void *txn, VOLK_Store *store, const VOLK_Term *uri, size_t *ct);
108
110#define VOLK_graph_get(...) VOLK_graph_get_txn (NULL, __VA_ARGS__)
111
112
135 void *txn, const VOLK_Graph *src, VOLK_Graph *dest,
136 const VOLK_Term *s, const VOLK_Term *p, const VOLK_Term *o);
137
138/* @brief Copy all triples from a graph (non-transactional).
139 *
140 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
141 * specify a transaction handle for the copy, use that.
142 *
143 * @param[in] src Source graph.
144 *
145 * @param[in] dest Destination graph.
146 *
147 * @param[in] s, p, o Terms to look up for filtering. Any and all terms can be
148 * NULL, which indicate unbound terms.
149 *
150 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
151 * if an error occurred.
152 */
153#define VOLK_graph_copy_contents(...) \
154 VOLK_graph_copy_contents_txn (NULL, __VA_ARGS__)
155
156
157/* @brief Copy all triples from a graph.
158 *
159 * This is a shortcut for #VOLK_graph_copy_contents_txn(). If you need to
160 * specify a transaction handle and/or a filter for the copy, use that.
161 *
162 * @param[in] src Source graph.
163 *
164 * @param[in] dest Destination graph.
165 *
166 * @return VOLK_OK on success; VOLK_NOACTION if no triples were copied; <0
167 * if an error occurred.
168 */
169#define VOLK_graph_copy(src, dest) \
170 VOLK_graph_copy_contents_txn (NULL, src, dest, NULL, NULL, NULL)
171
172
198 void *txn, const VOLK_bool_op op,
199 const VOLK_Graph *gr1, const VOLK_Graph *gr2, VOLK_Graph *res);
200
202#define VOLK_graph_bool_op(...) VOLK_graph_bool_op_txn (NULL, __VA_ARGS__)
203
204
207void
208VOLK_graph_free (VOLK_Graph *gr);
209
210
224bool
225VOLK_graph_equals_txn (void *txn, const VOLK_Graph *gr1, const VOLK_Graph *gr2);
226
228#define VOLK_graph_equals(...) VOLK_graph_equals_txn (NULL, __VA_ARGS__)
229
230
238const VOLK_Term *
239VOLK_graph_uri (const VOLK_Graph *gr);
240
241
245VOLK_graph_store (const VOLK_Graph *gr);
246
247
267VOLK_graph_set_uri_txn (void *txn, VOLK_Graph *gr, const char *uri_str);
268
270#define VOLK_graph_set_uri(...) VOLK_graph_set_uri_txn (NULL, __VA_ARGS__)
271
272
281size_t
282VOLK_graph_size_txn (void *txn, const VOLK_Graph *gr);
283
285#define VOLK_graph_size(...) VOLK_graph_size_txn (NULL, __VA_ARGS__)
286
287
298bool
300 void *txn, const VOLK_Graph *gr, const VOLK_Triple *spo);
301
303#define VOLK_graph_contains(...) VOLK_graph_contains_txn (NULL, __VA_ARGS__)
304
305
316VOLK_GraphIterator *
317VOLK_graph_add_init_txn (void *txn, VOLK_Graph *gr);
318
320#define VOLK_graph_add_init(...) VOLK_graph_add_init_txn (NULL, __VA_ARGS__)
321
322
331VOLK_graph_add_iter (VOLK_GraphIterator *it, const VOLK_Triple *spo);
332
333
347 void *txn, VOLK_Graph *gr, VOLK_Triple *const *trp, size_t *ct);
348
350#define VOLK_graph_add(...) VOLK_graph_add_txn (NULL, __VA_ARGS__)
351
352
366 void *txn, VOLK_Graph *gr, const VOLK_Term *s, const VOLK_Term *p,
367 const VOLK_Term *o, size_t *ct);
368
370#define VOLK_graph_remove(...) VOLK_graph_remove_txn (NULL, __VA_ARGS__)
371
372
394VOLK_GraphIterator *
395VOLK_graph_lookup_txn (void *txn, const VOLK_Graph *gr, const VOLK_Term *s,
396 const VOLK_Term *p, const VOLK_Term *o, size_t *ct);
397
399#define VOLK_graph_lookup(...) VOLK_graph_lookup_txn (NULL, __VA_ARGS__)
400
401
414VOLK_graph_iter_next (VOLK_GraphIterator *it, VOLK_Triple **spo);
415
416
419const VOLK_Graph *
420VOLK_graph_iter_graph (VOLK_GraphIterator *it);
421
422
430void
431VOLK_graph_iter_free (VOLK_GraphIterator *it);
432
433
438void
439VOLK_graph_print (const VOLK_Graph *gr);
440
441
463 void *txn, const VOLK_Graph *gr, const VOLK_Term *t,
464 const VOLK_LinkType type
465);
466
468#define VOLK_graph_connections(...) \
469 VOLK_graph_connections_txn (NULL, __VA_ARGS__)
470
471
490 void *txn, const VOLK_Graph *gr,
491 const VOLK_Term *t1, const VOLK_TriplePos t1_pos,
492 const VOLK_Term *t2, const VOLK_TriplePos t2_pos);
493
495#define VOLK_graph_term_set(...) VOLK_graph_term_set_txn (NULL, __VA_ARGS__)
496
497
508 void *txn, const VOLK_Graph *gr, VOLK_TriplePos pos);
509
511#define VOLK_graph_unique_terms(...) \
512 VOLK_graph_unique_terms_txn (NULL, __VA_ARGS__)
513
514
524VOLK_graph_list_txn (void *txn, VOLK_Store *store);
525
527#define VOLK_graph_list(...) VOLK_graph_list_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
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:661
const VOLK_Graph * VOLK_graph_iter_graph(VOLK_GraphIterator *it)
Return the graph related to an iterator.
Definition graph.c:595
VOLK_TermSet * VOLK_graph_list_txn(void *txn, VOLK_Store *store)
List all graph URIs in a store.
Definition graph.c:634
void VOLK_graph_print(const VOLK_Graph *gr)
Print graph information and triples to stdout.
Definition graph.c:677
size_t VOLK_graph_size_txn(void *txn, const VOLK_Graph *gr)
Number of triples in a graph.
Definition graph.c:311
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
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:705
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:825
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:487
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:515
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_rc VOLK_graph_set_uri_txn(void *txn, VOLK_Graph *gr, const char *uri_str)
Definition graph.c:272
VOLK_Store * VOLK_graph_store(const VOLK_Graph *gr)
Underlying graph store handle.
Definition graph.c:267
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:802
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:575
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:767
VOLK_Term * VOLK_bnode_add_collection(VOLK_GraphIterator *it, VOLK_TermSet *ts)
Add triples for an anonymous collection to a graph.
Definition graph.c:844
bool VOLK_graph_equals_txn(void *txn, const VOLK_Graph *gr1, const VOLK_Graph *gr2)
Compare two graphs.
Definition graph.c:330
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:605
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
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:352
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