Page MenuHomePhabricator

[M] Units support for quantity datatype
Closed, ResolvedPublic

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

Restricted Application removed a project: Patch-For-Review. · View Herald TranscriptNov 29 2019, 1:36 PM

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.
Addshore claimed this task.Jan 23 2020, 2:41 PM

Stealing to fix the bit in wikibase backend

Restricted Application added a project: User-Addshore. · View Herald TranscriptJan 23 2020, 2:42 PM

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

Addshore removed Addshore as the assignee of this task.Jan 23 2020, 3:50 PM

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

Jarekt added a subscriber: Jarekt.Jan 29 2020, 4:54 AM

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:

Once it receives input, the customization panel pops out:

Where units can be searched:

And are eventually rendered with units:


And pretty much the exact same for qualifiers:

Where units can be searched:

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

Etonkovidova closed this task as Resolved.Mar 23 2020, 10:56 PM

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

(2) Fields without entered data


(3) data entered

(4) the list with drop-down suggestions




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.