|
@@ -10,10 +10,13 @@
|
|
*/
|
|
*/
|
|
typedef struct {
|
|
typedef struct {
|
|
const LSUP_Codec * codec; ///< Codec that generated this iterator.
|
|
const LSUP_Codec * codec; ///< Codec that generated this iterator.
|
|
- const LSUP_Graph *gr; ///< Graph being encoded.
|
|
|
|
|
|
+ const LSUP_Graph * gr; ///< Graph being encoded.
|
|
LSUP_TermSet * subjects; ///< All subjects in the graph.
|
|
LSUP_TermSet * subjects; ///< All subjects in the graph.
|
|
size_t s_cur; ///< Term set cursor.
|
|
size_t s_cur; ///< Term set cursor.
|
|
LSUP_rc rc; ///< Internal return code.
|
|
LSUP_rc rc; ///< Internal return code.
|
|
|
|
+ char * s_str; ///< Serialized subject block (output).
|
|
|
|
+ char * p_str; ///< Serialized predicate block.
|
|
|
|
+ char * o_str; ///< Serialized object block.
|
|
} LSUP_TTLCodecIterator;
|
|
} LSUP_TTLCodecIterator;
|
|
|
|
|
|
|
|
|
|
@@ -172,13 +175,12 @@ static void *
|
|
gr_to_ttl_init (const LSUP_Graph *gr)
|
|
gr_to_ttl_init (const LSUP_Graph *gr)
|
|
{
|
|
{
|
|
LSUP_TTLCodecIterator *it;
|
|
LSUP_TTLCodecIterator *it;
|
|
- MALLOC_GUARD (it, NULL);
|
|
|
|
|
|
+ CALLOC_GUARD (it, NULL);
|
|
|
|
|
|
it->codec = &ttl_codec;
|
|
it->codec = &ttl_codec;
|
|
it->gr = gr;
|
|
it->gr = gr;
|
|
it->subjects = LSUP_graph_unique_terms (gr, TRP_POS_S);
|
|
it->subjects = LSUP_graph_unique_terms (gr, TRP_POS_S);
|
|
// Sets the condition to build the prolog on 1st iteration.
|
|
// Sets the condition to build the prolog on 1st iteration.
|
|
- it->s_cur = 0;
|
|
|
|
it->rc = LSUP_NORESULT;
|
|
it->rc = LSUP_NORESULT;
|
|
|
|
|
|
return it;
|
|
return it;
|
|
@@ -249,36 +251,33 @@ gr_to_ttl_iter (void *h, char **res_p) {
|
|
|
|
|
|
LSUP_LinkMapIterator *lmit = LSUP_link_map_iter_new (lmap, s);
|
|
LSUP_LinkMapIterator *lmit = LSUP_link_map_iter_new (lmap, s);
|
|
LSUP_Term *p = NULL;
|
|
LSUP_Term *p = NULL;
|
|
- char *p_str = NULL;
|
|
|
|
LSUP_TermSet *o_ts = NULL;
|
|
LSUP_TermSet *o_ts = NULL;
|
|
char *p_join = " ";
|
|
char *p_join = " ";
|
|
// Begin predicate loop.
|
|
// Begin predicate loop.
|
|
while (LSUP_link_map_next (lmit, &p, &o_ts) != LSUP_END) {
|
|
while (LSUP_link_map_next (lmit, &p, &o_ts) != LSUP_END) {
|
|
// Add predicate representation.
|
|
// Add predicate representation.
|
|
- RCCK (term_to_ttl (p, LSUP_graph_namespace (it->gr), &p_str));
|
|
|
|
|
|
+ RCCK (term_to_ttl (p, LSUP_graph_namespace (it->gr), &it->p_str));
|
|
char *tmp = realloc (
|
|
char *tmp = realloc (
|
|
- res, strlen (res) + strlen (p_str) + strlen (p_join) + 1);
|
|
|
|
|
|
+ res, strlen (res) + strlen (it->p_str) + strlen (p_join) + 1);
|
|
if (UNLIKELY (!tmp)) goto memfail;
|
|
if (UNLIKELY (!tmp)) goto memfail;
|
|
- res = strcat (strcat (tmp, p_join), p_str);
|
|
|
|
|
|
+ res = strcat (strcat (tmp, p_join), it->p_str);
|
|
|
|
|
|
- free (p_str);
|
|
|
|
p_join = " ; ";
|
|
p_join = " ; ";
|
|
|
|
|
|
// Add objects for predicate.
|
|
// Add objects for predicate.
|
|
size_t i = 0;
|
|
size_t i = 0;
|
|
LSUP_Term *o = NULL;
|
|
LSUP_Term *o = NULL;
|
|
- char *o_str = NULL;
|
|
|
|
char *o_join = " ";
|
|
char *o_join = " ";
|
|
while (LSUP_term_set_next (o_ts, &i, &o) != LSUP_END) {
|
|
while (LSUP_term_set_next (o_ts, &i, &o) != LSUP_END) {
|
|
- it->rc = term_to_ttl (o, LSUP_graph_namespace (it->gr), &o_str);
|
|
|
|
|
|
+ it->rc = term_to_ttl (
|
|
|
|
+ o, LSUP_graph_namespace (it->gr), &it->o_str);
|
|
RCCK (it->rc);
|
|
RCCK (it->rc);
|
|
char *tmp = realloc (
|
|
char *tmp = realloc (
|
|
- res, strlen (res) + strlen (o_str) + strlen (o_join) + 1);
|
|
|
|
|
|
+ res, strlen (res) + strlen (it->o_str) + strlen (o_join) + 1);
|
|
if (UNLIKELY (!tmp)) goto memfail;
|
|
if (UNLIKELY (!tmp)) goto memfail;
|
|
- res = strcat (strcat (tmp, o_join), o_str);
|
|
|
|
|
|
+ res = strcat (strcat (tmp, o_join), it->o_str);
|
|
o_join = " , ";
|
|
o_join = " , ";
|
|
}
|
|
}
|
|
- free (o_str);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
char *s_sep = " .\n";
|
|
char *s_sep = " .\n";
|
|
@@ -304,6 +303,9 @@ gr_to_ttl_done (void *h)
|
|
{
|
|
{
|
|
LSUP_TTLCodecIterator *it = h;
|
|
LSUP_TTLCodecIterator *it = h;
|
|
LSUP_term_set_free (it->subjects);
|
|
LSUP_term_set_free (it->subjects);
|
|
|
|
+ free (it->s_str);
|
|
|
|
+ free (it->p_str);
|
|
|
|
+ free (it->o_str);
|
|
free (it);
|
|
free (it);
|
|
}
|
|
}
|
|
|
|
|