simplerdf0.2.14 • Public • Published
The future simplest RDF library ever
RDF should be as easy as playing with JSON objects.
Read the original blog post: Towards the future RDF Library
var simple =var context = 'name': ''var me =// You can now edit the foaf name simply withmename = 'Nicola'// as well as using the full predicateme'' = 'Nicola'
As a Node.js library
npm install --save simplerdf
To generate a browser-ready version:
$ git clone https://github.com/nicola/simplerdf $ cd simplerdf $ npm install $ npm run build-browser # This will generate `simplerdf.js` that you can load in your web application
1) Create a SimpleRDF object (easy peasy)
// The constructor takes 4 optional parameters:// `context` is a JSON-LD context, useful if you want to// map predicates to nice property names// `uri` is the name of the resource// `graph` if you want to load an `rdf-ext` graph// `store` see the FAQ!var simple =var me =// You can directly set properties defined in your contextmename = 'Nicola'console// 'Nicola'// Or you can set the property with a particular type pointerme'' = 'Nicola'console// 'Nicola'// These are interchangableme'' = 'Nicola'console
2) Using arrays (simple pimple)
You want to enforce an property to be always an array? Pass
'@container': '@set' in the schema description!
me// now we can use me.knows (this will be an array!)meknows = ''meknowsmeknowsmeknowslength
Note: You just want to do me.knows ? We are implementing this at the moment, stay tuned!
3) Use CRUD features
.save (crifty crafty)
SimpleRDF supports some simple .get/.save. These respects the Linked Data Platform standard (have a look at LDP)
// This gets the iri specified in the constructor// This saves the graph in the iri specified in the constructorvar g =gname = "Nicola"g// Hint for the brave:// You can also do this
.child (master jedi)
Imagine the you set the
iri of your graph to be
http://amazing-libraries.org and you now would like to change the subject to let's say
http://amazing-libraries.org/simplerdf, you can use
.child(iri). This will create a new SimpleRDF object.
var amazinglibraries = simple(context, 'http://amazing-libraries.org') var simplerdf = amazinglibraries.child('http://amazing-libraries.org/simplerdf') // done!
.iri() (wicky wacky)
Both these functions are setters if passed with a parameter and getters if no parameter is found.
.graph() will give you access to an rdf-ext graph,
.graph(newGraph) will replace the current graph with the new graph.
.iri() will give you the
iri that is the subject of your simple object. Finally
.iri(newIri) will replace your subject
Bonus: Full working example
See other working examples
var context ='name': '''homepage':'@id': '''@type': '@id'var me =mename = 'Nicola'mehomepage = ''consoleconsoleconsole // this returns turtle!
- Only subject-centric queries (e.g.
graph.match(you_know_this[, predicate, object]))
- Schemas must be typed
Can I use it without CRUD, parsers and serializers?
Of course, when you require it, use the lite version
var simple =
Can I customize the
Of course, there are plenty of rdf-ext stores availabe, here are some:
- rdf-store-fs to use the file system as database
- rdf-store-inmemory to use memory - can be handy if you are using multiple graphs
Now, when you create a SimpleRDF object you can do the following:
var store =var graph =
How can I do queries that are not subject-centric?
var simpleObject =// ... //simpleObject
- Support of ES6 Proxy
- No need to specify context
- Use uri as context
- Simple array support (e.g.
- Simple query language