Apps-android-commons: Fill P2096 (media legend) of P18 image using metadata typed by user

Created on 16 Aug 2018  路  12Comments  路  Source: commons-app/apps-android-commons

Insert image descriptions (or title? or both?) into Wikidata as qualifiers.
This is quite often done using property P2096.

Example:
screenshot from 2018-08-16 17-33-36

Infoboxes could then read this description when transcluding images from Wikidata.

enhancement nearby

Most helpful comment

I would go with the title as it's more concise, what do you think @nicolas-raoul @VojtechDostal ?

All 12 comments

The app currently does not know which language the uploader is using hence the addition of P2096. However it will know so once #1501 is deployed. Thanks for the suggestion Nicolas, I really like this direction!

This can be done using wbsetclaim API. This is how the request would look:

Screen Shot 2020-01-12 at 6 50 33 PM

Sample JSON for claim object:

{
  "type": "statement",
  "mainsnak": {
    "snaktype": "value",
    "property": "P18",
    "datavalue": {
      "type": "string",
      "value": "Praia da Costa da Caparica 4.jpg"
    }
  },
  "id": "Q49323665$8BD552FA-6904-4B93-BF34-CA5F6E207783",
  "references": [
    {
      "snaks": {
        "P2096": [
          {
            "snaktype": "value",
            "property": "P2096",
            "datavalue": {
              "type": "monolingualtext",
              "value": {
                "text": "some value",
                "language": "en"
              }
            }
          }
        ]
      },
      "snaks-order": [
        "P2096"
      ]
    }
  ],
  "rank": "normal"
}

It would be great if we could decide whether the title or description needs to be set in P2096? Accordingly, I can pick up the task.

cc: @nicolas-raoul @misaochan

I would go with the title as it's more concise, what do you think @nicolas-raoul @VojtechDostal ?

Absolutely, title is a great media legend, while description is not a good media legend, I don't know what I was thinking when writing the text of the original issue.
Thanks! :-)

If we go ahead with the title then what should be filled in the language attribute? In the case of description, we are aware of the language but in the case of title, the user can type it in any language.

@misaochan @nicolas-raoul

When Vanshika's SDoC branch gets merged, we get language-specific titles :-)

To start off can I assume "en" as the language for the title (or descriptions for media legends) and work on this task. Once #3222 is fixed, we can update the feature to use captions instead of descriptions/titles. We will take care to release the feature only after we start using captions.

Sounds good to me @maskaravivek .

I am unable to add the media legends as the API is giving some error. I have created a phab ticket asking for help.

https://phabricator.wikimedia.org/T255852

@maskaravivek it looks like you aren't setting the claim parameter but instead posting the claim in the body, the examples make it seem like that is not an acceptable method

I was sending the claim param as a form-encoded param but i was not converting it to string. I am now converting it to a string and am getting a different error.

{
    "error": {
        "code": "internal_api_error_Deserializers\\Exceptions\\DeserializationException",
        "info": "[5b3b0826-e761-43e6-b577-1afa39901a47] Caught exception of type Deserializers\\Exceptions\\DeserializationException",
        "errorclass": "Deserializers\\Exceptions\\DeserializationException"
    },
    "servedby": "mw1314"
}

Here's the PR. https://github.com/commons-app/apps-android-commons/pull/3838

Here's the sandbox URL:

https://www.wikidata.org/wiki/Special:ApiSandbox#action=wbsetclaim&format=json&claim=%7B%22id%22%3A%22Q7110921%24150c615e-9708-4836-b5c5-3ecc55efd1f4%22%2C%22mainsnak%22%3A%7B%22datatype%22%3A%22string%22%2C%22datavalue%22%3A%7B%22value%22%3A%22File%3ATest.jpg%22%2C%22type%22%3A%22string%22%7D%2C%22property%22%3A%22P18%22%2C%22snaktype%22%3A%22value%22%7D%2C%22rank%22%3A%22normal%22%2C%22references%22%3A%5B%7B%22snaks%22%3A%7B%22P2096%22%3A%7B%22datatype%22%3A%22monolingualtext%22%2C%22datavalue%22%3A%7B%22value%22%3A%7B%22value%22%3A%7B%22language%22%3A%22en%22%2C%22text%22%3A%22Test%22%7D%7D%2C%22type%22%3A%22monolingualtext%22%7D%2C%22property%22%3A%22P2096%22%2C%22snaktype%22%3A%22value%22%7D%7D%2C%22snaks-order%22%3A%5B%22P2096%22%5D%7D%5D%2C%22type%22%3A%22statement%22%7D&token=943bc0fb9741e372e27627211a9271765ef0de05%2B%5C

@macgills It would be great if you could take a look at it.

I managed to make the API work. The parameters have changed. For ref this is the expected claim object.

{
    "id": "Q7110921$35f7634d-f4b9-4d51-aac8-1143ea95230c",
    "mainsnak": {
        "datavalue": {
            "value": "Test.jpg",
            "type": "string"
        },
        "property": "P18",
        "snaktype": "value"
    },
    "qualifiers": {
        "P2096": {
            "datavalue": {
                "value": {
                    "language": "en",
                    "text": "Test"
                },
                "type": "monolingualtext"
            },
            "property": "P2096",
            "snaktype": "value"
        }
    },
    "qualifiers-order": [
        "P2096"
    ],
    "rank": "normal",
    "type": "statement"
}
Was this page helpful?
0 / 5 - 0 ratings