Search in sources :

Example 1 with CountryCount

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

the class LocationChooserRule method evaluate.

/**
     * Yet unchosen location.
     * Consider given evidence first, creating some weight there,
     * then introducing innate properties of possible locations, thereby amplifying the
     * differences in the candidates.
     * 
     */
@Override
public void evaluate(PlaceCandidate name, Place geo) {
    if (boundaryContext.isEmpty() && countryContext.isEmpty()) {
        return;
    }
    double countryScalar = 1.0;
    CountryCount ccnt = countryContext.get(geo.getCountryCode());
    if (ccnt != null) {
        countryScalar = GLOBAL_POINTS * ccnt.getRatio();
    }
    // This is inferred stuff from the document at large.
    if (geo.getHierarchicalPath() != null && boundaryContext.containsKey(geo.getHierarchicalPath())) {
        name.incrementPlaceScore(geo, countryScalar * ADMIN_CONTAINS_PLACE_WT);
    } else if (countryContext.containsKey(geo.getCountryCode())) {
        name.incrementPlaceScore(geo, countryScalar * COUNTRY_CONTAINS_PLACE_WT);
    }
    // 
    for (PlaceEvidence ev : name.getEvidence()) {
        if (ev.wasEvaluated()) {
            continue;
        }
        ev.defaultHierarchicalPath();
        // Evaluate evidence
        if ((ev.getAdmin1() != null && geo.getAdmin1() != null)) {
            if (geo.getHierarchicalPath().equals(ev.getHierarchicalPath())) {
                name.incrementPlaceScore(geo, ADMIN_CONTAINS_PLACE_WT);
            }
        } else {
            if (geo.getCountryCode().equals(ev.getCountryCode())) {
                name.incrementPlaceScore(geo, COUNTRY_CONTAINS_PLACE_WT);
            }
        }
        ev.setEvaluated(true);
        log.debug("\tEvidence: {} {}", ev, ev.getAdmin1());
    }
}
Also used : CountryCount(org.opensextant.extractors.geo.CountryCount) PlaceEvidence(org.opensextant.extractors.geo.PlaceEvidence)

Example 2 with CountryCount

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

the class LocationChooserRule method debuggingHistograms.

/**
     * What can we learn from assembling better stats at the document level?
     * Evidence breaks down into concrete locations vs. inferred.
     * 
     * @param names
     */
private void debuggingHistograms(List<PlaceCandidate> names) {
    /*
         * TODO:  Is this histogram helpful.?
         * 
         * Uniqueness or popularity of a given name.
         */
    for (PlaceCandidate name : names) {
        if (name.isFilteredOut()) {
            continue;
        }
        PlaceCount x = namespace.get(name.getTextnorm());
        if (x == null) {
            x = new PlaceCount();
            x.place = new Place(name.getTextnorm(), name.getTextnorm());
            x.total = names.size();
            namespace.put(name.getTextnorm(), x);
        } else {
            ++x.count;
        }
    }
    for (String cc : countryContext.keySet()) {
        CountryCount count = countryContext.get(cc);
        //log.debug("Country: {}/{} ({})", cc, count.country, count.count);
        log.debug("Country: {}", count);
    }
    for (PlaceCount count : boundaryContext.values()) {
        //log.debug("Boundary: {} ({})", count.place, count.count);
        log.debug("Boundary: {}", count);
        String cc = count.place.getCountryCode();
        CountryCount Ccnt = inferredCountries.get(cc);
        if (Ccnt == null) {
            Ccnt = new CountryCount();
            Ccnt.country = new Country(cc, cc);
            inferredCountries.put(cc, Ccnt);
        } else {
            ++Ccnt.count;
        }
    }
    log.debug("Places: {}/{}", namespace.size(), namespace);
}
Also used : PlaceCount(org.opensextant.extractors.geo.PlaceCount) CountryCount(org.opensextant.extractors.geo.CountryCount) Country(org.opensextant.data.Country) Place(org.opensextant.data.Place) PlaceCandidate(org.opensextant.extractors.geo.PlaceCandidate)

Aggregations

CountryCount (org.opensextant.extractors.geo.CountryCount)2 Country (org.opensextant.data.Country)1 Place (org.opensextant.data.Place)1 PlaceCandidate (org.opensextant.extractors.geo.PlaceCandidate)1 PlaceCount (org.opensextant.extractors.geo.PlaceCount)1 PlaceEvidence (org.opensextant.extractors.geo.PlaceEvidence)1