Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
add ancestry to geonames lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulbot committed Jun 24, 2015
1 parent f7e6e94 commit 1278721
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.mediameter</groupId>
<artifactId>CLIFF</artifactId>
<packaging>war</packaging>
<version>2.1.1</version>
<version>2.2.0</version>

<name>CLIFF</name>
<url>http://cliff.mediameter.org/</url>
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/org/mediameter/cliff/ParseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ParseManager {
* Minor: small new features, changes to the json result format, or changes to the disambiguation algorithm
* Revision: minor change or bug fix
*/
static final String PARSER_VERSION = "2.1.1";
static final String PARSER_VERSION = "2.2.0";

private static final Logger logger = LoggerFactory.getLogger(ParseManager.class);

Expand Down Expand Up @@ -74,9 +74,26 @@ public static GeoName getGeoName(int id) throws UnknownGeoNameIdException{

@SuppressWarnings({ "rawtypes" })
public static HashMap getGeoNameInfo(int id) {
return getGeoNameInfo(id, true);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public static HashMap getGeoNameInfo(int id, boolean withAncestry) {
try {
GeoName geoname = getGeoName(id);
HashMap response = getResponseMap( writeGeoNameToHash(geoname) );
HashMap info = writeGeoNameToHash(geoname);
if(withAncestry){
HashMap childInfo = info;
GeoName child = geoname;
while(child.getParent()!=null){
GeoName parent = child.getParent();
HashMap parentInfo = writeGeoNameToHash(parent);
childInfo.put("parent", parentInfo);
child = parent;
childInfo = parentInfo;
}
}
HashMap response = getResponseMap( info );
return response;
} catch (UnknownGeoNameIdException e) {
logger.warn(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void test() {
assertEquals(GEONAME_MASSACHUSETTS_STATE,mitParent2.getGeonameID());
GeoName mitParent3 = mitParent2.getParent();
assertEquals(GEONAME_USA,mitParent3.getGeonameID());
GeoName mitParent4 = mitParent3.getParent();
assertEquals(null,mitParent4);
} catch (UnknownGeoNameIdException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 1278721

Please sign in to comment.