Jdouglas has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/205621

Change subject: Add walkthrough of simple linked data exploration
......................................................................

Add walkthrough of simple linked data exploration

Fixes #T96624

This should probably also live on mediawiki.org, but it's useful to
bundle it with the code, so that it's easy to find and (ideally)
keeps up to date as the code changes.

Change-Id: Ic36d26a82c0de3e2fa743167f76ec0766539570d
---
A docs/exploring-linked-data.md
1 file changed, 128 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/rdf 
refs/changes/21/205621/1

diff --git a/docs/exploring-linked-data.md b/docs/exploring-linked-data.md
new file mode 100644
index 0000000..9fe2d43
--- /dev/null
+++ b/docs/exploring-linked-data.md
@@ -0,0 +1,128 @@
+# Exploring linked data
+
+*April 20, 2015*
+
+In the following examples, we'll walk through an analog to "casually clicking 
around the Web"; we'll learn information by exploring linked relationships.
+
+Instead of clicking on links in a Web page, we'll run SPARQL queries.
+
+## Using both SPARQL and wikidata.org
+
+### George Washington's linked data
+
+George Washington has id `Q23` on Wikidata:
+
+*https://www.wikidata.org/wiki/Q23*
+
+Let's see what we can learn about the national founder through RDF.
+
+```sparql
+prefix wd: <http://www.wikidata.org/entity/>
+select ?predicate ?object WHERE {
+  wd:Q23 ?predicate ?object
+}
+```
+
+This query asks for the *predicate* and *object* of every 
*subject/predicate/object* triple which has the subject *Q23*.  It yields 
dozens of rows of linked data:
+
+| predicate                               | object                             
                                       |
+| --------------------------------------- | 
------------------------------------------------------------------------- |
+| <http://www.wikidata.org/entity/P1005s> | 
<http://www.wikidata.org/entity/Q23S6ED74C28-53ED-4D7B-A039-BFD0AF2E4380> |
+| <http://www.wikidata.org/entity/P1006s> | 
<http://www.wikidata.org/entity/Q23S065319EA-9AE1-4630-879C-C9E0F2916467> | 
+| <http://www.wikidata.org/entity/P1017s> | 
<http://www.wikidata.org/entity/Q23SC7F45442-BF99-422E-A5D0-72AFA9C60F57> |
+| <http://www.wikidata.org/entity/P102s>  | 
<http://www.wikidata.org/entity/Q23S1173e514-4fcd-951d-e66b-2f9888dc48f0> |
+| ...                                     | ...                                
                                       |
+
+Let's explore the first row, which says that *"wd:Q23 wd:P1005s 
wd:Q23S6ED74C28-53ED-4D7B-A039-BFD0AF2E4380"*.  On Wikidata, `P1005` is the 
identifier for the Portuguese National Library:
+
+*https://www.wikidata.org/wiki/Property:P1005*
+
+The predicate appends an *s* to the property URI, indicating that it is 
`P1005`, used as a statement.
+
+In other words, this statement says that George Washington has an identifier 
in the Portugese National Library, with the Wikidata ID 
`Q23S6ED74C28-53ED-4D7B-A039-BFD0AF2E4380`.  It's not yet apparent what the 
Library identifier is.
+
+Let's find out everything we know about this item.
+
+```sparql
+prefix wd: <http://www.wikidata.org/entity/>
+select ?predicate ?object WHERE {
+  wd:Q23S6ED74C28-53ED-4D7B-A039-BFD0AF2E4380 ?predicate ?object
+}
+```
+
+| predicate                                  | object                          
                                   |
+| ------------------------------------------ | 
------------------------------------------------------------------ |
+| <http://www.w3.org/ns/prov#wasDerivedFrom> | 
<http://www.wikidata.org/entity/Ref404a80529754c8404ae9a20ffb34da> |
+| <http://www.wikidata.org/entity/P1005v>    | 64839                           
                                   |
+| rdf:type                                   | 
<http://www.wikidata.org/ontology#Statement>                       |
+
+Here we see a predicate that appends a *v* to the property URI from before, 
indicating that it is `P1005` used as a value.  The value itself is `64839`.  
Now we know that George Washington has the identifier number *64839* in the 
Portugese National Library.
+
+### Data linked to George Washington
+
+Let's flip things around and see what data are associated with George 
Washington.
+
+```sparql
+prefix wd: <http://www.wikidata.org/entity/>
+select ?subject ?predicate WHERE {
+  ?subject ?predicate wd:Q23
+}
+```
+
+| subject                                                                      
  | predicate                              |
+| 
------------------------------------------------------------------------------ 
| -------------------------------------- |
+| 
<http://www.wikidata.org/entity/Q511164Scd0598a2-4b84-3acf-79c0-5c044cb6a054>  
| <http://www.wikidata.org/entity/P138v> |
+| 
<http://www.wikidata.org/entity/Q744159S3a1c5a77-413a-b0c5-401b-f2c0b8ec73ed>  
| <http://www.wikidata.org/entity/P138v> |
+| 
<http://www.wikidata.org/entity/Q2301794S2c01366b-4526-ea3a-edd4-d87952225ff8> 
| <http://www.wikidata.org/entity/P138v> |
+| 
<http://www.wikidata.org/entity/Q3497629S24d67468-4fda-3a01-881c-66c88fbb6f83> 
| <http://www.wikidata.org/entity/P180v> |
+| ...                                                                          
  | ...                                    |
+
+We get a few dozen results.  Many of them have the predicate `P138`, which in 
Wikidata means *"named after"*:
+
+*https://www.wikidata.org/wiki/Property:P138*
+
+It appears that quite a few things have been named after George Washington.  
Let's see about the first one:
+
+```sparql
+prefix wd: <http://www.wikidata.org/entity/>
+select ?subject ?predicate WHERE {
+  ?subject ?predicate wd:Q511164Scd0598a2-4b84-3acf-79c0-5c044cb6a054
+}
+```
+
+This query asks about what data are related to item 
`Q511164Scd0598a2-4b84-3acf-79c0-5c044cb6a054`, and how they are related.
+
+| subject                                  | predicate                         
     |
+| ---------------------------------------- | 
-------------------------------------- |
+| <http://www.wikidata.org/entity/Q511164> | 
<http://www.wikidata.org/entity/P138s> |
+
+There's but one result, that says item `Q511164` is named after George 
Washington.
+
+Checking Wikidata, we find that `Q511164` is the ID of [Washington 
County](https://www.wikidata.org/wiki/Q511164) in Maryland, United States.
+
+## Using only SPARQL (and the Wikidata ontology)
+
+It's kind of tedious to keep going back to the Web browser to find out things 
like this, so let's see if we can enhance our queries to be more 
self-sufficient.
+
+In the Wikidata ontology, property `P373` is the name of a Wikimedia Commons 
category.  Let's use this property to find out which Wikidata item is George 
Washington.  Let's also use the property `P31`, *instance of*, to find out 
which items are (human) people, `Q5`.
+
+```sparql
+prefix wd: <http://www.wikidata.org/entity/>
+select ?subject WHERE {
+  ?subject wd:P373s ?a                  .
+  ?a       wd:P373v "George Washington" .
+  ?subject wd:P31s  ?b                  .
+  ?b       wd:P31v  wd:Q5               .
+}
+```
+
+This query asks two questions, and takes the intersection:
+
+* Which subjects have a Wikimedia Commons category named "George Washington"
+* Which subjects are an instance of *human*
+
+The results contain exactly one row, `Q23`, which we know from before to be 
George Washington:
+
+| subject                                   |
+| ----------------------------------------- |
+| <http://www.wikidata.org/entity/Q23>      |

-- 
To view, visit https://gerrit.wikimedia.org/r/205621
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic36d26a82c0de3e2fa743167f76ec0766539570d
Gerrit-PatchSet: 1
Gerrit-Project: wikidata/query/rdf
Gerrit-Branch: master
Gerrit-Owner: Jdouglas <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to