Skip to content

Commit

Permalink
Add osm_value to dedupe key (komoot#367)
Browse files Browse the repository at this point in the history
Signed-off-by: Holger Bruch <[email protected]>
  • Loading branch information
hbruch committed Oct 15, 2018
1 parent f4ada8c commit fa72749
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ public List<JSONObject> execute(List<JSONObject>... 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<JSONObject> allResults = new ArrayList<>();
allResults.add(createDummyResult("99999", "Main Street", "highway", "Unclassified"));
allResults.add(createDummyResult("99999", "Main Street", "highway", "Unclassified"));

List<JSONObject> dedupedResults = streetDupesRemover.execute(allResults);
Assert.assertEquals(1, dedupedResults.size());
}

@Test
public void testStreetAndBusStopNotDeduplicated() {
StreetDupesRemover streetDupesRemover = new StreetDupesRemover("en");
List<JSONObject> allResults = new ArrayList<>();
allResults.add(createDummyResult("99999", "Main Street", "highway", "bus_stop"));
allResults.add(createDummyResult("99999", "Main Street", "highway", "Unclassified"));

List<JSONObject> 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));
}

}

0 comments on commit fa72749

Please sign in to comment.