openVirus icon indicating copy to clipboard operation
openVirus copied to clipboard

Need to write from [R] to wikidata via API

Open TS404 opened this issue 4 years ago • 7 comments

There s a current capability gap in the WikidataR package in that it can only read from, not write to wikidata. This will be a key and valuable feature. I've also added a note at that repo.

TS404 avatar Mar 18 '20 10:03 TS404

I'm checking how this can be done. The COVID-19 Wikidata item already exists (https://www.wikidata.org/wiki/Q84263196) and inside it you have different things.

First, you have a series of 'statements' identified by a specific property numner (i.e. 'instance of' P31) and each of them lists a serires of other Wikidata items (i.e. 'disease' Q12136).

Then we have 'identifiers', where we have again properties but that only list one ID (not a Wikidata item).

And at the end we have all the pages on that item in all Wikimedia foundation projects.

My question is: what do you want to be able to edit? Everything? Or just statements and identifiers? This is crucial as we need to think about a way to possibly structure the queries.

serenasignorelli avatar Mar 18 '20 16:03 serenasignorelli

Hmm, ideally everything, since being able to edit aliases and descriptions would be useful. However the two highest priority capabilities would be:

  • being able to add specific statements to existing item
  • being able to create a new item that is missing (may require descriptions and aliases anyway)

Backup option: outputting Quickstatments tables. Relevant issue link.

TS404 avatar Mar 19 '20 01:03 TS404

The QS API and its token system are detailed here (if you are logged into QS)

magnusmanske avatar Mar 19 '20 10:03 magnusmanske

&data=COMMANDS [commands in the above format]

@magnusmanske, could you confirm what the relevant quickstatements API format is?

TS404 avatar Mar 25 '20 03:03 TS404

Successful first test (using token code as per my QS userpage)!

https://tools.wmflabs.org/quickstatements/api.php
	?action=import
	&submit=1
	&username=Evolution_and_evolvability
	&token=[the token code as per my QS userpage]
	&format=v1
	&data=Q89093122%09P7347%09%22https:%2F%2Fen.wikiversity.org%2Fwiki%2FTalk:WikiJournal_of_Medicine%2FEpidemiology_of_the_Hepatitis_D_virus%22
	&batchname=ts_API_test1

Resulting in this batch being correctly implemented.

TS404 avatar Apr 03 '20 11:04 TS404

The new API almost works (now committed to wikiPackageTesting.R). There seem to currently be some problems with qualifiers submitted via the API. When the exact same submission is made via the API it returns errors, whereas submitted as a table via the website it runs fine:

I've also added a query about this at Wikidata Help_talk:QuickStatements. Next requirement will be proper handling of CREATE and LAST capabilities.

TS404 avatar Apr 04 '20 22:04 TS404