Search in sources :

Example 1 with SolrGazetteer

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);
    }
}
Also used : SolrGazetteer(org.opensextant.extractors.geo.SolrGazetteer) GeonamesUtility(org.opensextant.util.GeonamesUtility) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Country(org.opensextant.data.Country) Place(org.opensextant.data.Place)

Aggregations

ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 Country (org.opensextant.data.Country)1 Place (org.opensextant.data.Place)1 SolrGazetteer (org.opensextant.extractors.geo.SolrGazetteer)1 GeonamesUtility (org.opensextant.util.GeonamesUtility)1