Mechanical Edits/Mateusz Konieczny - bot account/fixing State Bank of India wikipedia links

From OpenStreetMap Wiki
Jump to navigation Jump to search

Page content created as advised on Automated_Edits_code_of_conduct#Document_and_discuss_your_plans.

Who

I, Mateusz Konieczny using my bot account

contact

message via OSM I will respond also to PMs to the bot account.

What

Changing wikipedia=en:State Bank of India into brand:wikipedia=en:State Bank of India

Editing is restricted to where this tag appears - to India.

Wikidata tag would not be modified as it is not used in such incorrect way - see https://overpass-turbo.eu/s/Nzh

Why

In this case brand:wikipedia=* is correct and wikipedia=* is not.

Fixing it manually is highly tedious and bot making this kind of edit is less likely to make mistakes than a human.

Numbers

Around 1000 instances in India.

How

A theoretical example:
state before a mechanical edit:

state after a mechanical edit:

Changeset would be described and tagged with tags that mark it as automatic, provide link to discussion approving edit, link place with source code etc

Discussion

Posted at talk-in ( https://lists.openstreetmap.org/pipermail/talk-in/2019-October/003308.html ) and in OpenStreetMap India telegram channel ( https://t.me/OSMIndia/3389 ).

Repetition

Not planned. Would be done as a separate and new bot edit.

Code

GNU GPLv3 licensed

from osm_bot_abstraction_layer.generic_bot_retagging import run_simple_retagging_task

def transformation():
    return {
        'from': {"wikipedia": "en:State Bank of India"},
        'to': {"brand:wikipedia": "en:State Bank of India"},
    }

def is_element_editable(tag_dictionary, identifier):
    for key, value in transformation()['from'].items():
        if tag_dictionary.get(key) != (value):
            return False
    return True
 
def edit_element(tags):
    for key in transformation()['from'].keys():
        tags.pop(key, None)

    for key, value in transformation()['to'].items():
        tags[key] = value
    return tags

def escape_overpass_query_text(text):
    return "'" +text.replace("\\", "\\\\").replace("'", "\\'") + "'"

def dictionary_to_overpass_tag_filter(tag_dictionary):
    returned = ""
    for key, value in tag_dictionary.items():
        returned += "[" + escape_overpass_query_text(key) + "=" + escape_overpass_query_text(value) + "]"
    return returned

def main(tag_dictionary):
    run_simple_retagging_task(
        max_count_of_elements_in_one_changeset=500,
        objects_to_consider_query="""
[out:xml][timeout:25000];
(
  nwr""" + dictionary_to_overpass_tag_filter(tag_dictionary['from']) + """;
);
out body;
>;
out skel qt;
""",
        objects_to_consider_query_storage_file='/media/mateusz/5bfa9dfc-ed86-4d19-ac36-78df1060707c/OSM-cache/overpass/sboi_cleanup.osm',
        is_in_manual_mode=False,
        changeset_comment='fix tagging: wikipedia=en:State Bank of India to brand:wikipedia=en:State Bank of India',
        discussion_url="https://lists.openstreetmap.org/pipermail/talk-in/2019-October/003308.html https://t.me/OSMIndia/3389",
        osm_wiki_documentation_page='https://wiki.openstreetmap.org/wiki/Mechanical_Edits/Mateusz_Konieczny_-_bot_account/fixing_State_Bank_of_India_wikipedia_links',
        is_element_editable_checker_function=is_element_editable,
        edit_element_function=edit_element,
    )

main(transformation())

Opt-out

Please write at talk-in .