Skip to content

Is it possible to use SPARQL in the project? #51

Answered by labra
labra asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, there is no problem to use SPARQL, and indeed, SPARQL is a very flexible and powerful language to obtain data from Wikidata. As an example, the following query, retrieves the capitals of all the autonomous communities of Spain.

SELECT ?city ?cityLabel ?com ?comLabel WHERE {
  
  # Get the values that are instances of (P31) Spanish Autonomous Community (Q10742)
  ?com wdt:P31 wd:Q10742 .
  
  # Get the values that are capitals of (P1376) of ?com 
  ?city wdt:P1376 ?com .
  
  # Service that generates labels
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

}

The previous query can be run directly here: https://w.wiki/95DU

Replies: 1 comment

Comment options

labra
Feb 5, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by labra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
1 participant