JAvascript Suite for Sparql Access (Jassa) Core
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) ;)
Module Overview
How to obtain
-
npm
npm install jassa
-
bower; will fetch files from the jassa-bower release git repo
bower install jassa
How to build/test
- Make sure you have latest node.js installed
- Install gulp with
npm -g install gulp
- Clone this repo
cd
into repo folder and runnpm install
Now you can run gulp
to see if the tests complete as well as results for code covarage.
Browser-based Set Up
TODO: add explanation here
NodeJs-based Set Up
Example of a nodejs based set up:
// require librariesvar Promise = ;var request = Promise; // create ajax function for sending requestsvar { return request;}; // init jassa with loaded Promise and ajax request functionvar jassa = Promise ajax;
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 = jassaservice; var sparqlService = "http://dbpedia.org/sparql" "http://dbpedia.org"; var qe = sparqlService;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.