use of org.opensextant.extractors.geo.SolrGazetteer in project Xponents by OpenSextant.
the class TestGazetteer method main.
/**
* Do a basic test -- This main prog makes use of the default JVM arg for solr: -Dopensextant.solr=/path/to/solr
*
*
* @param args the arguments
* @throws Exception the exception
*/
public static void main(String[] args) {
try {
GeonamesUtility geodataUtil = new GeonamesUtility();
Country aus = geodataUtil.getCountry("AUS");
System.out.println("Got Australia..." + aus);
gaz = new SolrGazetteer();
// Try to get countries
Map<String, Country> countries = gaz.getCountries();
for (Country c : countries.values()) {
System.out.println(c.getKey() + " = " + c.name + "\t Aliases: " + c.getAliases().toString());
}
/*
* This test organizes country names to see if there are any country names
* that are unique.
*/
List<String> cnames = new ArrayList<>();
Map<String, Boolean> done = new TreeMap<>();
for (Country C : geodataUtil.getCountries()) {
String q = String.format("name:%s AND -feat_code:PCL* AND -feat_code:TERR", C.getName());
List<Place> country_name_matches = gaz.search(q, true);
//System.out.println("Matched names for " + C.getName() + ":\t");
String cname = TextUtils.removeDiacritics(C.getName()).toLowerCase();
done.put(cname, false);
for (Place p : country_name_matches) {
String pname = TextUtils.removeDiacritics(p.getName());
if (pname.equalsIgnoreCase(cname)) {
done.put(p.getName().toLowerCase(), true);
}
}
cnames.add(cname);
}
//Collections.sort(cnames);
for (String cname : done.keySet()) {
System.out.println(String.format("\"%s\", Has Duplicates:", cname) + done.get(cname));
}
// US
testPlacesAt(44, -118, 25, /*km*/
"P");
// East Asia
testPlacesAt(44, 118, 100, /*km*/
"A");
// Europe
testPlacesAt(44, 0, 250, /*km*/
"A");
// Europe
testPlacesAt(44, 0, 10, /*km*/
"P");
} catch (Exception err) {
err.printStackTrace();
} finally {
gaz.shutdown();
System.exit(0);
}
}
Aggregations