Page MenuHomePhabricator

Update LabelResolver class to gather the description and aliases
Closed, ResolvedPublic

Description

As per T245023, we need to update the LabelResolver class to gather the description and aliases in addition to labels in order to avoid degraded performance on the client side.

Acceptance Criteria:

  • Labels and descriptions should follow language fallback chains
  • Aliases should only display if there is one in the current language
  • Is not a breaking API change (and compatibility with Android app is maintained)

@Mholloway has agreed to help with code review on this ticket, thanks!

Event Timeline

I'm willing to take a stab at this, as it should be pretty straightforward and I'd like to learn more about how to work with API endpoints in MediaWiki PHP. @Mholloway would it be okay to add you as a reviewer to any patches I submit here?

Change 585526 had a related patch set uploaded (by Eric Gardner; owner: Eric Gardner):
[mediawiki/extensions/MachineVision@master] Add descriptions and aliases to label data from API

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

It looks like labels and descriptions could be handled the same way in terms of language fallback chains, but aliases might need to be treated differently – namely, just don't display them at all if we can't find one for the current language. @Ramsey-WMF does that sound right to you?

 namely, just don't display them at all if we can't find one for the current language. @Ramsey-WMF does that sound right to you?

Yes 👍🏼

One other thing about this patch – this is a public API change so we'll need to make sure the Android team knows about this before we merge. @Ramsey-WMF or @CBogen can you ensure that they get a heads up about this? We don't version our APIs in the traditional way here as far as I understand, but is there anything else we need to do before changing the response of a public endpoint in the way we're considering here?

I'll update the patch to ensure the change is additive and doesn't interfere with the existing "label" key, but we should still make sure they know we're about to send more data over.

For reference, here's what the current data for a single image looks like from the unreviewedimagelabels endpoint (images are keys of the "pages" object):

"15": {
    "pageid": 15,
    "ns": 6,
    "title": "File:Frozen.jpeg",
    "imagelabels": [
        {
            "wikidata_id": "Q1136525",
            "state": "unreviewed",
            "confidence": {
                "google": 0.769716
            },
            "label": "snow storm"
        },
        {
            "wikidata_id": "Q1802779",
            "state": "unreviewed",
            "confidence": {
                "google": 0.748598
            },
            "label": "land vehicle"
        },
        {
            "wikidata_id": "Q3044530",
            "state": "unreviewed",
            "confidence": {
                "google": 0.831766
            },
            "label": "snow removal"
        },
        {
            "wikidata_id": "Q42889",
            "state": "unreviewed",
            "confidence": {
                "google": 0.748598
            },
            "label": "vehicle"
        }
    ]
}

The plan is to add two more keys, description, and alias. Ideally these keys should always be present even if their values are null. Values will be strings if present.

Change 585526 merged by jenkins-bot:
[mediawiki/extensions/MachineVision@master] Add descriptions and aliases to label data from API

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