Jump to content

User:Mhl20/SPARQL Prefixes

From Wikidata

The most confusing thing I've come across so far in trying to understand and write SPARQL queries in order to get data out of Wikidata is figuring out when you should use each of the prefixes corresponding different namespaces.

Fortunately, my colleague User:Oravrattas was helpful in explaining where you use some of these prefixes depending on what information you want to pick out of the example labelled statement group here:

Labelled diagram showing elements of Wikidata's data model

In order to try to understand this better, I've made a series of edits of that diagram to show how the different elements can be related in SPARQL query using the various namespace prefixes, essentially most of those shown in this diagram:

The Wikidata data model in RDF

... and I've added sample SPARQL queries corresponding to each diagram underneath. I hope this is helpful to someone! (Unfortunately the images I made in Inkscape aren't being rendered properly in several ways, so I'll need to fix them at some point in the future.)

The wdt: prefix

[edit]

A diagram showing elements of a statement selected by the wdt: prefix in SPARQL queries for Wikidata

SELECT ?institution WHERE { wd:Q42 wdt:P69 ?institution }
Try it!

The p: prefix

[edit]

A diagram showing elements of a statement selected by the p: prefix in SPARQL queries for Wikidata

SELECT ?institution WHERE { wd:Q42 p:P69 ?institution }
Try it!

The ps: prefix

[edit]

A diagram showing elements of a statement selected by the ps: prefix in SPARQL queries for Wikidata

SELECT ?institution WHERE { wds:q42-0E9C4724-C954-4698-84A7-5CE0D296A6F2 ps:P69 ?institution }
Try it!

The pq: prefix

[edit]

A diagram showing elements of a statement selected by the pq: prefix in SPARQL queries for Wikidata

SELECT ?date WHERE { wds:q42-0E9C4724-C954-4698-84A7-5CE0D296A6F2 pq:P580 ?date }
Try it!

The prov:wasDerivedFrom relationship

[edit]

A diagram showing elements of a statement selected by the prov:wasDerivedFrom relationship in SPARQL queries for Wikidata

SELECT ?reference WHERE { wds:q42-0E9C4724-C954-4698-84A7-5CE0D296A6F2 prov:wasDerivedFrom ?reference }
Try it!

The pr: prefix

[edit]

A diagram showing elements of a statement selected by the pr: prefix in SPARQL queries for Wikidata

SELECT ?value WHERE { wdref:93e4b46a54654511255efce1b0c0057095924d36 pr:P854 ?value }
Try it!

The prv: prefix

[edit]

TODO - I still don't understand this one well enough