Skip to content

Commit 9a0b934

Browse files
committed
feat(names): Detect near duplicate names
This handles the case where one alt name is a substring fully contained in another.
1 parent 4678b49 commit 9a0b934

3 files changed

Lines changed: 39 additions & 20 deletions

File tree

stream/tag_mapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = function(){
4343
if (trimmed_value) {
4444
if (!trimmed_name ) {
4545
doc.setName('default', trim( tags[key]));
46-
} else {
46+
} else if(!trimmed_name.includes(trimmed_value)) {
4747
doc.setNameAlias('default', trim( tags[key]));
4848
}
4949
}

test/fixtures/combined_vancouver_queens.json

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -856354,16 +856354,10 @@
856354856354
"_type": "_doc",
856355856355
"data": {
856356856356
"name": {
856357-
"default": [
856358-
"Mountain Equipment Co-op (MEC)",
856359-
"MEC"
856360-
]
856357+
"default": "Mountain Equipment Co-op (MEC)"
856361856358
},
856362856359
"phrase": {
856363-
"default": [
856364-
"Mountain Equipment Co-op (MEC)",
856365-
"MEC"
856366-
]
856360+
"default": "Mountain Equipment Co-op (MEC)"
856367856361
},
856368856362
"address_parts": {
856369856363
"number": "212",
@@ -892395,8 +892389,7 @@
892395892389
"_type": "_doc",
892396892390
"data": {
892397892391
"name": {
892398-
"default": "IPOH Asian House"
892399-
},
892392+
"default": "IPOH Asian House" },
892400892393
"phrase": {
892401892394
"default": "IPOH Asian House"
892402892395
},
@@ -892430,16 +892423,10 @@
892430892423
"_type": "_doc",
892431892424
"data": {
892432892425
"name": {
892433-
"default": [
892434-
"On Lok Restaurant & Wun Tun House",
892435-
"On Lok"
892436-
]
892426+
"default": "On Lok Restaurant & Wun Tun House"
892437892427
},
892438892428
"phrase": {
892439-
"default": [
892440-
"On Lok Restaurant & Wun Tun House",
892441-
"On Lok"
892442-
]
892429+
"default": "On Lok Restaurant & Wun Tun House"
892443892430
},
892444892431
"address_parts": {
892445892432
"number": "2010",
@@ -956785,4 +956772,4 @@
956785956772
"bounding_box": "{\"min_lat\":49.2174915,\"max_lat\":49.2194865,\"min_lon\":-123.2018987,\"max_lon\":-123.1991481}"
956786956773
}
956787956774
}
956788-
]
956775+
]

test/stream/tag_mapper.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,38 @@ module.exports.tests.osm_names = function(test, common) {
112112
});
113113
};
114114

115+
// Reject alt names that are a substring of the main name
116+
module.exports.tests.substring_alt_name = function(test, common) {
117+
var doc = new Document('a','b',1);
118+
doc.setMeta('tags', { 'name': 'test place', 'alt_name': 'test pl' });
119+
120+
test('rejects - substring alt name', function(t) {
121+
var stream = mapper();
122+
stream.pipe( through.obj( function( doc, enc, next ){
123+
t.deepEqual(doc.name, { default: 'test place' }, 'substring name removed');
124+
t.end(); // test will fail if not called (or called twice).
125+
next();
126+
}));
127+
stream.write(doc);
128+
});
129+
};
130+
131+
// Reject alt names that are a substring of the main name, even if they appear before the name in list of tags
132+
module.exports.tests.substring_alt_name2 = function(test, common) {
133+
var doc = new Document('a','b',1);
134+
doc.setMeta('tags', { 'alt_name': 'test pl', name: 'test place'});
135+
136+
test('rejects - substring alt name', function(t) {
137+
var stream = mapper();
138+
stream.pipe( through.obj( function( doc, enc, next ){
139+
t.deepEqual(doc.name, { default: 'test place' }, 'substring name removed');
140+
t.end(); // test will fail if not called (or called twice).
141+
next();
142+
}));
143+
stream.write(doc);
144+
});
145+
};
146+
115147
// Cover the case of a tag key being 'name:' eg. { 'name:': 'foo' }
116148
// Not to be confused with { 'name': 'foo' } (note the extraneous colon)
117149
module.exports.tests.extraneous_colon = function(test, common) {

0 commit comments

Comments
 (0)