|
Volksdata 1.0b7
RDF library
|

Data Structures | |
| struct | MatchCoord |
| Match coordinates in IRI parsing results. More... | |
| struct | VOLK_IRIInfo |
| Matching sub-patterns for IRI parts. More... | |
| struct | VOLK_Term |
| RDF term. More... | |
| struct | VOLK_Triple |
| RDF triple. More... | |
Macros | |
| #define | UUID4_URN_SIZE UUIDSTR_SIZE + 10 |
| #define | VOLK_RDF_TYPE "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" |
| #define | VOLK_RDF_TYPE_NS "rdf:type" |
| #define | DEFAULT_DTYPE "http://www.w3.org/2001/XMLSchema#string" |
| Default data type for untyped literals (prefixed IRI). | |
| #define | DEFAULT_DTYPE_NS "xsd:string" |
| #define | VOLK_IS_LITERAL(term) |
| Shorthand to test if a term is a literal of any kind. | |
| #define | TERM_DUMMY VOLK_term_new (VOLK_TERM_UNDEFINED, NULL, NULL) |
| Placeholder term to use with VOLK_term_reset. | |
| #define | TRP_DUMMY VOLK_triple_new (NULL, NULL, NULL) |
| Dummy triple with NULL slots. It is not a valid triple. | |
Typedefs | |
| typedef char | VOLK_LangTag[8] |
| Language tag, currently restricted to 7 characters. | |
| typedef struct link_map | VOLK_LinkMap |
| The immediate neighborhood of terms connected to a term. | |
| typedef struct hashmap | VOLK_TermSet |
| a set of unique terms. | |
Enumerations | |
| enum | VOLK_TermType { VOLK_TERM_UNDEFINED = 0 , VOLK_TERM_IRIREF , VOLK_TERM_LITERAL , VOLK_TERM_LT_LITERAL , VOLK_TERM_BNODE } |
| Term type. More... | |
| enum | VOLK_LinkType { VOLK_LINK_INBOUND , VOLK_LINK_OUTBOUND , VOLK_LINK_EDGE } |
| Link type. More... | |
Functions | |
| VOLK_Term * | VOLK_term_new (VOLK_TermType type, const char *data, void *metadata) |
| Create a new term. | |
| VOLK_Term * | VOLK_iriref_new (const char *data) |
| Create an IRI reference. | |
| VOLK_Term * | VOLK_iriref_new_ns (const char *data) |
| Create an IRI reference from a namespace-prefixed string. | |
| 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. | |
| 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. | |
| VOLK_Term * | VOLK_literal_new (const char *data, VOLK_Term *datatype) |
| Shortcut to create a literal term. | |
| VOLK_rc | VOLK_parse_iri (char *iri_str, VOLK_IRIInfo *iri_info) |
| scan an IRI string and parse IRI parts. | |
| VOLK_Term * | VOLK_lt_literal_new (const char *data, char *lang) |
| Shortcut to create a language-tagged literal term. | |
| VOLK_Term * | VOLK_bnode_new (const char *data) |
| Shortcut to create a blank node. | |
| VOLK_Term * | VOLK_term_copy (const VOLK_Term *src) |
| Copy a term. | |
| VOLK_Term * | VOLK_term_new_from_buffer (const VOLK_Buffer *sterm) |
| Deserialize a buffer into a term. | |
| VOLK_Buffer * | VOLK_term_serialize (const VOLK_Term *term) |
| Serialize a term into a buffer. | |
| VOLK_Key | VOLK_term_hash (const VOLK_Term *term) |
| Hash a buffer. | |
| bool | VOLK_term_equals (const VOLK_Term *term1, const VOLK_Term *term2) |
| Compare two terms. | |
| void | VOLK_term_free (VOLK_Term *term) |
| char * | VOLK_iriref_prefix (const VOLK_Term *iri) |
| Get the prefix portion of a IRI ref. | |
| char * | VOLK_iriref_path (const VOLK_Term *iri) |
| Get the path portion of a IRI ref. | |
| char * | VOLK_iriref_frag (const VOLK_Term *iri) |
| Get the fragment portion of a IRI ref. | |
| VOLK_Triple * | VOLK_triple_new (VOLK_Term *s, VOLK_Term *p, VOLK_Term *o) |
| Create a new triple from three terms. | |
| VOLK_Triple * | VOLK_triple_new_from_btriple (const VOLK_BufferTriple *sspo) |
| VOLK_BufferTriple * | VOLK_triple_serialize (const VOLK_Triple *spo) |
| 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. | |
| void | VOLK_triple_done (VOLK_Triple *spo) |
| Free the internal pointers of a triple. | |
| void | VOLK_triple_free (VOLK_Triple *spo) |
| Free a triple and all its internal pointers. | |
| VOLK_Term * | VOLK_triple_pos (const VOLK_Triple *trp, const VOLK_TriplePos n) |
| Get triple by term position. | |
| VOLK_Key | VOLK_triple_hash (const VOLK_Triple *trp) |
| Hash a triple. | |
| VOLK_TermSet * | VOLK_term_set_new (void) |
| Create a new term set. | |
| void | VOLK_term_set_free (VOLK_TermSet *ts) |
| Free a term set. | |
| VOLK_rc | VOLK_term_set_add (VOLK_TermSet *ts, VOLK_Term *term, VOLK_Term **existing) |
| Add term to a term set. | |
| const VOLK_Term * | VOLK_term_set_get (VOLK_TermSet *ts, VOLK_Key key) |
| Get a term from a term set. | |
| VOLK_rc | VOLK_term_set_next (VOLK_TermSet *ts, size_t *i, VOLK_Term **term) |
| Iterate trough a term set. | |
| size_t | VOLK_term_set_size (VOLK_TermSet *ts) |
| Size of a term set. | |
| VOLK_LinkMap * | VOLK_link_map_new (const VOLK_Term *linked_term, VOLK_LinkType type) |
| New link map. | |
| void | VOLK_link_map_free (VOLK_LinkMap *lm) |
| Free a link map. | |
| VOLK_LinkType | VOLK_link_map_type (const VOLK_LinkMap *map) |
| Return the link map type. | |
| 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. | |
| VOLK_LinkMapIterator * | VOLK_link_map_iter_new (const VOLK_LinkMap *lmap) |
| Create a new iterator to loop through a link map. | |
| VOLK_rc | VOLK_link_map_next (VOLK_LinkMapIterator *it, VOLK_Term **lt, VOLK_TermSet **ts) |
| Iterate through a link map. | |
| void | VOLK_link_map_iter_free (VOLK_LinkMapIterator *it) |
| Free a link map iterator. | |
| VOLK_rc | VOLK_link_map_triples (VOLK_LinkMapIterator *it, VOLK_Triple *spo) |
| Iterate over a link map and generate triples. | |
Variables | |
| uint32_t | VOLK_default_dtype_key |
| Compiled hash of default literal data type. | |
| VOLK_Term * | VOLK_default_datatype |
| Default literal data type URI. | |
| VOLK_TermSet * | VOLK_term_cache |
| Global term cache. | |
| VOLK_Term * | VOLK_default_ctx |
| Default context. | |
| #define UUID4_URN_SIZE UUIDSTR_SIZE + 10 |
| #define VOLK_RDF_TYPE "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" |
| #define DEFAULT_DTYPE "http://www.w3.org/2001/XMLSchema#string" |
| #define VOLK_IS_LITERAL | ( | term | ) |
Shorthand to test if a term is a literal of any kind.
| #define TERM_DUMMY VOLK_term_new (VOLK_TERM_UNDEFINED, NULL, NULL) |
| #define TRP_DUMMY VOLK_triple_new (NULL, NULL, NULL) |
| typedef char VOLK_LangTag[8] |
| typedef struct link_map VOLK_LinkMap |
The immediate neighborhood of terms connected to a term.
This is a hash map whose each term is related to a set of one or more other terms. The hash map is inside an opaque handle and is manipulated via the VOLK_link_map_* functions.
If the type of the link map is VOLK_LINK_INBOUND, the map keys represent predicates and the sets related to them are the objects, and the term associated to the link map is the object.
If the type is VOLK_LINK_OUTBOUND, the keys represent predicates, the related sets objects, and the associated term is the subject.
If the type is VOLK_LINK_EDGE, the keys represent subjects and the related sets objects, and the associated term is the predicate.
| typedef struct hashmap VOLK_TermSet |
| enum VOLK_TermType |
| enum VOLK_LinkType |
| VOLK_Term * VOLK_term_new | ( | VOLK_TermType | type, |
| const char * | data, | ||
| void * | metadata ) |
Create a new term.
This is a generic function; it is recommended to use specialized functions such as VOLK_iriref_new(), VOLK_literal_new(), etc. as they have strict type checks for the metadata parameter.
| [in] | type | Term type. One of VOLK_TermType. |
| [in] | data | Term data: textual URI, literal value without data type or langtag, etc. It may be NULL for IRI refs and BNodes, in which case a random identifier is generated. |
| [in] | metadata | language tag (VOLK_LangTag *) for language-tagged literals; or data type (VOLK_Term *) for other literals. It may be NULL. |
|
inline |
Create an IRI reference.
Must be freed with VOLK_term_free.
| [in] | data | The fully qualified URI. If NULL, a UUID4 URN is generated. |
|
inline |
Create an IRI reference from a namespace-prefixed string.
Must be freed with VOLK_term_free.
| [in] | data | Namespace-prefixed URI. It MUST NOT be NULL, |
Create a new absolute IRI from a path relative to a root IRI.
If the provided IRI is already an absolute IRI, the result is semantically identical to the input.
If the relative IRI begins with a '/', the resulting IRI is relative to the web root of the root IRI. I.e. if a root IRI has a path after the webroot, it is ignored.
Otherwise, the resulting IRI is relative to the full root string.
| [in] | root | Root IRI that the new IRI should be relative to. |
| [in] | iri | Term with an IRI relative to the webroot. |
Create a new relative IRI from an absolute IRI and a web root IRI.
This works with namespace-prefixed IRIs and returns a term of the same type as the input.
| [in] | root | Root IRI that the new IRI should be relative to. |
| [in] | iri | Full IRI. |
Shortcut to create a literal term.
Must be freed with VOLK_term_free.
| [in] | data | The literal string. |
| [in] | datatype | Data type URI string. If NULL, the default data type (xsd:string) is used. The new term takes ownership of the pointer. |
| VOLK_rc VOLK_parse_iri | ( | char * | iri_str, |
| VOLK_IRIInfo * | iri_info ) |
scan an IRI string and parse IRI parts.
Replacement of a regex engine for better performance.
Slightly adapted from regex on https://datatracker.ietf.org/doc/html/rfc3986#appendix-B to capture relevant parts of the IRI.
Reference regex and group numbering: ^((?([^:/?#]+):)?(?//([^/?#]*))?)((?[^?#]*)(??([^#]*))?(?#(.*))?) 1 2 3 4 5 6
Capturing groups:
#0: Full parsed URI (http://example.org/123/456/?query=blah#frag) #1: Prefix (http://example.org) #2: Scheme (http) #3: Authority (example.org) #4: Path, including query and fragment (/123/456/?query=blah#frag) #5: Query (query=blah) #6: Fragment (frag)
| [in] | iri_str | IRI string to parse. |
| [in,out] | iri_info | Coordinates to be stored. |
The first element of each MatchCoord element stores the position of a match, and the second one stores the length of the match. A length of 0 indicates no match.
|
inline |
Shortcut to create a language-tagged literal term.
Must be freed with VOLK_term_free.
| [in] | data | The literal string. |
| [in] | lang | Language tag string. |
|
inline |
Shortcut to create a blank node.
Must be freed with VOLK_term_free.
| [in] | data | The BNode identifier. It can be NULL, in which case, a random identifier is minted. |
| VOLK_Term * VOLK_term_new_from_buffer | ( | const VOLK_Buffer * | sterm | ) |
Deserialize a buffer into a term.
| [in] | sterm | Buffer to convert into a term. It must be a valid serialized term from store or obtained with VOLK_term_serialize(). |
Deserialize a buffer into a term.
| VOLK_Buffer * VOLK_term_serialize | ( | const VOLK_Term * | term | ) |
Serialize a term into a buffer.
| [in] | term | Term to convert into a buffer. |
| char * VOLK_iriref_prefix | ( | const VOLK_Term * | iri | ) |
| char * VOLK_iriref_path | ( | const VOLK_Term * | iri | ) |
| char * VOLK_iriref_frag | ( | const VOLK_Term * | iri | ) |
| VOLK_Triple * VOLK_triple_new | ( | VOLK_Term * | s, |
| VOLK_Term * | p, | ||
| VOLK_Term * | o ) |
Create a new triple from three terms.
Terms are NOT copied. To free them with the triple, use VOLK_triple_free(). To only free the triple, use free().
TODO Term types are not validated at the moment.
| [in] | s | Triple subject. It must be an IRIRef or BNode. |
| [in] | p | Triple predicate. It must be an IRIRef. |
| [in] | o | Triple object. |
| VOLK_Triple * VOLK_triple_new_from_btriple | ( | const VOLK_BufferTriple * | sspo | ) |
| VOLK_BufferTriple * VOLK_triple_serialize | ( | const VOLK_Triple * | spo | ) |
| 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.
| [in] | spo | Triple pointer to initialize. |
| [in] | s | Triple subject. It must be an IRIRef or BNode. |
| [in] | p | Triple predicate. It must be an IRIRef. |
| [in] | o | Triple object. |
| void VOLK_triple_done | ( | VOLK_Triple * | spo | ) |
| void VOLK_triple_free | ( | VOLK_Triple * | spo | ) |
|
inline |
|
inline |
| VOLK_TermSet * VOLK_term_set_new | ( | void | ) |
| void VOLK_term_set_free | ( | VOLK_TermSet * | ts | ) |
| VOLK_rc VOLK_term_set_add | ( | VOLK_TermSet * | ts, |
| VOLK_Term * | term, | ||
| VOLK_Term ** | existing ) |
Add term to a term set.
If the same term is already in the set, it is not replaced, and the existing term's handle is made available in the existing variable. In this case, the caller may want to free the passed term which has not been added.
| [in] | ts | Term set to be added to. |
| [in] | term | Term to be added to the list. The term set will take ownership of the term and free it when it's freed with VOLK_term_set_free()—only if the return code is VOLK_OK. |
| [out] | existing | If not NULL, and if the term being added is a duplicate, this variable will be populated with the existing term handle. |
| const VOLK_Term * VOLK_term_set_get | ( | VOLK_TermSet * | ts, |
| VOLK_Key | key ) |
| VOLK_rc VOLK_term_set_next | ( | VOLK_TermSet * | ts, |
| size_t * | i, | ||
| VOLK_Term ** | term ) |
Iterate trough a term set.
| [in] | ts | Term set handle. |
| [in,out] | i | Iterator to be initially set to 0. |
| [out] | term | Pointer to be populated with the next term on success. It may be NULL. |
| size_t VOLK_term_set_size | ( | VOLK_TermSet * | ts | ) |
| VOLK_LinkMap * VOLK_link_map_new | ( | const VOLK_Term * | linked_term, |
| VOLK_LinkType | type ) |
New link map.
| [in] | linked_term | Term to be linked to map. The term is copied and may be freed after this function call. |
| [in] | type | Type of links that the link map shall contain. |
| void VOLK_link_map_free | ( | VOLK_LinkMap * | lm | ) |
Free a link map.
All arrays and term handles are recursively freed.
| [in] | lm | link map handle obtained with VOLK_link_map_new(). |
| VOLK_LinkType VOLK_link_map_type | ( | const VOLK_LinkMap * | map | ) |
| 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.
If there is already a term set for the given term, items from the added term are added to the existing term set (if not duplicated). Otherwise, the term set handle is linked to the new term.
In any case, the caller should not directly use the term and term set after passing them to this function.
| [in] | lmap | Link map handle obtained with VOLK_link_map_new(). |
| [in] | term | Term to be associated with the given object list. The link map takes ownership of the term. |
| [in] | tset | term set to be associated with the given term. The link map takes ownership of the term set and the terms in it. |
| VOLK_LinkMapIterator * VOLK_link_map_iter_new | ( | const VOLK_LinkMap * | lmap | ) |
| VOLK_rc VOLK_link_map_next | ( | VOLK_LinkMapIterator * | it, |
| VOLK_Term ** | lt, | ||
| VOLK_TermSet ** | ts ) |
Iterate through a link map.
Each call to this function yields a linked term and the related term set.
| [in] | it | Link map iterator obtained with VOLK_link_map_iter_new(). |
| [out] | lt | Linked term returned. |
| [out] | ts | Term set returned. |
| void VOLK_link_map_iter_free | ( | VOLK_LinkMapIterator * | it | ) |
| VOLK_rc VOLK_link_map_triples | ( | VOLK_LinkMapIterator * | it, |
| VOLK_Triple * | spo ) |
Iterate over a link map and generate triples.
Calling this function repeatedly builds triples for all the linked terms and term sets in the map, based on a given related term.
| [in] | it | Link map iterator handle, obtained with VOLK_link_map_iter_new(). |
| [in,out] | spo | Result triple. The triple handle must be pre-allocated (it may be TRP_DUMMY) and calls to this function will be set its memebers to term handles owned by the link map. If rc != VOLK_OK, the contents are undefined. |
|
extern |
|
extern |
|
extern |