SWI-Prolog / packages-semweb

The SWI-Prolog RDF store
28 stars 14 forks source link

Add ability to customize Accept header when making sparql_query/3 calls #91

Closed cmungall closed 3 years ago

cmungall commented 5 years ago

At biohackathon with @skwsm

Currently some endpoints do not work with the values provided here:

sparql_extra_headers(
        [ request_header('Accept' = 'application/sparql-results+xml, \c
                                     application/n-triples, \c
                                     application/x-turtle; q=0.9, \c
                                     application/turtle; q=0.9, \c
                                     text/turtle, \c
                                     application/sparql-results+json, \c
                                     application/rdf+xml, \c
                                     text/rdf+xml; q=0.8, \c
                                     */*; q=0.1'),
          cert_verify_hook(ssl_verify)
        ]).

An example endpoint is https://integbio.jp/rdf/sparql

This one requires that only application/sparql-results+json or application/sparql-results+xml is used with SELECT queries.

We can make a PR to make an option that allows the client to override, but we are wondering if there are reasons for/against this change.

koo5 commented 3 years ago

confirmed, the endpoint really sends back html, given the default Accept list. I have another usecase: sparql_read_xml_result/2 seems broken, because space(remove) causes literals to be read with whitespace characters missing. Yet agraph obviously sends me xml, because it's the first one on the list.

JanWielemaker commented 3 years ago

confirmed, the endpoint really sends back html, given the default Accept list.

So this is still open? I fear I missed it ...

causes literals to be read with whitespace characters missing

Please do not combine topics in one issue and supply an example that can be reproduced.

koo5 commented 3 years ago

the swipl issue that would be mitigated by the said PR is here: https://github.com/SWI-Prolog/packages-semweb/issues/99

koo5 commented 3 years ago

both issues still happen on 60891b85d1aa6e9de550899bd8bbba2819fccc21

koo5 commented 3 years ago

The issue with integbio.jp can be observed by running: https://github.com/koo5/hackery2/blob/master/src/data/swipl/sparql/bug1_2.pl

JanWielemaker commented 3 years ago

Thanks. This now works using the code below. I fear there is no one size fits all for the accept header, so this is second best :cry:

:- use_module(library(semweb/sparql_client)).
%
run :- sparql_query('
select * where {
  ?s ?p ?o.
}
limit 1
', Row,
                    [ host('integbio.jp'),
                      path('/rdf/sparql'),
                      request_header('Accept' = 'application/sparql-results+xml')
                    ]),
    writeq(Row),
    nl.