Sort N-Quads output, update to latest jsonld.js.
--- a/playground/jsonld.js Mon Apr 30 19:14:07 2012 -0700
+++ b/playground/jsonld.js Mon Apr 30 22:16:17 2012 -0400
@@ -1708,14 +1708,6 @@
*/
Processor.prototype.toRDF = function(
element, namer, subject, property, graph, callback) {
- // recurse into arrays
- if(_isArray(element)) {
- for(var i in element) {
- this.toRDF(element[i], namer, subject, property, graph, callback);
- }
- return;
- }
-
if(_isObject(element)) {
// convert @value to object
if(_isValue(element)) {
@@ -1814,6 +1806,14 @@
return;
}
+ if(_isArray(element)) {
+ // recurse into arrays
+ for(var i in element) {
+ this.toRDF(element[i], namer, subject, property, graph, callback);
+ }
+ return;
+ }
+
if(_isString(element)) {
// property can be null for string subject references in @graph
if(property === null) {
@@ -4039,16 +4039,14 @@
}
// create RDF statement
- var s = {subject: {}, property: {}, object: {}};
+ var s = {};
// get subject
if(!_isUndefined(match[1])) {
- s.subject.nominalValue = match[1];
- s.subject.interfaceName = 'IRI';
+ s.subject = {nominalValue: match[1], interfaceName: 'IRI'};
}
else {
- s.subject.nominalValue = match[2];
- s.subject.interfaceName = 'BlankNode';
+ s.subject = {nominalValue: match[2], interfaceName: 'BlankNode'};
}
// get property
@@ -4056,16 +4054,13 @@
// get object
if(!_isUndefined(match[4])) {
- s.object.nominalValue = match[4];
- s.object.interfaceName = 'IRI';
+ s.object = {nominalValue: match[4], interfaceName: 'IRI'};
}
else if(!_isUndefined(match[5])) {
- s.object.nominalValue = match[5];
- s.object.interfaceName = 'BlankNode';
+ s.object = {nominalValue: match[5], interfaceName: 'BlankNode'};
}
else {
- s.object.nominalValue = match[6];
- s.object.interfaceName = 'LiteralNode';
+ s.object = {nominalValue: match[6], interfaceName: 'LiteralNode'};
if(!_isUndefined(match[7])) {
s.object.datatype = {nominalValue: match[7], interfaceName: 'IRI'};
}
--- a/playground/playground.js Mon Apr 30 19:14:07 2012 -0700
+++ b/playground/playground.js Mon Apr 30 22:16:17 2012 -0400
@@ -242,16 +242,16 @@
}
else if(playground.activeTab === 'tab-nquads') {
options.format = 'application/nquads';
- var nquads = '';
+ var nquads = [];
jsonld.toRDF(input, options, function(err, quad) {
if(err) {
return callback(err);
}
if(quad === null) {
- $('#nquads').html(playground.htmlEscape(nquads));
+ $('#nquads').html(playground.htmlEscape(nquads.sort().join('')));
return callback();
}
- nquads += quad;
+ nquads.push(quad);
});
}
};