|
@@ -30,23 +30,40 @@ term_to_ttl (const LSUP_Term *term, const LSUP_NSMap *nsm, char **out_p)
|
|
|
LSUP_rc md_rc = LSUP_NORESULT;
|
|
|
switch (term->type) {
|
|
|
case LSUP_TERM_IRIREF:
|
|
|
- md_rc = LSUP_nsmap_denormalize_uri (nsm, term->data, &tmp);
|
|
|
- PRCCK (md_rc);
|
|
|
- if (md_rc == LSUP_NORESULT) {
|
|
|
- // If URI counld not be shortened, add `<>`
|
|
|
- out = realloc (*out_p, strlen (tmp) + 3);
|
|
|
- if (UNLIKELY (!out)) return LSUP_MEM_ERR;
|
|
|
- sprintf (out, "<%s>", tmp);
|
|
|
- free (tmp);
|
|
|
-
|
|
|
- } else out = tmp;
|
|
|
+ if (strcmp (term->data, LSUP_RDF_TYPE) == 0) {
|
|
|
+ // Shorten RDF type
|
|
|
+ buf_len = 2;
|
|
|
+ tmp = "a";
|
|
|
+ } else {
|
|
|
+ md_rc = LSUP_nsmap_denormalize_uri (nsm, term->data, &tmp);
|
|
|
+ PRCCK (md_rc);
|
|
|
+ if (md_rc == LSUP_NORESULT) {
|
|
|
+ // If URI counld not be shortened, add `<>`
|
|
|
+ out = realloc (*out_p, strlen (tmp) + 3);
|
|
|
+ if (UNLIKELY (!out)) return LSUP_MEM_ERR;
|
|
|
+ sprintf (out, "<%s>", tmp);
|
|
|
+ free (tmp);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ free (*out_p);
|
|
|
+ out = tmp;
|
|
|
+ }
|
|
|
+ }
|
|
|
rc = LSUP_OK;
|
|
|
break;
|
|
|
|
|
|
case LSUP_TERM_NS_IRIREF:
|
|
|
- out = realloc (*out_p, strlen (term->data) + 1);
|
|
|
+ if (strcmp (term->data, LSUP_RDF_TYPE_NS) == 0) {
|
|
|
+ // Shorten RDF type
|
|
|
+ tmp = "a";
|
|
|
+ buf_len = 2;
|
|
|
+ } else {
|
|
|
+ tmp = term->data;
|
|
|
+ buf_len = strlen (term->data) + 1;
|
|
|
+ }
|
|
|
+ out = realloc (*out_p, buf_len);
|
|
|
if (UNLIKELY (!out)) return LSUP_MEM_ERR;
|
|
|
- strcpy (out, term->data);
|
|
|
+ strcpy (out, tmp);
|
|
|
rc = LSUP_OK;
|
|
|
break;
|
|
|
|
|
@@ -222,7 +239,7 @@ gr_to_ttl_iter (void *h, char **res_p) {
|
|
|
res = strcat (strcat (tmp, p_join), p_str);
|
|
|
|
|
|
free (p_str);
|
|
|
- p_join = "; ";
|
|
|
+ p_join = " ; ";
|
|
|
|
|
|
// Add objects for predicate.
|
|
|
size_t i = 0;
|
|
@@ -236,12 +253,12 @@ gr_to_ttl_iter (void *h, char **res_p) {
|
|
|
res, strlen (res) + strlen (o_str) + strlen (o_join) + 1);
|
|
|
if (UNLIKELY (!tmp)) goto memfail;
|
|
|
res = strcat (strcat (tmp, o_join), o_str);
|
|
|
- o_join = ", ";
|
|
|
+ o_join = " , ";
|
|
|
}
|
|
|
free (o_str);
|
|
|
}
|
|
|
|
|
|
- char *s_sep = ".\n";
|
|
|
+ char *s_sep = " .\n";
|
|
|
char *tmp = realloc (res, strlen (res) + strlen (s_sep) + 1);
|
|
|
if (UNLIKELY (!tmp)) goto memfail;
|
|
|
|