Need to format sqarql select results for tableau

Trying to be nice to my Tableau dashboard developer. Let's say we have a few triples such as:

PREFIX b: <http://books/>
PREFIX a: <http://authors/>

INSERT DATA
{   a:author1 rdf:type  "Author" ;
        rdfs:label "John".
}; 
INSERT DATA
{   b:book3 rdf:type "Book" ;
        rdfs:label  "A new book" ;
        b:hasAuthor a:author1 .
}; 

The defautl select * where {?s ?p ?o) brings URIs which dashboard developer doesn't like:

One ugly way to get rid of the URIs is to use replace functions (see below). But even that doesn't take care of all URIs...

select (replace(str(?s), "http://books/", "") as ?id) ?p ?o where{?s ?p ?o}
  • Any better way to get rid of URIs in the results?

Also to unquote the double qotes in the ?o column....

Thanks,
Radu

If you want to transform IRIs in ?p and ?o, too, then you should apply functions to them as well. You may try to use the built-in localname function:

prefix sdf: <tag:stardog:api:functions:> 
select (sdf:localname(?s) as ?subject) (if(isIRI(?o), sdf:localname(?o), ?o) as ?object) { ?s ?p ?o }

Pavel,

Thanks! That works just fine.

The only challenge now is to get rid of double quotes.

  • Any idea?

Thanks,
Radu

I don't think you have many options there other than maybe a postprocessing step. Sparql doesn't really know that they're there. You might try serializing the results as CSV and they might get consumed by whatever csv parser you use to read it. I'm not sure exactly what the CSV serilizaer does with quotes so you'll need to see whta it does.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.