=Paper=
{{Paper
|id=Vol-1268/paper6
|storemode=property
|title=Jassa - A JavaScript suite for SPARQL-based faceted search
|pdfUrl=https://ceur-ws.org/Vol-1268/paper6.pdf
|volume=Vol-1268
|dblpUrl=https://dblp.org/rec/conf/semweb/StadlerWL14
}}
==Jassa - A JavaScript suite for SPARQL-based faceted search==
Jassa - A JavaScript Suite for SPARQL-based Faceted Search Claus Stadler, Patrick Westphal, Jens Lehmann Universität Leipzig, Institut für Informatik, AKSW, {cstadler|pwestphal|lehmann}@informatik.uni-leipzig.de http://aksw.org Abstract. The availability of SPARQL endpoints on the Web provides interesting opportunities for rapid Web application development. How- ever, sophisticated applications need components that can adopt to the data, yet, the efficient generic exploration and visualization of data con- tained in those endpoints is still challenging. In this paper, we present the “JAvascript Suite for Sparql Access” (Jassa) framework, which features various abstractions and utilities for the creation and transformation of SPARQL queries, as well as the processing of corresponding result sets. The current highlights comprise modules for RDF, SPARQL, data ac- cess, conversion of result sets to objects and faceted browsing, together with corresponding user interface components based on AngularJS. 1 Introduction The Linked Data initiative led to a paradigm shift, in which large amounts of structured data were made publicly available. With RDF, a data model was introduced, which enables global identification and integration of resources as well as cross-dataset interlinking. On top of RDF, SPARQL1 became a standard language for accessing Web databases. Yet, the development of Web applica- tions for the exploration and visualization of SPARQL-accessible data still poses several challenges related to performance and design. In this paper, we present the Open Source JavaScript framework called JAvaScript Suite for Sparql Access (Jassa). Jassa is motivated by the goal of creating the generic widgets for faceted browsing of RDF data depicted in Figure 2. The library is designed to tackle many of the challenges encountered during the development process. The remainder of this paper is structured as follows. In Section 2 we outline the high-level structure of Jassa as well as its highlights. In Section 3 we briefly summarize related work. Finally, in Section 4 we conclude this paper. 2 The Jassa Architecture Jassa is an umbrella term for a set of three related projects. A depiction of the architecture is shown in Figure 1. These projects are summarized as follows: 1 http://www.w3.org/TR/sparql11-query/ ISWC 2014 Developers Workshop Copyright held by the authors 31 Fig. 1: The Jassa Architecture – Jassa Core 2 is a project that provides a layered set of modules for: the representation of RDF and SPARQL, the execution of queries, SPARQL-to- JSON mapping, and most prominently, faceted search. – Jassa UI 3 is a project for user interface components based on Jassa Core and the AngularJS4 framework. – Complementary Services for Jassa 5 is a Java project that offers server side APIs that enhance Jassa, such as a SPARQL cache proxy. Another service is capable of finding property paths connecting two sets of resources. In the following, we explain selected components of Jassa in a bottom-up fashion, starting from the RDF API and ending in the faceted browsing widgets. 2.1 The RDF, VOCAB and SPARQL modules The rdf module features the basic components for working with RDF data. The most important class is rdf.NodeFactory, from which rdf.Node objects can be created that represent RDF terms. The vocab module provides predefined node objects for the commonly used xsd, rdf, rdfs and owl vocabularies. The sparql module features classes for representing the syntactic constructs of SPARQL queries. 1 var s = rdf . NodeFactory . createVar ( ’s ’) ; 2 var o = rdf . NodeFactory . createUri ( ’ http :// dbpedia . org / ontology / Airport ’) ; 3 var t = new rdf . Triple (s , vocab . rdf . type , o ) ; 4 5 var query = new sparql . Query () ; 6 query . setResultStar ( true ) ; 7 query . setQueryPattern ( new sparql . E l e m e n t T r i p l e s B l o c k ([ t ]) ) ; 8 query . setLimit (10) 9 console . log ( ’ As string : ’ + query ) ; 10 // Output : Select * { ? s a < http :// dbpedia . org / ontology / Airport > } Limit 10 Listing 1: Example for forming a query Note, that all mentioned namespaces reside in the global jassa object. As can be seen from Listing 1, we decided to follow designs of the well-known Apache Jena 2 https://github.com/GeoKnow/Jassa-Core 3 https://github.com/GeoKnow/Jassa-UI-Angular 4 https://angularjs.org/ 5 https://github.com/AKSW/jena-sparql-api ISWC 2014 Developers Workshop Copyright held by the authors 32 project6 , with the intention of providing a consistent development experience when combining these frameworks in a project. 2.2 The Sparql Service API Web applications could run SPARQL queries against HTTP SPARQL endpoints by directly using an AJAX API. However, this simple approach has several drawbacks: The server may limit the sizes of result sets. Triple stores may have limited or even erroneous SPARQL implementations, forcing clients to phrase queries differently. In many cases, caching query responses is desired. On some occasions it can happen that an application launches a new query although the same query is already running. Jassa provides a decorator-based approach to transparently deal with these issues. The main interface is service.SparqlService, which defines methods for creating service.QueryExecution objects from a query string7 or query object. Usually, decorators that apply query transformations will first parse the string before passing the transformation result as an object to the delegate. The sparql.QueryExecution class offers methods for retrieving the response: execSelect(), execConstruct(), exectDescribe() and exectAsk(), which yield promises of appropriate type, i.e. sparql.ResultSet, rdf.Graph and boolean. Listing 2 demonstrates the creation of a SPARQL service that performs pag- ination8 , query transformations for some issues with Virtuoso9 and caching of the individual pages. 1 var sparqlService = new service . S p a r q l S e r v i c e H t t p ( 2 ’ http :// dbpedia . org / sparql ’ , [ ’ http :// dpbedia . org ’]) ; 3 sparqlService = new service . S p a r q l S e r v i c e V i r t F i x ( sparqlService ) ; 4 sparqlService = new service . S p a r q l S e r v i c e C a c h e ( sparqlService ) ; 5 sparqlService = new service . S p a r q l S e r v i c e P a g i n a t e ( sparqlService , 1000) 6 7 // Note : This accompanying fluent API is offered for convenience : 8 sparqlService = service . S p a r q l S e r v i c e B u i l d e r 9 . http ( ’ http :// dbpedia . org / sparql ’, [ ’ http :// dpbedia . org ’]) 10 . virtFix () . cache () . paginate (1000) . create () ; 11 12 var qe = sparqlService 13 . c r e a t e Q u e r y E x e c u t i o n ( ’ Select * { ? s ? p ? o } Limit 10000 ’) ; 14 qe . execSelect () . then ( function ( rs ) { 15 while ( rs . hasNext () ) { 16 var binding = rs . nextBinding () ; 17 binding . get ( rdf . NodeFactory . createVar ( ’s ’) ) ; 18 } 19 }) ; Listing 2: Usage example of the SparqlService API 6 http://jena.apache.org/ 7 We are currently experimenting with the integration of the SPARQL.js parser: https://github.com/RubenVerborgh/SPARQL.js 8 The default implementation assumes that limit and offset do not influence the result set order. 9 For example, some versions of Virtuoso do not support queries having an outer-most OFFSET greater than 20000 in conjunction with an ORDER BY clause. Please refer to the Jassa github page for implementation details. ISWC 2014 Developers Workshop Copyright held by the authors 33 2.3 The SPARQL-to-JSON mapper Between SPARQL and JSON (or JavaScript objects in general) there is an impedance mismatch similar to that encountered in the object/relational world: SPARQL result sets are relations, however these are of little direct use in JavaScript applications without a transformation into objects. In general, object creation requires aggregation of data from multiple result set rows. Sponate uses maps to express the SPARQL-to-JSON mappings, and it supports initial query capa- bilities over the mapped objects using an interface similar to that of the JSON database MongoDB10 . A usage example of Sponate is shown in Listing 3. 1 var store = new sponate . StoreFacade ( sparqlService , prefixMap ) ; 2 store . addMap ({ 3 template : [{ 4 id : ’? s ’ , name : ’? l ’ , 5 partners : [{ 6 id : ’? f ’ , name : ’? pl ’ , amount : ’? a ’ , 7 }] 8 }] , 9 from : ’? s a o : Project ; rdfs : label ? l ; o : funding ? f . ? f o : partner [ rdfs : label ? pl ] . ? f o : amount ? a ’ }) ; 10 }) ; 11 var criteria = { partners : { $elemMatch : { name : { $regex : ’ university ’ }}}}; 12 store . projects . find ( criteria ) . limit (10) . asList () . done ( function ( arr ) { 13 // arr is an array of JavaScript objects according to the JSON template 14 }) Listing 3: Example of a Sponate mapping 2.4 The LookupService API Given a set of URIs, Jassa makes retrieval of related information easy using the LookupService interface and its corresponding implementations. The only method on this interface is Promise