In this session, we are going to build on the simple application that was already used during session 2, and which related to places in the world. We will use two SPARQL endpoints: DBpedia and AEMET. You will need to use the web interfaces of these two endpoints to test your queries, so keep them around. As with the hands-on on session 2, you will need to rely extensively on the documentation of the SPARQL Query language, and on the SSN Ontology documentation.

Basic set-up

Go to http://localhost/sssw12-ho-s7/index.html?uri=http://dbpedia.org/resource/Madrid. This should show the initial state of the application for the city of Madrid. You can try different locations by changing the DBpedia URI in the address of the application (and please take into account that the geographical coverage of the AEMET SPARQL endpoint is that of Spain, so it would be better to focus on Spanish cities).

The application is currently rather incomplete. What we will do is to create the SPARQL queries that will make it display the right and relevant information. In order to do that, and test you ideas, you will need to work with the SPARQL endpoints of DBpedia and AEMET, as well as generally understanding their content. As you are already familiarised with DBpedia from session 2, we recommend you to go to the AEMET SPARQL endpoint and try entering simple SSN-related queries, like:
PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#> 
SELECT distinct ?obs ?y
WHERE { 
?obs a ?y .
?y owl:equivalentClass ssn:Observation
}
(gives all the objects that are observations, which are defined as such through an owl:equivalentClass property assertion between classes)

It will be also relevant to consider the following prefixes:
PREFIX aemet: <http://aemet.linkeddata.es/ontology/> 
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 

Finding weather stations

We are now going to start the two relevant queries that we are aiming at constructing into the application. All these queries are written in the js/sssw12-s7.js file, which is the based Javascript code for this application. You will need to edit this file (and only this file) so open it in a text editor.

The top part of the page currently shows the name and description of the place (as it was obtained from session 2, although you may have other results from that session that you may want to incorporate here). The second box from the top of the page should show weather stations that are located nearby the city that we have selected. The information about the location of these weather stations is available in the AEMET SPARQL endpoint (you can visualise them at the corresponding Map4RDF-powered browser. The corresponding query to AEMET is located in the queryWeatherStations function, and is currently incomplete:
squery = 'PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> '+
	'PREFIX aemet: <http://aemet.linkeddata.es/ontology/> '+
	'PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> '+
	'SELECT distinct ?station ?lat ?lon ?squareDistance'+
	'WHERE { '+
	insert the query here
	'} ORDER BY ?squareDistance '
  1. Complete the query so that the ?station variable contains the URIs of weather stations located nearby the considered place (uri), and the ?squareDistance variable contains the result of the square distance between the locations (in terms of latitude and longitude) of the weather station and the city. The page should now display the URIs of those weather stations, their latitude and longitude, as well as the distance to the city, ordered from closest to furthest
  2. Does it always work? What are the problems of associating just a point to a complete city? Is this OK for every city?

Obtaining weather data from the closest weather station

The third box in the page will contain measurements made by the closest weather station during 18/09/2011. Each station has a set of measurements that it can make (it has several sensors attached to it, to measure wind, temperature, humidity, etc.), and for each of these there is a measurement every 10 minutes (you can check that at the AEMET browser). We will now make further use of the skeleton part of the SSN Ontology. The query for weather data is located in the queryWeather function. It currently looks like this, where stationURI already contains the value of the closest station:
squery = 'PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> '+
	'PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#> '+
	'PREFIX aemet: <http://aemet.linkeddata.es/ontology/> '+
	'PREFIX w3ctime: <http://www.w3.org/2006/time#> '+
	'PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> '+
	'SELECT distinct ?obs ?prop ?value ?h ?min '+
	'WHERE { '+
	'?obs ssn:observedBy <'+stationURI +'> . '+
	insert the query here
	'FILTER (?year = 2011 && ?month = 09 && ?day = 18) '+
	'} ORDER BY ?h ?min'

It retrieves the URIs (?obs), properties (?prop) and measurement values (?value) of all observations taken by the instruments in the weather station, organised by hour (?h) and minute (?min).
  1. Can you change it so that it shows all the properties that the station can measure?
  2. Can you make sure that you show the labels of those properties instead of their URIs?