0.0.7 • Published 8 years ago
simplified-rdfstore v0.0.7
simplified-rdfstore
This is a simplified API of the JavaScript rdfstore-js perfectly adapted to my needs. It only permits to have one graph (the default one) as well as provides different or slightly modified or enhanced API methods.
Installation
npm install --save simplified-rdfstore
OR
git clone https://github.com/n1try/simplified-rdfstore.git
API
init(options, callback)
// OR: var rdfstore = require('./simplified-rdfstore') if you had cloned it
var rdfstore = require('simplified-rdfstore');
rdfstore.init({}, (err) => {
if (err) console.log('Sth. went wrong.');
})
- options: Object
- load: Object => data to initially fill the store with
- mediaType: string => e.g.
application/ld+json
orapplication/rdf+xml
- data: string => the actual serialized graph data in e.g. JSON-LD format
- mediaType: string => e.g.
- callback: function (err)
insert(dataToAdd, callback)
rdfstore.insert(myNewJsonLd, (err) => {
if (err) console.log('Sth. went wrong.');
})
- dataToAdd: string | Object
- callback: function (err)
delete(dataToDelete, callback)
rdfstore.delete(myJsonLdTriplesToRemove, (err) => {
if (err) console.log('Sth. went wrong.');
})
- dataToDelete: string | Object
- callback: function (err)
query(query, callback)
rdfstore.insert(mySparqlQueryString, (err, results) => {
if (err) console.log('Sth. went wrong.');
// process the results
})
- query: string
- a SPARQL query
- callback: Function (err, results)
clear(callback)
rdfstore.clear((err) => {
if (err) console.log('Sth. went wrong.');
else console.log('Store is clean now.');
})
- callback: Function (err)
subscribe(subject, predicate, object, context, subscribeFunction)
var storeListener = function (event, data) {
console.log('Sth. has changed:', event);
// process the results
};
rdfstore.subscribe(null, 'ab:contains', null, {ab: 'http://domain.tld/ab/vocab#'}, storeListener);
- subject, predicate, object: string or null
- either an absolute URL, like
http://domain.tld/ab/vocab#Person
or including a prefix, likeab:Person
, if a context is passed
- either an absolute URL, like
- context: Object
- prefix => URI for each prefix used in subject, predicate or object, e.g.
{ab: "http://domain.tld/ab/vocab#Person"}
- prefix => URI for each prefix used in subject, predicate or object, e.g.
- subscribeFunction: Function (event, data)
unsubscribe(subscribeFunction)
rdfstore.unsubscribe(storeListener);
- subscribeFunction: Function (event, data)
- reference to the function that was previously passes in subscribe()
getGraph(callback)
Wraps the original store.graph() method, dismissing the ability to select a graph, since we only support one.
rdfstore.getGraph((err, graph) => {
// process the graph
});
- callback: Function (err, graph)
exportJsonLd(callback)
Serializes the graph to JSON-LD, which can be loaded (using init
) or inserted (using insert
) again.
rdfstore.exportJsonLd((err, exportData) => {
if (err) console.log('Sth. went wrong.');
// process the data
});
- callback: Function (err, exportData)
exportJsonLdToFile(absolutePath, callback)
Same as above, but doesn't return the serialized graph to the callback but saves it to a file.
rdfstore.exportJsonLdToFile('/tmp/graph.jsonld', (err) => {
if (err) console.log('Sth. went wrong.');
});
- absolutePath: string
- callback: Function (err, exportData)
$getStore()
Returns the original store object from rdfstore-js, just in case somebody still needs it.
var $store = rdfstore.$getStore();
More information
For more information take a look at the examples and to the originally underlying project rdfstore-js.