User:Jerimee/csvbatch-using-qs
Intro
I'm using QuickStatements v2 https://quickstatements.toolforge.org/ to apply SDC to Commons files in batch.
Use "qid" as the header despite it being a commons file. Then, for the values of qid you use the page id with an M in front (ie M123456789)
you get the file id from page information (example: https://commons.wikimedia.org/w/index.php?title=File:Girl_selling_for_Palm_Sunday.jpg&action=info )
https://quickstatements.toolforge.org/#/batch needs the "form-control" field (Create new command batch for) set to "commons"

Then you paste in a csv formatted set of batch commands. The header for the first column (cell AI) should be "qid" and the values for that column with commons page ids prefixed with M. You can get the page id from the page info. So, for example, M25393559 is for File:Girl selling for Palm Sunday.jpg and you can find that value at File:Girl_selling_for_Palm_Sunday.jpg&action=info
Simple Examples
To do a simple test here is an example with one file and one statement:
qid,P31 M163540091,Q208594
Additional rows represent additional files. Additional columns represent additional statements.
Below is an example with three files. The first two files (M163540091 and M63149037) set instance of (P31) to Q208594, and the third file is set to Q138754.
qid,P31 M163540091,Q208594 M63149037,Q208594 M58519728,Q138754
Below is an example with two statement applied to one file. The two properties are in the header: instance of (P31) and color (P462).
qid,P31,P462 M163540091,Q208594,Q22006653
From a spreadsheet
You can get a spreadsheet from PetScan https://petscan.wmcloud.org/ as well as other tools. To get from petscan, go to the output tab and select CSV from the first option at top. Here is a spreadsheet of the files in Anthropomorphic frogs exported from PetScan: https://docs.google.com/spreadsheets/d/1Q4648lvbqyMxI8HvwIhDJFQ1B42N1XoJ3LzczimYu6k
The only column you need is the pageid, and it needs to renamed to qid. The page ids all need to prefixed with an "M." Like this: https://docs.google.com/spreadsheets/d/1kdP4WMq8PxSju-odaun50TT522rE9Crx4PEVoCEEJ4c
Once you have that, you can add the data you wish to batch update. The values of the statements will go next to the "M" ids and the properties are the column headers. So in the next example sheet, the 2nd column is populated with anthropomorphic frog or toad (Q89349539) and the 3rd with anthropomorphic animal (Q2369882), and both have the headers set to depicts (P180). The values will be applied to that property. https://docs.google.com/spreadsheets/d/18GaAI0Qcd8hQ8NOwmTsIlyFaJFZE-r7ZDeBSkJgyrK8/edit?usp=sharing
That entirety of the csv can now be cut and paste to QuickStatements. (You may want to paste into a text editor to double check the formatting.) Because the spreadsheet has 195 media files and is adding two depicts (P180) statements per file, there are a total of 390 operations. Press run to start.
Note that if you make a mistake you may be able to undo the whole batch or, failing that, run a new batch to remove statements. One tool to help you view batches is at https://editgroups.toolforge.org/ Wikidata:Wikidata:Edit_groups
Adding qualifiers and reference
A qualifier can be added using the "qal" prefix in place of P for the relevant property.
qid,P180,qal5102 M44075725,Q53636,Q27058
References use the S prefix. The first statement in a reference will use an uppercase "S" and subsequent statements in that reference will use lowercase "s." "S123,S234,S234" would generate three references each with a single statement. "S123,s234,s340" is a single reference with three statements.
Text values required triple quotes. Note that google sheets will escape quotes with a triple quote.
qid,P180,qal5102,S887,s4656 M91610191,Q53636,Q27058,Q133818885,"""https://commons.wikimedia.org/wiki/Category:Line_art_of_Anura"""
Dates do not use quotes, but need to be formatted in a specific manner.
qid,P180,qal5102,S887,s4656,s5017 M62118764,Q53636,Q27058,Q133818885,"""https://commons.wikimedia.org/wiki/Category:Line_art_of_Anura""",+2025-04-14T00:00:00Z/11
Additional statements can be added. The reference is applied to the statement it follows from left to right. So in this example the depicts (P180) statement will have the qualifier and reference, but the instance of (P31) at the end will not.
qid,P180,qal5102,S887,s4656,s5017,P31 M64870196,Q53636,Q27058,Q133818885,"""https://commons.wikimedia.org/wiki/Category:Line_art_of_Anura""",+2025-04-14T00:00:00Z/11,Q365552
The spreadsheet looks like this in Google Sheets: https://docs.google.com/spreadsheets/d/1GsYdmMc0q0_VBPjYb4f5dO16MqFh66-J5UYTXzRL9AI/
If the csv data above is input and processed with QuickStatements, the following two statements will be added to file "M64870196."
- depicts (P180) → Anura (Q53636)
- with qualifier
- with reference
- based on heuristic (P887) → inferred from Commons category (Q133818885)
- Wikimedia import URL (P4656) → "https://commons.wikimedia.org/wiki/Category:Line_art_of_Anura"
- last update (P5017) → "+2026-04-15T00:00:00Z/11"
- instance of (P31) → line art (Q365552)
See Also
- Wikidata:Help:QuickStatements#CSV_file_syntax
- category: QuickStatements
- QS v3, built by a different group of people: https://qs-dev.toolforge.org/
- https://docs.google.com/spreadsheets/d/1GsYdmMc0q0_VBPjYb4f5dO16MqFh66-J5UYTXzRL9AI/
- https://www.wikidata.org/wiki/User:Jerimee/iop/examples
- convert file names to mids with https://hay.toolforge.org/minefield/
- User:Jerimee/csvbatch-petscan-qs-workflow
- example spreadsheets
- rabbits
- frogs
- QS tpl