Community Wishlist Survey 2023/Multimedia and Commons/Provide example code for adding depict statements with a command line script
Provide example code for adding depict statements with a command line script
- Problem: Structured Data on Commons will only become useful if many files have good depictions
- Proposed solution: Provide examples on how to add depict statements from a command line script
- Who would benefit: Me
- More comments:
- Phabricator tickets:
- Proposer: C.Suthorn (talk) 17:46, 28 January 2023 (UTC)
Discussion
Did some digging, and the page we'll probably want to improve is mw:Wikibase/API. It appears that pywikibot is also capable of adding structured data: phab:T213904, phab:T223796, release notes, proof of concept -FASTILY 22:48, 28 January 2023 (UTC)
- Example for python3: commons:User:SchlurcherBot/commonsapiaddclaimsoauth (please read the wikitext, the page does not render well). Let me know if you need another working example. --Schlurcher (talk) 18:07, 29 January 2023 (UTC)
- After a quick look: It adds copyright and license. But I am after an expample for getting the ID for a category and then adding the depict statement. For license and copyright the P-number are known and do not change, so they can be hard coded in the script. C.Suthorn (talk) 00:10, 30 January 2023 (UTC)
- What does the ID for a category exactly mean? --Matěj Suchánek (talk) 16:52, 30 January 2023 (UTC)
- Upload a picture of a blue-red stripped cat that is hunting an Uber car. While uploading you assign "Category:Images of blue-red cats hunting Uber cars". As uploader you have the knowledge, what depicts are useful. You can derive it (programmatically supported) from the category. A script would be able to fetch the Q-numbers and add the depicts to the image. Adding statements, if the Q-numbers are already known. C.Suthorn (talk) 22:50, 30 January 2023 (UTC)
- Is there actually a way to do that? I.e., is the relation between the category and suitable entity IDs for depicts stored somewhere? Because I believe that's the key, and I believe there is not at the moment. Maybe bringing this up to c:Commons talk:Structured data can make it clear. By coincidence, a similar topic is being discussed there right now: c:Commons talk:Structured data#Using categories as a proxy for P180 depicts values. --Matěj Suchánek (talk) 09:13, 31 January 2023 (UTC)
- Upload a picture of a blue-red stripped cat that is hunting an Uber car. While uploading you assign "Category:Images of blue-red cats hunting Uber cars". As uploader you have the knowledge, what depicts are useful. You can derive it (programmatically supported) from the category. A script would be able to fetch the Q-numbers and add the depicts to the image. Adding statements, if the Q-numbers are already known. C.Suthorn (talk) 22:50, 30 January 2023 (UTC)
- What does the ID for a category exactly mean? --Matěj Suchánek (talk) 16:52, 30 January 2023 (UTC)
- After a quick look: It adds copyright and license. But I am after an expample for getting the ID for a category and then adding the depict statement. For license and copyright the P-number are known and do not change, so they can be hard coded in the script. C.Suthorn (talk) 00:10, 30 January 2023 (UTC)
@C.Suthorn: Could you elaborate a bit more on the requirements? I could provide an compliled "command line tool that adds depict statements" in case the above code would not work. The call would look like this:
APISchlurcherBot.exe "Username" "Password" "M66593822" "Q68"
This code would perform this edit: [1] Questions:
- Windows or Linux (the code I have is Windows)
- Is password provided in command line ok (only ok for non-shared PCs, but easier)
- Is M id ok, or title of page better (M id easier, but conversion can be done as well)
If that fulfills the need, I can share an executable for this task. If more complex is envisioned, then not. --Schlurcher (talk) 10:46, 4 February 2023 (UTC)
- While I could integrate such a tool (on Linux, and User,Passsword is no problem), I think, it would be better not to have a complete working software, but example code (which could be in a pseudo language, or basically any language like php, java, perl, python, c, whatever - as this is not about high performance operations like computing raytracing images, or implementing social scoring algorihms) for these basic tasks:
- 1 computing Q, M, and P numbers from a text string (like page name to Q number, ...)
- 2 setting an SDC value for a file
- 3 testing for values already set
- From such examples other people with other tools could profit too C.Suthorn (talk) 12:47, 4 February 2023 (UTC)
- It sounds like this is looking for more "tutorial" style documentation than what is available for e.g. wbcreateclaim. How to find the Wikidata item for a category, and the media ID of a file, and to add the item as a depicts (P180) claim (and, presumably, more detail about what all those bits mean). SWilson (WMF) (talk) 05:04, 7 February 2023 (UTC)
Voting
- Support EiersalatmitGurken (talk) 14:39, 12 February 2023 (UTC)
- Support cyrfaw (talk) 12:36, 17 February 2023 (UTC)
- Support Hans5958 (talk) 05:33, 20 February 2023 (UTC)
- Support Althair (talk) 04:10, 23 February 2023 (UTC)
- Support CmdrDan (talk) 17:51, 24 February 2023 (UTC)