graphdb-js

1.0.2 • Public • Published

graphdb-js

This module is a convenient wrapper for GraphDB's REST API. Large parts are still to be implemented, however, it's already providing key features like SPARQL querying and document uploading.

Disclaimer

This module was only tested against the API of GraphDB-free version 8.7.2.

Usage

Install this package via npm:

npm i graphdb-js

Initialization

const GraphDB = require('graphdb-js');
 
let graphdb = new GraphDB({
    hostname: "localhost",
    repository: "test"
});

In theory you can pass on everything according to the http module's configuration, since these parameters are used by this exact module. However, it is recommended to stick to the one's listed, since you might override stuff that's already correctly configured for you, also there's some options that are not directly related to http like the repository field, which is required. For instance if you pass {method: "GET"} you'll override SPARQL query request parameter's, such that they won't work anymore, since they work with POST requests only. Parameters you might actually be required to modify are listed in the table below.

Parameter Datatypes Description
hostname String Name of the host
port Integer The port the GraphDB instance listens on
repository String The repository you want to connect to

Authorization

Non-free versions of GraphDB also support authorization techniques, which might require you, depending on the repository setup, to perform a login.

/* TODO: not possible yet since I did not have any repo to test this on */

Issuing SPARQL Queries

The following was taken from the w3.org SPARQL specification page. Assuming GraphDB follows this specification, every valid SPARQL query should be possible using this client.

SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF via middleware. SPARQL contains capabilities for querying required and optional graph patterns along with their conjunctions and disjunctions. SPARQL also supports aggregation, subqueries, negation, creating values by expressions, extensible value testing, and constraining queries by source RDF graph. The results of SPARQL queries can be result sets or RDF graphs.

SELECT Queries

const select = "select * where { ?s ?p ?o . }";
 
graphdb.Query.query(select, (err, data) => {
    console.log(data);
    console.log(err);
});

UPDATE Queries

const insert = "insert data { <http://purl.org/dc/elements/1.1/title> <http://purl.org/dc/elements/1.1/title\"Fundamentals of Compiler Construction\" .}"; 
 
graphdb.Query.query(insert, (err, data) => {
    console.log(data);
    console.log(err);
});

Upload RDF Files

When it comes to uploading files, there are different ways to do that. Either as strings or by URL, in either case, you are free to use any format that is supported by GraphDB.

As String

graphdb.Import.text({
    data: JSON.stringify(require('./test.json')),
}, (err, data) => {
    console.log(data);
    console.log(err);
});

Parameters

You can pass any of the following parameters to the above method call.

{
  "baseURI": "",
  "context": "",
  "data": "{}",
  "forceSerial": true,
  "format": "Application/ld+json",
  "message": "automatically issued import",
  "parserSettings": {
    "failOnUnknownDataTypes": false,
    "failOnUnknownLanguageTags": false,
    "normalizeDataTypeValues": false,
    "normalizeLanguageTags": false,
    "preserveBNodeIds": false,
    "stopOnError": true,
    "verifyDataTypeValues": false,
    "verifyLanguageTags": true,
    "verifyRelativeURIs": true,
    "verifyURISyntax": true
  },
  "replaceGraphs": [],
  "status": "NONE",
  "type": "text",
  "name": "Text Snippet",
  "timestamp": 0
}

By URL

graphdb.Import.url({
    data: "https://raw.githubusercontent.com/julietcetera/graphdb-js/master/__test__/test.json",
}, (err, data) => {
    console.log(data);
    console.log(err);
});

Parameters

You can pass any of the following parameters to the above method call.

{
  "baseURI": "",
  "context": "",
  "data": "https://example.org/samplejsonld.json",
  "forceSerial": true,
  "format": "Application/ld+json",
  "message": "automatically issued import",
  "parserSettings": {
    "failOnUnknownDataTypes": false,
    "failOnUnknownLanguageTags": false,
    "normalizeDataTypeValues": false,
    "normalizeLanguageTags": false,
    "preserveBNodeIds": false,
    "stopOnError": true,
    "verifyDataTypeValues": false,
    "verifyLanguageTags": true,
    "verifyRelativeURIs": true,
    "verifyURISyntax": true
  },
  "replaceGraphs": [],
  "status": "NONE",
  "type": "url",
  "name": "https://example.org/samplejsonld.json",
  "timestamp": 0
}

Readme

Keywords

none

Package Sidebar

Install

npm i graphdb-js

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

17.2 kB

Total Files

15

Last publish

Collaborators

  • desislava.hristova.ontotext