Skip to content

Commit

Permalink
'#1487 Process some nominatim responses that uses the term "town"
Browse files Browse the repository at this point in the history
instead of city.
  • Loading branch information
patrickdalla committed Sep 19, 2023
1 parent b2d9bd6 commit b2d92b5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions iped-geo/src/main/java/iped/geo/nominatim/NominatimTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,29 @@ private void processNominatimResult(IItem evidence, String content) {

try {
JSONObject obj = (JSONObject) new JSONParser().parse(content);

JSONArray features = (JSONArray) obj.get("features");
JSONObject properties = (JSONObject) ((JSONObject) features.get(0)).get("properties");
JSONObject address = (JSONObject) properties.get("address");
String country = (String) address.get("country");
evidence.getMetadata().add(NOMINATIM_COUNTRY_METADATA, country);
String state = (String) address.get("state");
evidence.getMetadata().add(NOMINATIM_STATE_METADATA, country + ":" + state);
String city = (String) address.get("city");
evidence.getMetadata().add(NOMINATIM_CITY_METADATA, country + ":" + state + ":" + city);
String suburb = (String) address.get("suburb");
if (suburb != null) {
evidence.getMetadata().add(NOMINATIM_SUBURB_METADATA,
country + ":" + state + ":" + city + ":" + suburb);
if (features != null) { // no error
JSONObject properties = (JSONObject) ((JSONObject) features.get(0)).get("properties");
JSONObject address = (JSONObject) properties.get("address");
String country = (String) address.get("country");
evidence.getMetadata().add(NOMINATIM_COUNTRY_METADATA, country);
String state = (String) address.get("state");
evidence.getMetadata().add(NOMINATIM_STATE_METADATA, country + ":" + state);
String city = (String) address.get("city");
if (city == null) {
city = (String) address.get("town");
}
evidence.getMetadata().add(NOMINATIM_CITY_METADATA, country + ":" + state + ":" + city);
String suburb = (String) address.get("suburb");
if (suburb != null) {
evidence.getMetadata().add(NOMINATIM_SUBURB_METADATA,
country + ":" + state + ":" + city + ":" + suburb);
}
String addresstype = (String) properties.get("addresstype");
evidence.getMetadata().add(NOMINATIM_ADDRESSTYPE_METADATA, addresstype);
}
String addresstype = (String) properties.get("addresstype");
evidence.getMetadata().add(NOMINATIM_ADDRESSTYPE_METADATA, addresstype);

} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit b2d92b5

Please sign in to comment.