Wikidata has a mechanism for eliminating duplicates. When a duplicate entry is found, it is deleted. From that point on, references to the deleted Wikidata entry are redirected to the surviving entry.
As a result, OSM has wikidata tag values that do not relate to actual Wikidata entries. This is usually not a problem. However, attempts to align OSM and Wikidata elements are more complex because of the hidden redirects.
For example, it is not possible to find if a given Wikidata QID is not included in OSM by a direct search in OSM wikidata tags, using a simple Overpass query. It may be the case that some OSM element holds a wikidata value that redirects to the desired QID. Similarly, for finding groups of Wikidata entries.
I propose to run a script that will find such redirects and will create an .osm file to be used in JOSM for updating the wikidata tags with the post-redirection value.
The script also provides some statistics. The Israel and Palestine area has
- 11628 OSM elements with
wikidatatags - 7630 unique QIDs
- 119 redirects
- 250 OSM elements to be modified
I have reviewed the code and had validated several modifications, at random.
The script is available at fix_wikidata_redirects.py