@Test public void shoudParseSettlement() throws MalformedURLException { Settlement settlement = WikipediaSettlementChileanRegionInfoboxParser.parse(INFOBOX); Assert.assertEquals("Santiago Metropolitan Region", settlement.getName()); Assert.assertEquals("33.0", "" + settlement.getCoordinate().getLatD()); Assert.assertEquals("26.0", "" + settlement.getCoordinate().getLatM()); Assert.assertEquals("16.0", "" + settlement.getCoordinate().getLatS()); Assert.assertEquals("S", settlement.getCoordinate().getLatNS()); Assert.assertEquals("70.0", "" + settlement.getCoordinate().getLongD()); Assert.assertEquals("39.0", "" + settlement.getCoordinate().getLongM()); Assert.assertEquals("1.0", "" + settlement.getCoordinate().getLongS()); Assert.assertEquals("W", settlement.getCoordinate().getLongEW()); Assert.assertEquals("http://www.gobiernosantiago.cl/", settlement.getWebsite()); Assert.assertEquals("Chilean region", settlement.getType()); }
public static Settlement parse(String text) { Map<String, String> map = InfoboxMap.asMap(text); Settlement settlement = new Settlement(); Coordinate coordinate = new Coordinate(); for (String key : map.keySet()) { switch (key) { case NAME: settlement.setName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case STYLE: settlement.setType(InfoboxTypeParserUtil.getType(map.get(key))); break; case OFFICIAL_NAME: settlement.setOfficialName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case NATIVE_NAME: settlement.setNativeName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case NATIVE_NAME_LANG: settlement.setNativeNameLang(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case OTHER_NAME: settlement.setOtherName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case SETTLEMENT_TYPE: settlement.setSettlementType(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case LATITUDE: coordinate.setLatD(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGITUDE: coordinate.setLongD(map.get(key)); settlement.setCoordinate(coordinate); break; case LATD: coordinate.setLatD(map.get(key)); settlement.setCoordinate(coordinate); break; case LATM: coordinate.setLatM(map.get(key)); settlement.setCoordinate(coordinate); break; case LATS: coordinate.setLatS(map.get(key)); settlement.setCoordinate(coordinate); break; case LATDEG: coordinate.setLatD(map.get(key)); settlement.setCoordinate(coordinate); break; case LATMIN: coordinate.setLatM(map.get(key)); settlement.setCoordinate(coordinate); break; case LATSEC: coordinate.setLatS(map.get(key)); settlement.setCoordinate(coordinate); break; case LATNS: coordinate.setLatNS(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGD: coordinate.setLongD(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGM: coordinate.setLongM(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGS: coordinate.setLongS(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGDEG: coordinate.setLongD(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGMIN: coordinate.setLongM(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGSEC: coordinate.setLongS(map.get(key)); settlement.setCoordinate(coordinate); break; case LONGEW: coordinate.setLongEW(map.get(key)); settlement.setCoordinate(coordinate); break; case WEB: settlement.setWebsite(InfoboxWebsiteParserUtil.getWebsite(map.get(key))); break; case WEBSITE: settlement.setWebsite(InfoboxWebsiteParserUtil.getWebsite(map.get(key))); break; } } return settlement; }
public static Settlement parse(String text) { Map<String, String> map = WikipediaInfoboxParserUtils.asMap(text); Settlement settlement = new Settlement(); Coordinates coordinates = new Coordinates(); for (String key : map.keySet()) { try { switch (key) { case NAME: settlement.setName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case STYLE: settlement.setType(InfoboxTypeParserUtil.getType(map.get(key))); break; case OFFICIAL_NAME: settlement.setOfficialName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case NATIVE_NAME: settlement.setNativeName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case OTHER_NAME: settlement.setOtherName(InfoboxParserUtil.removeAllParenthesis(map.get(key))); break; case LATITUDE: coordinates.setLatD(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGITUDE: coordinates.setLongD(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATD: coordinates.setLatD(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATM: coordinates.setLatM(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATS: coordinates.setLatS(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATDEG: coordinates.setLatD(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATMIN: coordinates.setLatM(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATSEC: coordinates.setLatS(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LATNS: coordinates.setLatNS(map.get(key)); settlement.setCoordinates(coordinates); break; case LONGD: coordinates.setLongD(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGM: coordinates.setLongM(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGS: coordinates.setLongS(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGDEG: coordinates.setLongD(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGMIN: coordinates.setLongM(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGSEC: coordinates.setLongS(Double.parseDouble(map.get(key))); settlement.setCoordinates(coordinates); break; case LONGEW: coordinates.setLongEW(map.get(key)); settlement.setCoordinates(coordinates); break; case WEB: settlement.setWebsite(WikipediaInfoboxParserUtils.parseAsURL(map.get(key))); break; case WEBU: settlement.setWebsite(WikipediaInfoboxParserUtils.parseAsURL(map.get(key))); break; case WEBSITE: settlement.setWebsite(WikipediaInfoboxParserUtils.parseAsURL(map.get(key))); break; } } catch (Exception e) { } } return settlement; }