0

My query in Virtuoso SPARQL Query Editor is as follows which resuted it 74

SELECT (COUNT (*) AS ?count) WHERE {?s ?p <http://dbpedia.org/resource/Machine_learning> .}

I used the same query in SPARQLWrapper as follows which gave me the count as 1195.

from SPARQLWrapper import SPARQLWrapper, JSON
sparqlw = SPARQLWrapper("http://dbpedia.org/sparql")
dbpedia_uri = "http://dbpedia.org/resource/Machine_learning"
sparqlw.setQuery(f"SELECT (COUNT (*) AS ?count) WHERE {{?s ?p <{dbpedia_uri}> .}}")
sparqlw.setReturnFormat(JSON)
results = sparqlw.query().convert()
results_df = pd.io.json.json_normalize(results['results']['bindings'])
print(results_df)

I re-checked the following details.

  • both are using http://dbpedia.org/ version
  • my f-string is equivalent to the query

Therefore, I am very confused why this big change of the results happen.

I am happy to provide more details if needed.

TallTed
  • 9,069
  • 2
  • 22
  • 37
EmJ
  • 4,398
  • 9
  • 44
  • 105
  • 1
    `sparqlw.addDefaultGraph("http://www.dbpedia.org")` – UninformedUser Jul 18 '19 at 01:53
  • @AKSW Thank you very much. Could you please tell me what happens with the above line? :) – EmJ Jul 18 '19 at 01:56
  • 2
    It sets the graph in which the data is searched to the same graph as in the wen interface. You should already have seen this textfield above the query field in the web interface. An RDF dataset can consist of multiple graphs, without specifying the default graph (yes, it may be empty), some internal setting which is usually the union of all graphs is used as context for the query. But it depends on the triple store. Read https://www.w3.org/TR/rdf-sparql-query/#unnamedGraph for better undertstanding – UninformedUser Jul 18 '19 at 03:05
  • 1
    `SELECT ?g (COUNT (*) AS ?count) WHERE { graph ?g {?s ?p .}} group by ?g` - you can see that DBpedia has a separate graph for the Wikipedia pagelinks – UninformedUser Jul 18 '19 at 03:09
  • @AKSW wow, this is exactly what I was looking for. Thank you very much :) – EmJ Jul 18 '19 at 03:45
  • @AKSW I am using the query in this question to get the in-degree page links of the DBpedia category: http://dbpedia.org/page/Category:Diseases_of_arteries,_arterioles_and_capillaries. My query is as follows. `SELECT (COUNT (*) AS ?count) WHERE {?s ?p dbc:Diseases_of_arteries,_arterioles_and_capillaries .}`. However, I get an error saying `Virtuoso 37000 Error SP030: SPARQL compiler, line 3: syntax error at '_arterioles_and_capillaries' before '.'`. I am not sure why DBpedia gives me this error. Please kindly let me know your thoughts on this :) – EmJ Jan 16 '20 at 08:21

0 Answers0