Package com.bericotech.clavin.resolver

Examples of com.bericotech.clavin.resolver.ResolvedLocation


        this.expectedId = expectedId;
    }

    @Test
    public void testResolveMultipartLocation() throws ClavinException {
        ResolvedLocation loc = resolver.resolveLocation(false, parts);
        if (expectedId == null) {
            assertNull("expected null location", loc);
        } else {
            assertNotNull("expected non-null location", loc);
            GeoName geo = loc.getGeoname();
            assertEquals(String.format("Incorrect Location [%s]", geo), expectedId.intValue(), geo.getGeonameID());
        }
    }
View Full Code Here


                            parentMap.put(parentId, geos);
                        }
                        geos.add(geoname);
                    }
                }
                matches.add(new ResolvedLocation(location, geoname, matchedName, fuzzy));
                // stop processing results if we have reached maxResults matches
                if (matches.size() >= maxResults) {
                    break;
                }
            }
View Full Code Here

        Map<SearchLevel, List<ResolvedLocation>> resultsMap = new EnumMap<SearchLevel, List<ResolvedLocation>>(SearchLevel.class);
        for (SearchResult result : results) {
            resultsMap.put(result.level, result.locations);
        }

        ResolvedLocation bestMatch = results.peek().getBestLocation();
        matches.put(results.peek().level, new Match(results.peek().level, bestMatch, 0));
        // if the geoname's ancestry is fully resolved, find the
        // matched ancestors in the search results and populate the map;
        // otherwise, we cannot populate the map with anything other than
        // the best result because we cannot verify which search result
        // is the parent of the selected location
        if (bestMatch.getGeoname().isAncestryResolved()) {
            GeoName parent = bestMatch.getGeoname().getParent();
            while (parent != null) {
                SearchLevel level = SearchLevel.forGeoName(parent);
                if (resultsMap.containsKey(level)) {
                    // find parent GeoName in the results; this should exist because
                    // searches are filtered by ancestry from prior results
                    ResolvedLocation parentLoc = null;
                    List<ResolvedLocation> searchResults = resultsMap.get(level);
                    int depth;
                    for (depth = 0; depth < searchResults.size(); depth++) {
                        ResolvedLocation loc = searchResults.get(depth);
                        if (parent.getGeonameID() == loc.getGeoname().getGeonameID()) {
                            parentLoc = loc;
                            break;
                        }
                    }
                    if (parentLoc == null) {
View Full Code Here

            }
        }
        List<ResolvedLocation> cities = gazetteer.getClosestLocations(queryBuilder.build());

        // initialize return objects components
        ResolvedLocation finalCity = null;
        ResolvedLocation finalState = null;
        ResolvedLocation finalCountry = null;

        // assume the most populous valid city is the correct one return
        // note: this should be a reasonably safe assumption since we've attempted to enforce the
        // notional hierarchy of given place names (e.g., city --> state/province/etc. --> country)
        // and have therefore weeded out all other matches that don't fit this hierarchy
        if (!cities.isEmpty()) {
            finalCity = cities.get(0);
        }

        if (!states.isEmpty()) {
            // if we couldn't find a valid city, just take the most populous valid state/province/etc.
            if (finalCity == null) {
                finalState = states.get(0);
            } else {
                for (ResolvedLocation state : states) {
                    // select the first state that is an ancestor of the selected city
                    if (finalCity.getGeoname().isDescendantOf(state.getGeoname())) {
                        finalState = state;
                        break;
                    }
                }
            }
        }

        if (!countries.isEmpty()) {
            // use the selected city if available and the selected state if not to identify the selected country
            ResolvedLocation best = finalCity != null ? finalCity : finalState;
            // if neither city nor state was resolved, take the most populous valid country
            if (best == null) {
                finalCountry = countries.get(0);
            } else {
                for (ResolvedLocation country : countries) {
                    // select the first country that is an ancestor of the selected city or state
                    if (best.getGeoname().isDescendantOf(country.getGeoname())) {
                        finalCountry = country;
                        break;
                    }
                }
            }
View Full Code Here

            for (MatchedLocation candidate : candidateList) {
                LOG.debug(String.format("[%.3f] %s", scorer.score(terms, candidate), candidate.toString()));
            }
        }
        MatchedLocation bestMatch = candidateList.isEmpty() ? null : candidateList.get(0);
        ResolvedLocation location = null;
        if (bestMatch != null && (bestMatch.isFullySpecified() || bestMatch.getMatchCount() == terms.size())) {
            location = bestMatch.getMostSpecificMatch().getLocation();
        }
        return location;
    }
View Full Code Here

        for (ResolvedLocation resolvedLocation : resolvedLocationNames) {
            // assumes start/end positions are real, i.e., unique start positions for each extracted term
            resolvedLocationOffsetMap.put(resolvedLocation.getLocation().getPosition(), resolvedLocation);
        }

        ResolvedLocation loc;
        String processId = getClass().getName();
        for (Vertex termMention : termMentions) {
            loc = resolvedLocationOffsetMap.get((int) LumifyProperties.TERM_MENTION_START_OFFSET.getPropertyValue(termMention, 0));
            if (isLocation(termMention) && loc != null) {
                String id = String.format("CLAVIN-%d", loc.getGeoname().getGeonameID());
                GeoPoint geoPoint = new GeoPoint(loc.getGeoname().getLatitude(), loc.getGeoname().getLongitude(), LumifyProperties.TERM_MENTION_TITLE.getPropertyValue(termMention));
                String title = toSign(loc);
                String termMentionConceptType = LumifyProperties.TERM_MENTION_CONCEPT_TYPE.getPropertyValue(termMention);
                String conceptType = getOntologyClassUri(loc, termMentionConceptType);

                VisibilityJson sourceVertexVisibilityJson = LumifyProperties.VISIBILITY_JSON.getPropertyValue(sourceVertex);
View Full Code Here

                    (bestCandidates.size() == 0 ||
                      (bestCandidates.size() != 0 && inSameCountry(candidate, bestCandidates)))){
                  //   candidate.geoname.population>0){
                    //candidate.geoname.population>0 && inSameCountry(candidate, bestCandidates)){
    
                    ResolvedLocation cityCandidate = findFirstCityCandidate(candidates, true);
                    ResolvedLocation adminCandidate = findFirstAdminCandidate(candidates, true);
                    if (chooseCityOverAdmin(cityCandidate, adminCandidate)){
                      bestCandidates.add(cityCandidate);
                      possibilitiesToRemove.add(candidates);
                      foundOne = true;
                    }else if (adminCandidate != null){             
View Full Code Here

         */
        for( List<ResolvedLocation> candidates: possibilitiesToDo){
         
            List<ResolvedLocation> exactMatches = getExactMatches(candidates);
            if(exactMatches.size()>0){
                ResolvedLocation cityCandidate = findFirstCityCandidate(exactMatches,true);
                ResolvedLocation adminCandidate = findFirstAdminCandidate(exactMatches,true);

                if (chooseCityOverAdmin(cityCandidate, adminCandidate)){
                    bestCandidates.add(cityCandidate);
                    possibilitiesToRemove.add(candidates);
                }else if (adminCandidate != null){             
                    bestCandidates.add(adminCandidate);
                    possibilitiesToRemove.add(candidates);
                }
            } else {
           
                ResolvedLocation cityCandidate = findFirstCityCandidate(candidates,false);
                ResolvedLocation adminCandidate = findFirstAdminCandidate(candidates,false);
   
                if (chooseCityOverAdmin(cityCandidate, adminCandidate)){
                  bestCandidates.add(cityCandidate);
                  possibilitiesToRemove.add(candidates);
                }else if (adminCandidate != null){             
View Full Code Here

    public List<ResolvedLocation> select(CliffLocationResolver resolver, List<List<ResolvedLocation>> allPossibilities) {
           
        logger.debug("Starting with "+allPossibilities.size()+" lists to do:");
        // print all of them
        for( List<ResolvedLocation> candidates: allPossibilities){
            ResolvedLocation firstCandidate = candidates.get(0);
            logger.debug("  Location: "+firstCandidate.getLocation().getText()+"@"+firstCandidate.getLocation().getPosition());
            for( ResolvedLocation candidate: candidates){
                GenericPass.logResolvedLocationInfo(candidate);
            }
        }
View Full Code Here

    protected List<List<ResolvedLocation>> disambiguate(
            List<List<ResolvedLocation>> possibilitiesToDo,
            List<ResolvedLocation> bestCandidates) {
        List<List<ResolvedLocation>> possibilitiesToRemove = new ArrayList<List<ResolvedLocation>>();
        for( List<ResolvedLocation> candidates: possibilitiesToDo){
            ResolvedLocation firstcandidate = candidates.get(0);
            if(firstcandidate.getGeoname().getPopulation()>0 &&
                    firstcandidate.getGeoname().getAdmin1Code().equals("00")){
                bestCandidates.add(firstcandidate);
                possibilitiesToRemove.add(candidates);
            }
        }
        return possibilitiesToRemove;
View Full Code Here

TOP

Related Classes of com.bericotech.clavin.resolver.ResolvedLocation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.