SPARQL/WIKIDATA Precision, Units and Coordinates



The data on WIKIDATA contains more info than only the triples. For a full description see Wikidata:Glossary.

Values on Wikidata often have additional info like precision, units etc. Wikidata's solution for almost everything is more triples. And it means more prefixes.

Entities
For entities there is no additional information.

Strings
For strings there is no additional information.

Time
The prefix  points to a statement node. The prefix  within a statement node retrieves a time node. The  within the time node retrieves the time. The  within a time node retrieves the precision of the time.
 * The codes for precision are 0: billion years, 1: hundred million years, 3: million years, 4: hundred thousand years, 5: ten thousand years, 6: millennium, 7: century, 8: decade, 9: year, 10: month, 11: day, 12: hour, 13: minute, 14: second.

The  within a time node retrieves the timezone, as an offset from UTC in minutes. The  within a time node retrieves the calendar, a common used value is.

Comment on filtering on dates. On filtering dates the code  should be added, like:

Monolingual texts
For monolingual text there is no additional information. The text is represented as a string literal with language tag. It has only simple value.

Coordinates
The prefix  points to a statement node. The prefix  within a statement node for a coordinate retrieves the full coordinate, like Point(2.1749 41.3834). The prefix  within a statement node retrieves a coordinate node. The  within the coordinate node retrieves the longitude value. The  within a coordinate node retrieves the latitude value. The  within a coordinate node retrieves the globe object. For coordinates on earth it will be. The  within a coordinate node retrieves the precision of the coordinate values, measured in degrees. Multiply by 111000 to convert to meters.

Here an example of mountains not located on Earth.

Quantities
The prefix  points to a statement node. The prefix  within a statement node retrieves a value node. The  within the value node retrieves a quantity value. The  within a value node retrieves a unit. Not all quantities have units. The  and   can be used to indicate the precision.

Within the Unit you can retrieve the statement for converting the unit to the SI unit etc. See in the example the length of the Mississippi River is in miles, and can be converted to SI units. The conversion could also be needed if some lengths are in meters and some in kilometers to so.

Some variables are used only for demonstration. Without those the query will be:

The code can be abbreviated a lot with the [ ] syntax by eliminating the variables for the nodes and unused variables.

Normalised units
Instead of converting by SPARQL code as above the units can be converted automatically by using prefix  (normalised) instead of.

The prefix  within a statement node retrieves a value node. The prefix  within a statement node retrieves a normalised value node. Note that a query with  will give you only the values with units presents in [//gerrit.wikimedia.org/r/plugins/gitiles/operations/mediawiki-config/+/master/wmf-config/unitConversionConfig.json this list].

Notice that the units changed from km and miles into meters, and that the values are all calculated accordingly. Also the lower- and upper-bound values change accordingly. The precision now is in meters.

Normalized quantity values are value nodes that are parallel to the original data nodes but represented in base units. They are connected to their parent nodes by predicates with prefix having "v" replaced with "n" - i.e.,   (for references) and   (for qualifiers).

The code can be abbreviated a lot with the [ ] syntax by eliminating the variables for the nodes and unused variables.