• Stars
    star
    340
  • Rank 124,317 (Top 3 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 10 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A parser for the SPARQL query language in JavaScript

SPARQL.js – A SPARQL 1.1 parser for JavaScript

Build Status npm version DOI

The SPARQL 1.1 Query Language allows to query datasources of RDF triples. SPARQL.js translates SPARQL into JSON and back, so you can parse and build SPARQL queries in your JavaScript applications. It also contains support for the SPARQL* extension under the sparqlStar option.

It fully supports the SPARQL 1.1 specification, including property paths, federation, and updates.

Usage

Library

// Parse a SPARQL query to a JSON object
var SparqlParser = require('sparqljs').Parser;
var parser = new SparqlParser();
var parsedQuery = parser.parse(
  'PREFIX foaf: <http://xmlns.com/foaf/0.1/> ' +
  'SELECT * { ?mickey foaf:name "Mickey Mouse"@en; foaf:knows ?other. }');

// Regenerate a SPARQL query from a JSON object
var SparqlGenerator = require('sparqljs').Generator;
var generator = new SparqlGenerator({ /* prefixes, baseIRI, factory, sparqlStar */ });
parsedQuery.variables = ['?mickey'];
var generatedQuery = generator.stringify(parsedQuery);

Set sparqlStar to true to allow SPARQL* syntax.

Set pathOnly to true to parse SPARQL paths such as foaf:name/foaf:knows rather than the full SPARQL Algebra.

Validation

By default SPARQL.js throws on queries that are syntactically correct, but not allowed by the spec. Set skipValidation to true to skip validation.

// Parse a SPARQL query without validation.
var SparqlParser = require('sparqljs').Parser;
var parser = new SparqlParser({ skipValidation: true });
var parsedQuery = parser.parse(
  'select (?x as ?xString)' +
  '(count(?y) as ?count)' +
  '{ ?x ?y ?z }');

Standalone

$ sparql-to-json --strict query.sparql

Parse SPARQL* syntax by default. For pure SPARQL 1.1, use the --strict flag.

Representation

Queries are represented in a JSON structure. The most easy way to get acquainted with this structure is to try the examples in the queries folder through sparql-to-json. All examples of the SPARQL 1.1 specification have been included, in case you wonder how a specific syntactical construct is represented.

Here is a simple query in SPARQL:

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?p ?c WHERE {
    ?p a dbpedia-owl:Artist.
    ?p dbpedia-owl:birthPlace ?c.
    ?c <http://xmlns.com/foaf/0.1/name> "York"@en.
}

And here is the same query in JSON:

{
  "queryType": "SELECT",
  "variables": [
    {
      "termType": "Variable",
      "value": "p"
    },
    {
      "termType": "Variable",
      "value": "c"
    }
  ],
  "where": [
    {
      "type": "bgp",
      "triples": [
        {
          "subject": {
            "termType": "Variable",
            "value": "p"
          },
          "predicate": {
            "termType": "NamedNode",
            "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
          },
          "object": {
            "termType": "NamedNode",
            "value": "http://dbpedia.org/ontology/Artist"
          }
        },
        {
          "subject": {
            "termType": "Variable",
            "value": "p"
          },
          "predicate": {
            "termType": "NamedNode",
            "value": "http://dbpedia.org/ontology/birthPlace"
          },
          "object": {
            "termType": "Variable",
            "value": "c"
          }
        },
        {
          "subject": {
            "termType": "Variable",
            "value": "c"
          },
          "predicate": {
            "termType": "NamedNode",
            "value": "http://xmlns.com/foaf/0.1/name"
          },
          "object": {
            "termType": "Literal",
            "value": "York",
            "language": "en",
            "datatype": {
              "termType": "NamedNode",
              "value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"
            }
          }
        }
      ]
    }
  ],
  "type": "query",
  "prefixes": {
    "dbpedia-owl": "http://dbpedia.org/ontology/"
  }
}

The representation of triples uses the RDF/JS representation.

Installation

$ [sudo] npm [-g] install sparqljs

License, status and contributions

The SPARQL.js library is copyrighted by Ruben Verborgh and released under the MIT License.

Contributions are welcome, and bug reports or pull requests are always helpful.

Contributors

More Repositories

1

promiscuous

An old and obsolete Promise experiment for pre-ES6 JavaScript
JavaScript
177
star
2

Solid-React-Components

Core React components for building your own Solid components and apps
JavaScript
118
star
3

WebFundamentals

Slides for the Web Fundamentals module of my Ghent University class “Web Development”
HTML
75
star
4

Refine-NER-Extension

Named-Entity Recognition extension for Google Refine / OpenRefine
Java
71
star
5

AsyncIterator

An asynchronous iterator library for advanced object pipelines in JavaScript
JavaScript
46
star
6

solid-hue

Philips Hue module for the Community Solid Server
TypeScript
21
star
7

WebsiteToRDF

A simple ETL pipeline for HTML+RDFa websites
Shell
19
star
8

RESTdesc-Photo-Example

RESTful Web API Description - A sample implementation. This is _not_ the actual RESTdesc method. It is still a working draft at the moment.
JavaScript
14
star
9

solid-server-architecture

Proposed architecture for a Solid server
TeX
13
star
10

JavaScript-Error-Handling

A collection of various JavaScript error handling techniques.
JavaScript
12
star
11

BibMarkdown

A Markdown pre-processor with support for BibTeX citations.
Ruby
11
star
12

dotfiles

Ruben Verborgh's dotfiles
Shell
10
star
13

solid-architecture

Drafts on the intended architecture of a concrete implementation of Solid
9
star
14

Web-APIs-for-decentralized-knowledge-graphs

Slides for my talk at Solid World January 2022
HTML
8
star
15

solid-yo

A simple example app for Solid, created for educational purposes
JavaScript
7
star
16

Quick-SPARQL-Endpoint

A quick SPARQL endpoint with reasoning.
Java
7
star
17

Semantic-Web-Reasoning

Slides for a mini-lecture on “Rule-based reasoning on the Semantic Web”
HTML
7
star
18

profile-viewer-react

The Solid profile viewer tutorial in React
HTML
7
star
19

tsv-to-json

TSV to JSON converts a list of numbered, tab-separated records with header row to a tree of JSON files.
JavaScript
7
star
20

SPARQL-Parser

Obsolete SPARQL parser based on rdfstore-js, use SPARQL.js instead.
JavaScript
7
star
21

mavo-solid

A Solid storage backend for Mavo
JavaScript
6
star
22

Hydra-Architecture-Diagram

TeX
6
star
23

nanoc-bibtex

BibTeX data source for nanoc.
Ruby
6
star
24

HTTP-methods-in-JavaScript

What happens if we model the semantics of HTTP methods in JavaScript?
JavaScript
6
star
25

solid-server-ts

Experiment for modeling Solid server components in TypeScript
TypeScript
6
star
26

VOGIN-IP-2018

Slides for my talk at the VOGIN-IP-lezing on 28 March 2018
HTML
5
star
27

Solid-DeSemWeb-2018

Slides for my talk on Solid at the DeSemWeb 2018 workshop
HTML
5
star
28

DataPublicationPlatform

An example data publication platform following the REST architectural principles
JavaScript
5
star
29

Solid-Context

A handy JSON-LD context for Solid
5
star
30

community-server-demos

A collection of scripts for trying out the Community Solid Server
HTML
4
star
31

Knowledge-Graph-Conference-2020

Slides for my talk at the Knowledge Graph Conference 2020
HTML
4
star
32

FastScroller

High-performance scroller in vanilla JavaScript.
JavaScript
4
star
33

Decentralized-Web-Query-Challenges-2019

Slides for my talk “The Decentralized Web and its challenges for querying”
HTML
4
star
34

wac-allow

Parser of the WAC-Allow HTTP header
JavaScript
4
star
35

DV-Workshop-Data-Vaults-2021

HTML
3
star
36

AsksForApp

Find out which websites ask you to “use the app instead”.
JavaScript
3
star
37

SemWeb.Pro-2016

Slides for my talk at SemWeb.Pro 2016.
HTML
3
star
38

Alzheimer

Advanced memoization library for Node with promise and stream support
CoffeeScript
3
star
39

ldp-glob

Client-side RDF graph merge of all user-readable RDF files in an LDP container
JavaScript
3
star
40

RDF-for-Solid-2022

Slides for a 2022 tech talk on how to use RDF within Solid
HTML
3
star
41

HTML5small

HTML5small is a general-purpose minifier for HTML5 documents.
Ruby
3
star
42

solid-metadata-extender

Experimental metadata module for the Community Solid Server
TypeScript
2
star
43

Technology-Human-Rights-2022

Slides for my lecture on technology and human rights
HTML
2
star
44

LDK-2023

Slides for my keynote at the 2023 Conference on Language, Data and Knowledge
HTML
2
star
45

NSS2CSS

Migration script to copy pods from an NSS to a CSS instance
JavaScript
2
star
46

CSCC2019

Slides for my talk at Connected Smart Cities Conference 2019
HTML
2
star
47

Slides-FOSDEM-2019

Slides for my talk on Solid at FOSDEM 2019
HTML
2
star
48

Slides-DataCommons-2019

Slides for my talk at the Data Commons on Biking Data in Amsterdam
HTML
2
star
49

Solid-Lecture-2018

Slides for my 2018 lecture in the Linked Data Scholarship course at KU Leuven
HTML
2
star
50

Blockchain-Education-France-2019

Slides for my talk at the 2019 Conference on Blockchain, Open Education & Digital Citizenship
HTML
2
star
51

Masters-Thesis-Intro

Your Master's Thesis – Introduction
HTML
2
star
52

GraphQL-Day-2018

Slides for my talk at the 2018 GraphQL Day
HTML
1
star
53

GhentJS-2019

Slides for my 2019 talk at GhentJS
HTML
1
star
54

Connected-Data-London-2019

Slides for my talk at Connected Data London 2019
HTML
1
star
55

rdflib-evaluation

JavaScript
1
star
56

Informatie-aan-Zee-2021

Slides for my keynote at Informatie aan Zee 2021
HTML
1
star
57

London-Enterprise-Tech-Meetup-2020

Slides for my flash talk at the London Enterprise Tech Meetup
HTML
1
star
58

solid-patch-tool

A simple browser app for sending patches to Solid servers
JavaScript
1
star
59

SparqlQueryAnalyzer

JavaScript
1
star
60

dweb-summit-2018

Slides for Decentralized Web Summit 2018
HTML
1
star
61

PLDN-Solid-Kick-Off-2019

Slides for my talk at the PLDN Solid Kick-Off 2019
HTML
1
star
62

add-oidc-issuer

Adds the solid:oidcIssuer triple to profile documents on disk
Shell
1
star
63

OverWeb-Meetup-Ghent-2019

Slides for my talk at the 2019 OverWeb Meetup in Ghent
HTML
1
star
64

dbpedia-lookup-page

A simple webpage to look up topics on DBpedia.
1
star
65

Media-Fast-Forward-2018

Slides for my talk at Media Fast Forward 2018
HTML
1
star
66

Shower-UGent

UGent template for the Shower HTML presentation engine.
CSS
1
star
67

Reasoning-website

Source code for the "Bringing reasoning to the Web" website.
Ruby
1
star
68

ShowInBrowser

Google Chrome Extension showing text files inside the browser instead of downloading them.
1
star
69

RESTdesc-Composition-Benchmark

A benchmark suite for RESTdesc composition.
JavaScript
1
star
70

ISWS2018

Slides for my class at the International Semantic Web Research Summer School
HTML
1
star
71

WS-REST2016-Website

CSS
1
star
72

SALAD-Website

Website for the SALAD2015 ESWC workshop
CSS
1
star
73

ResourceCache

Node.js library that caches resources from a string or URL in local files.
JavaScript
1
star
74

solid-list-viewer

A simple Solid app that shows lists
JavaScript
1
star
75

Open-Belgium-2019

Slides for my talk at Open Belgium 2019
HTML
1
star
76

Open-Belgium-2022

Slides for my talk at Open Belgium 2022
HTML
1
star
77

MailMerge

Simple e-mail merge script for OS X
Ruby
1
star
78

Knowledge-for-Growth-2021

Slides for my talk at the Knowledge for Growth 2021 conference
HTML
1
star
79

Personal-Health-Knowledge-Graph-2020

Slides for the panel discsussion at the Personal Health Knowledge Graph Panel
HTML
1
star
80

SEMIC-Workshop-2020

Slides for the SEMIC hands-on workshop on Solid
HTML
1
star
81

Chrome-Citation-Explorer

Browser extension that makes it easier to export citations.
JavaScript
1
star
82

JavaScript-Style-Guide

Developing sustainable projects in JavaScript – a style guide
1
star
83

vim-markup-assistant

One-key changes of marked-up text in Vim
Ruby
1
star
84

Slides-EBDVF-2018

Slides for my talk at the Big Data in Media workshop at the European Big Data Value Forum 2018
HTML
1
star
85

PFIA-2019

Slides for my talk at the Artificial Intelligence Platform 2019
HTML
1
star
86

Technology-Human-Rights-2021

Slides for my lecture on technology and human rights
HTML
1
star
87

Technology-Human-Rights-2023

Slides for my lecture on technology and human rights
HTML
1
star
88

Data-Sharing-Days-2020

Slides for my talk at the 2020 Data Sharing Days in The Hague
HTML
1
star
89

Data-Sharing-Winter-School-2021

Slides for my talk at the Data Sharing Winter School 2021
HTML
1
star