JAvascript Suite for Sparql Access (Jassa)
This repository contains several tools for JavaScript based Sparql access. It works both from the client side from the browser and server side with nodejs.
The highlights of this repository are:
- A high level JavaScript API for RDF. Provides core RDF classes (such as Node and Triple), SPARQL classes (such as Query, Element, Expr) and Service classes (such QueryExecutionFactoryHttp, QueryExecutionHttp). If you are familiar with Apache Jena, you have most likely seen these names before.
- The Facete-API, a powerful faceted search API for generic faceted search on SPARQL endpoints. Under heavy development - TODO Add demo link.
- The Sponate-API, a SPARQL-to-JSON mapper which is somewhat similar to Hibernate (Sponate = SParql, jsON, hiberNATE). This component unfolds its full potential in combination with latest generation frameworks that keep the DOM and controller logic separate, e.g. AngularJS. (Possibly also Ember.js, but at present we only develop using the former framework).
Terminology
You may have noticed that we repeatedly used the term '''class'''. While it is true that plain JavaScript does not offer them (yet), there are however frameworks which introduce this level of abstraction. For Jassa we chose the Class object of the prototype.js framework.
Personal anecdote: Use of classes (and inheritance) at least doubled my JavaScript productivity - if you are working on a sufficiently complex project, never ever listen to the voices that tell you that design is overrated (and there are many in the JS community) - its everything! (TODO Most likely someone famous could be quoted here) ;)
How to obtain
-
npm
npm install jassa
-
bower
Will come once bower does not silently exit with status code 1 ...
-
direct download
to be done...
Dependencies
Jassa depends on the following libraries:
jquery
: Asynchronous requests are based on $.ajaxprototype
: Only theClass
object is needed from prototype.underscore
: Provides several utility functions for working with (associative) arrays.underscore.string
: Provides several utility function for working with strings.xmlhttprequest
: NodeJs only; i.e. not needed for browser based set up. This library emulates the browser's XMLHttpRequest object, and makes jQuery's $.ajax work from nodejs. Include it before jQuery.
Browser-based Set Up
Adjust paths and versions to your needs.
NodeJs-based Set Up
Example of a nodejs based set up:
var XMLHttpRequest = XMLHttpRequest; $ = ; $supportcors = true;$ajaxSettings { return ;} ; _ = ;_str = ; _; var Jassa = ;
Components and Usage
The Jassa
object defines the following modules
rdf
and vocab
modules
The The rdf
module holds core RDF classes which are similar to those of Jena.
The vocab
module defines the following vocabularies (work in progress):
- xsd
- rdf
- rdfs
- owl
- wgs84
These two modules depend on each other (and thus cannot be used separately), because the vocabulary is expressed in
terms of rdf
classes, however literals require the xsd vocabulary.
Example usage:
var rdf = Jassardf;var vocab = Jassavocab; var s = rdfNodeFactory;var p = vocabrdftype;var o = rdfNodeFactory; var triple = s p o; console;console;
sparql
module
The The sparql
module contains several classes for the syntactic
representation of SPARQL queries. In addition to the Query
class, there
alse exist the Expr
and Element
class hierarchies known from Apache Jena.
Example usage:
var rdf = Jassardf;var sparql = Jassasparql; var query = ;var s = rdfNodeFactory;var p = rdfNodeFactory;var o = rdfNodeFactory; var triple = s p o; query;query;query; console;
service
module
The The service module provides an abstraction layer for communicating with a SPARQL endpoint.
var service = Jassardf; var qef = "http://dbpedia.org/sparql" "http://dbpedia.org"; var qe = qef;qe; // timout in milliseconds qe ;
Successful execution of a SPARQL queries yields a ResultSet
object, which is essentially an iterator over Binding
objects.
A binding is a map that associates variables with values (instances of rdf.Node
) or null.
Obviously, this API in principle frees you from the hassle of dealing with a concrete SPARQL result set format.
Currently, the API is only implemented for SPARQL endpoints that yield Talis RDF JSON.
Facete
Facete is library for faceted search based on concepts and constraints. Conceptually, a facete-concept is a pair comprised of SPARQL graph pattern and a variable that appears in it.
Facete then allows one to retrieve a concept's properties and sub-properties under a (possibly empty) set of constraints.
TODO Add demo, complete example below (service is missing)
var service = Jassaservice;var facete = Jassafacete; var constraintManager = ; var baseVar = rdfNodeFactory;var baseConcept = faceteConceptUtils;var rootFacetNode = faceteFacetNode; // Based on above objects, create a provider for the configuration// which the facet service can build uponvar facetConfigProvider = baseConcept rootFacetNode constraintManager; var fcgf = facetConfigProvider;var facetConceptGenerator = fcgf; var expansionSet = ;expansionSet; var facetService = qef facetConceptGenerator;var facetTreeService = facetService expansionSet; facetService ;
Sponate
Sponate is a SPARQL-to-JSON mapper. TODO Add more description...
var service = Jassaservice;var sponate = Jassasponate; var prefixes = 'dbpedia-owl': 'http://dbpedia.org/ontology/' 'dbpedia': 'http://.org/resource/' 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#' 'foaf': 'http://xmlns.com/foaf/0.1/'; var qef = 'http://dbpedia.org/sparql' 'http://dbpedia.org'; var store = qef prefixes; store; var criteria = name: $regex: filterText;var flow = storecastles flow ;