SuLab / WikidataIntegrator

A Wikidata Python module integrating the MediaWiki API and the Wikidata SPARQL endpoint
MIT License
244 stars 46 forks source link

How to set a qualifier property? Is this implemented? #193

Closed WolfgangFahl closed 2 years ago

WolfgangFahl commented 2 years ago

In https://github.com/WolfgangFahl/pyOnlineSpreadSheetEditing/blob/main/wd/gsimport.py i am successfully using wikibaseintegrator to read data from a google spreadsheet including the mapping information and then interactively add the data row by row to wikidata. An input e.g. might be https://docs.google.com/spreadsheets/d/1-6llZSTVxNrYH4HJ0DotMjVu9cTHv2WnT_thfQ-3q14

and the results would show up in https://scholia.toolforge.org/event-series/Q111739322

The events would need a qualifier e.g. https://www.wikidata.org/wiki/Q111739923 is the 92nd installement of the series. so https://www.wikidata.org/wiki/Property:P179 (part of the series) needs to be qualified with https://www.wikidata.org/wiki/Property:P1545 (series ordinal).

Originally i was using wikidataintegrator for the task but ran into a followup problem. I might re-add wikidataintegrator support if that works better e.g. for the qualifier problem at hand?

How are qualifiers to be set with WikidataIntegegrator?

andrawaag commented 2 years ago

Yes, the wikidataintegrator does support adding qualifiers, which is similar to how references are added. See for example line 82 in the Wikipathwaysbot. In the same script at line 276-277 how both the references and qualifiers are being added to a wikidata item.

The workflow is that references and qualifiers are being created similarly as times, with the added parameter of resp is_reference and is_qualifier to be set to True. Both the references and qualifiers are then added to the item when the items is instantiated.

I hope this help.

WolfgangFahl commented 2 years ago

@andrawaag thx for the swift response. https://github.com/SuLab/WikidataIntegrator/blob/f2c92d2d3ecd7ee3cba03d81e50b008af4ea0a13/wikidataintegrator/wdi_core.py#L1981 does the actual setting of the qualifiers. This is forced to be at construction time at this time so qualifiers need to be known at construction time. I think this should be refactored to allow to add qualifiers after construction. The additional checks added in WikibaseIntegrator also seem to be useful.

andrawaag commented 2 years ago

@WolfgangFahl In principle, it is possible to add qualifiers post setting the statements. I do this often. Internally what WDI does is that it updates the full item before sending it back to the Wikidata API. Recreate the same item, but this time with the qualifiers and the item will be updated with the qualified statements

WolfgangFahl commented 2 years ago

@andrawaag thanks for the explanation i think we used the feature recently