Automated edits/darkonus - bot account/Renaming of streets in Ukraine according to new recommendations of the Ukrainian community

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, darkonus using my bot account

Сontact

message via OSM I will respond also to personal messages to the bot account. I will be notified about incoming PMs via email and notifications in OSM editors.

What

Changing the order of words in some street names. Objects that will be selected for possible renaming:

Tags whose values will be changed if a match is found:

Why

Changes in the word order of street names were discussed on the Ukrainian forum thread. The main idea is that the names will be written in a way that is more natural for Ukrainian language.

Numbers

Road segments, relations type=associatedStreet, objects with addr:street=* and addr:place=* tags in Ukraine.

How

An 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 repository with source code etc. It would include at least


Changeset split into small areas to avoid continent-sized bounding boxes.

Edits generated by an osmapi based program using https://github.com/matkoniecz/osm_bot_abstraction_layer . The bot was developed by Mateusz Konieczny.

Discussion

https://community.openstreetmap.org/t/topic/97007

Repetition

I plan to make automated edits in one region of Ukraine at a time. Each time, the list of names will be published for verification and discussion in the relevant thread of the Ukrainian forum.

Code for renaming

Code is GNU GPLv3 licensed.

from osm_bot_abstraction_layer.generic_bot_retagging import run_simple_retagging_task

# Function to load renaming data from a file
def load_renaming_data(file_name):
    renaming_dict = {}

    # Read the file line by line
    with open(file_name, 'r', encoding='utf-8') as file:
        for line in file:
            # Split each line into original_name and new_name
            original_name, new_name = line.strip().split('\t')
            # Add the names to the renaming_dict
            renaming_dict[original_name] = new_name

    return renaming_dict

# Function to edit tags based on loaded renaming data
def edit_element(tags, renaming_data):
    # List of keys to edit
    keys_to_edit = [
        # Add all the keys you want to edit here
        "addr:place", 
        "addr:street", 
        "loc_name:left:uk", 
        "loc_name:left", 
        "loc_name:right:uk", 
        "loc_name:right", 
        "loc_name:uk", 
        "loc_name", 
        "name:left:uk", 
        "name:left", 
        "name:right:uk", 
        "name:right", 
        "name:uk", 
        "name", 
        "official_name:left:uk", 
        "official_name:left", 
        "official_name:right:uk", 
        "official_name:right", 
        "official_name:uk", 
        "official_name", 
        "old_name:left:uk", 
        "old_name:left", 
        "old_name:right:uk", 
        "old_name:right", 
        "old_name:uk", 
        "old_name", 
        "short_name:left:uk", 
        "short_name:left", 
        "short_name:right:uk", 
        "short_name:right", 
        "short_name:uk", 
        "short_name" 
    ]

    # Iterate over the keys to edit
    for key in keys_to_edit:
        # If the key exists in tags and its value is in renaming_data, update the value
        if key in tags and tags[key] in renaming_data:
            tags[key] = renaming_data[tags[key]]

    return tags

def main():
    # Prompt for region name
    region_name = input("Введіть назву області: ")
    region_name_eng = input("Введіть назву області англійською: ")
    # File name for renaming data
    renaming_file = f"{region_name} (перейменування).txt"
    # Load renaming data from the file
    renaming_data = load_renaming_data(renaming_file)

    # Run the simple retagging task
    run_simple_retagging_task(
        max_count_of_elements_in_one_changeset=500,
        # Set up the Overpass query to get the data
        objects_to_consider_query=f"""
[out:xml][timeout:1000];
area["name"="{region_name}"]->.a;
(
  nwr(area.a)[~"^(addr:street|addr:place)$"~"."];
  way(area.a)["highway"~"^(motorway|trunk|primary|secondary|tertiary|unclassified|residential|motorway_link|trunk_link|primary_link|secondary_link|tertiary_link|living_street|service|pedestrian|track|bus_guideway|escape|raceway|road|busway|footway|bridleway|steps|corridor|path|cycleway|proposed|construction)$"][~"^(name:left:uk|name:left|name:right:uk|name:right|name:uk|name|old_name:left:uk|old_name:left|old_name:right:uk|old_name:right|old_name:uk|old_name|official_name:left:uk|official_name:left|official_name:right:uk|official_name:right|official_name:uk|official_name|loc_name:left:uk|loc_name:left|loc_name:right:uk|loc_name:right|loc_name:uk|loc_name|short_name:left:uk|short_name:left|short_name:right:uk|short_name:right|short_name:uk|short_name)$"~"."];
  rel(area.a)[type=associatedStreet][~"^(name:left:uk|name:left|name:right:uk|name:right|name:uk|name|old_name:left:uk|old_name:left|old_name:right:uk|old_name:right|old_name:uk|old_name|official_name:left:uk|official_name:left|official_name:right:uk|official_name:right|official_name:uk|official_name|loc_name:left:uk|loc_name:left|loc_name:right:uk|loc_name:right|loc_name:uk|loc_name|short_name:left:uk|short_name:left|short_name:right:uk|short_name:right|short_name:uk|short_name)$"~"."];
);
out body;
>;
out skel qt;
""",
        cache_folder_filepath='/Users/user/test',
        is_in_manual_mode=False,
        changeset_comment=f'Renaming of streets in {region_name_eng} according to new recommendations of the Ukrainian community',
        discussion_url='https://community.openstreetmap.org/t/topic/97007',
        osm_wiki_documentation_page='https://wiki.openstreetmap.org/wiki/Automated_edits/darkonus_-_bot_account/Renaming_of_streets_in_Ukraine_according_to_new_recommendations_of_the_Ukrainian_community',
        # Pass the edit_element function as an argument, and pass renaming_data through a lambda function
        edit_element_function=lambda tags: edit_element(tags, renaming_data),
    )

main()

Opt-out

Please comment in the discussion thread (see #Discussion).