Ejemplo n.º 1
0
 public boolean getData(
     File tmp, String stateCode, String countyCode, OntModel owlModel, Model pmlModel) {
   try {
     Resource usgs =
         pmlModel.createResource(
             Ontology.EPA.NS + "USGS", pmlModel.createResource(Ontology.PMLP.Organization));
     usgs.addLiteral(RDFS.label, "United States Geological Survey");
     Collection<MeasurementSite> data = process(tmp, stateCode, countyCode);
     for (MeasurementSite m : data) {
       m.asIndividual(owlModel, pmlModel);
     }
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
Ejemplo n.º 2
0
  Collection<MeasurementSite> process(File tmp, String stateCode, String countyCode)
      throws Exception {
    HashMap<String, MeasurementSite> data = new HashMap<String, MeasurementSite>();

    String source = downloadSiteInfo1(tmp, stateCode, countyCode.replaceAll(":", "%3A"));

    BufferedReader readbuffer1 = new BufferedReader(new FileReader(new File(tmp, "sites.txt")));
    String line1;
    boolean first1 = true;
    int counter = 0;
    while ((line1 = readbuffer1.readLine()) != null) {
      if (first1) {
        first1 = false;
        continue;
      }
      counter++;
      String parts[];
      parts = split(line1, "\t");
      String loc_id = parts[2];
      String label = parts[3];
      String lat = parts[11];
      String longitude = parts[12];
      String country_code = parts[24];
      String state_code = parts[25];
      String county_code = parts[26];
      MeasurementSite x =
          new MeasurementSite(
              loc_id,
              label,
              Double.parseDouble(lat),
              Double.parseDouble(longitude),
              country_code,
              Integer.parseInt(state_code),
              Integer.parseInt(county_code));
      x.setSourceDocument(source, counter);
      data.put(x.getID(), x);
    }

    source = downloadSiteInfo2(tmp, stateCode, countyCode.replaceAll(":", "%3A"));
    BufferedReader readbuffer2 = new BufferedReader(new FileReader(new File(tmp, "data.txt")));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String line2;
    boolean first2 = true;
    counter = 0;
    while ((line2 = readbuffer2.readLine()) != null) {
      if (first2) {
        first2 = false;
        continue;
      }
      String parts[];
      parts = split(line2, "\t");
      String ID = parts[21];
      String date = parts[6];
      String time = parts[7];
      String chemical = parts[31];
      String value = parts[33];
      String unit = parts[34];

      MeasurementSite temp = data.get(ID);
      if (value.equals("")) value = "0";
      if (date.equals("") || time.equals("")) continue;
      Measurement x =
          new Measurement(
              ID, counter++, sdf.parse(date), time, chemical, Double.parseDouble(value), unit);
      x.setSourceDocument(source, counter);
      temp.addData(x);
    }
    return data.values();
  }
Ejemplo n.º 3
0
  /**
   * @param args
   * @return
   * @return
   * @throws MalformedURLException
   */
  public static void main(String[] args) throws Exception {

    // @SuppressWarnings("unused")
    HashMap<String, MeasurementSite> data = new HashMap<String, MeasurementSite>();

    downloadSiteInfo1(new File("/tmp/"), "44", "44%3A001");

    BufferedReader readbuffer1 = new BufferedReader(new FileReader("/tmp/sites.txt"));
    String line1;
    boolean first1 = true;
    while ((line1 = readbuffer1.readLine()) != null) {
      if (first1) {
        first1 = false;
        continue;
      }

      String parts[] = new String[1000];
      parts = split(line1, "\t");
      String loc_id = parts[2];
      String label = parts[3];
      String lat = parts[11];
      String longitude = parts[12];
      String country_code = parts[24];
      String state_code = parts[25];
      String county_code = parts[26];
      MeasurementSite x =
          new MeasurementSite(
              loc_id,
              label,
              Double.parseDouble(lat),
              Double.parseDouble(longitude),
              country_code,
              Integer.parseInt(state_code),
              Integer.parseInt(county_code));
      data.put(x.getID(), x);
    }

    downloadSiteInfo2(new File("/tmp/"), "44", "44%3A001");
    BufferedReader readbuffer2 = new BufferedReader(new FileReader("/tmp/data.txt"));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String line2;
    boolean first2 = true;
    int counter = 0;
    while ((line2 = readbuffer2.readLine()) != null) {
      if (first2) {
        first2 = false;
        continue;
      }

      String parts[] = new String[1000];
      parts = split(line2, "\t");
      String ID = parts[21];
      String date = parts[6];
      String time = parts[7];
      String chemical = parts[31];
      String value = parts[33];
      String unit = parts[34];

      MeasurementSite temp = data.get(ID);
      if (value.equals("")) value = "0";
      if (date.equals("") || time.equals("")) continue;
      Measurement x =
          new Measurement(
              ID, counter++, sdf.parse(date), time, chemical, Double.parseDouble(value), unit);
      temp.addData(x);
    }
    for (MeasurementSite x : data.values()) {
      System.out.println(x.toString());
    }

    /*catch(Exception e) {
    	e.printStackTrace();
    	return false;
    }
    return true;*/

  }