Page MenuHomePhabricator

(MS 3) query for quantity values
Closed, ResolvedPublic5 Estimated Story Points

Description

As an editor I want to query for data involving quantity values.

Problem:
We currently don't allow querying for values of Properties with datatype quantity. We should.

Example:

  • people with an Erdős number of 1

Error messages:
value empty
Copy: Please enter a number

image.png (87×246 px, 6 KB)

value is NaN
Copy: Please enter a number

image.png (90×248 px, 5 KB)

invalid unit selected
Copy: Please select a valid unit or remove input

image.png (114×257 px, 7 KB)

error in value and unit
Copy: Please enter a number and select a valid unit or remove input

image.png (108×244 px, 7 KB)

BDD
GIVEN a visual query
WHEN selecting a Property of datatype quantity
THEN the value input accepts quality values
AND the query result contains only results including an exact match for the given value

Acceptance criteria:

  • queries with Properties of datatype quantity are possible
  • quantity values incl. and excl. units are possible

Needed components:

Notes:

  • We do not handle less than/more than etc. in this ticket, only exact matches. Ranges are handled in T272692.
  • Not dealing with precision at all

The query that we're going to produce should look something like the following:

SELECT ?person ?Erdos
WHERE {
  ?person p:P2021/psv:P2021/wikibase:quantityAmount ?Erdos .
  FILTER( ?Erdos = 1)
}
LIMIT 3

https://w.wiki/34zj

The query if the user provides a unit:

# convert kilometer into meter and then query
SELECT * WHERE {
  BIND(4 AS ?userQuantity)
  BIND(wd:Q828224 AS ?userUnit)
  ?userUnit p:P2370/psv:P2370 [
    wikibase:quantityAmount ?conversionFactor;
    wikibase:quantityUnit ?coherentUnit
  ].
  BIND(?userQuantity * ?conversionFactor AS ?coherentQuantity)
  ?mountain p:P2044/psn:P2044 [
    wikibase:quantityAmount ?elevation;
    wikibase:quantityUnit ?coherentUnit
  ].
  FILTER(?elevation >= ?coherentQuantity)
  BIND(?elevation / ?conversionFactor AS ?userElevation)
}
LIMIT 10

https://w.wiki/34zm

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
amy_rc triaged this task as High priority.Jan 18 2021, 11:56 AM
Michael renamed this task from (MS 3) query for quantity values to (MS 3) 🛑 query for quantity values.Feb 24 2021, 1:04 PM
Michael renamed this task from (MS 3) 🛑 query for quantity values to (MS 3) query for quantity values.Mar 15 2021, 5:11 PM

This looks good! After a first check I noticed a couple of things:

  • It would be nice to fix the WiKit component and make the info icon/button vertically centered with the QuantityInput label. In WiKit, this component is using a different suffix for some reason (we should replace it there with the right one), which didn't allow catching this detail before:

    Screenshot 2021-04-08 at 13.33.16.png (296×2 px, 61 KB)
  • I remember we talked about only displaying "real" units in the Quantity lookup. How feasible is that? Would we want to document that as a future improvement?
  • Question for @Charlie_WMDE: would it make sense to simplify this error message to something like "Please enter a number and select a valid unit (optional)", I'd also suggest saying "leave empty" instead of "remove input" (e.g. when an invalid unit is provided), which sounds a bit too jargon-y in my opinion.

    Screenshot 2021-04-08 at 14.17.15.png (266×544 px, 36 KB)
  • I found this case where an item was wrongly excluded from the results after the (right?) unit was specified. I thought this could be related to the fact that the omitted item's quantity value has a qualifier (in comparison to the items that kept being shown in the results), but trying other queries* refuted that hypotheses, so now I'm not sure what might be wrong, if anything.

    To reproduce: If you query for the property "speed" and just indicate a matching value of "12", your results will retrieve – among others– the items Q479726 and Q88008887. But the former item will not appear if I specify the unit "knot" (I tried selecting various knot units just in case) in my query. The only difference between these values is the use of qualifiers, therefore the inference.

    *A similar case where the value having a qualifier doesn't prevent the item from appearting in the results: human painters that are 168 centimeters tall. The fact that Takeshi Kitano is included in the list refutes the qualifier hypothesis.

This looks good! After a first check I noticed a couple of things:

  • It would be nice to fix the WiKit component and make the info icon/button vertically centered with the QuantityInput label. In WiKit, this component is using a different suffix for some reason (we should replace it there with the right one), which didn't allow catching this detail before:

    Screenshot 2021-04-08 at 13.33.16.png (296×2 px, 61 KB)

Could you create an new Ticket for that? It is something that we should fix, but it is somewhat detached from the functionality that is implemented here.

  • I remember we talked about only displaying "real" units in the Quantity lookup. How feasible is that? Would we want to document that as a future improvement?

I don't think that this is feasible and I also remember it different. In my memory we said we wanted explicitly allow all units, because: 1. that is what Wikidata does and 2. the world is complex. Afaik, it was a user that requested to only show real units. But I think @Lydia_Pintscher could confirm this either way.

  • I found this case where an item was wrongly excluded from the results after the (right?) unit was specified. I thought this could be related to the fact that the omitted item's quantity value has a qualifier (in comparison to the items that kept being shown in the results), but trying other queries* refuted that hypotheses, so now I'm not sure what might be wrong, if anything.

    To reproduce: If you query for the property "speed" and just indicate a matching value of "12", your results will retrieve – among others– the items Q479726 and Q88008887. But the former item will not appear if I specify the unit "knot" (I tried selecting various knot units just in case) in my query. The only difference between these values is the use of qualifiers, therefore the inference.

    *A similar case where the value having a qualifier doesn't prevent the item from appearting in the results: human painters that are 168 centimeters tall. The fact that Takeshi Kitano is included in the list refutes the qualifier hypothesis.

Yes, that is strange, but probably needs some dedicated investigation. E.g. are we sure the used the correct item "knot" for the speed? Because there are a couple of other items with the label "knot" and I'm not sure how to get to the Q-ID of the unit to check.


Also, I just noticed that quantity queries are broken with "regardless of value" selected. Will fix after my "lunch" break.

  • It would be nice to fix the WiKit component and make the info icon/button vertically centered with the QuantityInput label. In WiKit, this component is using a different suffix for some reason (we should replace it there with the right one), which didn't allow catching this detail before:

Could you create an new Ticket for that? It is something that we should fix, but it is somewhat detached from the functionality that is implemented here.

Of course, I agree. Done.

  • I remember we talked about only displaying "real" units in the Quantity lookup. How feasible is that? Would we want to document that as a future improvement?

I don't think that this is feasible and I also remember it different. In my memory we said we wanted explicitly allow all units, because: 1. that is what Wikidata does and 2. the world is complex. Afaik, it was a user that requested to only show real units. But I think @Lydia_Pintscher could confirm this either way.

Sorry yes, I think I remember now that it was mentioned that there was no straightforward way to achieve this.

Yes, that is strange, but probably needs some dedicated investigation. E.g. are we sure the used the correct item "knot" for the speed? Because there are a couple of other items with the label "knot" and I'm not sure how to get to the Q-ID of the unit to check.

I actually tried selecting different "knot" units.

Also, I just noticed that quantity queries are broken with "regardless of value" selected. Will fix after my "lunch" break.

True! The query's not run at all. Guess that I didn't notice the results were not updated if the option is selected after runing the query.

amy_rc claimed this task.
amy_rc moved this task from Test (Verification) to Done on the Wikidata Query Builder board.
amy_rc added a subscriber: amy_rc.

Worked for the given BDD. \o/