From fa7274941369c8b70ba1e5ca164d4b78e10ab45b Mon Sep 17 00:00:00 2001 From: Holger Bruch Date: Mon, 15 Oct 2018 17:30:32 +0200 Subject: [PATCH] Add osm_value to dedupe key (#367) Signed-off-by: Holger Bruch --- .../photon/searcher/StreetDupesRemover.java | 9 ++-- .../searcher/StreetDupesRemoverTest.java | 45 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/test/java/de/komoot/photon/searcher/StreetDupesRemoverTest.java diff --git a/src/main/java/de/komoot/photon/searcher/StreetDupesRemover.java b/src/main/java/de/komoot/photon/searcher/StreetDupesRemover.java index 42c8fc1fe..5ec2da07f 100644 --- a/src/main/java/de/komoot/photon/searcher/StreetDupesRemover.java +++ b/src/main/java/de/komoot/photon/searcher/StreetDupesRemover.java @@ -37,17 +37,18 @@ public List execute(List... allResults) { // street has a postcode and name String postcode = properties.getString(Constants.POSTCODE); String name = properties.getString(Constants.NAME); - String key; + // OSM_VALUE is part of key to avoid deduplication of e.g. bus_stops and streets with same name + String key = (properties.has(Constants.OSM_VALUE) ? properties.getString(Constants.OSM_VALUE) : "") + ":"; if (language.equals("nl")) { String onlyDigitsPostcode = Utils.stripNonDigits(postcode); - key = onlyDigitsPostcode + ":" + name; + key += onlyDigitsPostcode + ":" + name; } else { - key = postcode + ":" + name; + key += postcode + ":" + name; } if (keys.contains(key)) { - // a street with this name + postcode is already part of the result list + // an osm highway object (e.g. street or bus_stop) with this osm_value + name + postcode is already part of the result list continue; } keys.add(key); diff --git a/src/test/java/de/komoot/photon/searcher/StreetDupesRemoverTest.java b/src/test/java/de/komoot/photon/searcher/StreetDupesRemoverTest.java new file mode 100644 index 000000000..c6c71fa72 --- /dev/null +++ b/src/test/java/de/komoot/photon/searcher/StreetDupesRemoverTest.java @@ -0,0 +1,45 @@ +package de.komoot.photon.searcher; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Test; + +import de.komoot.photon.Constants; + +public class StreetDupesRemoverTest { + + @Test + public void testDeduplicatesStreets() { + StreetDupesRemover streetDupesRemover = new StreetDupesRemover("en"); + List allResults = new ArrayList<>(); + allResults.add(createDummyResult("99999", "Main Street", "highway", "Unclassified")); + allResults.add(createDummyResult("99999", "Main Street", "highway", "Unclassified")); + + List dedupedResults = streetDupesRemover.execute(allResults); + Assert.assertEquals(1, dedupedResults.size()); + } + + @Test + public void testStreetAndBusStopNotDeduplicated() { + StreetDupesRemover streetDupesRemover = new StreetDupesRemover("en"); + List allResults = new ArrayList<>(); + allResults.add(createDummyResult("99999", "Main Street", "highway", "bus_stop")); + allResults.add(createDummyResult("99999", "Main Street", "highway", "Unclassified")); + + List dedupedResults = streetDupesRemover.execute(allResults); + Assert.assertEquals(2, dedupedResults.size()); + } + + private JSONObject createDummyResult(String postCode, String name, String osmKey, + String osmValue) { + return new JSONObject().put(Constants.PROPERTIES, new JSONObject() + .put(Constants.POSTCODE, postCode).put(Constants.NAME, name) + .put(Constants.OSM_KEY, osmKey).put(Constants.OSM_VALUE, osmValue)); + } + +}