sparqlwrapper icon indicating copy to clipboard operation
sparqlwrapper copied to clipboard

QueryResult.convert() should be able to provide predictable result format

Open indeyets opened this issue 12 years ago • 2 comments

Currently, result of QueryResult.convert depends on the input type:

  • SPARQL_XML results in DOM object
  • SPARQL_JSON results in associative array (decoded json)
  • RDF_N3 results in string
  • RDF_XML and RDF_JSONLD result in rdflib.ConjunctiveGraph

It is low-level stuff and while it works in a controlled environment (users of library might get a working workflow via trial-and-error), in real-world usecases endpoint might give results in unexpected format, which will be handled differently and users application will just break as result will be of the wrong type.

convert() should have only 2 options for returned values (similar to what is listed in spec):

  1. SPARQL_* should return "SPARQL Results Document" in the form of object which gives access to metadata and provides iterator for getting rows. Both resources and literals should be provided as corresponding rdflib objects (I think #15 is just about this)
  2. RDF_* should return "RDF graph" in the form of rdflib.ConjunctiveGraph

So, in most cases, users of the library should never need to specify desired response-type. Whatever it is on the low-level, sparqlwrapper should present it via proper high-level objects

indeyets avatar Dec 15 '13 17:12 indeyets

Addition: ASK queries return boolean values and there should be a shortcut in "SPARQL Results Document" for getting straight to it

indeyets avatar Apr 24 '14 11:04 indeyets

There's code doing something like this in SmartWrapper.py, but it isn't elegant or complete

indeyets avatar Apr 24 '14 13:04 indeyets