Skip to content

Commit

Permalink
add exception for dual names
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Mar 3, 2024
1 parent fc669be commit 8da0e42
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ describe('compareFeatures', () => {
),
).toStrictEqual({ natural: 'spring' }); // default preset is suggested
});
});

describe('exceptions', () => {
it.each`
nzgb | osm
${'Saint Martin'} | ${'St Martin'}
Expand All @@ -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();
});
});
2 changes: 2 additions & 0 deletions src/stage3-conflate/compareFeatures/compareFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions src/stage3-conflate/compareFeatures/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)
);
}

0 comments on commit 8da0e42

Please sign in to comment.