Пример #1
0
  private static void readLatLong() {

    String buildingCode = "EEB";

    StringBuilder query = new StringBuilder("");
    query.append("PREFIX sgns: <http://www.smartgrid.usc.edu/Ontology/2012.owl#> \n");
    query.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n");
    query.append("PREFIX gmlns: <http://purl.org/ifgi/gml/0.1/> \n");
    query.append("SELECT ?latitude ?longitude WHERE { \n");
    query.append(
        "			?building  <http://dbpedia.org/ontology/hasBuildingNo> '" + buildingCode + "'  .\n");
    query.append("			?building  gmlns:GeometryProperty ?gml . \n");
    query.append("			?gml  sgns:hasLatitude  ?latitude . \n");
    query.append("			?gml  sgns:hasLongitude  ?longitude . \n");
    query.append("	 } \n");

    String sparql = query.toString();
    System.out.println("\nSelectQuery: " + sparql);

    Store store = null;
    try {

      store = new Store(IIPProperties.getStoreURL());
      String response = store.query(sparql, -1);
      System.out.println("Select response: " + response);
    } catch (MalformedURLException e) {
      e.getMessage();
      e.printStackTrace();
    } catch (ProtocolException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  private static void readKWH(
      String buildingCode, String startDate, String endDate, String startTime, String endTime) {

    StringBuilder query = new StringBuilder("");
    query.append("PREFIX sgns: <http://www.smartgrid.usc.edu/Ontology/2012.owl#> \n");
    query.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n");
    query.append("PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n");
    // query.append("SELECT (MAX(xsd:double(?kwhReading)) AS ?KWh_MAX)  WHERE { \n");
    query.append("SELECT ?kwhReading  WHERE { \n");
    query.append(
        " ?building  <http://dbpedia.org/ontology/hasBuildingCode> '" + buildingCode + "'  .\n");

    String triple = " ?building  sgns:KiloWattLoadObservable ?kwhURI . \n";
    query.append(triple);

    triple = " ?kwhURI  rdf:type sgns:ElectricalMeasurement . \n";
    query.append(triple);

    triple = " ?kwhURI  sgns:hasMeasurementRecordedDate  ?date . \n"; // ^^xsd:date
    query.append(triple);

    triple = " ?kwhURI  sgns:hasMeasurementRecordedTime  ?time . \n"; // ^^xsd:time
    query.append(triple);

    triple = "  FILTER ( ?date >= '" + startDate + "' && ?date <= '" + endDate + "')  \n";
    query.append(triple);

    //		triple = "  FILTER ( ?time >= '"+ startTime +"' && ?time <= '"+ endTime + "')  \n";
    //		query.append(triple);

    triple = " ?kwhURI  sgns:hasMeasuredValue  ?kwhReading   . \n\n";
    query.append(triple);

    query.append("	 } \n");

    String sparql = query.toString();
    System.out.println("\nSelectQuery: " + sparql);

    Store store = null;
    try {
      store = new Store(IIPProperties.getStoreURL());
      String response = store.query(sparql, -1);
      System.out.println("Select response: " + response);
    } catch (MalformedURLException e) {
      e.getMessage();
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  private static void insertBuildings(int count)
      throws MalformedURLException, ProtocolException, IOException, InterruptedException {

    String sparql1 = getBuildingInsertQuery(count);
    System.out.println(sparql1);

    Store store = null;
    try {
      store = new Store(IIPProperties.getStoreURL());
      //			String response = store.insert(sparql1);
      //			System.out.println("Insert response: "+ response);
    } catch (MalformedURLException e) {
      e.getMessage();
      e.printStackTrace();
    }

    StringBuilder sparql2 = new StringBuilder("");
    sparql2.append("PREFIX Building: <http://dbpedia.org/ontology/> \n");
    sparql2.append("PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n");
    sparql2.append("PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> \n");
    sparql2.append("PREFIX sgns: <http://www.smartgrid.usc.edu/Ontology/2012.owl#> \n");
    sparql2.append("PREFIX gmlns: <http://purl.org/ifgi/gml/0.1/> \n");
    sparql2.append(" SELECT ?BuildingCode ?GrossArea ?latitude  ?longitude  \n");
    sparql2.append(" WHERE { \n");
    sparql2.append("     ?contributor rdf:type ?BuildingEntityClass . \n");
    sparql2.append("     ?contributor Building:hasBuildingNo ?BuildingNum . \n"); // \"100000\"
    //	    sparql2.append(" 	 FILTER(xsd:integer(?BuildingNum) > 9999) \n");
    //	    sparql2.append("     ?contributor ?BuildingProperty \"BC1\" . \n");
    sparql2.append("     ?contributor Building:hasBuildingCode ?BuildingCode . \n");
    sparql2.append("     ?contributor Building:address ?Address . \n");
    sparql2.append("     ?contributor Building:elevation ?Elevation . \n");
    sparql2.append("     ?contributor Building:buildingstartdate ?YearBuilt . \n");
    sparql2.append("     ?contributor Building:floorArea ?GrossArea . \n");

    sparql2.append("     ?contributor Building:Architect ?architect . \n");
    sparql2.append("     ?architect rdf:type ?ArchitectEntityClass . \n");
    sparql2.append("     ?architect Building:birthname ?ArchitectName . \n");

    sparql2.append("			?contributor  gmlns:GeometryProperty ?gml . \n");
    sparql2.append("			?gml  sgns:hasLatitude  ?latitude . \n");
    sparql2.append("			?gml  sgns:hasLongitude  ?longitude . \n");

    sparql2.append(" } ");

    System.out.println("SPARQL Query: " + sparql2.toString());
    String response2 = store.query(sparql2.toString(), -1);
    System.out.println("Results: \n" + response2);
  }
Пример #4
0
  private static void insertKWH(String kwhReadingFile, String buildingCode, int buildingNo)
      throws IOException {

    System.out.println(
        "Starting insertKWH(): BuildingCode = "
            + buildingCode
            + "  Building# = "
            + buildingNo
            + "  file = "
            + kwhReadingFile);

    FileReader reader = new FileReader(kwhReadingFile);
    BufferedReader read = new BufferedReader(reader);

    StringBuilder insertQuery = new StringBuilder("");
    insertQuery.append("PREFIX sgns: <http://www.smartgrid.usc.edu/Ontology/2012.owl#> \n");
    insertQuery.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n");
    insertQuery.append("PREFIX gmlns: <http://purl.org/ifgi/gml/0.1/> \n");
    insertQuery.append("INSERT DATA { \n");

    String date = null;
    String time = null;
    String kwhReading = null;

    int readingCount = 0;
    String line = read.readLine(); // First line is the column headers
    line = read.readLine();
    while (line != null) {

      // System.out.println(line);

      StringTokenizer tok = new StringTokenizer(line, ", ");

      if (!tok.hasMoreTokens()) {
        line = read.readLine();
        continue;
      }
      if (!(buildingNo + "").equals(tok.nextToken())) {
        line = read.readLine();
        continue;
      }

      if (!tok.hasMoreTokens()) {
        line = read.readLine();
        continue;
      }
      date = tok.nextToken();

      if (!tok.hasMoreTokens()) {
        line = read.readLine();
        continue;
      }
      time = tok.nextToken();

      if (!tok.hasMoreTokens()) {
        line = read.readLine();
        continue;
      }
      kwhReading = tok.nextToken();

      readingCount++;
      System.out.println(date + "   " + time + "   " + kwhReading);

      // buildingCode = "testBuildingCode111";

      String buildingURI = "ran" + System.nanoTime();
      String kwhURI = "ran" + System.nanoTime();

      String triple =
          " 	sgns:" + buildingURI + " rdf:type <http://dbpedia.org/ontology/Building> . \n";
      insertQuery.append(triple);

      triple =
          " 	sgns:"
              + buildingURI
              + " <http://dbpedia.org/ontology/hasBuildingCode> '"
              + buildingCode
              + "' . \n";
      insertQuery.append(triple);

      triple = " 	sgns:" + buildingURI + " sgns:KiloWattLoadObservable sgns:" + kwhURI + " . \n";
      insertQuery.append(triple);

      triple = " 	sgns:" + kwhURI + " rdf:type sgns:ElectricalMeasurement . \n";
      insertQuery.append(triple);

      triple =
          " 	sgns:"
              + kwhURI
              + " sgns:hasMeasurementRecordedDate  '"
              + date
              + "' . \n"; // ^^xsd:date
      insertQuery.append(triple);

      triple =
          " 	sgns:"
              + kwhURI
              + " sgns:hasMeasurementRecordedTime  '"
              + time
              + "' . \n"; // ^^xsd:time
      insertQuery.append(triple);

      triple = " 	sgns:" + kwhURI + " sgns:hasMeasuredValue  '" + kwhReading + "' . \n\n";
      insertQuery.append(triple);

      line = read.readLine();
    }

    insertQuery.append(" 	} \n");
    String sparql = insertQuery.toString();
    System.out.println("InsertQuery: " + sparql);

    System.out.println("# of Readings = " + readingCount);

    Store store = null;
    try {
      store = new Store(IIPProperties.getStoreURL());
      String response = store.insert(sparql);
      System.out.println("Insert response: " + response);
    } catch (MalformedURLException e) {
      e.getMessage();
      e.printStackTrace();
    }
  }
Пример #5
0
  private static void insertLatLong() throws IOException {

    System.out.println("Starting insertLatLong()");

    FileReader reader = new FileReader("data/latlong.csv");
    BufferedReader read = new BufferedReader(reader);

    StringBuilder insertQuery = new StringBuilder("");
    insertQuery.append("PREFIX sgns: <http://www.smartgrid.usc.edu/Ontology/2012.owl#> \n");
    insertQuery.append("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n");
    insertQuery.append("PREFIX gmlns: <http://purl.org/ifgi/gml/0.1/> \n");
    insertQuery.append("INSERT DATA { \n");

    String buildingCode = null;
    String lat = null;
    String longi = null;
    String line = read.readLine(); // First line is the column headers
    line = read.readLine();
    while (line != null) {

      System.out.println(line);
      if (line == null || line.startsWith(",")) continue;

      StringTokenizer tok = new StringTokenizer(line, ",");

      buildingCode = tok.nextToken();
      lat = tok.nextToken();
      longi = tok.nextToken();

      // buildingCode = "testBuildingCode111";

      String buildingURI = "ran" + System.nanoTime();
      String gmlURI = "ran" + System.nanoTime();

      String triple =
          " sgns:" + buildingURI + " rdf:type <http://dbpedia.org/ontology/Building> . \n";
      insertQuery.append(triple);

      triple =
          " sgns:"
              + buildingURI
              + " <http://dbpedia.org/ontology/hasBuildingNo> '"
              + buildingCode
              + "' . \n";
      insertQuery.append(triple);

      triple = " sgns:" + buildingURI + " gmlns:GeometryProperty sgns:" + gmlURI + " . \n";
      insertQuery.append(triple);

      triple = " sgns:" + gmlURI + " sgns:hasLatitude  '" + lat + "' . \n";
      insertQuery.append(triple);

      triple = " sgns:" + gmlURI + " sgns:hasLongitude  '" + longi + "' . \n";
      insertQuery.append(triple);

      line = read.readLine();
    }

    insertQuery.append(" 	} \n");
    String sparql = insertQuery.toString();
    System.out.println("InsertQuery: " + sparql);

    Store store = null;
    try {
      store = new Store(IIPProperties.getStoreURL());
      String response = store.insert(sparql);
      System.out.println("Insert response: " + response);
    } catch (MalformedURLException e) {
      e.getMessage();
      e.printStackTrace();
    }
  }