SPARQL & Pseudo Code Example – Sami


One of the technologies that Koh.Tu.Me will use is SPARQL [1] which is the query language of the Semantic Web. The University of Southampton has made a lot of Open Data available [2] and have set up a SPARQL Endpoint [3] in order to facilitate easy querying of this data.

This images below illustrates a SPARQL query that can be used to get the bus route and bus stops information, complete with name and latitude and longitude information. This means that if a user requested to travel by bus and put in their location details then this information could be used to locate the bus stop closest to their location, ascertain which bus routes that was on, and then locate which stop on one of those routes was closest to their start location.

The pseudo code would look something like this:

#in the case the user selects bus
select case: “bus”
      Stop dest_stop = nearestStopFromCoordinates(dest_lat,dest_long);
      List<Route> dest_routes = routeFromStop(dest_lat,dest_long);
      Stop start_stop = nearestStopFromCoordinates(user_lat,user_long,dest_routes);
Route bus_route = locate_root(start_stop, dest_stop); 

#works out the nearest bus stop from any route to the lat/long provided
nearestStopFromCoordinates(String lat, String long){};

#works out the nearest bus stop on the routes provided, using the lat/long provided
nearestStopFromCoordinates(String lat, String long, List<Route> routes){};

#works out which bus route has both of these stops on
locate_root(Stop start_stop, Stop end_stop);
SPARQL Query
Sparql

SPARQL Query & Results
Sparql2

 

 

References
[1] http://www.w3.org/TR/sparql11-query/
[2] http://data.southampton.ac.uk/
[3] http://sparql.data.southampton.ac.uk/

, , , , , , , , , , , , , ,

  1. No comments yet.
(will not be published)