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
- Basic
- Applications
- Chrome Extension 'Semantic Spider'