Page MenuHomePhabricator

[M] Units support for quantity datatype
Closed, ResolvedPublic

Assigned To
Authored By
matthiasmullie
Nov 29 2019, 1:36 PM
Referenced Files
F31699462: Screen Shot 2020-03-23 at 3.19.32 PM.png
Mar 23 2020, 10:56 PM
F31699477: Screen Shot 2020-03-20 at 6.03.23 PM.png
Mar 23 2020, 10:56 PM
F31699470: Screen Shot 2020-03-23 at 3.10.16 PM.png
Mar 23 2020, 10:56 PM
F31699466: Screen Shot 2020-03-20 at 6.01.13 PM.png
Mar 23 2020, 10:56 PM
F31699464: Screen Shot 2020-03-23 at 3.32.42 PM.png
Mar 23 2020, 10:56 PM
F31699474: Screen Shot 2020-03-20 at 6.04.42 PM.png
Mar 23 2020, 10:56 PM
F31552245: set-units.png
Feb 11 2020, 1:08 PM
F31546127: Screenshot 2020-02-03 17.10.30.png
Feb 3 2020, 4:14 PM

Description

We have this:
When entering data for a qualifier whose property has a data type of "quantity", the user can't enter units for the quantity, only a number.
In wikidata the user can enter the number and the units - e.g. if the statement is 'length' they can add the value for length plus 'metres', 'inches', etc.

We want this:
We want to support units for those quantity values, so we can have statements about, for example, the dimensions of an image

Examples:
A quantity can be population, maximum capacity, floors above ground, and numeric value, or others (see full list of Wikidata properties that use the quantity data type).

Acceptance Criteria:

  • can enter units for the quantity values
    • via File page
    • via UploadWizard

Event Timeline

Here's a question – where do the units come from? Are we using a hard-coded list, or somehow fetching a list of appropriate units based on the property? Units will also be property-specific (a "length" property will have different units from a "weight" property).

How does Wikidata handle this?

egardner renamed this task from Units support for quantity datatype to [Medium] Units support for quantity datatype.Dec 10 2019, 5:36 PM
egardner renamed this task from [Medium] Units support for quantity datatype to [M] Units support for quantity datatype.

Here's a question – where do the units come from? Are we using a hard-coded list, or somehow fetching a list of appropriate units based on the property? Units will also be property-specific (a "length" property will have different units from a "weight" property).

How does Wikidata handle this?

Wikidata. You can put in centimeter or Cameroon

Any news on this? We just created https://www.wikidata.org/wiki/Property:P7787 to indicate the heading the photographer was looking when taking the image. The unit would be degree (http://www.wikidata.org/entity/Q28390). Currently can't use that, just without a unit, see for example https://commons.wikimedia.org/w/index.php?title=File:%D0%A1h%C3%A2teau_d%27Amboise_4.jpg&diff=prev&oldid=387384011

This is work that will be coming up soon. Best estimate for deployment is early Feb., but it could be earlier if things work out. We're a bit short-handed at the moment.

@matthiasmullie what am I doing wrong at /w/api.php?action=wbeditentity&format=json&id=M51867633&token=123445678903dd2%2B%5C&data=%7B%22claims%22%3A%5B%7B%22mainsnak%22%3A%7B%22snaktype%22%3A%22value%22%2C%22property%22%3A%22P7787%22%2C%22datavalue%22%3A%7B%22value%22%3A%20%7B%22amount%22%20%3A%20%22%2B67%22%2C%20%22unit%22%20%3A%20%22http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ28390%22%7D%2C%22type%22%3A%22quantity%22%7D%7D%2C%22type%22%3A%22statement%22%2C%22rank%22%3A%22normal%22%7D%5D%7D ?

@matthiasmullie what am I doing wrong at /w/api.php?action=wbeditentity&format=json&id=M51867633&token=123445678903dd2%2B%5C&data=%7B%22claims%22%3A%5B%7B%22mainsnak%22%3A%7B%22snaktype%22%3A%22value%22%2C%22property%22%3A%22P7787%22%2C%22datavalue%22%3A%7B%22value%22%3A%20%7B%22amount%22%20%3A%20%22%2B67%22%2C%20%22unit%22%20%3A%20%22http%3A%2F%2Fwww.wikidata.org%2Fentity%2FQ28390%22%7D%2C%22type%22%3A%22quantity%22%7D%7D%2C%22type%22%3A%22statement%22%2C%22rank%22%3A%22normal%22%7D%5D%7D ?

Probably nothing :)
I have a feeling this @todo has something to do with it: https://github.com/wikimedia/mediawiki-extensions-Wikibase/blob/master/repo/includes/WikibaseRepo.php#L1235
It looks like only entities from a local repo (in this case Commons) are allowed, but we need it to accept Wikidata concept uris.
Will continue looking into this - stay tuned!

Change 566397 had a related patch set uploaded (by Matthias Mullie; owner: Matthias Mullie):
[mediawiki/extensions/WikibaseMediaInfo@master] Implement units support for quantity input UI

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

Yup, it looks like the issue is:

	/**
	 * @return string
	 */
	private function getVocabularyBaseUri() {
		//@todo: We currently use the local repo concept URI here. This should be configurable,
		// to e.g. allow 3rd parties to use Wikidata as their vocabulary repo.
		if ( $this->getDataAccessSettings()->useEntitySourceBasedFederation() ) {
			return $this->getLocalEntitySource()->getConceptBaseUri();
		}

		return $this->settings->getSetting( 'conceptBaseUri' );
	}

This need to be switched based on entity type, as mediainfos need the concept base URI of commons, and items and properties need the concept base URI of wikidata.

In WikibaseRepo this base uri is currently used by getLocalItemUriParser which sounds like it only ever needs the actually local concept URI base.
It is also used in newValidatorBuilders however, which in turn is used in buildQuantityValidators, this should probably only ever have the concept URI base for Items.

Addshore triaged this task as Medium priority.Jan 23 2020, 8:55 AM
Addshore added a project: Wikidata.
Addshore added a project: Wikidata-Campsite.
Addshore moved this task from Incoming to Ready to pick up on the Wikidata-Campsite board.

Change 566753 had a related patch set uploaded (by Addshore; owner: Addshore):
[mediawiki/extensions/Wikibase@master] Cleanup repo Item vocab uri parsing & fix federated units

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

Change 566766 had a related patch set uploaded (by Addshore; owner: Addshore):
[mediawiki/extensions/WikibaseLexeme@master] Adjust for Repo, LocalItemUriParser -> ItemUrlParser

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

Change 566767 had a related patch set uploaded (by Addshore; owner: Addshore):
[mediawiki/extensions/Wikibase@master] Remove deprecated WikibaseRepo::getLocalItemUriParser

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

Change 566753 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Cleanup repo Item vocab uri parsing & fix federated units

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

Change 566766 merged by jenkins-bot:
[mediawiki/extensions/WikibaseLexeme@master] Adjust for Repo, LocalItemUriParser -> ItemUrlParser

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

Change 566767 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Remove deprecated WikibaseRepo::getLocalItemUriParser

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

I just come here to report this bug. Luckily it is being fixed.

Actual (backend) support for other entities has already been merged.
Patch to bring support to the frontend is in code review.

Here's what that'll look like - pretty much the exact same as Wikidata & support for time inputs.

Empty:

Screenshot 2020-02-03 17.10.30.png (256×1 px, 18 KB)

Once it receives input, the customization panel pops out:

Screenshot 2020-02-03 17.10.36.png (358×1 px, 39 KB)

Where units can be searched:

Screenshot 2020-02-03 17.10.53.png (422×1 px, 48 KB)

And are eventually rendered with units:

Screenshot 2020-02-03 17.11.01.png (498×1 px, 50 KB)


And pretty much the exact same for qualifiers:

Screenshot 2020-02-03 17.11.19.png (728×1 px, 103 KB)

Where units can be searched:

Screenshot 2020-02-03 17.10.53.png (422×1 px, 48 KB)

If we're building a new interface, can you make it a bit smarter so it actually suggests a relevant unit? If I'm adding things like height and width, I probably want something like cm (not Cameroon) and when I add heading I probably want degree. Now I just get everything .

Wanted to test this, but looks like 1.35.0-wmf.18 got rolled back everywhere 2 days ago.

If we're building a new interface, can you make it a bit smarter so it actually suggests a relevant unit? If I'm adding things like height and width, I probably want something like cm (not Cameroon) and when I add heading I probably want degree. Now I just get everything .

I like the idea, but it's going to be a bit of a pain to figure out how to best go about this (can't hardcode specific items into the code)
Wikidata has a bazillion config vars to reference specific items, I guess we could go with something similar here.
Either way, I filed T244856 - it's outside this task's scope :)

I agree, let's continue in the other task about that part.

Change 566397 merged by jenkins-bot:
[mediawiki/extensions/WikibaseMediaInfo@master] Implement units support for quantity input UI

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

This is testable on Production Commons

Checked in wmf.24- all specs are in place (checked them with F31552245).

Also, selectively checked List of Properties - all looks ok.
The screenshots below are for illustration only (no issues have been found):
(1) A property with data type 'quantity` is selected; 'Set unit' field is available

Screen Shot 2020-03-20 at 6.01.13 PM.png (287×910 px, 39 KB)

(2) Fields without entered data

Screen Shot 2020-03-23 at 3.32.42 PM.png (379×914 px, 45 KB)

(3) data entered
Screen Shot 2020-03-23 at 3.19.32 PM.png (670×885 px, 290 KB)

(4) the list with drop-down suggestions

Screen Shot 2020-03-23 at 3.10.16 PM.png (328×823 px, 56 KB)

Screen Shot 2020-03-20 at 6.04.42 PM.png (379×946 px, 60 KB)


Note:
It's possible to enter e into the field that has type="number" - it's the same for wikidata also, so it's not an issue. However, it might be confusing for some users who are not familiar with e notation.
Screen Shot 2020-03-20 at 6.03.23 PM.png (276×899 px, 39 KB)