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

sparql-hollandaise

v0.3.0

Published

A JS client lib to communicate with a triple store database through SPARQL queries over HTTP.

Downloads

10

Readme

SPARQL Hollandaise

Codacy Badge Build Status peerDependency Status devDependency Status Code Climate

A JS client lib to communicate with a triple store database through SPARQL queries over HTTP.

Stability

Experimental: Expect the unexpected. Please provide feedback on api and your use-case.

Disclaimer

If you think this is a fully fledged SPARQL client for JS: nope. This is rather a starting point than a complete implementation. Also, I am not exactly an expert in using SPARQL (that's an understatement) so there might be all sorts of bullshit going on in the lib. Feel free to bash me in the issues...

Features

The library is supposed to be modeled after the 1.1 version of the SPARQL spec but is not yet complete.

Install

Node (min 0.11 or iojs): npm install sparql-hollandaise

Browser: bower install sparql-hollandaise or download/clone the repo and use the files in dist/web/.

Usage

Node:

var SPH = require('sparql-hollandaise'),
    query = new SPH.Query('https://here.goes.the/endpoint');

Browser:

<head>
    <script type="text/javascript" src="/bower_components/babel-polyfill/browser-polyfill.js"></script>
    <script type="text/javascript" src="/bower_components/sparql-hollandaise/dist/web/sparql-hollandaise.js"></script>
</head>

Alternatively, if you are using ES6 JavaScript you can also just import the untranspiled code:

import * as SPH from 'sparql-hollandaise/src/index'

Make sure to check out the basic Angular example as well.

Creating Graph Patterns

The .where() function takes either a single GraphPattern object, or a GroupGraphPattern that in turn contains multiple GraphPattern objects.

var graphPattern = new SPH.GraphPattern(
    ['array of triple strings'] ||
    'single triple string' ||
    new SPH.Filter('filter string')
);

// additional args for the GraphPattern
var graphPatternOptional = new SPH.GraphPattern('my super triple', true, false); // this pattern is OPTIONAL
var graphPatternAlternative = new SPH.GraphPattern('my super triple', false, true); // this pattern is an alternative (UNION)

var groupGraphPattern = new SPH.GraphPattern([graphPattern, graphPatternAlternative] || graphPattern);
groupGraphPattern.addElement(graphPatternOptional);

Once you have created your pattern, you can pass it to any of the queries.

SELECT

var query = new SPH.Query('https://here.goes.the/endpoint')
    .prefix(['foo: <http://bar>', 'pre: <http://fix>'] || 'pre: <http://fix>')
    .select('*') // you can add 'DISTINCT' or 'REDUCED' as a modifier in the second parameter
    .from('dataset clause', true) // second param indicates a named dataset (only pass this if named set)
    // you can add items to the where clause in any order
    // and at any time before calling exec()
    .where(graphPattern)
    .order('order string')
    .limit(10)
    .offset(5)
    .exec().then(function (result) {
        console.log(result);
    });

DESCRIBE

var query = new SPH.Query('https://here.goes.the/endpoint')
    .prefix('foo: <http://bar>')
    .describe('?x')
    .where(graphPattern)
    .exec().then(function (result) {
       console.log(result);
    });

ASK

var query = new SPH.Query('https://here.goes.the/endpoint')
    .prefix('foo: <http://bar>')
    .ask()
    .where(graphPattern)
    .exec().then(function (result) {
       console.log(result);
    });

CONSTRUCT

var query = new SPH.Query('https://here.goes.the/endpoint')
    .prefix('foo: <http://bar>')
    .construct(['array of triple strings'] || 'single triple string')
    .where(graphPattern)
    .order('order string')
    .limit(10)
    .offset(5)
    .exec().then(function (result) {
       console.log(result);
    });

Convenience

You can initialize a QueryFactory to create queries from the same endpoint (mandatory), base (optional) and prefix(es) (optional).

var queryFactory = new SPH.QueryFactory(
  'http://localhost',             // endpoint URL
  {},                             // auth (optional)
  'GET',                          // method (optional)
  '<http://example.org/foo/>',    // base (optional)
  'foo: http://bar'               // prefix(es) (optional)
);

// then get a query object based on those settings
var query = queryFactory.make();

// further configure the query as stated above
query.ask()
  .where(...)
  ...

Other methods

These might be useful to you:

// get the query's string representation that will be sent to the server
var queryString = query.toString();

// reset the entire query to reuse the object
query.reset();

Development

API docs for the classes in src/sparql/ can be found here

The classes in src/ use most of the ES6 keywords, so transpiling is necessary. The project uses gulp, Babel and Browserify.

npm install
# build browser lib and transpile for NodeJS
gulp
# you can also do:
gulp build-web
gulp build-node

Run the tests with npm test and generate code coverage with npm run-script cover (view coverage).

YUIDocs can be generated with npm run-script docs.

Credits

This client was conceived at a hackathon initiated by the Pina Bausch Foundation at the Mediencampus Hochschule Darmstadt in December 2015.