Wikidata:Bureaucrats' noticeboard/Archive/2017/11
This page is an archive. Please do not modify it. Use the current page, even to continue an old discussion. |
Flood flag request
Hi, I'm coming to request a temporary flood flag. I've been involved with deprecating P794 (P794) (see this discussion) and I'm about to run a batch operation that will migrate 6436 items from regulates (molecular biology) (P128)
- P.S. relevant SPARQL: Try it!
SELECT DISTINCT ?item ?asObject ?asObjectLabel WHERE { ?prop pq:P794 ?asObject . hint:Query hint:optimizer "None" . ?item ?p ?prop . ?property wikibase:claim ?p . ?property wikibase:statementProperty ?ps . ?prop ?ps ?value . wd:P128 wikibase:claim ?p . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } LIMIT 10000
- --Deryck Chan (talk) 18:12, 24 November 2017 (UTC)
- What tool will you use to run the batch operation? Did you consider that these statements have references which should not be dropped? --Pasleim (talk) 18:43, 24 November 2017 (UTC)
Hello Pasleim. I have written a PAWS script specifically for qualifier migration. It only changes the qualifier that I specify towards the top of the script and preserves all other qualifiers and references of the same statement. I have already used this script in small batches totalling over 1000 edits and can confirm that it behaves as I have described above.
The source code is reproduced below (PAWS's "make notebook public" button is currently broken). The first three lines refer to the migration of Wikidata property (P1687)
Extended content |
---|
#input vars
main_property = 'P1687'
qualifier_property = 'P794'
new_qualifier_property = 'P1013'
query_filename = 'qualifier_migrate.rq'
allowed_qualifier_targets = {} #leave empty for everything to be processed
edit_summary = qualifier_property + ' is deprecated, migrating ' + main_property + '/' + qualifier_property + ' to ' + '/' + new_qualifier_property
no_promptbox = 1 #set to 1 to operate on entire query automatically, 0 to prompt once per item
#start of actual script
import pywikibot
from pywikibot import pagegenerators as pg
site = pywikibot.Site("wikidata", "wikidata")
wikidata_site = site #compatibility stuff
repo = site.data_repository()
def getLabelFromObject(WDObject):
item_dict = WDObject.get()
item_label = False
if 'labels' in item_dict:
if 'en' in item_dict['labels']:
item_label = item_dict['labels']['en']
label = item_label
if (label):
return label
else:
return WDObject.getID()
def getLabelFromWDID(ID): #works for properties only. need separate function for items. why why why
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
item = pywikibot.PropertyPage(repo, ID)
return getLabelFromObject(item)
main_property_label = getLabelFromWDID(main_property)
qualifier_property_label = getLabelFromWDID(qualifier_property)
new_qualifier_property_label = getLabelFromWDID(new_qualifier_property)
with open(query_filename, 'r') as query_file:
QUERY = query_file.read()
generator = pg.WikidataSPARQLPageGenerator(QUERY, site=wikidata_site)
generator = site.preloadpages(generator, pageprops=True)
break_flag = 0
edit_count = 0
for item in generator:
#operate on the most recent one for testing
item_dict = item.get()
item_label = getLabelFromObject(item)
print('Now working on ', item.getID(), ' ', item_label)#, 'Ready? ("yes" to go, "break" to stop)')
#promptbox = ''
#while (promptbox not in acceptable_prompt_set):
# promptbox = input()
#if promptbox == 'break' or promptbox == 'no':
# break
for claim_object in item_dict['claims'][main_property]:
claim_target = claim_object.getTarget()
claim_target_label = getLabelFromObject(claim_target) if type(claim_target) ==pywikibot.page.ItemPage else '[none]'
if qualifier_property in claim_object.qualifiers:
for qualifier_object in claim_object.qualifiers[qualifier_property]:
qualifier_target = qualifier_object.getTarget()
if (len(allowed_qualifier_targets) > 0 and
qualifier_target.getID() not in allowed_qualifier_targets):
continue
qualifier_target_label = getLabelFromObject(qualifier_target) if type(qualifier_target) == pywikibot.page.ItemPage else '[none]'
print(item_label, main_property_label, claim_target_label,
qualifier_property_label, qualifier_target_label,
'change to', new_qualifier_property_label, '!')
acceptable_prompt_set = {'y', 'yes', 'n', 'no', 'break'}
promptbox = ''
if (no_promptbox == 1):
promptbox = 'yes'
while (promptbox not in acceptable_prompt_set):
promptbox = input() #becomes automatic if set to 'y'
if promptbox == 'y' or promptbox == 'yes':
qualifier_dict = qualifier_object.toJSON()
qualifier_dict['property'] = new_qualifier_property #set up the qualifier change
print('Changing to', new_qualifier_property_label)
new_qualifier_object = qualifier_object.qualifierFromJSON(site = wikidata_site, data = qualifier_dict)
claim_object.addQualifier(new_qualifier_object, summary=edit_summary)
edit_count = edit_count + 1
elif promptbox == 'n' or promptbox == 'no':
print('Skipped')
elif promptbox == 'break':
break_flag = 1
break
else:
print('Error - Deryck made a mistake')
if break_flag == 1:
break
if break_flag == 1:
break
print('All done, thanks for using! We edited', edit_count, 'items.')
|
- Support ok, looks good to me --Pasleim (talk) 19:17, 24 November 2017 (UTC)
- Done, please remove the flag after the task has been completed.--Ymblanter (talk) 20:32, 24 November 2017 (UTC)
Done. I have finished the large-volume batch edits and removed my flooder flag. Between Pasleim's PLbot and me, we have emigrated all use cases of P794 (P794) that affect more than 1000 items per use case, totalling almost 20,000 edits in the last two days. The remaining changes will happen in small enough batches that shouldn't require the flooder flag. Deryck Chan (talk) 12:41, 26 November 2017 (UTC)