Package com.bericotech.clavin.gazetteer

Examples of com.bericotech.clavin.gazetteer.GeoName


   
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static HashMap writeResolvedLocationToHash(ResolvedLocation resolvedLocation){
      HashMap loc = new HashMap();
      int charIndex = resolvedLocation.getLocation().getPosition();
      GeoName place = resolvedLocation.getGeoname();
        loc.put("confidence", resolvedLocation.getConfidence()); // low is good
        loc.put("id",place.getGeonameID());
        loc.put("name",place.getName());
        String primaryCountryCodeAlpha2 = "";
        if(place.getPrimaryCountryCode()!=CountryCode.NULL){
            primaryCountryCodeAlpha2 = place.getPrimaryCountryCode().toString();
        }
        String admin1Code = "";
       
        if(place.getAdmin1Code() !=null){
            admin1Code = place.getAdmin1Code();
        }
        String featureCode = place.getFeatureCode().toString();
        loc.put("featureClass", place.getFeatureClass().toString());
        loc.put("featureCode", featureCode);
        loc.put("population", place.getPopulation());
        loc.put("stateCode", admin1Code);
        loc.put("countryCode",primaryCountryCodeAlpha2);
        loc.put("lat",place.getLatitude());
        loc.put("lon",place.getLongitude());
        HashMap sourceInfo = new HashMap();
        sourceInfo.put("string",resolvedLocation.getLocation().getText());
        sourceInfo.put("charIndex",charIndex)
        if(resolvedLocation.getLocation() instanceof SentenceLocationOccurrence){
            sourceInfo.put("storySentencesId", ((SentenceLocationOccurrence) resolvedLocation.getLocation()).storySentenceId);
View Full Code Here


    }
   
    public static GeoName lookup(String countryCodeDotAdm1Code){
        try{
            Adm1GeoNameLookup lookup = getInstance();
            GeoName geoName = lookup.get(countryCodeDotAdm1Code);
            logger.debug("Found '"+countryCodeDotAdm1Code+"': "+geoName);
            return geoName;
        } catch (IOException ioe){
            logger.error("Couldn't lookup state ADM1 geoname!");
            logger.error(ioe.toString());
View Full Code Here

    }
   
    public static GeoName lookup(String countryCodeAlpha2) {
        try{
            CountryGeoNameLookup lookup = getInstance();
            GeoName countryGeoName = lookup.get(countryCodeAlpha2);
            logger.debug("Found '"+countryCodeAlpha2+"': "+countryGeoName);
            return countryGeoName;
        } catch (IOException ioe){
            logger.error("Couldn't lookup country geoname!");
            logger.error(ioe.toString());
View Full Code Here

    public static void logSelectedCandidate(ResolvedLocation candidate){
        logger.debug("  PICKED: "+candidate.getLocation().getText()+"@"+candidate.getLocation().getPosition());
    }
   
    public static void logResolvedLocationInfo(ResolvedLocation resolvedLocation){
        GeoName candidatePlace = resolvedLocation.getGeoname();
        logger.debug("    "+candidatePlace.getGeonameID()+" "+candidatePlace.getName()+
                ", "+ candidatePlace.getAdmin1Code()+
                ", " + candidatePlace.getPrimaryCountryCode()
                + " / "+resolvedLocation.getConfidence()
                +" / "+candidatePlace.getPopulation() + " / " + candidatePlace.getFeatureClass()
                + " ( isExactMatch="+isExactMatch(resolvedLocation)+" )");
    }
View Full Code Here

    @Test
    public void testCountryLookup() throws Exception {
        CountryGeoNameLookup lookup = new CountryGeoNameLookup();
        assertEquals(lookup.size(),250);
        GeoName usa = lookup.get("US");
        assertEquals(usa.getGeonameID(),6252001);
    }
View Full Code Here

    @Test
    public void testAdm1Lookup() throws Exception {
        Adm1GeoNameLookup lookup = new Adm1GeoNameLookup();
        assertEquals(lookup.size(),3895);
        GeoName newYorkState = lookup.get("US","NY");
        assertEquals(newYorkState.getGeonameID(),5128638);
    }
View Full Code Here

    @Test
    public void testGetByGeoNameId() throws Exception {
        Gazetteer gazetteer = new LuceneGazetteer(new File(ParseManager.PATH_TO_GEONAMES_INDEX));
        CliffLocationResolver resolver = new CliffLocationResolver(gazetteer);
        GeoName geoName = resolver.getByGeoNameId(6252001);
        assertEquals(geoName.getGeonameID(),6252001);
        assertEquals(geoName.getName(),"United States");
        assertEquals(geoName.getFeatureCode(),FeatureCode.PCLI);
    }
View Full Code Here

        HashMap<GeoName,Integer> cityCounts = FocusUtils.getCityCounts(resolvedLocations);
        if(cityCounts.size()==0){
            return results;
        }
        // find the most mentioned
        GeoName primaryCity = null;      
        int highestCount = 0;
        for(GeoName geoname: cityCounts.keySet()){
            int count = cityCounts.get(geoname);
            if( (primaryCity==null) || count > highestCount ){
                highestCount = count;
                primaryCity = geoname;
            }
        }
        logger.info("Found primary city "+primaryCity.toString());
        // return results
        if(primaryCity!=null) {
            int primaryCityCount = cityCounts.get(primaryCity);
            results.add( new FocusLocation( primaryCity, primaryCityCount ) );
            for(GeoName city: cityCounts.keySet()){
View Full Code Here

     * @param geonameEntry  single record from GeoNames gazetteer
     * @throws IOException
     */
    private static void addToIndex(IndexWriter indexWriter, String geonameEntry) throws IOException {
        // create a GeoName object from a single gazetteer record
        GeoName geoname = GeoName.parseFromGeoNamesRecord(geonameEntry);
       
        // add the primary (UTF-8) name for this location
        if (geoname.name.length() > 0)
            indexWriter.addDocument(buildDoc(geoname.name, geonameEntry, geoname.geonameID, geoname.population));
       
View Full Code Here

   * @throws IOException
   */
    private static void addToIndex(IndexWriter indexWriter, String geonameEntry) throws IOException {
     
      // create a GeoName object from a single gazetteer record
      GeoName geoname = GeoName.parseFromGeoNamesRecord(geonameEntry);
     
      // add the primary (UTF-8) name for this location
      if (geoname.name.length() > 0)
        indexWriter.addDocument(buildDoc(geoname.name, geonameEntry, geoname.geonameID, geoname.population));
     
View Full Code Here

TOP

Related Classes of com.bericotech.clavin.gazetteer.GeoName

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.