# SPARQL/WIKIDATA Qualifiers, References and Ranks

The data on WIKIDATA contains more info than only the triples. For a full description see Wikidata:Glossary.
Let us look at Douglas Adams (Q42) and where he is educated at (P69).

### Qualifiers

Let us list the education of Douglas Adams and the qualifiers Start time end End time:
Try it!
The prefix p: points not to the object, but to a statement node. This node then is the subject of other triples.
The prefix ps: within the statement node retrieves the object. The prefix pq: within the statement node retrieves the qualifier information.
The code can be abbreviated a lot with the [ ] syntax by eliminating the variable ?statement.
Try it!

### References

Let us list the education of Douglas Adams and the stated in (P248) reference:
Try it!
The prefix p: points not to the object, but to a statement node. This node then is the subject of other triples.
The prefix ps: within the statement node retrieves the object. The prov:wasDerivedFrom within the statement node points to a new reference node. The prefix pr: within the reference node retrieves the reference information.
The code can be abbreviated a lot with the [ ] syntax by eliminating the variables ?statement and ?refnode.
Try it!
You might have noticed that only one of the 2 educations is listed in the queries above. To list both we need to introduce OPTIONAL{ }. As this can only be used with full sentences we need to use the full expanded syntax with triples as short sentence:
Try it!

### Ranks

Let us list the education of Douglas Adams and the ranks of them:
Try it!
The prefix p: points not to the object, but to a statement node. This node then is the subject of other triples.
The prefix ps: within the statement node retrieves the object. The wikibase:rank within the statement node retrieves the rank information.
The code can be abbreviated a lot with the [ ] syntax by eliminating the variable ?statement.
Try it!
An example with different ranks is the (historcal) countries in which Berlin lied.
Try it!
The 3 possible values for ranks are wikibase:PreferredRank, wikibase:NormalRank and wikibase:DeprecatedRank
Compare this with the normal triples, which will select only the value(s) with the highest rank. In this case only the Preferred Rank value Germany (Q183).
Try it!

#### Ignore ranks in queries

Ranks might cause unexpected results. For example, consider this query, that will give you back all Dutch municipalities that share a border with Alphen aan den Rijn (Q213246):
Try it!
This will not show Boskoop (Q894442), because its rank for municipality of the Netherlands (Q2039348) is 'normal' while the other three values for instance of (P31) are 'preferred'. To see Boskoop in the previous query as well, rewrite it like this:
Try it!
Or use a property path to shorten the query like this:
Try it!

### Summary

| | Example | |
| Statements | wd:Q42 wdt:P69 wd:Q691283. or wd:Q42 p:P69 ?s. ?s ps:P69 wd:Q691283. or wd:Q42 p:P69 [ ps:P69 wd:Q691283 ]. | Wikidata datamodel |
| Rank | wd:Q42 p:P69 [ wikibase:rank ?rank ]. | Wikidata datamodel |
| Qualifier | wd:Q42 p:P69 [ pq:P580 ?qualifier ]. | Wikidata datamodel |
| Reference | wd:Q42 p:P69 [ prov:wasDerivedFrom [ pr:P248 ?ref ] ]. | Wikidata datamodel |
A full query of Douglas Adams education, with rank, qualifiers and references could look like
Try it!

### References

* d:User:TweetsFactsAndQueries/A Guide To WDQS