Exemplo n.º 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();
    }
  }
Exemplo n.º 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();
    }
  }
Exemplo n.º 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);
  }