From 8da0e426603820bbb9acec56c0ea2bc0b35dac36 Mon Sep 17 00:00:00 2001 From: Kyle Hensel Date: Sun, 3 Mar 2024 17:56:14 +1100 Subject: [PATCH] add exception for dual names --- .../__tests__/compareFeatures.test.ts | 14 ++++++++++++++ .../compareFeatures/compareFeatures.ts | 2 ++ src/stage3-conflate/compareFeatures/exceptions.ts | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/stage3-conflate/compareFeatures/__tests__/compareFeatures.test.ts b/src/stage3-conflate/compareFeatures/__tests__/compareFeatures.test.ts index c057c78..e80e376 100644 --- a/src/stage3-conflate/compareFeatures/__tests__/compareFeatures.test.ts +++ b/src/stage3-conflate/compareFeatures/__tests__/compareFeatures.test.ts @@ -378,7 +378,9 @@ describe('compareFeatures', () => { ), ).toStrictEqual({ natural: 'spring' }); // default preset is suggested }); + }); + describe('exceptions', () => { it.each` nzgb | osm ${'Saint Martin'} | ${'St Martin'} @@ -389,4 +391,16 @@ describe('compareFeatures', () => { expect(conflateTags({ name: nzgb }, { name: osm })).toBeUndefined(); }); }); + + it('allows dual names in the name tag', () => { + expect( + conflateTags( + { name: 'Ōmanawa Falls' }, + { + name: 'Te Rere o Ōmanawa / Ōmanawa Falls', + 'name:mi': 'Te Rere o Ōmanawa', + }, + ), + ).toBeUndefined(); + }); }); diff --git a/src/stage3-conflate/compareFeatures/compareFeatures.ts b/src/stage3-conflate/compareFeatures/compareFeatures.ts index ffd6ac5..174237a 100644 --- a/src/stage3-conflate/compareFeatures/compareFeatures.ts +++ b/src/stage3-conflate/compareFeatures/compareFeatures.ts @@ -5,6 +5,7 @@ import type { NZGBFeature, OSMFeature } from '../../types'; import { createDiamond, distanceBetween } from '../../core'; import { DONT_TRY_TO_MOVE, NZGB_NAME_TYPES, __SKIP } from '../../data'; import { + allowDualNames, allowSlashInsteadOfOr, allowTrivialDifferences, isUnofficialAndOsmHasMacrons, @@ -44,6 +45,7 @@ export function compareFeatures( isUnofficialAndOsmHasMacrons(nzgb, osm), allowSlashInsteadOfOr(nzgb, osm), allowTrivialDifferences(nzgb, osm), + allowDualNames(nzgb, osm), ]; // if every exception is false, then propose changing the name if (exceptions.every((x) => !x)) { diff --git a/src/stage3-conflate/compareFeatures/exceptions.ts b/src/stage3-conflate/compareFeatures/exceptions.ts index 8d0eba7..0104c08 100644 --- a/src/stage3-conflate/compareFeatures/exceptions.ts +++ b/src/stage3-conflate/compareFeatures/exceptions.ts @@ -62,3 +62,18 @@ export function allowTrivialDifferences(nzgb: NZGBFeature, osm: OSMFeature) { normaliseTrivialNameDifferences(osm.tags.name || '') ); } + +/** + * Allow name:mi to be repeated in the name tag for dual names + * that are separated by a `/` + */ +export function allowDualNames(nzgb: NZGBFeature, osm: OSMFeature) { + const nameSegments = osm.tags.name?.split(' / '); + + return ( + nameSegments?.length === 2 && + nameSegments.every( + (segment) => segment === nzgb.name || segment === osm.tags['name:mi'], + ) + ); +}