0

I am a student and I'm learning to use sparql. I would like to query an endpoint by running the sparql query from GRAPHDB. So looking online I found that the solution is to use SERVICE with the endpoint link.

I have tried with the wikidata endpoint on GRAPHDB but the query result is empty.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>

SELECT DISTINCT
?partyLabel
WHERE {
     SERVICE <https://query.wikidata.org/bigdata/namespace/categories/sparql> { 
      ?party wdt:P31 wd:Q7278;
              wdt:P17 wd:Q38.

      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      }
}
LIMIT 5

However, the same query (without SERVICE) works on https://query.wikidata.org.

SELECT DISTINCT
?partyLabel
WHERE { 
      ?party wdt:P31 wd:Q7278;
              wdt:P17 wd:Q38.

      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
LIMIT 5

Surely I didn't understand how SERVICE works or something else, could you help me out? Thank you in advance

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
  • 1
    why do you use `https://query.wikidata.org/bigdata/namespace/categories/sparql` instead of `https://query.wikidata.org/sparql` ? – UninformedUser Jun 03 '20 at 10:00
  • I found it here [link](https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/SPARQL_Federation_endpoints) – Luca Squadrone Jun 03 '20 at 10:14
  • well, this list contains endpoints which you can query from the public Wikidata endpoint. But you want to query the public Wikidata from your own SPARQL endpoint, or not? IF so, use the other URL I provided – UninformedUser Jun 03 '20 at 10:16
  • or do you use the public wikidata endpoint? I mean, this is indeed empty because it just contains category data? Your second query is correct as it queries all the Wikidata facts – UninformedUser Jun 03 '20 at 10:22
  • ok, I tried on graphdb with the link you provided me, but it doesn't work. the result is empty – Luca Squadrone Jun 03 '20 at 10:29
  • 1
    the issue is with the nested SERVICE clause, this fails here. Do `PREFIX wd: PREFIX wdt: SELECT DISTINCT ?partyLabel WHERE { SERVICE { ?party wdt:P31 wd:Q7278; wdt:P17 wd:Q38. ?party ?partyLabel . filter(lang(?partyLabel) = "en") } } LIMIT 5` instead – UninformedUser Jun 03 '20 at 11:58
  • You solved my problem, thank you very much – Luca Squadrone Jun 03 '20 at 12:29

0 Answers0