=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== https://ceur-ws.org/Vol-1268/paper6.pdf
                   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 lookup(keys). The API is similar to
                that of the sparql service: Functionality is enhanced using decorators, as shown
                in Listing 4, where the basic lookup service is based on a Sponate store.
           1    var ls = new service . L o o k u p S e r v i c e S p o n a t e ( store . projects ) ;
           2    ls = new service . L o ok u pS er v i c e C a c h e ( ls ) ;
           3    // Execute the original lookup request by performing lookups with
           4    // partitions of at most 20 keys - avoids large SPARQL queries
           5    ls = new service . L o o k u p S e r v i c e P a r t i t i o n ( ls , 20) ;
           6    // Validate each key by a filter predicate before doing the actual request
           7    ls = new service . L o o k u p S e r v i c e K e y F i l t e r ( ls , p r e d i c a t e F o r V a l i d a t i n g U r i s ) ;
           8    // Merge all lookup requests within a 50 ms time window into a single request
           9    ls = new service . L o o k u p S e r v i c e T i m e o u t ( ls , 50) ;
           10   ls . lookup ([ /* rdf . Node objects for the lookup */ ]) . then ( function ( map ) {
           11      /* Use map . get ( key ) to retrieve the key ’s value */
           12   }) ;

                                                Listing 4: Decoration of a LookupService


                2.5 The Faceted Browsing Widgets
                Jassa comes with a powerful SPARQL-based faceted search module in the facete
                namespace, which supports the definition of custom constraint types as well as
                10
                     http://docs.mongodb.org/manual/reference/operator/nav-query/




ISWC 2014 Developers Workshop                           Copyright held by the authors                                                           34
               constraining sets of resources by indirectly (possibly inversely) related proper-
               ties. Due to space limitations, we only demonstrate the usage of the faceted
               browsing widgets, shown in Figure 2. These widgets are implemented as Angu-
               larJS directives and can thus be embedded into AngularJS applications using the
               corresponding HTML snippets. The HTML attribute values refer to JavaScript
               objects, of which a basic setup is shown in Listing 5. Note that the widgets are
               synchronized by AngularJS on the state of the fctTreeConfig object; any change
               will automatically trigger an update of the widgets.
           1   $scope . fctTreeConfig = new facete . F ac et Tr e eC on fi g () ;
           2   $scope . selectedPath = null ; // Start with no selection
           3   $scope . selectFacet = function ( path ) { $scope . selectedPath = path ; }

               Listing 5: Basic setup to make the facet-value-list show the values for a selected facet




           1   < facet - tree                                 1   < facet - value - list
           2      sparql - service = " sparqlService "        2     sparql - service = " sparqlService "
           3      facet - tree - config = " fctTreeConfig "   3     facet - tree - config = " fctTreeConfig "
           4      select = " selectFacet ( path ) "           4     path = " selectedPath "
           5   >                             5   > 


                               (a) Facet Tree                                 (b) Facet Value List


               Fig. 2: Widgets for Faceted Browsing & the HTML (AngularJS-based) to create them

               3      Related Work
               A generic JavaScript-based RDF data browser called Tabulator [3] was developed
               under the umbrella of the World Wide Web Consortium. Besides the tree based
               traversing the tool also provides a map and a calendar view. Another library
               providing RDF access in JavaScript is RDFQuery11 , which provides an API
               for manipulation and querying of RDF data within JavaScript as well as the
               extraction of RDF data from Web content. However, neither of these projects
               11
                    http://code.google.com/p/rdfquery/




ISWC 2014 Developers Workshop                 Copyright held by the authors                                     35
              seem to offer the powerful abstractions and implementations provided by Jassa.
              As for RDF JavaScript APIs, there are recent efforts in re-continuing work on
              a specification on RDF interfaces in JavaScript12 . In regard to faceted browsing
              of RDF datasets, there are for instance the Sparklis browser13 and the Pelorus
              faceted navigation tool14 . Jassa however features support for nested and inverse
              properties and offers reusable components. Very recent development efforts which
              provide similar features are [2] and [1].

              4    Conclusions and Future Work
              In this software description, we explained the components of the JAvascript
              Suite for Sparql Access (Jassa). Its foundation is built on a core library, which
              includes an RDF, SPARQL API, advanced service abstractions (e.g. transparent
              caching, query transformation, pagination and page expansion) and a faceted
              search module. The jassa-ui modules introduce user interface components for
              faceted browsing and map display. Thanks to AngularJS, these widgets can be
              embedded as ordinary HTML elements in websites. Overall, Jassa simplifies Se-
              mantic Web application development via light-weight but powerful and efficient
              APIs. In the future, Sponate’s feature set will be extended, such as with sup-
              port for references between maps. We are also working on new facet retrieval
              strategies with the aim of improving overall performance. Examples of applica-
              tions built using Jassa include the generic SPARQL browser Facete2 15 and the
              Linked Data Presentation Framework [4].
              Acknowledgment
              This work was supported by grants from the EU’s 7th Framework Programme
              provided for the projects LOD2 (GA no. 257943) and GeoKnow (GA no. 318159).

              References
              1. M. Arenas, B. Cuenca Grau, E. Kharlamov, Š. Marciuška, D. Zheleznyakov, and
                 E. Jimenez-Ruiz. Semfacet: Semantic faceted search over yago. In 23rd International
                 World Wide Web Conference, WWW ’14, Seoul, Republic of Korea, April 7-11,
                 2014, Companion Volume, pages 123–126, New York, NY, USA, 2014. ACM Press.
              2. H. Bast, F. Bäurle, B. Buchhold, and E. Haußmann. Easy access to the freebase
                 dataset. In 23rd WWW ’14, Seoul, Republic of Korea, April 7-11, 2014, Companion
                 Volume, pages 95–98, New York, NY, USA, 2014. ACM Press.
              3. T. Berners-Lee, Y. Chen, L. Chilton, D. Connolly, R. Dhanaraj, J. Hollenbach,
                 A. Lerer, and D. Sheets. Tabulator: Exploring and analyzing linked data on the
                 semantic web. In The 3rd Intl. Semantic Web User Interaction Workshop, 2006.
              4. D. Lukovnikov, C. Stadler, and J. Lehmann. Ld viewer - linked data presenta-
                 tion framework. In Proceedings of the 10th International Conference on Semantic
                 Systems, SEM ’14, pages 124–131, New York, NY, USA, 2014. ACM.

              12
                 http://www.w3.org/TR/rdf-interfaces/
              13
                 http://www.irisa.fr/LIS/ferre/sparklis/osparklis.html
              14
                 http://clarkparsia.com/pelorus/
              15
                 http://facete.aksw.org




ISWC 2014 Developers Workshop            Copyright held by the authors                                 36