Volksdata 1.0b10
RDF library
Loading...
Searching...
No Matches
term.h
Go to the documentation of this file.
1#ifndef VOLK_TERM_H
2#define VOLK_TERM_H
3
4#include "volksdata/buffer.h"
6
7
12
13#define UUID4_URN_SIZE UUIDSTR_SIZE + 10
14
15// Some common RDF term values.
16#define VOLK_RDF_TYPE "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
17#define VOLK_RDF_TYPE_NS "rdf:type"
19#define DEFAULT_DTYPE "http://www.w3.org/2001/XMLSchema#string"
20#define DEFAULT_DTYPE_NS "xsd:string"
21
22/*
23 * Data types.
24 */
25
27typedef char VOLK_LangTag[8];
28
39
41typedef struct match_coord_t {
42 unsigned int offset;
43 unsigned int size;
45
56
58typedef struct link_map_iter VOLK_LinkMapIterator;
59
61typedef struct term_t {
62 char * data;
63 union {
64 struct term_t * datatype;
67 void * metadata;
68 };
70} VOLK_Term;
71
72
75#define VOLK_IS_LITERAL(term) \
76 ((term)->type == VOLK_TERM_LITERAL || (term)->type == VOLK_TERM_LT_LITERAL)
77
78
85typedef struct triple_t {
90
91
98
99
116typedef struct link_map VOLK_LinkMap;
117
118
123typedef struct hashmap VOLK_TermSet;
124
125
126/*
127 * External variables.
128 */
129
132extern uint32_t VOLK_default_dtype_key;
133
140
146
149
150
151/*
152 * API functions.
153 */
154
173VOLK_Term *
174VOLK_term_new (VOLK_TermType type, const char *data, void *metadata);
175
176
179#define TERM_DUMMY VOLK_term_new (VOLK_TERM_UNDEFINED, NULL, NULL)
180
181
190inline VOLK_Term *
191VOLK_iriref_new (const char *data)
192{ return VOLK_term_new (VOLK_TERM_IRIREF, data, NULL); }
193
194
203inline VOLK_Term *
204VOLK_iriref_new_ns (const char *data)
205{
206 char *fquri;
207 RCNL (VOLK_nsmap_normalize_uri (data, &fquri));
208
209 VOLK_Term *t = VOLK_term_new (VOLK_TERM_IRIREF, fquri, NULL);
210 free (fquri);
211
212 return t;
213}
214
215
233VOLK_Term *
234VOLK_iriref_new_abs (const VOLK_Term *root, const VOLK_Term *iri);
235
236
249VOLK_Term *
250VOLK_iriref_new_rel (const VOLK_Term *root, const VOLK_Term *iri);
251
252
265inline VOLK_Term *
266VOLK_literal_new (const char *data, VOLK_Term *datatype)
267{ return VOLK_term_new (VOLK_TERM_LITERAL, data, datatype); }
268
269
303VOLK_parse_iri (char *iri_str, VOLK_IRIInfo *iri_info);
304
305
316inline VOLK_Term *
317VOLK_lt_literal_new (const char *data, char *lang)
318{ return VOLK_term_new (VOLK_TERM_LT_LITERAL, data, lang); }
319
320
330inline VOLK_Term *
331VOLK_bnode_new (const char *data)
332{ return VOLK_term_new (VOLK_TERM_BNODE, data, NULL); }
333
334
343VOLK_Term *
344VOLK_term_copy (const VOLK_Term *src);
345
346
354VOLK_Term *
356
357
365VOLK_term_serialize (const VOLK_Term *term);
366
367
371VOLK_term_hash (const VOLK_Term *term);
372
373
379inline bool VOLK_term_equals (const VOLK_Term *term1, const VOLK_Term *term2)
380{ return term1 == term2 || VOLK_term_hash (term1) == VOLK_term_hash (term2); }
381
382
383void
385
386
394char *
395VOLK_iriref_prefix (const VOLK_Term *iri);
396
397
406char *
407VOLK_iriref_path (const VOLK_Term *iri);
408
409
417char *
418VOLK_iriref_frag (const VOLK_Term *iri);
419
420/*
421 * TRIPLES
422 */
423
440
441
444#define TRP_DUMMY VOLK_triple_new (NULL, NULL, NULL)
445
446
449
450
453
454
469
470
475void
477
478
486void
488
489
500inline VOLK_Term *
502{
503 if (n == TRP_POS_S) return trp->s;
504 if (n == TRP_POS_P) return trp->p;
505 if (n == TRP_POS_O) return trp->o;
506 return NULL;
507}
508
509
514inline VOLK_Key
516{
518 VOLK_Key hash = VOLK_btriple_hash (strp);
519 VOLK_btriple_free (strp);
520
521 return hash;
522}
523
524
530VOLK_term_set_new (void);
531
532
537void
539
540
564 VOLK_TermSet *ts, VOLK_Term *term, VOLK_Term **ins);
565
566
576const VOLK_Term *
578
579
593VOLK_term_set_next (VOLK_TermSet *ts, size_t *i, VOLK_Term **term);
594
595
611
612
620VOLK_Term *
622
623
630size_t
632
633
645VOLK_link_map_new (const VOLK_Term *linked_term, VOLK_LinkType type);
646
647
654void
656
657
664
665
687 VOLK_LinkMap *lmap, VOLK_Term *term, VOLK_TermSet *tset);
688
689
694VOLK_LinkMapIterator *
696
697
713 VOLK_LinkMapIterator *it, VOLK_Term **lt, VOLK_TermSet **ts);
714
715
717void
718VOLK_link_map_iter_free (VOLK_LinkMapIterator *it);
719
720
738VOLK_link_map_triples (VOLK_LinkMapIterator *it, VOLK_Triple *spo);
739
741
742#endif // VOLK_TERM_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
VOLK_Key VOLK_triple_hash(const VOLK_Triple *trp)
Hash a triple.
Definition term.h:515
VOLK_Term * VOLK_lt_literal_new(const char *data, char *lang)
Shortcut to create a language-tagged literal term.
Definition term.h:317
VOLK_Triple * VOLK_triple_new_from_btriple(const VOLK_BufferTriple *sspo)
Definition term.c:470
struct hashmap VOLK_TermSet
a set of unique terms.
Definition term.h:123
VOLK_rc VOLK_term_set_next(VOLK_TermSet *ts, size_t *i, VOLK_Term **term)
Iterate trough a term set.
Definition term.c:597
VOLK_Triple * VOLK_triple_new(VOLK_Term *s, VOLK_Term *p, VOLK_Term *o)
Create a new triple from three terms.
Definition term.c:455
char * VOLK_iriref_frag(const VOLK_Term *iri)
Get the fragment portion of a IRI ref.
Definition term.c:435
VOLK_Term * VOLK_iriref_new_rel(const VOLK_Term *root, const VOLK_Term *iri)
Create a new relative IRI from an absolute IRI and a web root IRI.
Definition term.c:278
VOLK_rc VOLK_parse_iri(char *iri_str, VOLK_IRIInfo *iri_info)
scan an IRI string and parse IRI parts.
Definition term.c:907
void VOLK_link_map_iter_free(VOLK_LinkMapIterator *it)
Free a link map iterator.
Definition term.c:741
VOLK_LinkType
Link type.
Definition term.h:93
VOLK_Term * VOLK_iriref_new(const char *data)
Create an IRI reference.
Definition term.h:191
VOLK_TermType
Term type.
Definition term.h:30
bool VOLK_term_equals(const VOLK_Term *term1, const VOLK_Term *term2)
Compare two terms.
Definition term.h:379
size_t VOLK_term_set_size(VOLK_TermSet *ts)
Size of a term set.
Definition term.c:646
VOLK_rc VOLK_term_set_remove(VOLK_TermSet *ts, VOLK_Term *term)
Remove a specific term from a term set.
Definition term.c:617
VOLK_Term * VOLK_iriref_new_abs(const VOLK_Term *root, const VOLK_Term *iri)
Create a new absolute IRI from a path relative to a root IRI.
Definition term.c:236
VOLK_Term * VOLK_literal_new(const char *data, VOLK_Term *datatype)
Shortcut to create a literal term.
Definition term.h:266
VOLK_LinkMapIterator * VOLK_link_map_iter_new(const VOLK_LinkMap *lmap)
Create a new iterator to loop through a link map.
Definition term.c:729
char * VOLK_iriref_prefix(const VOLK_Term *iri)
Get the prefix portion of a IRI ref.
Definition term.c:402
VOLK_LinkMap * VOLK_link_map_new(const VOLK_Term *linked_term, VOLK_LinkType type)
New link map.
Definition term.c:651
VOLK_Term * VOLK_default_datatype
Default literal data type URI.
Definition term.c:60
VOLK_rc VOLK_link_map_triples(VOLK_LinkMapIterator *it, VOLK_Triple *spo)
Iterate over a link map and generate triples.
Definition term.c:760
void VOLK_triple_done(VOLK_Triple *spo)
Free the internal pointers of a triple.
Definition term.c:520
VOLK_rc VOLK_triple_init(VOLK_Triple *spo, VOLK_Term *s, VOLK_Term *p, VOLK_Term *o)
Initialize internal term pointers in a heap-allocated triple.
Definition term.c:498
const VOLK_Term * VOLK_term_set_get(VOLK_TermSet *ts, VOLK_Key key)
Get a term from a term set.
Definition term.c:586
VOLK_Term * VOLK_bnode_new(const char *data)
Shortcut to create a blank node.
Definition term.h:331
VOLK_TermSet * VOLK_term_set_new(void)
Create a new term set.
Definition term.c:548
uint32_t VOLK_default_dtype_key
Compiled hash of default literal data type.
Definition term.c:58
void VOLK_term_set_free(VOLK_TermSet *ts)
Free a term set.
Definition term.c:609
VOLK_Key VOLK_term_hash(const VOLK_Term *term)
Hash a buffer.
Definition term.c:376
VOLK_rc VOLK_link_map_next(VOLK_LinkMapIterator *it, VOLK_Term **lt, VOLK_TermSet **ts)
Iterate through a link map.
Definition term.c:745
void VOLK_link_map_free(VOLK_LinkMap *lm)
Free a link map.
Definition term.c:671
VOLK_Term * VOLK_iriref_new_ns(const char *data)
Create an IRI reference from a namespace-prefixed string.
Definition term.h:204
char * VOLK_iriref_path(const VOLK_Term *iri)
Get the path portion of a IRI ref.
Definition term.c:419
char VOLK_LangTag[8]
Language tag, currently restricted to 7 characters.
Definition term.h:27
void VOLK_term_free(VOLK_Term *term)
Definition term.c:392
VOLK_Term * VOLK_triple_pos(const VOLK_Triple *trp, const VOLK_TriplePos n)
Get triple by term position.
Definition term.h:501
VOLK_Buffer * VOLK_term_serialize(const VOLK_Term *term)
Serialize a term into a buffer.
Definition term.c:298
VOLK_Term * VOLK_default_ctx
Default context.
Definition term.c:59
VOLK_Term * VOLK_term_new_from_buffer(const VOLK_Buffer *sterm)
Deserialize a buffer into a term.
Definition term.c:194
VOLK_rc VOLK_link_map_add(VOLK_LinkMap *lmap, VOLK_Term *term, VOLK_TermSet *tset)
Add a term - term set pair to a link map.
Definition term.c:686
VOLK_Term * VOLK_term_set_pop(VOLK_TermSet *ts)
Pop a term from a term set.
Definition term.c:633
VOLK_rc VOLK_term_set_add(VOLK_TermSet *ts, VOLK_Term *term, VOLK_Term **ins)
Add term to a term set.
Definition term.c:561
VOLK_LinkType VOLK_link_map_type(const VOLK_LinkMap *map)
Return the link map type.
Definition term.c:680
VOLK_BufferTriple * VOLK_triple_serialize(const VOLK_Triple *spo)
Definition term.c:484
VOLK_Term * VOLK_term_new(VOLK_TermType type, const char *data, void *metadata)
Create a new term.
Definition term.c:157
VOLK_TermSet * VOLK_term_cache
Global term cache.
Definition term.c:61
void VOLK_triple_free(VOLK_Triple *spo)
Free a triple and all its internal pointers.
Definition term.c:531
VOLK_Term * VOLK_term_copy(const VOLK_Term *src)
Copy a term.
Definition term.c:174
@ VOLK_LINK_EDGE
Edge link (so).
Definition term.h:96
@ VOLK_LINK_INBOUND
Inbound link (sp).
Definition term.h:94
@ VOLK_LINK_OUTBOUND
Outbound link (po).
Definition term.h:95
@ VOLK_TERM_IRIREF
IRI reference.
Definition term.h:34
@ VOLK_TERM_UNDEFINED
Definition term.h:31
@ VOLK_TERM_LT_LITERAL
Language-tagged string literal.
Definition term.h:36
@ VOLK_TERM_LITERAL
Literal without language tag.
Definition term.h:35
@ VOLK_TERM_BNODE
Blank node.
Definition term.h:37
VOLK_Key VOLK_btriple_hash(const VOLK_BufferTriple *strp)
Hash a buffer triple.
Definition buffer.h:317
void VOLK_btriple_free(VOLK_BufferTriple *sspo)
Free a buffer triple and all its internal pointers.
Definition buffer.c:147
VOLK_TriplePos
Triple position of s, p, o.
Definition buffer.h:19
@ TRP_POS_O
Definition buffer.h:22
@ TRP_POS_S
Definition buffer.h:20
@ TRP_POS_P
Definition buffer.h:21
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
size_t VOLK_Key
Term key, i.e., hash of a serialized term.
Definition core.h:244
Match coordinates in IRI parsing results.
Definition term.h:41
unsigned int size
Length of match.
Definition term.h:43
unsigned int offset
Offset of match from start of string.
Definition term.h:42
Triple of byte buffers.
Definition buffer.h:60
General-purpose data buffer.
Definition buffer.h:47
Matching sub-patterns for IRI parts.
Definition term.h:47
MatchCoord frag
Fragment (frag).
Definition term.h:54
MatchCoord auth
Authority (example.org).
Definition term.h:50
MatchCoord query
Query (query=blah).
Definition term.h:53
MatchCoord prefix
Prefix (http://example.org).
Definition term.h:48
MatchCoord path
Definition term.h:51
MatchCoord scheme
Scheme (http).
Definition term.h:49
RDF term.
Definition term.h:61
VOLK_Key bnode_id
BN ID for comparison & skolemization.
Definition term.h:66
void * metadata
Generic metadata pointer.
Definition term.h:67
char * data
URI, literal value, or BNode label.
Definition term.h:62
struct term_t * datatype
Data type IRI for VOLK_TERM_LITERAL.
Definition term.h:64
VOLK_TermType type
Term type.
Definition term.h:69
VOLK_LangTag lang
Lang tag for VOLK_TERM_LT_LITERAL.
Definition term.h:65
RDF triple.
Definition term.h:85
VOLK_Term * p
Predicate.
Definition term.h:87
VOLK_Term * s
Subject.
Definition term.h:86
VOLK_Term * o
Object.
Definition term.h:88