|
@@ -2,9 +2,10 @@
|
|
|
|
|
|
|
|
|
|
/// NT codec iterator type.
|
|
/// NT codec iterator type.
|
|
-typedef struct {
|
|
|
|
|
|
+typedef struct nt_codec_iterator {
|
|
const VOLK_Codec * codec; // Codec that generated this iterator.
|
|
const VOLK_Codec * codec; // Codec that generated this iterator.
|
|
VOLK_GraphIterator *gr_it; // Graph iterator.
|
|
VOLK_GraphIterator *gr_it; // Graph iterator.
|
|
|
|
+ const VOLK_Term * gr_uri; // Graph URI.
|
|
size_t cur; // Internal cursor.
|
|
size_t cur; // Internal cursor.
|
|
VOLK_rc rc; // Internal return code.
|
|
VOLK_rc rc; // Internal return code.
|
|
char * str_s, // Temporary string.
|
|
char * str_s, // Temporary string.
|
|
@@ -115,6 +116,7 @@ gr_to_nt_init (const VOLK_Graph *gr)
|
|
|
|
|
|
it->codec = &nt_codec;
|
|
it->codec = &nt_codec;
|
|
it->gr_it = VOLK_graph_lookup(gr, NULL, NULL, NULL, &it->cur);
|
|
it->gr_it = VOLK_graph_lookup(gr, NULL, NULL, NULL, &it->cur);
|
|
|
|
+ it->gr_uri = VOLK_graph_uri (gr);
|
|
|
|
|
|
return it;
|
|
return it;
|
|
}
|
|
}
|
|
@@ -124,12 +126,25 @@ static VOLK_rc
|
|
gr_to_nt_iter (void *h, char **res) {
|
|
gr_to_nt_iter (void *h, char **res) {
|
|
VOLK_NTCodecIterator *it = h;
|
|
VOLK_NTCodecIterator *it = h;
|
|
VOLK_Triple *spo = NULL;
|
|
VOLK_Triple *spo = NULL;
|
|
|
|
+
|
|
VOLK_rc rc = VOLK_graph_iter_next (it->gr_it, &spo);
|
|
VOLK_rc rc = VOLK_graph_iter_next (it->gr_it, &spo);
|
|
if (rc != VOLK_OK) goto finally;
|
|
if (rc != VOLK_OK) goto finally;
|
|
|
|
|
|
- term_to_nt (spo->s, &it->str_s);
|
|
|
|
|
|
+ // If IRIRefs are relative to the graph URI, make them absolute.
|
|
|
|
+ VOLK_Term *abs_s, *abs_o;
|
|
|
|
+ if (spo->s->type == VOLK_TERM_IRIREF)
|
|
|
|
+ abs_s = VOLK_iriref_new_abs (it->gr_uri, spo->s);
|
|
|
|
+ else abs_s = spo->s;
|
|
|
|
+ if (spo->o->type == VOLK_TERM_IRIREF)
|
|
|
|
+ abs_o = VOLK_iriref_new_abs (it->gr_uri, spo->o);
|
|
|
|
+ else abs_o = spo->o;
|
|
|
|
+
|
|
|
|
+ term_to_nt (abs_s, &it->str_s);
|
|
term_to_nt (spo->p, &it->str_p);
|
|
term_to_nt (spo->p, &it->str_p);
|
|
- term_to_nt (spo->o, &it->str_o);
|
|
|
|
|
|
+ term_to_nt (abs_o, &it->str_o);
|
|
|
|
+
|
|
|
|
+ if (abs_s != spo->s) VOLK_term_free (abs_s);
|
|
|
|
+ if (abs_o != spo->o) VOLK_term_free (abs_o);
|
|
VOLK_triple_free (spo);
|
|
VOLK_triple_free (spo);
|
|
|
|
|
|
// 3 term separators + dot + newline + terminal = 6
|
|
// 3 term separators + dot + newline + terminal = 6
|