352 Wikidata API and Wikidata Query Service Guidlines - bounswe/bounswe2024group1 GitHub Wiki
Wikidata API and Query Service are powerful tools for accessing structured data from Wikidata, a collaborative knowledge base. Here's a brief explanation of each and how to use them:
Wikidata API 💻
- The Wikidata API allows you to programmatically access and retrieve data from Wikidata.
- It provides various endpoints to perform actions such as searching for entities, fetching entity data, querying for properties, and more.
- The API supports multiple output formats like JSON, XML, and RDF.
- You can use the API to integrate Wikidata content into your applications, websites, or research projects.
How to use it ❓
- To use the Wikidata API, you need to construct HTTP requests to the appropriate endpoints, specifying the action you want to perform and any parameters required.
- For example, to search for an entity, you would construct a request to the wbsearchentities endpoint, providing the search query as a parameter.
- You can then parse the response, which will contain the requested data in the specified format.
Wikidata Query Service:
- The Wikidata Query Service (WDQS) is a powerful tool that allows you to run complex queries against the Wikidata knowledge base using the SPARQL query language.
- SPARQL (SPARQL Protocol and RDF Query Language) is a query language for querying RDF (Resource Description Framework) data.
- With WDQS, you can retrieve structured data from Wikidata according to your specific criteria, such as retrieving all instances of a particular class, finding relationships between entities, or obtaining statistical information.
- WDQS provides a web-based interface where you can compose and execute SPARQL queries, as well as an API endpoint for programmatic access.
How to use it:
To use the Wikidata Query Service, you can visit the web interface at https://query.wikidata.org/ and compose your SPARQL queries directly in the text editor. Write your query following the SPARQL syntax, specifying the patterns you want to match and the data you want to retrieve. Execute the query, and the results will be displayed in table format on the web interface. You can also use the API endpoint programmatically by sending HTTP requests with your SPARQL query as a parameter, and parsing the JSON response. Both the Wikidata API and Query Service are invaluable resources for accessing and utilizing the vast amount of structured data available on Wikidata. Whether you're building applications, conducting research, or simply exploring knowledge, these tools provide convenient ways to interact with Wikidata's wealth of information.
More Examples of Wikidata Using SPARQL ⭐
- Largest cities of the world
SELECT ?cityLabel ?population ?gps
WITH {
SELECT DISTINCT *
WHERE {
?city wdt:P31/wdt:P279* wd:Q515 .
?city wdt:P1082 ?population .
?city wdt:P625 ?gps .
}
ORDER BY DESC(?population)
LIMIT 100
} AS %i
WHERE {
INCLUDE %i
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
}
ORDER BY DESC(?population)
- Longest river of each continent
SELECT ?continent ?river ?continentLabel ?riverLabel ?maxlength
WHERE
{
{
SELECT ?continent (MAX(?length) AS ?maxlength)
WHERE
{
?river wdt:P31/wdt:P279* wd:Q355304;
wdt:P2043 ?length;
wdt:P30 ?continent.
}
GROUP BY ?continent
}
?river wdt:P31/wdt:P279* wd:Q355304;
wdt:P2043 ?maxlength;
wdt:P30 ?continent.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?continentLabel
- Locations of Pablo Picasso works
#defaultView:Map
SELECT ?label ?coord ?subj
WHERE
{
?subj wdt:P170 wd:Q5593 .
OPTIONAL {?subj wdt:P276 ?loc .
?loc wdt:P625 ?coord } .
?subj rdfs:label ?label FILTER (lang(?label) = "en")
}
References 🔗
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples
- https://query.wikidata.org/
Prepeared by Enes Baser