npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jassa-core

v0.6.0

Published

JAvascript Suite for Sparql Access Core

Downloads

5

Readme

JAvascript Suite for Sparql Access (Jassa) Core

Build Status Code Climate Dependency Status Coverage Status Coverage Status Develop

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

Jassa Module Overview

How to obtain

How to build/test

  1. Make sure you have latest node.js installed
  2. Install gulp with npm -g install gulp
  3. Clone this repo
  4. cd into repo folder and run npm 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

<html>
    <head>
        <script src="resources/libs/jassa/0.5.0/jassa.js"></script>

        <script type="text/javascript">
            // Init jassa with native promise and jquery.ajax
            var jassa = new Jassa(Promise, $.ajax);

            // The jassa object is now readily available
            // We hope that the name Jassa is sufficiently exotic to never cause a name clash
            // But who knows. I wished JavaScript had native namespace support...
            console.log("The Jassa object: ", jassa);
        </script>
    </head>
</html>

NodeJs-based Set Up

Example of a nodejs based set up:

// require libraries
var Promise = require('bluebird');
var request = Promise.promisifyAll(require('request'));

// create ajax function for sending requests
var ajax = function(param) {
    return request.postAsync(param.url, {
        json: true,
        form: param.data,
    }).then(function(res) {
        return new Promise(function(resolve) {
            resolve(res[0].body);
        });
    });
};

// init jassa with loaded Promise and ajax request function
var jassa = require('jassa')(Promise, ajax);

Components and Usage

The jassa object defines the following modules

The rdf and vocab modules

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 = jassa.rdf;
var vocab = jassa.vocab;

var s = rdf.NodeFactory.createVar("s");
var p = vocab.rdf.type;
var o = rdf.NodeFactory.createUri("http://example.org/ontology/MyClass");

var triple = new rdf.Triple(s, p, o);

console.log("Triple: " + triple);
console.log("Subject is a variable: " + triple.getSubject().isVariable());

The sparql module

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 = jassa.rdf;
var sparql = jassa.sparql;

var query = new sparql.Query();
var s = rdf.NodeFactory.createVar("s");
var p = rdf.NodeFactory.createVar("p");
var o = rdf.NodeFactory.createVar("o");

var triple = new rdf.Triple(s, p, o);

query.setQueryPattern(new sparql.ElementTriplesBlock([triple]));
query.setResultStar(true);
query.setLimit(10);

console.log("QueryString: " + query);

The service module

The service module provides an abstraction layer for communicating with a SPARQL endpoint.

var service = jassa.service;

var sparqlService = new service.SparqlServiceHttp(
          "http://dbpedia.org/sparql",
          ["http://dbpedia.org"]
);

var qe = sparqlService.createQueryExecution("Select * { ?s ?p ?o } Limit 10");
qe.setTimeout(5000); // timout in milliseconds

qe.execSelect()
    .then(function(rs) {
        while(rs.hasNext()) {
            var binding = rs.nextBinding();
            console.log("Got binding: " + binding);
        }
    })
    .catch(function(err) {
        console.log("An error occurred: ", err);
    });

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.