paulovn / sparql-kernel

A Jupyter kernel to launch queries against SPARQL endpoints
BSD 3-Clause "New" or "Revised" License
98 stars 17 forks source link

XML renerding / media type error #34

Closed jpullmann closed 5 years ago

jpullmann commented 5 years ago

Request for RDF/XML rendering (%format XML) results in the following error: Unexpected response format: application/rdf+xml (requested: xml)

System configuration:

paulovn commented 5 years ago

That means the kernel asked the remote engine for XML results, and expected to receive a MIME type of application/sparql-results+xml (i.e. an SPARQL XML response). Instead, it received an RDF document (MIME type application/rdf+xml) so it complains.

Result formats from SPARQL engines are tricky, there is no clear standard on what they must provide. But in any case I'm afraid that the code does not currently have the possibility to request RDF as a choice; when it says XML it refers to XML results of a SPARQL query (though if you set the format to ANY and the server returns RDF, it might be able to render it).

jpullmann commented 5 years ago

In my case the query is a CONSTRUCT, according to Sparql 1.1 protocol it'd render to a graph representation as requested by content negotiation. Format XML would in case of CONSTRUCT and DESCRIBE equal to expected media type application/rdf+xml or to application/sparql-results+xml otherwise?

paulovn commented 5 years ago

No, right now XML is only valid for SELECT queries, for CONSTRUCT queries it won't work, basically because there is no code yet to parse the resulting RDF format.

You may try N3 as format (or use default, which will automatically select N3 for CONSTRUCTqueries), since N3 can be parsed and represented.

jpullmann commented 5 years ago

Hi Paulo, this was meant as a suggestion. N3 and the tabular graph rendering is almost unreadable when more then few resources are involved, e.g. sorting does not work, the statements are scattered. I expect this be considerably enhanced with a format like RDF/XML-ABBREV or JSON-LD for graphs.

paulovn commented 5 years ago

ok, I see. I'll try to take a look to see what's possible. At the very least raw output should be doable with not much effort.

paulovn commented 5 years ago

Ok, I finally got time to take a look at this. Handling it in a totally transparent way is difficult becase I use SPARQLWrapper to create the quaries, and that package has a limited set of allowed formats (it also sends the format in two places: as a query string parameter and as an Accept header, and it predefines what the Accept header will be based on the format).

The 1.3.0 branch (in testing now) allows removing a format request (%format none), and then the specifics of the format can be negotiated directly with the backend via custom %qparam and/or %http_header values. Hopefully with them it is possible to generate a version valid for any backend.

Of course, if the results are in a format that the code cannot parse, the only rendering possible is the raw one. But it is better than nothing.