QueryResult.convert() should be able to provide predictable result format
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):
- 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)
- 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
Addition: ASK queries return boolean values and there should be a shortcut in "SPARQL Results Document" for getting straight to it
There's code doing something like this in SmartWrapper.py, but it isn't elegant or complete