From dec4454165012b57f09c0891d88d5b238ff63b73 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Wed, 29 Jul 2020 10:40:45 +0200 Subject: [PATCH] fix address ranks for counties They were using the ones for state, thus hiding state information. Also cleans up and sorts the rank code a bit, to make it more easy to spot these kinds of mistakes. Fixes #482. --- src/main/java/de/komoot/photon/PhotonDoc.java | 1 + .../photon/nominatim/model/AddressRow.java | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/komoot/photon/PhotonDoc.java b/src/main/java/de/komoot/photon/PhotonDoc.java index c0c052400..c3f46f9cb 100644 --- a/src/main/java/de/komoot/photon/PhotonDoc.java +++ b/src/main/java/de/komoot/photon/PhotonDoc.java @@ -153,6 +153,7 @@ public void completeFromAddress() { district = extractAddress(district, "suburb"); locality = extractAddress(locality, "neighbourhood"); county = extractAddress(county, "county"); + state = extractAddress(state, "state"); String addressPostCode = address.get("postcode"); if (addressPostCode != null && !addressPostCode.equals(postcode)) { diff --git a/src/main/java/de/komoot/photon/nominatim/model/AddressRow.java b/src/main/java/de/komoot/photon/nominatim/model/AddressRow.java index b884ef6e8..a1efa99ef 100644 --- a/src/main/java/de/komoot/photon/nominatim/model/AddressRow.java +++ b/src/main/java/de/komoot/photon/nominatim/model/AddressRow.java @@ -21,6 +21,9 @@ public class AddressRow { static private final String[] USEFUL_CONTEXT_KEYS = new String[]{"boundary", "landuse", "place"}; // must be in alphabetic order to speed up lookup + /** + * @return whether nominatim thinks this place is a street + */ public boolean isStreet() { return 26 <= rankAddress && rankAddress < 28; } @@ -38,17 +41,29 @@ public boolean isLocality() { public boolean isDistrict() { return 17 <= rankAddress && rankAddress < 22; } + + /** + * @return whether nominatim thinks this place is a town or city + */ public boolean isCity() { - return 13 <= rankAddress && rankAddress <= 16; + return 13 <= rankAddress && rankAddress < 17; } /** * @return whether nominatim thinks this place is a county */ - public boolean isCounty() { - return 5 <= rankAddress && rankAddress <= 9; + public boolean isCounty() { return 10 <= rankAddress && rankAddress < 13; } + + /** + * @return whether nominatim thinks this place is a state + */ + public boolean isState() { return 5 <= rankAddress && rankAddress < 10; } + + public boolean isCountry() { + return (rankAddress == 4 && "boundary".equals(osmKey) && "administrative".equals(osmValue)); } + public boolean isPostcode() { if ("place".equals(osmKey) && "postcode".equals(osmValue)) { return true; @@ -82,19 +97,6 @@ public boolean isUsefulForContext() { return false; } - public boolean isCountry() { - if (rankAddress == 4 && "boundary".equals(osmKey) && "administrative".equals(osmValue)) { - return true; - } - - - return false; - } - - public boolean isState() { - return (5 <= rankAddress && rankAddress <= 9); - } - @Override public String toString() { return MoreObjects.toStringHelper(this)