18 const VOLK_Graph *
gr;
44 if (strlen (term->
data) == 0) {
60 out = realloc (*out_p, strlen (term->
data) + 3);
62 sprintf (out,
"<%s>", term->
data);
77 buf_len = strlen (tmp) + 3;
82#define XSD "http://www.w3.org/2001/XMLSchema#"
84 if (strcmp ( term->
datatype->data,
XSD "integer") == 0) {
87 }
else if (strcmp ( term->
datatype->data,
XSD "double") == 0) {
90 }
else if (strcmp ( term->
datatype->data,
XSD "decimal") == 0) {
93 }
else if (strcmp ( term->
datatype->data,
XSD "boolean") == 0) {
107 buf_len += strlen (metadata);
112 out = realloc (*out_p, buf_len);
115 if (shorten) strcpy (out, tmp);
120 sprintf (out, fmt, tmp, metadata);
122 if (metadata == term->
datatype->data) metadata = NULL;
124 else sprintf (out,
"\"%s\"", tmp);
136 buf_len = strlen (tmp) + 3;
138 if (term->
lang[0] !=
'\0') {
140 buf_len += strlen (metadata) + 1;
143 out = realloc (*out_p, buf_len);
146 sprintf (out,
"\"%s\"", tmp);
150 if (metadata) out = strcat (strcat (out,
"@"), metadata);
157 out = realloc (*out_p, strlen (term->
data) + 3);
160 sprintf (out,
"_:%s", term->
data);
167 log_error (
"Invalid term type: %d", term->
type);
182 TTLEncodeIterator *it;
185 it->flags = options ? options->
flags : 0;
186 if (options && options->
txn) {
187 it->txn = options->
txn;
206ttl_build_prolog (TTLEncodeIterator *it,
char **res_p)
211 char *ns_tpl =
"@prefix %s: <%s> .\n";
214 for (
size_t i = 0; nsm[i]; i++) {
215 const char **ns = nsm[i];
216 size_t old_len = strlen (res);
217 size_t ns_len = strlen (ns[0]) + strlen (ns[1]) + strlen (ns_tpl);
218 char *tmp = realloc (res, old_len + ns_len + 1);
222 sprintf (res + old_len, ns_tpl, ns[0], ns[1]);
229 char *base_stmt_tpl =
"\n@base <%s> .\n\n";
230 char *base_stmt = malloc (
231 strlen (base_stmt_tpl) + strlen (base_uri_str) + 1);
233 sprintf (base_stmt, base_stmt_tpl, base_uri_str);
234 res = realloc (res, strlen (res) + strlen (base_stmt) + 1);
236 res = strcat (res, base_stmt);
254 TTLEncodeIterator *it = h;
257 return ttl_build_prolog (it, res_p);
268 size_t indented_s_len = strlen (res) +
INDENT_L + 1;
269 char *tmp = realloc (res, indented_s_len);
272 for (
int i = indented_s_len -
INDENT_L - 1; i >= 0; i--) {
294 char *tmp = realloc (
295 res, strlen (res) + strlen (it->p_str) + strlen (p_join) + 1);
297 res = strcat (strcat (tmp, p_join), it->p_str);
311 char *tmp = realloc (
312 res, strlen (res) + strlen (it->o_str) + strlen (o_join) + 1
315 res = strcat (strcat (tmp, o_join), it->o_str);
326 s_sep =
"\n" INDENT ".\n\n";
329 char *tmp = realloc (res, strlen (res) + strlen (s_sep) + 1);
332 *res_p = strcat (tmp, s_sep);
350 TTLEncodeIterator *it = h;
char * fmt_header(char *pfx)
Format an informational header.
VOLK_CodecFlags
Parse error information.
VOLK_rc escape_lit(const char *in, char **out_p)
Add escape character (backslash) to illegal literal characters.
@ VOLK_CODEC_NO_PROLOG
Do not generate prolog.
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.
VOLK_Store * VOLK_graph_store(const VOLK_Graph *gr)
Underlying graph store handle.
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.
const VOLK_Term * VOLK_graph_uri(const VOLK_Graph *gr)
Read-only graph URI.
const char *** VOLK_nsmap_dump(void)
Dump all entries of the namespace map.
VOLK_rc VOLK_nsmap_denormalize_uri(const char *fq_uri, char **pfx_uri_p)
Convert a FQ URI string to a prefixed string if the prefix is found.
#define NLCHECK(exp, marker)
Log error and jump to marker if exp is NULL.
#define CALLOC_GUARD(var, rc)
Allocate one pointer with calloc and return rc if it fails.
char * strndup(const char *src, size_t max)
Replacement for GNU strndup.
#define RCCK(exp)
Return exp return value if it is of VOLK_rc type and nonzero.
#define NLRCCK(exp, _rc)
Return rc return code if exp is NULL.
#define PRCCK(exp)
Return exp return value if it is of VOLK_rc type and negative (=error).
#define VOLK_ERROR
Generic error return code.
#define VOLK_MEM_ERR
Memory allocation error.
#define VOLK_NORESULT
No result yielded.
#define VOLK_END
Loop end.
#define VOLK_OK
Generic success return code.
#define VOLK_PARSE_ERR
Codec parser error.
@ VOLK_STORE_TXN_RO
Start a read-only transaction.
@ VOLK_STORE_TXN
Supports transaction handling.
VOLK_StoreFeature VOLK_store_features(const VOLK_Store *store)
Feature flags belonging to the store interface.
VOLK_rc VOLK_store_begin(VOLK_Store *store, VOLK_StoreFlags flags, void **txn)
Begin a transaction.
void VOLK_store_abort(VOLK_Store *store, void *txn)
Abort (roll back) a transaction.
struct hashmap VOLK_TermSet
a set of unique terms.
VOLK_rc VOLK_term_set_next(VOLK_TermSet *ts, size_t *i, VOLK_Term **term)
Iterate trough a term set.
void VOLK_link_map_iter_free(VOLK_LinkMapIterator *it)
Free a link map iterator.
VOLK_LinkMapIterator * VOLK_link_map_iter_new(const VOLK_LinkMap *lmap)
Create a new iterator to loop through a link map.
VOLK_Term * VOLK_default_datatype
Default literal data type URI.
void VOLK_term_set_free(VOLK_TermSet *ts)
Free a term set.
VOLK_rc VOLK_link_map_next(VOLK_LinkMapIterator *it, VOLK_Term **lt, VOLK_TermSet **ts)
Iterate through a link map.
void VOLK_link_map_free(VOLK_LinkMap *lm)
Free a link map.
char VOLK_LangTag[8]
Language tag, currently restricted to 7 characters.
@ VOLK_LINK_OUTBOUND
Outbound link (po).
@ VOLK_TERM_IRIREF
IRI reference.
@ VOLK_TERM_LT_LITERAL
Language-tagged string literal.
@ VOLK_TERM_LITERAL
Literal without language tag.
@ VOLK_TERM_BNODE
Blank node.
VOLK_rc ttl_encode_term(const VOLK_Term *term, char **out_p)
Encode a single term as Turtle.
void ttl_encode_graph_done(void *h)
Finalize a TTL graph iteration.
VOLK_rc ttl_encode_graph_iter(void *h, char **res_p)
Run one encoding iteration.
void * ttl_encode_graph_init(const VOLK_Graph *gr, void *oh)
Initialize a TTL graph iteration.
Options passed to ttl_encode_graph_init().
void * txn
Transaction to use for encoding.
VOLK_CodecFlags flags
Iterator flags.
char * data
URI, literal value, or BNode label.
struct term_t * datatype
Data type IRI for VOLK_TERM_LITERAL.
VOLK_TermType type
Term type.
VOLK_LangTag lang
Lang tag for VOLK_TERM_LT_LITERAL.
VOLK_TermSet * subjects
All subjects in the graph.
VOLK_rc rc
Internal return code.
const VOLK_Graph * gr
Graph being encoded.
char * s_str
Serialized subject block (output).
char * p_str
Serialized predicate block.
VOLK_CodecFlags flags
Iterator flags.
char * o_str
Serialized object block.
void * txn
Transaction to use.
size_t s_cur
Term set cursor.