opendatahacklab - sparql suite

THE OPEN DATA HACKING LABORATORY - Powered by dydra.com WT-TECH

INTRODUCTION

SPARQL Suite is a set of javascript libraries to perform SPARQL queries and to process query results. This suite has been initially developed in the context of the PON project PRISMA - PiattafoRme cloud Interoperabili per SMArt-government and it is released under the CC-BY 4.0 license.

The core component of this suite is the SPARQL processing library, which provides the basic querying functionalities.

Backed by this library, a processor related with locations defined using the LOCN vocabulary is provided, namely the LOCN SPARQL processor. Finally, two ready-to-use utilities to show locations retrieved by a SPARQL endpoint is provided: the GoogleMapSPARQLprocessor to show locations on a Google map, and LeafletMapSPARQLprocessor to show locations on a map based on the Leafletjs library.

The DOAP processor allows one to handle projects specified with the DOAP vocabulary.

The Event Processor provide facilities to retrieve and process events described using the Event Ontology.

The DCAT Processor allows one to get all the datasets listed in a repository where these repositories are described using the Data Catalog Vocabulary.

CONTRIBUTORS

SPARQL PROCESSING LIBRARY

The SPARQL Processing Library is a javascript library to query a SPARQL enpoint from javascript. You can use it in your web pages by adding this line in the head section of your document:

<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/sparql_processor.js"></script>

Mainly, the query functionality is provided by the function sparql_query with the following signature:

sparql_query(endpoint, queryProcessor)

where endpoint is the URI (as string) of the endpoint to be queried and queryProcessor is the object delegate to specify the query and process query results. In more details, the queryProcessor object must provide

LOCN SPARQL PROCESSOR

The Core Location Vocabulary provides classes and properties to model physical locations of objects in terms of addresses and coordinates. Aside the location data, information about objects located there is useful as well. In the LOCN SPARQL Processor library a specialized processor for locn:Location instances is provided. It allows developers to deal with and process high-level representations of locations in the RDF store and with the items placed in the location itself. Such a location representation is implemented by the javascript class Location, which defines the following fields:

locatedItems is an array of LocatedItem instances, i.e. objects with the field name, indicating the item name, and with the optional field homepage, which is the URI of a web page about the item, if provided.

The following HTML elements can be used to import the LOCN SPARQL processor library in your web page (we remark that locn_sparql_processor requires locn_processor).

<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/sparql_processor.js"></script>
<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/locn_sparql_processor.js"></script>

A LOCNQueryProcessor, to be used with the sparl_query function defined in the SPARQL processing library, can be instantiated as follows:

var locnProcessor = new LOCNQueryProcessor(locationQueryProcessor)

where locationQueryProcessor is an object which provides

UTILITIES FOR SPARQL LOCATIONS

In the LOCN SPARQL Processor library some ready to usage examples of the LOCNQueryProcessor are provided.

The GoogleMapsSPARQLProcessor allows a developer to represent a set of locn:Location instances, retrieved and selected by querying a SPARQL endpoint, on a map based on the Google Maps API. Note that to use this processor you need to load the Google Maps library by means of the following HTML element:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

Analogously, the LeafletMapsLOCNProcessor allows one do draw a map with a set of locn:Location instances by means of the Leafletjs library. To use this processor you need to load the Leafletjs library and stylesheet as follows:

<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>	
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"></script>

DOAP SPARQL PROCESSOR

The DOAP SPARQL Processor is a SPARQL Processor implementation intended to retrieve and process instances of Projects, as defined in the DOAP vocabulary.

To use the DOAP SPARQL processor in your web page add the following elements in the head section of the page itself:

<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/sparql_processor.js"></script>
<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/doap_sparql_processor.js"></script>

A DOAPProcessor instance has to be customized by overriding its processProject(p) method, where p is in turn an instance of the Project class. Project class isntances have the following attributes:

The DOAPProcessor constructor has two optional parameters: additionalPrefixes and additionalConstraints. They can be used to provide additional filtering on the projects to be processed.

DCAT SPARQL PROCESSOR

The DCATProcessor class can be used to retrieve dcat:Dataset instances from a knowledge base (via a SPARQL Endpoint), where dcat is the Data Catalog Vocabulary.

In order to customize the processing of dataset instances, the processDataset(dataset) method of the processor has to be implemented. The solely argument of this method is the dataset to be processed. A Dataset is an object with the following attributes:

The current version is seminal. Other relevant properties of datasets (see DCAT distribution, for example) will be taken into account in future releases.

In addition, an helper method createDCAT2HTMLProcessor(containerElement, loadingElement, additionalPrefixes, additionalConstraints) is provided to create a processor which will put the retrieved datasets on a html page.

EVENT SPARQL PROCESSOR

The SPARQL suite provides the EventQueryProcessor to deal with events provided by a SPARQL endpoint, modeled as described in Event Ontology.

Such a processor is based on the delegate pattern, so that each instance of it must be created with an associated delegate object which will process the retrieved Event objects. In more detail, each EventQueryProcessor delegate has to implement the methods processPast(e), processNext(e) and processFuture(e). These methods will be invoked to process, respectively, every past event, the next upcoming event and the other future events. In addition, a flush() method has to be implemented (may be empty) to handle the fact that there are no more events to be processed.

Thus, EventQueryProcessor constructor parameters are such a delegate and the reference time, which will be used to determine if an event has to be cathegorized as past or future.

Event objects have the following fields:

To use the Event SPARQL processor in your web page add the following elements in the head section of the page itself:

<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/sparql_processor.js"></script>
<script src="http://dev.opendatasicilia.it/opendatahacklab/sparql_suite/event_sparql_processor.js"></script>

The events page of the opendatahacklab web sites provide a simple usage example of this processor.