Skip to content

Commit 94bec5f

Browse files
author
elf Pavlik
committed
updated README #1 + few small cosmetic changes
1 parent fde1251 commit 94bec5f

5 files changed

Lines changed: 68 additions & 70 deletions

File tree

README.md

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Status](https://travis-ci.org/mcollina/levelgraph-jsonld.png)](https://travis-ci
1414

1515
## Install on Node.js
1616

17-
```
18-
npm install levelgraph levelgraph-jsonld --save
17+
```shell
18+
$ npm install levelgraph levelgraph-jsonld --save
1919
```
2020

2121
At the moment it requires node v0.10.x, but the port to node v0.8.x
@@ -24,21 +24,22 @@ If you need it, just open a pull request.
2424

2525
## Install in the Browser
2626

27-
TO BE DONE!
27+
WORK IN PROGRESS! [#3](http://github.com/mcollina/levelgraph-jsonld/issues/3)
2828

2929
## Usage
3030

3131
Adding support for JSON-LD to LevelGraph is easy:
32-
```
32+
```javascript
3333
var levelgraph = require("levelgraph")
3434
, jsonld = require("levelgraph-jsonld")
3535
, db = jsonld(levelgraph("yourdb"));
3636
```
3737

3838
### Put
3939

40-
Storing a JSON-LD file in the database is extremey easy:
41-
```
40+
Please keep in mind that LevelGraph-JSONLD __doesn't store the original
41+
JSON-LD document but decomposes it into triples__! Storing triples from JSON-LD document is extremely easy:
42+
```javascript
4243
var manu = {
4344
"@context": {
4445
"name": "http://xmlns.com/foaf/0.1/name"
@@ -57,39 +58,39 @@ db.jsonld.put(manu, function(err, obj) {
5758
});
5859
```
5960

60-
if the object as no `'@id'` key, one will be generated for you,
61-
using a UUID and the `'base'` argument, like so:
62-
```
61+
if the top level objects have no `'@id'` key, one will be generated for
62+
each, using a UUID and the `'base'` argument, like so:
63+
```javascript
6364
delete manu["@id"];
6465
db.jsonld.put(manu, { base: "http://this/is/an/iri" }, function(err, obj) {
6566
// obj["@id"] will be something like
66-
http://this/is/an/iri/b1e783b0-eda6-11e2-9540-d7575689f4bc
67+
// http://this/is/an/iri/b1e783b0-eda6-11e2-9540-d7575689f4bc
6768
});
6869
```
6970

7071
`'base'` can also be specified when you create the db:
71-
```
72+
```javascript
7273
var levelgraph = require("levelgraph")
7374
, jsonld = require("levelgraph-jsonld")
7475
, opts = { base: "http://matteocollina.com/base" }
7576
, db = jsonld(levelgraph("yourdb"), opts);
7677
```
7778

7879
__LevelGraph-JSONLD__ also support nested objects, like so:
79-
```
80+
```javascript
8081
var nested = {
81-
"@context": {
82-
"name": "http://xmlns.com/foaf/0.1/name"
83-
, "knows": "http://xmlns.com/foaf/0.1/knows"
84-
}
85-
, "@id": "http://matteocollina.com"
86-
, "name": "matteo"
87-
, "knows": [{
88-
"name": "daniele"
89-
}, {
90-
"name": "lucio"
91-
}]
92-
};
82+
"@context": {
83+
"name": "http://xmlns.com/foaf/0.1/name"
84+
, "knows": "http://xmlns.com/foaf/0.1/knows"
85+
}
86+
, "@id": "http://matteocollina.com"
87+
, "name": "matteo"
88+
, "knows": [{
89+
"name": "daniele"
90+
}, {
91+
"name": "lucio"
92+
}]
93+
};
9394

9495
db.jsonld.put(nested, function(err, obj) {
9596
// do something...
@@ -98,8 +99,8 @@ db.jsonld.put(nested, function(err, obj) {
9899

99100
### Get
100101

101-
Retrieving a JSON-LD document from the store requires its `'@id'`:
102-
```
102+
Retrieving a JSON-LD object from the store requires its `'@id'`:
103+
```javascript
103104
db.jsonld.get(manu["@id"], { "@context": manu["@context"] }, function(err, obj) {
104105
// obj will be the very same of the manu object
105106
});
@@ -108,22 +109,22 @@ db.jsonld.get(manu["@id"], { "@context": manu["@context"] }, function(err, obj)
108109
The format of the loaded object is entirely specified by the
109110
`'@context'`, so have fun :).
110111

111-
As with `'put'` it correctly support nested objects, but it
112-
inserts `'@id'` properties for them, like so:
113-
```
112+
As with `'put'` it correctly support nested objects. If nested objects didn't originally include `'@id'` properties, now they will have them since `'put'` generates them by using UUID and formats
113+
them as *blank node identifiers*:
114+
```javascript
114115
var nested = {
115-
"@context": {
116-
"name": "http://xmlns.com/foaf/0.1/name"
117-
, "knows": "http://xmlns.com/foaf/0.1/knows"
118-
}
119-
, "@id": "http://matteocollina.com"
120-
, "name": "matteo"
121-
, "knows": [{
122-
"name": "daniele"
123-
}, {
124-
"name": "lucio"
125-
}]
126-
};
116+
"@context": {
117+
"name": "http://xmlns.com/foaf/0.1/name"
118+
, "knows": "http://xmlns.com/foaf/0.1/knows"
119+
}
120+
, "@id": "http://matteocollina.com"
121+
, "name": "matteo"
122+
, "knows": [{
123+
"name": "daniele"
124+
}, {
125+
"name": "lucio"
126+
}]
127+
};
127128

128129
db.jsonld.put(nested, function(err, obj) {
129130
// obj will be
@@ -135,19 +136,21 @@ db.jsonld.put(nested, function(err, obj) {
135136
// , "@id": "http://matteocollina.com"
136137
// , "name": "matteo"
137138
// , "knows": [{
138-
// "name": "daniele"
139+
// "@id": "_:7053c150-5fea-11e3-a62e-adadc4e3df79"
140+
// , "name": "daniele"
139141
// }, {
142+
// "@id": "_:9d2bb59d-3baf-42ff-ba5d-9f8eab34ada5"
140143
// "name": "lucio"
141144
// }]
142145
// }
143146
});
144147
```
145148

146-
### Deleting
149+
### Delete
147150

148151
In order to delete an object, you can just pass it's `'@id'` to the
149152
`'@del'` method:
150-
```
153+
```javascript
151154
db.jsonld.del(manu["@id"], function(err) {
152155
// do something after it is deleted!
153156
});
@@ -157,20 +160,20 @@ db.jsonld.del(manu["@id"], function(err) {
157160

158161
__LevelGraph-JSONLD__ does not support searching for objects, because
159162
that problem is already solved by __LevelGraph__ itself, like these:
160-
```
163+
```javascript
161164
var nested = {
162-
"@context": {
163-
"name": "http://xmlns.com/foaf/0.1/name"
164-
, "knows": "http://xmlns.com/foaf/0.1/knows"
165-
}
166-
, "@id": "http://matteocollina.com"
167-
, "name": "matteo"
168-
, "knows": [{
169-
"name": "daniele"
170-
}, {
171-
"name": "lucio"
172-
}]
173-
};
165+
"@context": {
166+
"name": "http://xmlns.com/foaf/0.1/name"
167+
, "knows": "http://xmlns.com/foaf/0.1/knows"
168+
}
169+
, "@id": "http://matteocollina.com"
170+
, "name": "matteo"
171+
, "knows": [{
172+
"name": "daniele"
173+
}, {
174+
"name": "lucio"
175+
}]
176+
};
174177

175178
db.jsonld.put(nested, function(err) {
176179
db.join([{

index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ var jsonld = require("jsonld")
44
, IRI = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
55
, RDFTYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
66
, async = require("async")
7-
, blanksRegexp = /^_:b\d+$/
8-
, genActionStream;
7+
, blanksRegexp = /^_:b\d+$/;
98

109
function levelgraphJSONLD(db, jsonldOpts) {
11-
10+
1211
if (db.jsonld) {
1312
return db;
1413
}
@@ -129,7 +128,7 @@ function levelgraphJSONLD(db, jsonldOpts) {
129128
if (!acc[triple.subject]) {
130129
acc[triple.subject] = { "@id": triple.subject };
131130
}
132-
131+
133132
if (triple.predicate === RDFTYPE) {
134133
if (acc[triple.subject]["@type"]) {
135134
acc[triple.subject]["@type"] = [acc[triple.subject]["@type"]];
@@ -181,6 +180,3 @@ function levelgraphJSONLD(db, jsonldOpts) {
181180

182181
module.exports = levelgraphJSONLD;
183182

184-
genActionStream = function(graphdb, type) {
185-
return
186-
};

test/del_spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
var level = require("level-test")()
22
, graph = require("levelgraph")
3-
, jsonld = require("../")
4-
, JSONLD = require("jsonld");
3+
, jsonld = require("../");
54

65
describe("jsonld.del", function() {
7-
6+
87
var db, manu, tesla;
98

109
beforeEach(function() {

test/get_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var level = require("level-test")()
55
, fs = require("fs");
66

77
describe("jsonld.get", function() {
8-
8+
99
var db, manu = fixture("manu.json");
1010

1111
beforeEach(function() {

test/put_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var level = require("level-test")()
44
, jsonld = require("../");
55

66
describe("jsonld.put", function() {
7-
7+
88
var db, manu;
99

1010
beforeEach(function() {
@@ -178,7 +178,7 @@ describe("jsonld.put", function() {
178178
});
179179

180180
describe("jsonld.put with default base", function() {
181-
181+
182182
var db, manu;
183183

184184
beforeEach(function() {

0 commit comments

Comments
 (0)