There’s a lot to Wikidata. The Wikidata Query Service (WDQS) is one of the most effective and efficient ways to help you make sense of all that data on Wikidata. This post will explore how you can use different kinds queries to get the most out of your Wikidata experience. Each different kind of query will include example queries that demonstrate everything you can get out of Wikidata. You’ll also be able to modify and save them yourself to better understand how they work.
Let’s start with the most important takeaway right now: querying is how a lot of people read and use Wikidata. Although it’s important to comprehend what’s happening on the item-level on Wikidata, most community members are concerned with the relationship among all of these items (nearly 100 million as of September 2021). If you’re new to querying, that’s great! You can think of querying as defining a set of things you’re interested in on Wikidata and learning more about those things. You don’t have to worry about concerning yourself with everything that’s on Wikidata — just the things and relationships you’re interested in.
Queries can serve many purposes and express many, detailed aspects of Wikidata. The following list will provide you with some different “styles” of queries written for specific, applied purposes.
Queries can tell you…
- Facts: Queries can answer questions. For example which cities have mayors who identify as female? This is another way of showing the relationship between items. You can think of this query as a group of city items relate to human items (who are female). What links these two sets together is the “head of government” property. City, Head of Government, Mayor. The query zips through Wikidata and serves up an answer for you. This is a common kind of query.
- Visualization: Queries can visualize a lot of data for you. The Wikidata Query Service has several visualization options built into it — maps, images, graphs — to help readers process and interpret big sets of data. This query builds off the previous query, but this time it pulls in images and geographic coordinates to enable a map visualization option. This is another compelling use of a Wikidata query.
- Existence: Queries can tell you if Wikidata has an item you’re interested in — or not. New items are created every day on Wikidata, but there are plenty of gaps. Queries can tell us what’s there vs what isn’t. You can also think of it as a detail about something, for example: does Wikidata have the date that architect Jeanne Gang was a MacArthur fellow?
- Maintenance: Queries can help define metrics, track progress, and evaluate item completeness. If you’re working on a project you can have a query that focuses on a set of statements. The WikiProject Sum of All Paintings gathers paintings and data about them on Wikidata. To track progress, this project use a query (coupled with a tool called Listeria) to see which paintings are missing creator statements. Follow this link to see that list. If you scroll down a little, you’ll be able to see the link back to the query. Or you can click here to view it. Revisiting this query over time will reveal changes the community makes to items. Sets of queries can support projects to illustrate progress, gaps, and connectedness over time.
- Wikipedia article data: Queries can tell you all about Wikipedia articles. Every Wikipedia article has a corresponding Wikidata item that describes the article as linked data. So queries can answer questions like what percentage of biographies on Wikipedia are about women? Or more specific, how many female geneticist have Wikipedia articles? Wikidata can help us understand crucial metrics from other Wikimedia projects. These data points can help better develop Wikipedia in an equitable way, as well as keep track of systemic biases that exist in all of the projects — including Wikidata itself.
- Enrichment: Queries can grab that little slice of Wikidata that may improve your local collection. Is your collection missing specific pieces of data? Maybe birthdates and birth places for some artists? Don’t forget that you can download any set of query results! Build a query, scope it to a set of artists, ask for birthdates and birth places, and take whatever you want. After you run the query, just click the “Download” button on the right side of the screen and select from the file format options that best suit you. (Don’t forget that you can download *all* of Wikidata too…queries are probably the better way to do this since all of Wikidata is BIG).
- Language analysis: Queries can render results in many different languages. Similar to above — what if you want to translate names and descriptions of things in your collection to another language. That could make your collection more accessible to whole new communities. You can query Wikidata for language labels and descriptions in over 300 languages. These queries can reveal where there’s more translation work to do. Any way you look at it, the more translation that happens on Wikidata, the more accessible its knowledge becomes.
- Wikidata data model use: Queries will allow you to see how the community describes specific things on Wikidata. These standard descriptions of things on Wikidata are called data models. They emerge organically and the community defines them. Queries can help reveal where there are consistencies (or inconsistencies). For example, cities are a diverse set of things, but there are some common ways of describing them. This query shows the most commonly used properties for describing cities from 100,000 different examples. This kind of data will tell us how the community is most commonly describing something vague, like cities. Better data models = more accurate descriptions = more consistent data.
- Research: Queries can answer (and inspire) research questions. One benefit of Wikidata’s immense size is the ability to query across all of Wikipedia — and beyond! Some of these questions may not have been answerable previously. Relationships between things may be known already or they could be a new discovery for most of the population. There is a tool called Scholia that acts as a platform for revealing these research insights. You can search for authors, articles, or topics and it will produce a series of associated queries to tell you more about whatever you have searched for. Take a look at the queries about Wikidata itself.
- Hierarchies: Queries can reveal hierarchies and taxonomy on Wikidata. Wikidata is chaotic, it’s true, but there is a hierarchy to it. Using the P279 (Subclass of) property, paired with an item in question, like cities again, you can learn where that thing “lives” in this hierarchy and make better edits.
- Keeping count: Queries can count. Counting items in Wikidata is simple enough, but this act can reveal some very important things about Wikidata and everything it represents. There is a feature of properties on Wikidata called “property constraints” — these constraints guide and recommend Wikidata community members to add the appropriate kind of data. This query shows which properties have the most constraints, which may indicate complexity and specificity when adding data. From there, more community members can add more data more accurately. Who knew querying could reveal so much!?
- Reveal the inner workings of the universe*: Okay, I exaggerated…but you can turn queries on Wikidata itself to learn about its inner workings. Wikidata describes properties the same way it describes items. This means you can write queries that can tell you all about how properties relate to each other. This can reveal not only the internal structure of Wikidata itself, but also how we describe relationships in a linked data environment. You can also search for inverse properties, usage examples, related properties, as well as a set of property constraints we can see — all thanks to queries.
I think you’ll agree, queries can tell us a lot more than just facts. Yes, they can answer questions, but queries can make Wikidata a much more useful, urgent, and accessible resource for everyone.
Interested in learning more about querying Wikidata? Take one of our Wikidata Institute courses: wikiedu.org/wikidata.
Will and Reema, Sending kudos for this and your recent posts that are so informative and useful re: Wikidata. I look forward to trying out several approaches you offer, and the raised eyebrows that will follow as I glean the results. Well done.