RDFLib / sparqlwrapper

A wrapper for a remote SPARQL endpoint
https://sparqlwrapper.readthedocs.io/
Other
520 stars 122 forks source link

Getting different result from wrapper and endpoint #155

Closed williamwong101 closed 4 years ago

williamwong101 commented 4 years ago

I tried the following SPARQL:

SELECT DISTINCT ?p ?o WHERE {{
    <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> ?p ?o .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://dbpedia.org/ontology/wikiPageWikiLink> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://dbpedia.org/ontology/wikiPageDisambiguates> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://dbpedia.org/ontology/wikiPageRedirects> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://dbpedia.org/ontology/wikiPageRevisionID> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://dbpedia.org/ontology/wikiPageID> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://dbpedia.org/ontology/wikiPageExternalLink> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://www.w3.org/2000/01/rdf-schema#seeAlso> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o}} .
    MINUS {{ <http://dbpedia.org/resource/The_Haunted_House_(1929_film)> <http://www.w3.org/2002/07/owl#sameAs> ?o}} .
    }}

Both directly on http://dbpedia.org/sparql and the wrapper, however, they end up with different result, for example the pair

p o
http://dbpedia.org/ontology/director http://dbpedia.org/resource/Walt_Disney

is missing from the wrapper result

nicholascar commented 4 years ago

@zhiyuanw101 can you repeat a similar query with different data and get a similar result? It's important to know if this is some kind of data-dependent, one-off or truly a code issue within SPARQLWrapper.

eknutov commented 4 years ago

@zhiyuanw101 you're using the SparqlWrapper w/o setting a graph parameter. when querying via the http://dbpedia.org/sparql UI the graph IRI is set to http://dbpedia.org by default, so if you use this:

mySparql = sparqlwr.SPARQLWrapper('http://dbpedia.org/sparql') 

mySparql.addParameter("default-graph-uri", "http://dbpedia.org")         # this is where you set the graph

mySparql.setQuery(your_query_here)
mySparql.setReturnFormat(sparqlwr.CSV)

you will have exactly the same result set as you would have querying via the web GUI

@nicholascar this issue can be closed as unreproducible/not an issue

nicholascar commented 4 years ago

Thanks @eknutov