Closed VojtechDostal closed 1 year ago
Yes it is possibe! :grin: See https://www.wikidata.org/w/index.php?title=Q117523&type=revision&diff=1763048325&oldid=1762491473
With
./query.rq
update_multiple_statements.js
and its dependencies
wd sparql ./query.rq | jq '.[]' -cr > ./results.ndjson
cat results.ndjson | wd edit-entity /path/to/wikibase-cli-template-collection/edit/edit_multiple_statements.js --batch --summary 'updating P1082 statements'
Very cool! 👍 This looks promising and now I know which part of the instructions I need to pay attention to, and what kinds of scripts I need to hack from your example collection :))
I tried but... jq and cat are probably not available on Windows. I wonder if there is a Windows-friendly way to do this?
cat
, but you could also just directly pipe the first line to the second: wd sparql ./query.rq | jq '.[]' -cr | wd edit-entity /path/to/wikibase-cli-template-collection/edit/edit_multiple_statements.js --batch --summary 'updating P1082 statements'
(but then you can't control what you got from the query before doing the edits)Otherwise, could you maybe use Windows Subsystem for Linux
? (I never used it, so I don't know if that works, but I don't see why that wouldn't)
Thanks, I am almost there, I think! Powershell install of wikibase-cli does not seem to install dependencies. I had to manually install wikibase-sdk but it's still asking for some libraries: "Error: Cannot find module '../lib/helpers'"
I guess those are the helpers from wikibase-cli-template-collection
on the update-multiple-statements
that you have to get locally too. I guess it could make sense to package some helpers with wikibase-cli itself, but I haven't explored that option much yet
Sorry, I don't really know what "getting it locally means" and what is "it". I was playing with it and I think I was able to get it working by pointing to the file like this:
const { getEntityClaims } = require('C:/Users/vojte/AppData/Roaming/npm/node_modules/wikibase-cli-templates/lib/helpers')
But now I get a different error:
TypeError: getEntityClaims is not a function
The full response is:
PS C:\Users\vojte\Downloads> wd sparql query.rq | jq '.[]' -cr | wd edit-entity update_multiple_statements.js --batch --summary 'updating P1082 statements - rank and date precision'
edit group: https://tools.wmflabs.org/editgroups/b/wikibase-cli/e120709cd0983/
processing line 1: {"item":"Q122690","s1":"Q122690$0A238085-79C0-465D-BD6E-5898BC61B8E7","s2":"Q122690$13B3D94B-9A6C-4D83-8C1C-1278A812B259"}
TypeError: getEntityClaims is not a function
at module.exports (C:\Users\vojte\Downloads\update_multiple_statements.js:7:30)
at getDataFromJsModule (C:\Users\vojte\AppData\Roaming\npm\node_modules\wikibase-cli\lib\object_arg_parser.js:63:12)
at getData (C:\Users\vojte\AppData\Roaming\npm\node_modules\wikibase-cli\lib\object_arg_parser.js:38:14)
at Command.module.exports [as customArgsParser] (C:\Users\vojte\AppData\Roaming\npm\node_modules\wikibase-cli\lib\object_arg_parser.js:9:16)
at runOnce (C:\Users\vojte\AppData\Roaming\npm\node_modules\wikibase-cli\lib\edit\edit_command.js:67:20)
at Stream.
By getting it locally, I meant having the files on which the JS template depends on your machine (="locally"). You can do that with git:
git clone https://github.com/maxlath/wikibase-cli-template-collection --branch update-multiple-statements
cd ./wikibase-cli-template-collection
npm install
wd sparql /path/to/query.rq | jq '.[]' -cr | wd edit-entity ./edit/update_multiple_statements.js --batch --summary 'updating P1082 statements - rank and date precision'
Thank you very much for the patience you've had with me. This time I was successful, I am able to run the commands: https://www.wikidata.org/w/index.php?title=Q130081&diff=prev&oldid=1764295342
Please let me summarize the required steps I needed to take (for my future reference):
1) run Powershell as admin. need to have chocolatey+jq and chocolatey+git installed there and wikibase-cli (if not working, also try installing wikibase-sdk package too). 2) go to working folder, eg. Downloads in my case 3) clone the template collection and install npm there like this
git clone https://github.com/maxlath/wikibase-cli-template-collection --branch update-multiple-statements
cd ./wikibase-cli-template-collection
npm install
4) put the update_multiple_statements.js and the query.rq file into the "wikibase-cli-template-collection" folder
5) (optional) check that the query is working as it should, outputting a correct file:
wd sparql ./query.rq | jq '.[]' -cr > ./results.ndjson
6) run the following command:
wd sparql query.rq | jq '.[]' -cr | wd edit-entity update_multiple_statements.js --batch --summary 'updating P1082 statements - rank and date precision'
That's hopefully all. Thank you again @maxlath
Hello, I've been using your tool for some time, mostly to edit multiple items in the batch mode. I usually download a list of statements or items from WQS and then run the batch, making the same change in each item. I really love the tool!
This time I need to do something more complex. I have 8800 statement pairs (https://w.wiki/5u9R). ?s1 - I need to change date qualifier from '2021' to '2021-03-26' and also change the rank to preferred. ?s2 - I need to change the rank to normal rank.
Is it possible to do all three changes in one edit with Wikibase-CLI?
I have been playing with the Javascript and JS templates in edit-entity but to no success. In your examples (https://github.com/maxlath/wikibase-cli-template-collection/tree/main/edit) I haven't found one that does changes in more than one statement (from a list of statement ids). How would I pass this information (list of statement ids to be changed accordingly + the three changes I want to do) via a command line?
thank you for help on this