Welcome to triplestoreJS

This JavaScript wrapper library enables web applications to store triples subject-property-value into HTML5 Web Storage. The API looks like an extension of W3C RDFa API.

Benefit

triplestoreJS reduces development cost of web applications which store triples into browser storage.
  • triplestoreJS conceals the routine work to resolve CURIE syntax
  • Overload-based simple API makes application logic simpler and enable to easily retrieve desired triples
  • WebStorage API doesn't fit to store triples well because handing triples requires applications to manage two keys of subject and property for the corresponding value though WebStorage API supports only one key. Application developers need not to take care the underlyning storage model.

Functionality

  • Save semantic data as triples into WebStorage
  • Get/Edit/Remove titples stored in WebStorage
  • API Documentation

Usage

Create triplestoreJS instance

Call simple constructor.

var st = new Triplestore();

Setup prefix mapping

Setup prefix and the corresponding URI mapping for CURIE resolution.

st.setMapping("foaf", "http://xmlns.com/foaf/0.1/");

Store triples

add and set functions save specified triples into WebStorage.

st.add("http://sample.org/people/#danbri", "foaf:name", "Dan Brickley");
st.add("http://sample.org/people/#danbri", "foaf:homepage", "http://old-1.org/");
st.add("http://sample.org/people/#danbri", "foaf:homepage", "http://old-2.org/");
//overwrite old values of property 'homepage' with new one
st.set("http://sample.org/people/#danbri", "foaf:homepage", "http://new.org/");

Retrieve stored triples

Overview: get* functions retrieve stored triples in WebStorage.

var subjects = st.getSubjects();
for(var i = 0; i < subjects.length; i++) {
  var subject = subjects[i];
  var proj = st.getProjection(subject);
  var properties = proj.getProperties(); 
  for(var j = 0; j < properties.length; j++) {
    var property = properties[j];
    var value = proj.getAll(property);
    console.log(subject, property, value);
  }
}

getSubjects([property], [value]) function retrieves a list of subject which are matched with an optional property and value.

//get subjects whose 'name' property is 'Bob'
st.getSubjects("foaf:name", "Bob");
//get subjects which have 'name' property
st.getSubjects("foaf:name");
//get subjects which have 'Bob' as value
st.getSubjects(null, "Bob");
//get all subjects
st.getSubjects();              

getProperties([subject]) function retrieves a list of property which are matched with an optional subject.

//get all properties of a subject
st.getProperties("http://sample.org/people/#danbri");
//get all properties of all subjects
st.getProperties();

getValues([subject], [property]) function retrieves a list of value which are matched with an optional subject and property.

//get values with a specified subject and property
st.getValues("http://sample.org/people/#danbri", "foaf:name");
//get all values of a subject
st.getValues("http://sample.org/people/#danbri");
//get all values of a property 'name' from all subjects
st.getValues(null, "foaf:name");
//get all values of all property from all subjects
st.getValues();

Remove stored triples

remove function deletes the matched triples from WebStorage.

Remove a subject

st.remove("http://sample.org/people/#danbri");

Remove a property of a subject

st.remove("http://sample.org/people/#danbri", "foaf:homepage");

Remove a property from each subject

st.remove(null, "foaf:homepage");

Remove all subjects

st.remove();

Sample Programs