Code Monkey home page Code Monkey logo

d3-sparql's Introduction

d3-sparql

This module allows to access data from SPARQL Endpoints in the vein of d3-csv and friends. The access through a SPARQL Endpoint allows a faster and more efficient data preparation (, once you got the hang of SPARQL and the RDF data model). Ultimately it keeps visualizations up to date. Think of SPARQL Endpoints as the most flexible API imaginable.

Define the SPARQL Query and Endpoint:

// Author of Q3011087 (D3.js)
var mikeQuery = `SELECT ?developerName WHERE {
  wd:Q3011087 wdt:P178 ?developer.
  ?developer rdfs:label ?developerName.
  FILTER(LANG(?developerName) = 'en')
}`

wikidataUrl = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql'

To query the Endpoint and return the result in a d3 ready data format:

d3.sparql(wikidataUrl, mikeQuery, function(error, data) {
  if (error) throw error;
  console.log(data); // [{'developerName': 'Mike Bostock'}]
})

More examples are provided in the repository.

Features

  • Based on d3-require to be in-line with other d3 request code (and assure the same compatibility with browsers.)
  • Transformation of XSD Datatypes (e.g. xsd:dateTime, xsd:boolean, ...) to native JavaScript types.
  • Reformatting of the JSON Structure to a d3 style layout while using the provided variables names of the SPARQL Query.
  • A backport to a d3 v3 implementation is provided.

Limitations

  • Only SELECT queries are supported. (This provides a projection of the graph data onto a table structure used by d3.)
  • Currently only supports Endpoints which are able to respond with application/sparql-results+json.
  • Only GET requests can be issued in the current version.

Installing

If you use NPM, npm install d3-sparql. Otherwise, download the latest release.

API Reference

The sparql request is based on a d3.request. It implements the sparql function and sets an according request.response which processes the response of the SPARQL endpoint.

# d3. sparql (endpoint, query[, callback]) <>

Returns a new sparql request for the specified SPARQL endpoint with the specified SPARQL query. If no callback is specified, the returned sparql request is not yet issued and can be further configured. If a callback is specified, it is equivalent to calling sparql.get immediately after construction:

d3.sparql(endpoint, query)
    .get(callback);

All other request functions can be used as specified to influence the final request (, except request.response and request.mimeType should not be changed, unless you know what you do, to assure correct working of the sparql request).

Acknowledgement

The initial development of this library by Zazuko was supported by the City of Zürich.

d3-sparql's People

Contributors

bergos avatar ktk avatar l00mi avatar vhf avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.