Search in sources :

Example 1 with CoordinateAssociationRule

use of org.opensextant.extractors.geo.rules.CoordinateAssociationRule in project Xponents by OpenSextant.

the class PlaceGeocoder method configure.

/**
     * We do whatever is needed to init resources... that varies depending on
     * the use case.
     * 
     * Guidelines: this class is custodian of the app controller, Corpus feeder,
     * and any Document instances passed into/out of the feeder.
     * 
     * This geocoder requires a default /exclusions/person-name-filter.txt,
     * which can be empty, but most often it will be a list of person names
     * (which are non-place names)
     * 
     * Rules Configured in approximate order:
     * 
     * <pre>
     * CountryRule    -- tag all country names
     * NameCodeRule   -- parse any Name, CODE, or Name1, Name2 patterns for "Place, AdminPlace" evidence
     * PersonNameRule -- annotate, negate any patterns or matches that appear to be known celebrity persons or organizations.
     *                   Qualified places are not negated, e.g., "Euguene, Oregon" is a place;  "Euguene" with no other evidence is a person name.  
     * CoordRule      -- if requested, parse any coordinate patterns;  Reverse geocode Country + Province.
     * ProvinceAssociationRule  -- associate places with Province inferred by coordinates.
     * MajorPlaceRule -- identify major places by feature type, class or location population.
     * LocationChooserRule    -- final rule that assigns confidence and chooses best location(s)
     * 
     * Your Rule Here -- use addRule( GeocodeRule ) to add a rule on the stack.  It will be evaluated just before the final LocationChooserRule.
     * your rule should improve Place scores on PlaceCandidates and name the rules that fire.
     * </pre>
     *
     * @throws ConfigException
     *             on err
     */
@Override
public void configure() throws ConfigException {
    // ==============
    // Rule setup:  Create GeocodeRules, add them to this.rules if they can be evaluated generically
    // on a list of place tags.
    // Otherwise such rules are configured, set during the request, and evaluated adhoc as you need.
    // 
    /* assess country names and codes */
    countryRule = new CountryRule();
    countryRule.setCountryObserver(this);
    /* assess NAME, CODE patterns */
    nameWithAdminRule = new NameCodeRule();
    nameWithAdminRule.setBoundaryObserver(this);
    // Nonsense is filtered out, rather than scored and ranked low.
    nonsenseFilter = new NonsenseFilter();
    rules.add(nonsenseFilter);
    /**
         * Files for Place Name filter are editable, as you likely have
         * different ideas of who are "person names" to exclude when they
         * conflict with place names. If you are filtering out such things, then
         * it makes sense to filter them out earliest and not incorporate them
         * in geocoding.
         * 
         */
    personNameRule = new PersonNameFilter("/filters/person-name-filter.txt", "/filters/person-title-filter.txt", "/filters/person-suffix-filter.txt");
    rules.add(personNameRule);
    /*
         * assess coordinates related to ADM1, CC
         */
    coordRule = new CoordinateAssociationRule();
    coordRule.setCountryObserver(this);
    coordRule.setLocationObserver(this);
    if (xcoord == null && (isCoordExtractionEnabled())) {
        xcoord = new XCoord();
        xcoord.configure();
        /*
             * assess ADM1 related to found NAMES as a result of coordinates
             */
        adm1Rule = new ProvinceAssociationRule();
        adm1Rule.setCountryObserver(this);
        rules.add(coordRule);
        rules.add(adm1Rule);
    }
    //
    try {
        Map<String, Integer> popstats = GeonamesUtility.mapPopulationByLocation(GeonamesUtility.loadMajorCities("/geonames.org/cities15000.txt"));
        majorPlaceRule = new MajorPlaceRule(popstats);
    } catch (IOException err) {
        log.error("Xponents 2.8: cities population data is used for geocoding. Will continue without it.");
        majorPlaceRule = new MajorPlaceRule(null);
    }
    majorPlaceRule.setCountryObserver(this);
    majorPlaceRule.setBoundaryObserver(this);
    rules.add(majorPlaceRule);
    // 
    if (isPersonNameMatchingEnabled()) {
        try {
            personMatcher = new TaxonMatcher();
            personMatcher.configure();
            /*
                 * Default catalog must be built. Extraction ./XTax folder has
                 * script for populating a catalog.
                 */
            personMatcher.addCatalogFilter("JRC");
            personMatcher.addCatalogFilter("nationality");
        } catch (IOException err) {
            throw new ConfigException("XTax resource not available.");
        }
    }
    // Un-filter city names that can be resolved if other ADMIN places line up.
    // E.g., "Cleveland Caveliers" filters out Cleveland, but if Cleveland is mentioned alone
    // then Cleveland itself will be promoted to a location.  E.g., sports teams travel
    // so mention of "Cleveland Caveliers visiting Seattle" would not geolocate this to Ohio
    // unless the city or state was mentioned separately.  
    // 
    placeInOrgRule = new ContextualOrganizationRule();
    placeInOrgRule.setBoundaryObserver(this);
    rules.add(placeInOrgRule);
    // Simple patterns such as city of x or  abc county.
    // 
    rules.add(new NameRule());
    chooser = new LocationChooserRule();
    chooser.setCountryObserver(this);
    chooser.setBoundaryObserver(this);
    chooser.setLocationObserver(this);
    //rules.add(chooser);
    countryCatalog = this.getGazetteer().getCountries();
}
Also used : MajorPlaceRule(org.opensextant.extractors.geo.rules.MajorPlaceRule) LocationChooserRule(org.opensextant.extractors.geo.rules.LocationChooserRule) NameRule(org.opensextant.extractors.geo.rules.NameRule) ConfigException(org.opensextant.ConfigException) IOException(java.io.IOException) TaxonMatcher(org.opensextant.extractors.xtax.TaxonMatcher) ContextualOrganizationRule(org.opensextant.extractors.geo.rules.ContextualOrganizationRule) XCoord(org.opensextant.extractors.xcoord.XCoord) CountryRule(org.opensextant.extractors.geo.rules.CountryRule) CoordinateAssociationRule(org.opensextant.extractors.geo.rules.CoordinateAssociationRule) ProvinceAssociationRule(org.opensextant.extractors.geo.rules.ProvinceAssociationRule) NonsenseFilter(org.opensextant.extractors.geo.rules.NonsenseFilter) PersonNameFilter(org.opensextant.extractors.geo.rules.PersonNameFilter) NameCodeRule(org.opensextant.extractors.geo.rules.NameCodeRule)

Aggregations

IOException (java.io.IOException)1 ConfigException (org.opensextant.ConfigException)1 ContextualOrganizationRule (org.opensextant.extractors.geo.rules.ContextualOrganizationRule)1 CoordinateAssociationRule (org.opensextant.extractors.geo.rules.CoordinateAssociationRule)1 CountryRule (org.opensextant.extractors.geo.rules.CountryRule)1 LocationChooserRule (org.opensextant.extractors.geo.rules.LocationChooserRule)1 MajorPlaceRule (org.opensextant.extractors.geo.rules.MajorPlaceRule)1 NameCodeRule (org.opensextant.extractors.geo.rules.NameCodeRule)1 NameRule (org.opensextant.extractors.geo.rules.NameRule)1 NonsenseFilter (org.opensextant.extractors.geo.rules.NonsenseFilter)1 PersonNameFilter (org.opensextant.extractors.geo.rules.PersonNameFilter)1 ProvinceAssociationRule (org.opensextant.extractors.geo.rules.ProvinceAssociationRule)1 XCoord (org.opensextant.extractors.xcoord.XCoord)1 TaxonMatcher (org.opensextant.extractors.xtax.TaxonMatcher)1