Tabular vs. Linked Data
To learn how to use the Wikidata Query Service, you will first need to understand the structure of Wikidata, that is, what a database of linked data looks like.
In this tutorial, many examples will be based on the data presented in the following table:
|Item ID||Title||Director||Duration||$Box office|
|wd:Q17738||Star Wars Episode IV: A New Hope||George Lucas||121||775398007|
|wd:Q181795||Star Wars Episode V: The Empire Strikes Back||Irvin Kershner||124||538400000|
|wd:Q181803||Star Wars Episode VI: Return of the Jedi||Richard Marquand||134||475100000|
|wd:Q165713||Star Wars: Episode I – The Phantom Menace||George Lucas||136||1027044677|
|wd:Q181069||Star Wars Episode II: Attack of the Clones||George Lucas||142||649398328|
|wd:Q42051||Star Wars: Episode III – Revenge of the Sith||George Lucas||140||848800000|
|wd:Q6074||Star Wars: The Force Awakens||J. J. Abrams||135||2068223624|
|wd:Q18486021||Star Wars: The Last Jedi||Rian Johnson||152||1332539889|
|wd:Q20977110||Star Wars: The Rise of Skywalker||J. J. Abrams||141||851058441|
This is a small dataset that details some information about films in the Star Wars series. For each film, a few attributes or properties are shown: the title of the film, its director, its duration (in minutes), and the box office takings accumulated by the film (in dollars). If you are familiar with Excel or SQL, this way of presenting data should look familiar to you. However, Wikidata is not a database based on tables, like the one above, but rather has a “Linked Data” format. What does that mean?
In a linked data model, the data in the first row of the table above would be represented as:
Wikidata, which uses the linked data format, stores information in the form of statements. Statements, formally known as “subject, predicate, object” triples, have an Item-Property-Value structure.
For instance, the statement “The sky has the color blue” consists of:
(1) a subject (“the sky”)
(2) a predicate (“has the color”)
(3) an object (“blue”).
Likewise, the statement “Star Wars Episode IV: A New Hope was directed by George Lucas” consists of (1) a subject/Item “Star Wars Episode IV: A New Hope ”, (2) a predicate/Property “was directed by”, and (3) an object/Value “George Lucas”.
You can think of each row in the data table above as an Item, the column headers as Property names, and the data cells as property Values.
So another way of describing this data is through statements. For example, for the item in the first row of the table, the data can be described with the statements:
|Q17738||title||Star Wars Episode IV: A New Hope|
Statements describe detailed characteristics of an Item, and consist of property-value pairs, such as “director: George Lucas”, or “duration: 121 minutes”.
Properties in Wikidata have a P followed by a number. For example, the property “director” is P57.
The value of this property for the item Q17738 (Star Wars Episode IV: A New Hope) is George Lucas, which is also an item – Q38222.
Not all values are also items. For example, the value for the property “duration” (P2047) for the item Q17738 is 121 minutes.