In the following examples, we'll see how we can discover information by exploring linked data by walking through a few SPARQL analogs of "casually clicking around the Web".
George Washington has the identifier Q23
on Wikidata. Let's see what we can learn about the national founder through RDF.
PREFIX entity: <http://www.wikidata.org/entity/>
SELECT ?predicate ?object WHERE {
entity:Q23 ?predicate ?object .
} LIMIT 10
This query asks for the predicate and object of every subject/predicate/object triple which has the subject Q23. It yields the following:
predicate | object |
---|---|
schema:dateModified | 2015-04-23T01:45:55Z |
schema:description | American politician, 1st president of the United States (in office from 1789 to 1797) |
schema:version | 212398883 |
http://www.wikidata.org/prop/direct/P1005 | 64839 |
http://www.wikidata.org/prop/direct/P1006 | 069038171 |
http://www.wikidata.org/prop/direct/P1017 | ADV10077200 |
http://www.wikidata.org/prop/direct/P106 | http://www.wikidata.org/entity/Q131512 |
http://www.wikidata.org/prop/direct/P106 | http://www.wikidata.org/entity/Q1734662 |
http://www.wikidata.org/prop/direct/P106 | http://www.wikidata.org/entity/Q189290 |
Let's explore the statement in last row:
<http://www.wikidata.org/entity/Q23> <http://www.wikidata.org/prop/direct/P106> <http://www.wikidata.org/entity/Q189290> .
On Wikidata, P106
is the identifier for the occupation property, and Q189290
is the identifier for the (military) officer entity. In other words, this statement says that George Washington held the occupation of officer. This is interesting, but it doesn't tell us a whole lot about where or where Washington was an officer, or what rank he held during that time.
Let's find out everything we know about this item.
PREFIX entity: <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
SELECT ?predicate ?object WHERE {
entity:Q23 p:P106 ?subject .
?subject ps:P106 entity:Q189290 .
?subject ?predicate ?object .
} LIMIT 10
There's nothing very interesting here; it looks like a dead end. Let's explore a different path, substituting position held (P39
) for occupation. First, we'll check whether Washington held any positions:
PREFIX entity: <http://www.wikidata.org/entity/>
PREFIX a: <http://www.wikidata.org/prop/direct/>
SELECT ?object WHERE {
entity:Q23 a:P39 ?object .
} LIMIT 10
object |
---|
http://www.wikidata.org/entity/Q11696 |
http://www.wikidata.org/entity/Q1115127 |
It looks like Washington held the position with the Wikidata identifier Q11696
, or President of the United States of America. Let's find out more about it.
PREFIX entity: <http://www.wikidata.org/entity/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
SELECT ?predicate ?object WHERE {
entity:Q23 p:P39 ?subject .
?subject ps:P39 entity:Q11696 .
?subject ?predicate ?object .
} LIMIT 10
There's lots of information about Washington's presidency. We can see a couple of dates with the years 1789 and 1797, which seem likely to be the beginning and ending of his presidency. Checking Wikidata, we can see that the corresponding property identifiers, P580
and P582
, are indeed start time and end time, respectively.
Let's flip things around and see what data are associated with George Washington.
PREFIX entity: <http://www.wikidata.org/entity/>
SELECT ?subject ?predicate WHERE {
?subject ?predicate entity:Q23 .
} LIMIT 10
A bunch of entities are linked to Washington via a variety of properties. Let's find out about the first one:
PREFIX entity: <http://www.wikidata.org/entity/>
SELECT ?subject WHERE {
entity:Q191789 rdfs:label ?subject .
} LIMIT 10
subject |
---|
Martha Washington |
We found Washington's wife. She is associated with him via P26
, the Wikidata identifier for spouse.
To discover this without manually looking it on the Wikidata wiki, we can inspect the label of the entity that connects Washington's wife to him:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX entity: <http://www.wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT ?relationship WHERE {
entity:Q191789 ?predicate entity:Q23 .
?property wikibase:directClaim ?predicate .
?property rdfs:label ?relationship .
} LIMIT 10
relationship |
---|
spouse |