Package com.ikanow.infinit.e.data_model.store.document

Examples of com.ikanow.infinit.e.data_model.store.document.GeoPojo


    {
      if (null != geoRSSModule.getPosition())
      {
        double lat = geoRSSModule.getPosition().getLatitude();
        double lon = geoRSSModule.getPosition().getLongitude();
        GeoPojo gp = new GeoPojo();
        gp.lat = lat;
        gp.lon = lon;
        doc.setDocGeo(gp);
      }
      if (null != geoRSSModule.getGeometry())
      {
        AbstractGeometry ag = geoRSSModule.getGeometry();
        if(ag.getClass().equals(new LineString().getClass()))
        { //<georss:line>
          LineString ls = ((LineString)geoRSSModule.getGeometry());
         
          double latAvg = 0.0;
          double lonAvg = 0.0;
          int length = ls.getPositionList().size();
          for (int i = 0; i < length; i ++)
          {
            latAvg += ls.getPositionList().getLatitude(i);
            lonAvg += ls.getPositionList().getLongitude(i);
          }
          latAvg = latAvg/length;
          lonAvg = lonAvg/length;
          GeoPojo gp = new GeoPojo();
          gp.lat = latAvg;
          gp.lon = lonAvg;
          doc.setDocGeo(gp);
        }
        else if (ag.getClass().equals(new Polygon().getClass())) //<georss:polygon>
        {
          Polygon poly = ((Polygon)geoRSSModule.getGeometry());
          AbstractRing ar = poly.getExterior();
          LinearRing lr = (LinearRing)ar;

          double latAvg = 0.0;
          double lonAvg = 0.0;
          int length = lr.getPositionList().size();
          for (int i = 0; i < length; i ++)
          {
            latAvg += lr.getPositionList().getLatitude(i);
            lonAvg += lr.getPositionList().getLongitude(i);
          }
          latAvg = latAvg/length;
          lonAvg = lonAvg/length;
          GeoPojo gp = new GeoPojo();
          gp.lat = latAvg;
          gp.lon = lonAvg;
          doc.setDocGeo(gp);
        }
        else if(ag.getClass().equals(new Envelope().getClass()))
        { //<georss:box>
          Envelope env = ((Envelope)geoRSSModule.getGeometry());
         
          double latAvg = (env.getMaxLatitude()+env.getMinLatitude())/2;
          double lonAvg = (env.getMaxLongitude()+env.getMinLongitude())/2;

          GeoPojo gp = new GeoPojo();
          gp.lat = latAvg;
          gp.lon = lonAvg;
          doc.setDocGeo(gp);
        }
      }
View Full Code Here


          // If the metadata contains a geotag then apply that:
          try {
            String lat = metadata.get(Metadata.LATITUDE);
            String lon = metadata.get(Metadata.LONGITUDE);
            if ((null != lat) && (null != lon)) {
              GeoPojo gt = new GeoPojo();
              gt.lat = Double.parseDouble(lat);
              gt.lon = Double.parseDouble(lon);
              doc.setDocGeo(gt);
            }
          }
View Full Code Here

    GeoFeaturePojo feature = GeoFeaturePojo.fromDb(location, GeoFeaturePojo.class);
    SearchSuggestPojo suggest = new SearchSuggestPojo();
    suggest.setOntology_type(feature.getOntology_type());
    suggest.setScore(distance);     
    suggest.setValue(buildLocation(feature));
    suggest.setGeotag(new GeoPojo(feature.getGeoindex().lat, feature.getGeoindex().lon));
    return suggest;
  }
View Full Code Here

    // If the metadata contains a geotag then apply that:
    try {
      String lat = metadata.get(Metadata.LATITUDE);
      String lon = metadata.get(Metadata.LONGITUDE);
      if ((null != lat) && (null != lon)) {
        GeoPojo gt = new GeoPojo();
        gt.lat = Double.parseDouble(lat);
        gt.lon = Double.parseDouble(lon);
        partialDoc.setDocGeo(gt);
      }
    }
View Full Code Here

                  ep.getSemanticLinks().add(resolutionFirst.get("id").getTextValue()); //this is a link to an alchemy page
                  ep.setDisambiguatedName(resolutionFirst.get("name").getTextValue());
                  //check if we need to create a geo object
                  if ( null != resolutionFirst.get("latitude") )
                  {
                    GeoPojo gp = new GeoPojo();
                    String lat = resolutionFirst.get("latitude").getValueAsText();
                    String lon = resolutionFirst.get("longitude").getValueAsText();
                    gp.lat = Double.parseDouble(lat);
                    gp.lon = Double.parseDouble(lon);
                    ep.setGeotag(gp);
View Full Code Here

     
     
      // Extract Entity GEO or set Entity Geo equal to DocGeo if specified via useDocGeo
      if (esp.getGeotag() != null)
      { 
        GeoPojo geo = getEntityGeo(esp.getGeotag(), null, field);
        if (null != geo) {
          e.setGeotag(geo);
        }
        // (Allow this field to be intrinsically optional)
       
        // If no ontology type is specified, derive it from getEntityGeo:
        if (null == esp.getOntology_type()) {
          esp.setOntology_type(esp.getGeotag().getOntology_type());
        }
      }
      else if (esp.getUseDocGeo() == true)
      {
        GeoPojo geo = getEntityGeo(null, f, field);
        if (null != geo) {
          e.setGeotag(geo);
        }
        // (Allow this field to be intrinsically optional)
      }
View Full Code Here

          //TESTED (INF1360_test_source:test4b)
        }
        //TESTED (INF1360_test_source:test4, test5, test6)
       
        if (null != geo_entity) e.setGeo_index(geo_entity);
        GeoPojo s1 = _geoMap.get(geo_entity);
        e.setGeotag(s1);
        //TESTED (INF1360_test_source:test4)
       
        // Allow this to be intrinsically optional
      }
     
      // Get geo information based on geo tag
      if (e.getGeotag() == null)
      {
        // Extract association geoTag if it exists in the association
        if (esp.getGeotag() != null)
        { 
          e.setGeotag(getEntityGeo(esp.getGeotag(), null, field));
        }
        // Otherwise search geoMap on index (entity1_index, entity2_index) for a geoTag
        else
        {
          if (e.getEntity1_index() != null || e.getEntity2_index() != null)
          {
            GeoPojo s1 = _geoMap.get(e.getEntity1_index());
            if (s1 != null)
            {
              e.setGeotag(s1);
              e.setGeo_index(e.getEntity1_index());
            }
            else {
              GeoPojo s2 = _geoMap.get(e.getEntity2_index());
              if (s2 != null)
              {
                e.setGeotag(s2);
                e.setGeo_index(e.getEntity2_index());
              }
View Full Code Here

   * @param d DocGeoSpecPojo
   * @return GeoJSONPojo
   */
  private GeoPojo getDocGeo(GeoSpecPojo d)
  {
    GeoPojo docGeo = new GeoPojo();
    String latValue = null;
    String lonValue = null;
   
    try
    {

      // The DocSpecGeoPojo already has lat and lon so we just need to retrieve the values
      if ((d.getLat() != null) && (d.getLon() != null))
      {
        if (JavaScriptUtils.containsScript(d.getLat()))
        {
          latValue = (String)getValueFromScript(d.getLat(), null, null);
        }
        else
        {
          latValue = getStringFromJsonField(d.getLat(), null);
        }

        if (JavaScriptUtils.containsScript(d.getLat()))
        {
          lonValue = (String)getValueFromScript(d.getLon(), null, null);
        }
        else
        {
          lonValue = getStringFromJsonField(d.getLon(), null);
        }
      }

      // Try and retrieve lat and lon using city, state, country values
      else
      {
        String city, region, country, countryCode = null;
       
        // Create a GeoReferencePojo from the DocSpecGeo object
        GeoFeaturePojo g = new GeoFeaturePojo();

        if (d.getCity() != null)
        {
          if (JavaScriptUtils.containsScript(d.getCity()))
          {
            city = (String)getValueFromScript(d.getCity(), null, null);
          }
          else
          {
            city = getFormattedTextFromField(d.getCity(), null);
          }

          g.setCity(city);
          g.setSearch_field(city);
        }

        if (d.getStateProvince() != null)
        {
          if (JavaScriptUtils.containsScript(d.getStateProvince()))
          {
            region = (String)getValueFromScript(d.getStateProvince(), null, null);
          }
          else
          {
            region = getFormattedTextFromField(d.getStateProvince(), null);
          }

          g.setRegion(region);
          if (g.getSearch_field() == null) g.setSearch_field(region);
        }

        if (d.getCountry() != null)
        {
          if (JavaScriptUtils.containsScript(d.getCountry()))
          {
            country = (String)getValueFromScript(d.getCountry(), null, null);
          }
          else
          {
            country = getFormattedTextFromField(d.getCountry(), null);
          }

          g.setCountry(country);
          if (g.getSearch_field() == null) g.setSearch_field(country);
        }

        if (d.getCountryCode() != null)
        {
          if (JavaScriptUtils.containsScript(d.getCountryCode()))
          {
            countryCode = (String)getValueFromScript(d.getCountryCode(), null, null);
          }
          else
          {
            countryCode = getFormattedTextFromField(d.getCountryCode(), null);
          }

          g.setCountry_code(countryCode);
          if (g.getSearch_field() == null) g.setSearch_field(countryCode);
        }

        // Send the GeoReferencePojo to enrichGeoInfo to attempt to get lat and lon values
        boolean bStrictMatch = (null == d.getStrictMatch()) || d.getStrictMatch();
        List<GeoFeaturePojo> gList = GeoReference.enrichGeoInfo(g, bStrictMatch, true, 1);
        latValue = gList.get(0).getGeoindex().lat.toString();
        lonValue = gList.get(0).getGeoindex().lon.toString();
      }

      // Set lat and long in DocGeo if possible
      docGeo.lat = Double.parseDouble(latValue);
      docGeo.lon = Double.parseDouble(lonValue);
     
      if (docGeo.lat == 0 && docGeo.lon == 0) docGeo = null; // Don't save 0,0 vals
    }
    catch (Exception e)
    {
      if (null != d.getAlternatives()) {
        for (GeoSpecPojo altIn: d.getAlternatives()) {
          GeoPojo altOut =  getDocGeo(altIn);
          if (null != altOut) {
            return altOut;
          }
        }
      }     
View Full Code Here

   */
  private GeoPojo getEntityGeo(GeoSpecPojo gsp, DocumentPojo f, String field)
  {
    try
    {
      GeoPojo g = null;
      Double dLat = (double) 0;
      Double dLon = (double) 0;
     
      if (gsp != null)
      {
        String latValue = null;
        String lonValue = null;
        // The GeoSpecPojo already has lat and lon so we just need to retrieve the values
        if ((gsp.getLat() != null) && (gsp.getLon() != null)) {
          if (JavaScriptUtils.containsScript(gsp.getLat()))
          {
            latValue = (String)getValueFromScript(gsp.getLat(), null, null);
          }
          else
          {
            latValue = getFormattedTextFromField(gsp.getLat(), field);
          }
 
          if (JavaScriptUtils.containsScript(gsp.getLon()))
          {
            lonValue = (String)getValueFromScript(gsp.getLon(), null, null);
          }
          else
          {
            lonValue = getFormattedTextFromField(gsp.getLon(), field);
          }
         
          if (latValue != null && lonValue != null)
          {
            dLat = Double.parseDouble(latValue);
            dLon = Double.parseDouble(lonValue);
          }
        }
       
        else
        {
          String city, region, country, countryCode = null;
         
          // Create a GeoReferencePojo from the GeoSpec object
          GeoFeaturePojo gfp = new GeoFeaturePojo();

          if (gsp.getCity() != null)
          {
            if (JavaScriptUtils.containsScript(gsp.getCity()))
            {
              city = (String)getValueFromScript(gsp.getCity(), null, null);
            }
            else
            {
              city = getFormattedTextFromField(gsp.getCity(), null);
            }

            gfp.setCity(city);
            gfp.setSearch_field(city);
          }

          if (gsp.getStateProvince() != null)
          {
            if (JavaScriptUtils.containsScript(gsp.getStateProvince()))
            {
              region = (String)getValueFromScript(gsp.getStateProvince(), null, null);
            }
            else
            {
              region = getFormattedTextFromField(gsp.getStateProvince(), null);
            }

            gfp.setRegion(region);
            if (gfp.getSearch_field() == null) gfp.setSearch_field(region);
          }

          if (gsp.getCountry() != null)
          {
            if (JavaScriptUtils.containsScript(gsp.getCountry()))
            {
              country = (String)getValueFromScript(gsp.getCountry(), null, null);
            }
            else
            {
              country = getFormattedTextFromField(gsp.getCountry(), null);
            }

            gfp.setCountry(country);
            if (gfp.getSearch_field() == null) gfp.setSearch_field(country);
          }

          if (gsp.getCountryCode() != null)
          {
            if (JavaScriptUtils.containsScript(gsp.getCountryCode()))
            {
              countryCode = (String)getValueFromScript(gsp.getCountryCode(), null, null);
            }
            else
            {
              countryCode = getFormattedTextFromField(gsp.getCountryCode(), null);
            }

            gfp.setCountry_code(countryCode);
            // (Don't set to search field for country code - it will be equal to country...)
          }

          // Send the GeoReferencePojo to enrichGeoInfo to attempt to get lat and lon values
          boolean bStrictMatch = (null == gsp.getStrictMatch()) || gsp.getStrictMatch();
          List<GeoFeaturePojo> gList = GeoReference.enrichGeoInfo(gfp, bStrictMatch, true, 1);
          GeoFeaturePojo firstGeo = gList.get(0);
          latValue = firstGeo.getGeoindex().lat.toString();
          lonValue = firstGeo.getGeoindex().lon.toString();
          gsp.setOntology_type(firstGeo.getOntology_type());
         
          // Set lat and long in DocGeo if possible
          dLat = Double.parseDouble(latValue);
          dLon = Double.parseDouble(lonValue);
        }
      }

      if (dLat != 0 && dLon !=0)
      {
        g = new GeoPojo();
        g.lat = dLat;
        g.lon = dLon;
      }

     
      return g;
    }
    catch (Exception e) // If alternatives are specified we can try them instead
    {
      if (null != gsp.getAlternatives()) {
        for (GeoSpecPojo altIn: gsp.getAlternatives()) {
          GeoPojo altOut =  getEntityGeo(altIn, f, field);
          if (null != altOut) {
            gsp.setOntology_type(altIn.getOntology_type());
            return altOut;
          }
        }
View Full Code Here

      {
        ent.setSemanticLinks(new ArrayList<String>());
        ent.setDisambiguatedName(pojoToConvert.disambiguated.name);
        if ( pojoToConvert.disambiguated.geo != null )
        {
          GeoPojo geo = new GeoPojo();
          String[] geocords = pojoToConvert.disambiguated.geo.split(" ");
          geo.lat = Double.parseDouble(geocords[0]);
          geo.lon = Double.parseDouble(geocords[1]);
          ent.setGeotag(geo);
        }
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.store.document.GeoPojo

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.