Comparing version 0.1.8 to 0.1.9
@@ -20,3 +20,3 @@ /* global rdf:true */ | ||
if (error != null) { | ||
return callback(null); | ||
return callback(null, error.message); | ||
} | ||
@@ -26,3 +26,3 @@ | ||
if (error != null) { | ||
return callback(null); | ||
return callback(null, error.message); | ||
} | ||
@@ -93,3 +93,7 @@ | ||
// is it a blank node? | ||
if (jNode == null || jNode.indexOf('_:') === 0) { | ||
if (jNode == null) { | ||
return rdf.createBlankNode(); | ||
} | ||
if (jNode.indexOf('_:') === 0) { | ||
return nodeCache[jNode] = rdf.createBlankNode(); | ||
@@ -154,2 +158,6 @@ } | ||
if ('@list' in jObject) { | ||
return processList(jObject['@list']); | ||
} | ||
// or complex literal | ||
@@ -159,5 +167,38 @@ return getLiteral(jObject); | ||
jsonldExpandFlat(data, base, function (jGraph) { | ||
var processList = function (jList) { | ||
var | ||
entry = getNode(), | ||
subject = entry, | ||
rest; | ||
jList.forEach(function (jItem, index) { | ||
if (index !== jList.length-1) { | ||
rest = getNode(); | ||
} else { | ||
rest = getNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'); | ||
} | ||
pushTriple( | ||
subject, | ||
getNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#first'), | ||
getNode(jItem['@id'])); | ||
pushTriple( | ||
subject, | ||
getNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#rest'), | ||
rest); | ||
subject = rest; | ||
}); | ||
return entry; | ||
}; | ||
jsonldExpandFlat(data, base, function (jGraph, error) { | ||
if (error != null) { | ||
return done(false, error); | ||
} | ||
if (jGraph == null) { | ||
return done(false); | ||
return done(true); | ||
} | ||
@@ -185,3 +226,3 @@ | ||
filter, | ||
function (success) { callback(success ? graph : null); }); | ||
function (success, error) { callback(success ? graph : null, error); }); | ||
}; | ||
@@ -188,0 +229,0 @@ }; |
@@ -51,3 +51,3 @@ /* global rdf:true, Promise:false */ | ||
this.remove = funcTemplate(function (args, callback) { store.remove(args[0], args[1], callback); }, p); | ||
this.removeMatch = funcTemplate(function (args, callback) { store.removeMatch(args[0], args[1], args[2], args[3], callback); }, p); | ||
this.removeMatches = funcTemplate(function (args, callback) { store.removeMatches(args[0], args[1], args[2], args[3], callback); }, p); | ||
this.delete = funcTemplate(function (args, callback) { store.delete(args[0], callback); }, p); | ||
@@ -54,0 +54,0 @@ }; |
{ | ||
"name": "rdf-ext", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Implements the RDF-Ext spec plus parsers (JSON-LD, RDF/XML, Turtle), serializers (JSON-LD, N-Triples) and stores (in memory, LDP, SPARQL)", | ||
@@ -5,0 +5,0 @@ "main": "rdf-ext.js", |
@@ -49,2 +49,30 @@ # RDF Interfaces Extension | ||
## Examples | ||
Use the global turtle parser instance to parse a triple from turtle data string and print the number of triples: | ||
var data = '<http://example.org/#s> <http://example.org/#p> <http://example.org/#o>.'; | ||
rdf.parseTurtle(data, function (graph) { | ||
console.log(graph.length); | ||
}); | ||
Use a `LdpStore` instance to read the http://dbpedia.org/resource/RDF graph from the turtle resource on DBpedia and | ||
print the first rdfs:label object value: | ||
var store = new rdf.LdpStore(); | ||
store.match( | ||
'http://dbpedia.org/data/RDF.ttl', | ||
'http://dbpedia.org/resource/RDF', | ||
'http://www.w3.org/2000/01/rdf-schema#label', | ||
null, | ||
function (graph) { | ||
console.log(graph.toArray()[0].object.toString()); | ||
} | ||
); | ||
## Implementations | ||
@@ -51,0 +79,0 @@ |
@@ -36,3 +36,4 @@ (function (root, factory) { | ||
var | ||
cardGraph; | ||
cardGraph, | ||
listGraph; | ||
@@ -80,5 +81,13 @@ var buildCardGraph = function() { | ||
before(function(done) { | ||
var parser = new rdf.promise.Parser(new rdf.TurtleParser()); | ||
cardGraph = buildCardGraph(); | ||
done(); | ||
readFile('support/list.nt') | ||
.then(function (list) { return parser.parse(list, 'https://example.com/list'); }) | ||
.then(function (graph) { | ||
listGraph = graph; | ||
}) | ||
.then(function () { done(); }); | ||
}); | ||
@@ -117,3 +126,3 @@ | ||
it('JSON-LD parser should forward error', function(done) { | ||
rdf.parseTurtle('this is not a JSON-LD string', function (graph, error) { | ||
rdf.parseJsonLd('{"@context": "urn:test"}', function (graph, error) { | ||
assert.equal(graph, null); | ||
@@ -126,2 +135,12 @@ assert.notEqual(error, null); | ||
it('JSON-LD parser should parse list.json', function(done) { | ||
var parser = new rdf.promise.Parser(new rdf.JsonLdParser()); | ||
readFile('support/list.json') | ||
.then(function (list) { return parser.parse(list, 'https://www.example.com/list') }) | ||
.then(function (graph) { return utils.p.assertGraphEqual(graph, listGraph); }) | ||
.then(function () { done() }) | ||
.catch(function (error) { done(error); }); | ||
}); | ||
it('RDF/XML parser should parse card.xml', function(done) { | ||
@@ -154,3 +173,3 @@ var parser = new rdf.promise.Parser(new rdf.RdfXmlParser()); | ||
serializer.serialize(cardGraph) | ||
.then(function (card) { console.log(card); return parser.parse(card, 'https://www.example.com/john/card'); }) | ||
.then(function (card) { return parser.parse(card, 'https://www.example.com/john/card'); }) | ||
.then(function (graph) { return utils.p.assertGraphEqual(graph, cardGraph); }) | ||
@@ -157,0 +176,0 @@ .then(function () { done() }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137414
135
3133
118