Provide advice and code review support to Cooltey for making this change.
The coding work will involve updating the existing image labels fetching query in order to retrieve the confidence scores, and then updating ApiQueryImageLabels to include them in the imagelabels API response.
The relevant DB query is defined in Repository::getLabels using the methods of MediaWiki's database abstraction object; that object is documented here. The existing code demonstrates the syntax for a join; you will need to update the query to retrieve the per-provider confidence scores for each label suggestion (which will involve a join on machine_vision_suggestion to get the confidence scores, and another on machine_vision_provider to get the provider name associated with the provider ID in machine_vision_suggestion).
Current query in raw SQL:
SELECT mvi_sha1, mvl_wikidata_id, mvl_review, mvl_reviewer_id FROM machine_vision_image INNER JOIN machine_vision_label on mvi_id = mvl_mvi_id WHERE mvi_sha1 = $sha1 ORDER BY mvl_id;
Desired query in raw SQL:
SELECT mvi_sha1, mvl_wikidata_id, mvl_review, mvl_reviewer_id, mvs_confidence, mvp_name FROM machine_vision_image INNER JOIN machine_vision_label on mvi_id = mvl_mvi_id INNER JOIN machine_vision_suggestion on mvl_id = mvs_mvl_id INNER JOIN machine_vision_provider on mvs_provider_id = mvp_id WHERE mvi_sha1 = $sha1;
(The ORDER BY clause can be removed when the raw confidence scores are returned, since clients will be able to sort by confidence if desired.)
Current response structure:
{ "batchcomplete": "", "query": { "pages": { "87316785": { "pageid": 87316785, "ns": 6, "title": "File:9058Jose Aspiras Highway Tubao, La Union 23.jpg", "imagelabels": [ { "wikidata_id": "Q10390031", "state": "unreviewed", "label": "public road" }, ... ] }, ... } } }
Desired response structure:
{ "batchcomplete": "", "query": { "pages": { "87316785": { "pageid": 87316785, "ns": 6, "title": "File:9058Jose Aspiras Highway Tubao, La Union 23.jpg", "imagelabels": [ { "wikidata_id": "Q10390031", "state": "unreviewed", "label": "public road", "confidence": { "google": 0.957253 } }, ... ] }, ... } } }