Page MenuHomePhabricator

Implement “Units” constraint
Closed, ResolvedPublic

Description

As a data maintainer I want to be able to define which units are allowed for a given property with datatype quantity.
I only want to define the base-unit for a dimension and then automatically all the other derived units are also allowed.

See Template:Constraint:Units: must use one of the listed units (or novalue for no units allowed).

This ought to cover T132704.

Steps:

  • see README for adding a new constraint type in general
  • this checker will need some unit resolver thingy injected – see RangeCheckerHelper (because we also want to accept millimetres if the constraint says metres)

Patch-For-Review:

Event Timeline

Lydia_Pintscher moved this task from incoming to ready to go on the Wikidata board.

We might also want to add another constraint, for the base unit of a quantity (kg, s, m, …), accepting any quantity whose conversion to standard units (via UnitConverter) has that base unit as unit.

I suppose this could also be done as the same constraint type with two different kinds of parameters.

@Lydia_Pintscher:

I only want to define the base-unit for a dimension and then automatically all the other derived units are also allowed.

That’s a change in behavior from KrBot (for example, P​2660 “topographic prominence” has a constraint stating that the unit should be “metre”, and the database report lists lots of items with unit “foot” as violations). Are we sure we want this to be the default behavior?

We just talked about it and it makes sense to have the default be more lenient for now. If needed we can add a parameter to be more strict later.

Change 423972 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseQualityConstraints@master] Add support for parsing units parameter

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

Change 423973 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseQualityConstraints@master] Add “allowed units” constraint type

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

I'm not sure if it's a good idea to allow any convertible unit by default.

There are several things that could be improved around quantity datatype and I wouldn't start with this one.

Change 423972 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Add support for parsing units parameter

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

Change 423973 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Add “allowed units” constraint type

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

Change 427391 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseQualityConstraints@master] Add missing roles to AllowedUnitsChecker messages

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

Change 427392 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseQualityConstraints@master] Use wbqc-violation-message-units-none message

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

Change 427393 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/WikibaseQualityConstraints@master] Move word inside {{PLURAL}} template

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

Change 427391 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Add missing roles to AllowedUnitsChecker messages

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

This is live on wikidata-constraints now – see e. g. the last four statements of Leonardo da Vinci.

Change 427392 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Use wbqc-violation-message-units-none message

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

Change 427393 merged by jenkins-bot:
[mediawiki/extensions/WikibaseQualityConstraints@master] Move word inside {{PLURAL}} template

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