From d977e71fe11186d1a22b2508233aedd4e9f2d324 Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Wed, 28 Aug 2019 17:17:19 -0400 Subject: [PATCH 1/9] Support list of lists. --- CHANGELOG.md | 3 +++ lib/compact.js | 32 +++++++++++++++++++++++-------- lib/expand.js | 12 ++---------- lib/fromRdf.js | 33 ++++++++++++++++---------------- lib/nodeMap.js | 27 +++++++++++++++++++++++--- lib/toRdf.js | 3 +++ lib/util.js | 9 ++++++++- tests/test-common.js | 28 --------------------------- tests/webidl/JsonLdProcessor.idl | 2 -- 9 files changed, 81 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd1ec40e..4ffead86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # jsonld ChangeLog +### Added +- Support list of lists. + ## 1.6.2 - 2019-05-21 ### Fixed diff --git a/lib/compact.js b/lib/compact.js index 9603bd12..78aad528 100644 --- a/lib/compact.js +++ b/lib/compact.js @@ -138,6 +138,22 @@ api.compact = ({ return rval; } + // if expanded property is @list and we're contained within a list + // container, recursively compact this item to an array + if(_isList(element)) { + const container = _getContextValue( + activeCtx, activeProperty, '@container') || []; + if(container.includes('@list')) { + return api.compact({ + activeCtx, + activeProperty, + element: element['@list'], + options, + compactionMap + }); + } + } + // FIXME: avoid misuse of active property as an expanded property? const insideReverse = (activeProperty === '@reverse'); @@ -399,14 +415,14 @@ api.compact = ({ relativeTo: {vocab: true} })] = expandedItem['@index']; } - } else if(nestResult.hasOwnProperty(itemActiveProperty)) { - // can't use @list container for more than 1 list - throw new JsonLdError( - 'JSON-LD compact error; property has a "@list" @container ' + - 'rule but there is more than a single @list that matches ' + - 'the compacted term in the document. Compaction might mix ' + - 'unwanted items into the list.', - 'jsonld.SyntaxError', {code: 'compaction to list of lists'}); + // FIXME + //} else if(nestResult.hasOwnProperty(itemActiveProperty)) { + } else { + _addValue(nestResult, itemActiveProperty, compactedItem, { + valueIsArray: true, + allowDuplicate: true + }); + continue; } } diff --git a/lib/expand.js b/lib/expand.js index 74e466f0..994debaf 100644 --- a/lib/expand.js +++ b/lib/expand.js @@ -122,11 +122,8 @@ api.expand = ({ insideIndex, typeScopedContext }); - if(insideList && (_isArray(e) || _isList(e))) { - // lists of lists are illegal - throw new JsonLdError( - 'Invalid JSON-LD syntax; lists of lists are not permitted.', - 'jsonld.SyntaxError', {code: 'list of lists'}); + if(insideList && _isArray(e)) { + e = {'@list': e}; } if(e === null) { @@ -672,11 +669,6 @@ function _expandObject({ insideList: isList, expansionMap }); - if(isList && _isList(expandedValue)) { - throw new JsonLdError( - 'Invalid JSON-LD syntax; lists of lists are not permitted.', - 'jsonld.SyntaxError', {code: 'list of lists'}); - } } else { // recursively expand value with key as new active property expandedValue = api.expand({ diff --git a/lib/fromRdf.js b/lib/fromRdf.js index dca067ec..286ef5e6 100644 --- a/lib/fromRdf.js +++ b/lib/fromRdf.js @@ -225,22 +225,23 @@ api.fromRDF = async ( } // the list is nested in another list - if(property === RDF_FIRST) { - // empty list - if(node['@id'] === RDF_NIL) { - // can't convert rdf:nil to a @list object because it would - // result in a list of lists which isn't supported - continue; - } - - // preserve list head - if(RDF_REST in graphObject[head['@id']]) { - head = graphObject[head['@id']][RDF_REST][0]; - } - - list.pop(); - listNodes.pop(); - } + // FIXME + //if(property === RDF_FIRST) { + // // empty list + // if(node['@id'] === RDF_NIL) { + // // can't convert rdf:nil to a @list object because it would + // // result in a list of lists which isn't supported + // continue; + // } + + // // preserve list head + // if(RDF_REST in graphObject[head['@id']]) { + // head = graphObject[head['@id']][RDF_REST][0]; + // } + + // list.pop(); + // listNodes.pop(); + //} // transform list into @list object delete head['@id']; diff --git a/lib/nodeMap.js b/lib/nodeMap.js index e71c28dc..bae62e5a 100644 --- a/lib/nodeMap.js +++ b/lib/nodeMap.js @@ -74,6 +74,11 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { list.push(input); } return; + } else if(graphTypes.isList(input)) { + if(list) { + list.push(input); + } + return; } // Note: At this point, input must be a subject. @@ -190,14 +195,30 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { subject, property, {'@id': id}, {propertyIsArray: true, allowDuplicate: false}); api.createNodeMap(o, graphs, graph, issuer, id); + } else if(graphTypes.isValue(o)) { + //if('@type' in o) { + // o['@type'] = o['@type'][0]; + //} + if(!list) { + util.addValue( + subject, property, o, + {propertyIsArray: true, allowDuplicate: false}); + } else { + list['@list'] = o; + } } else if(graphTypes.isList(o)) { // handle @list + // XXX const _list = []; api.createNodeMap(o['@list'], graphs, graph, issuer, name, _list); o = {'@list': _list}; - util.addValue( - subject, property, o, - {propertyIsArray: true, allowDuplicate: false}); + if(!list) { + util.addValue( + subject, property, o, + {propertyIsArray: true, allowDuplicate: false}); + } else { + list['@list'] = o; + } } else { // handle @value api.createNodeMap(o, graphs, graph, issuer, name); diff --git a/lib/toRdf.js b/lib/toRdf.js index f062ee28..be1b48d4 100644 --- a/lib/toRdf.js +++ b/lib/toRdf.js @@ -241,6 +241,9 @@ function _objectToRDF(item) { object.value = value; object.datatype.value = datatype || XSD_STRING; } + } else if(graphTypes.isList(item)) { + //_listToRDF(item, issuer, subject, predicate, dataset, graphTerm); + _listToRDF(item['@list'], issuer, subject, predicate, dataset, graphTerm); } else { // convert string/node object to RDF const id = types.isObject(item) ? item['@id'] : item; diff --git a/lib/util.js b/lib/util.js index a41e6e7b..2b9b482a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -249,6 +249,8 @@ api.hasValue = (subject, property, value) => { * @param [options] the options to use: * [propertyIsArray] true if the property is always an array, false * if not (default: false). + * [valueIsArray] true if the value to be added should be preserved as + * an array (lists) (default: false). * [allowDuplicate] true to allow duplicates, false not to (uses a * simple shallow comparison of subject ID or value) (default: true). */ @@ -257,11 +259,16 @@ api.addValue = (subject, property, value, options) => { if(!('propertyIsArray' in options)) { options.propertyIsArray = false; } + if(!('valueIsArray' in options)) { + options.valueIsArray = false; + } if(!('allowDuplicate' in options)) { options.allowDuplicate = true; } - if(types.isArray(value)) { + if(options.valueIsArray) { + subject[property] = value; + } else if(types.isArray(value)) { if(value.length === 0 && options.propertyIsArray && !subject.hasOwnProperty(property)) { subject[property] = []; diff --git a/tests/test-common.js b/tests/test-common.js index fc7c3946..1a5b455e 100644 --- a/tests/test-common.js +++ b/tests/test-common.js @@ -37,12 +37,6 @@ const TEST_TYPES = { specVersion: ['json-ld-1.0'], // FIXME idRegex: [ - // list of lists - /compact-manifest.jsonld#tli01$/, - /compact-manifest.jsonld#tli02$/, - /compact-manifest.jsonld#tli03$/, - /compact-manifest.jsonld#tli04$/, - /compact-manifest.jsonld#tli05$/, // terms /compact-manifest.jsonld#tp001$/, // rel iri @@ -110,17 +104,6 @@ const TEST_TYPES = { skip: { // FIXME idRegex: [ - // list of lists - /expand-manifest.jsonld#tli01$/, - /expand-manifest.jsonld#tli02$/, - /expand-manifest.jsonld#tli03$/, - /expand-manifest.jsonld#tli04$/, - /expand-manifest.jsonld#tli05$/, - /expand-manifest.jsonld#tli06$/, - /expand-manifest.jsonld#tli07$/, - /expand-manifest.jsonld#tli08$/, - /expand-manifest.jsonld#tli09$/, - /expand-manifest.jsonld#tli10$/, // mode /expand-manifest.jsonld#tp001$/, /expand-manifest.jsonld#tp002$/, @@ -252,10 +235,6 @@ const TEST_TYPES = { skip: { // FIXME idRegex: [ - // list of lists - /flatten-manifest.jsonld#tli01$/, - /flatten-manifest.jsonld#tli02$/, - /flatten-manifest.jsonld#tli03$/, // html /html-manifest.jsonld#tf001$/, /html-manifest.jsonld#tf002$/, @@ -333,10 +312,6 @@ const TEST_TYPES = { skip: { // FIXME idRegex: [ - // list of lists - /fromRdf-manifest.jsonld#tli01$/, - /fromRdf-manifest.jsonld#tli02$/, - /fromRdf-manifest.jsonld#tli03$/, // JSON literals /fromRdf-manifest.jsonld#tjs01$/, /fromRdf-manifest.jsonld#tjs02$/, @@ -366,9 +341,6 @@ const TEST_TYPES = { skip: { // FIXME idRegex: [ - // list of lists - /toRdf-manifest.jsonld#tli01$/, - /toRdf-manifest.jsonld#tli02$/, // blank node properties /toRdf-manifest.jsonld#t0118$/, // well formed diff --git a/tests/webidl/JsonLdProcessor.idl b/tests/webidl/JsonLdProcessor.idl index 31cac3a8..5f0906f5 100644 --- a/tests/webidl/JsonLdProcessor.idl +++ b/tests/webidl/JsonLdProcessor.idl @@ -37,7 +37,6 @@ dictionary JsonLdError { enum JsonLdErrorCode { "colliding keywords", - "compaction to list of lists", "conflicting indexes", "cyclic IRI mapping", "invalid @id value", @@ -70,7 +69,6 @@ enum JsonLdErrorCode { "invalid value object value", "invalid vocab mapping", "keyword redefinition", - "list of lists", "loading document failed", "loading remote context failed", "multiple context link headers", From 29e167e723484984df99cb8a0f968390b31b6885 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Thu, 29 Aug 2019 15:15:47 -0700 Subject: [PATCH 2/9] Add skip version to test runner to not run json-ld-1.0 tests. --- tests/test-common.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test-common.js b/tests/test-common.js index 1a5b455e..8913ec40 100644 --- a/tests/test-common.js +++ b/tests/test-common.js @@ -102,6 +102,9 @@ const TEST_TYPES = { }, 'jld:ExpandTest': { skip: { + // skip tests where behavior changed for a 1.1 processor + // see JSON-LD 1.0 Errata + specVersion: ['json-ld-1.0'], // FIXME idRegex: [ // mode @@ -233,6 +236,9 @@ const TEST_TYPES = { }, 'jld:FlattenTest': { skip: { + // skip tests where behavior changed for a 1.1 processor + // see JSON-LD 1.0 Errata + specVersion: ['json-ld-1.0'], // FIXME idRegex: [ // html @@ -259,6 +265,9 @@ const TEST_TYPES = { }, 'jld:FrameTest': { skip: { + // skip tests where behavior changed for a 1.1 processor + // see JSON-LD 1.0 Errata + specVersion: ['json-ld-1.0'], // FIXME idRegex: [ // ex @@ -310,6 +319,9 @@ const TEST_TYPES = { }, 'jld:FromRDFTest': { skip: { + // skip tests where behavior changed for a 1.1 processor + // see JSON-LD 1.0 Errata + specVersion: ['json-ld-1.0'], // FIXME idRegex: [ // JSON literals @@ -339,6 +351,9 @@ const TEST_TYPES = { }, 'jld:ToRDFTest': { skip: { + // skip tests where behavior changed for a 1.1 processor + // see JSON-LD 1.0 Errata + specVersion: ['json-ld-1.0'], // FIXME idRegex: [ // blank node properties From cf2ab04be4d6ab2bd3c0f28ca255b17cc899b07f Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Thu, 29 Aug 2019 15:16:47 -0700 Subject: [PATCH 3/9] Modernize for loops and variable declarations in nodeMap. --- lib/nodeMap.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/nodeMap.js b/lib/nodeMap.js index bae62e5a..b7ababb7 100644 --- a/lib/nodeMap.js +++ b/lib/nodeMap.js @@ -47,8 +47,8 @@ api.createMergedNodeMap = (input, options) => { api.createNodeMap = (input, graphs, graph, issuer, name, list) => { // recurse through array if(types.isArray(input)) { - for(let i = 0; i < input.length; ++i) { - api.createNodeMap(input[i], graphs, graph, issuer, undefined, list); + for(const node of input) { + api.createNodeMap(node, graphs, graph, issuer, undefined, list); } return; } @@ -64,7 +64,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { // add values to list if(graphTypes.isValue(input)) { if('@type' in input) { - let type = input['@type']; + const type = input['@type']; // rename @type blank node if(type.indexOf('_:') === 0) { input['@type'] = type = issuer.getId(type); @@ -86,8 +86,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { // spec requires @type to be named first, so assign names early if('@type' in input) { const types = input['@type']; - for(let i = 0; i < types.length; ++i) { - const type = types[i]; + for(const type of types) { if(type.indexOf('_:') === 0) { issuer.getId(type); } @@ -110,9 +109,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { const subject = subjects[name] = subjects[name] || {}; subject['@id'] = name; const properties = Object.keys(input).sort(); - for(let pi = 0; pi < properties.length; ++pi) { - let property = properties[pi]; - + for(const property of properties) { // skip @id if(property === '@id') { continue; @@ -124,8 +121,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { const reverseMap = input['@reverse']; for(const reverseProperty in reverseMap) { const items = reverseMap[reverseProperty]; - for(let ii = 0; ii < items.length; ++ii) { - const item = items[ii]; + for(const item of items) { let itemName = item['@id']; if(graphTypes.isBlankNode(item)) { itemName = issuer.getId(itemName); @@ -176,9 +172,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { util.addValue(subject, property, [], {propertyIsArray: true}); continue; } - for(let oi = 0; oi < objects.length; ++oi) { - let o = objects[oi]; - + for(var o of objects) { if(property === '@type') { // rename @type blank nodes o = (o.indexOf('_:') === 0) ? issuer.getId(o) : o; @@ -270,8 +264,7 @@ api.mergeNodeMaps = graphs => { // add all non-default graphs to default graph const defaultGraph = graphs['@default']; const graphNames = Object.keys(graphs).sort(); - for(let i = 0; i < graphNames.length; ++i) { - const graphName = graphNames[i]; + for(const graphName of graphNames) { if(graphName === '@default') { continue; } @@ -286,9 +279,8 @@ api.mergeNodeMaps = graphs => { subject['@graph'] = []; } const graph = subject['@graph']; - const ids = Object.keys(nodeMap).sort(); - for(let ii = 0; ii < ids.length; ++ii) { - const node = nodeMap[ids[ii]]; + for(const id of Object.keys(nodeMap).sort()) { + const node = nodeMap[id]; // only add full subjects if(!graphTypes.isSubjectReference(node)) { graph.push(node); From 669c0165f4fd6f0968332d73f0a50521d6f3ff64 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Thu, 29 Aug 2019 17:41:12 -0700 Subject: [PATCH 4/9] Fix nodeMap support for lists and reimplement toRdf lists to work from _objectToRDF. --- lib/nodeMap.js | 31 +++++--------- lib/toRdf.js | 107 ++++++++++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 70 deletions(-) diff --git a/lib/nodeMap.js b/lib/nodeMap.js index b7ababb7..d32aaf63 100644 --- a/lib/nodeMap.js +++ b/lib/nodeMap.js @@ -74,10 +74,10 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { list.push(input); } return; - } else if(graphTypes.isList(input)) { - if(list) { - list.push(input); - } + } else if(list && graphTypes.isList(input)) { + const _list = []; + api.createNodeMap(input['@list'], graphs, graph, issuer, name, _list); + list.push({'@list': _list}); return; } @@ -109,7 +109,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { const subject = subjects[name] = subjects[name] || {}; subject['@id'] = name; const properties = Object.keys(input).sort(); - for(const property of properties) { + for(let property of properties) { // skip @id if(property === '@id') { continue; @@ -193,26 +193,17 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { //if('@type' in o) { // o['@type'] = o['@type'][0]; //} - if(!list) { - util.addValue( - subject, property, o, - {propertyIsArray: true, allowDuplicate: false}); - } else { - list['@list'] = o; - } + util.addValue( + subject, property, o, + {propertyIsArray: true, allowDuplicate: false}); } else if(graphTypes.isList(o)) { // handle @list - // XXX const _list = []; api.createNodeMap(o['@list'], graphs, graph, issuer, name, _list); o = {'@list': _list}; - if(!list) { - util.addValue( - subject, property, o, - {propertyIsArray: true, allowDuplicate: false}); - } else { - list['@list'] = o; - } + util.addValue( + subject, property, o, + {propertyIsArray: true, allowDuplicate: false}); } else { // handle @value api.createNodeMap(o, graphs, graph, issuer, name); diff --git a/lib/toRdf.js b/lib/toRdf.js index be1b48d4..1e821123 100644 --- a/lib/toRdf.js +++ b/lib/toRdf.js @@ -85,8 +85,7 @@ api.toRDF = (input, options) => { */ function _graphToRDF(dataset, graph, graphTerm, issuer, options) { const ids = Object.keys(graph).sort(); - for(let i = 0; i < ids.length; ++i) { - const id = ids[i]; + for(const id of ids) { const node = graph[id]; const properties = Object.keys(node).sort(); for(let property of properties) { @@ -126,22 +125,16 @@ function _graphToRDF(dataset, graph, graphTerm, issuer, options) { continue; } - // convert @list to triples - if(graphTypes.isList(item)) { - _listToRDF( - item['@list'], issuer, subject, predicate, dataset, graphTerm); - } else { - // convert value or node object to triple - const object = _objectToRDF(item); - // skip null objects (they are relative IRIs) - if(object) { - dataset.push({ - subject, - predicate, - object, - graph: graphTerm - }); - } + // convert list, value or node object to triple + const object = _objectToRDF(item, issuer, dataset, graphTerm); + // skip null objects (they are relative IRIs) + if(object) { + dataset.push({ + subject, + predicate, + object, + graph: graphTerm + }); } } } @@ -154,59 +147,72 @@ function _graphToRDF(dataset, graph, graphTerm, issuer, options) { * * @param list the @list value. * @param issuer a IdentifierIssuer for assigning blank node names. - * @param subject the subject for the head of the list. - * @param predicate the predicate for the head of the list. * @param dataset the array of quads to append to. * @param graphTerm the graph term for each quad. + * + * @return the head of the list. */ -function _listToRDF(list, issuer, subject, predicate, dataset, graphTerm) { +function _listToRDF(list, issuer, dataset, graphTerm) { const first = {termType: 'NamedNode', value: RDF_FIRST}; const rest = {termType: 'NamedNode', value: RDF_REST}; const nil = {termType: 'NamedNode', value: RDF_NIL}; + const last = list.pop(); + // Result is the head of the list + const result = last ? {termType: 'BlankNode', value: issuer.getId()} : nil; + var subject = result; + for(const item of list) { - const blankNode = {termType: 'BlankNode', value: issuer.getId()}; + const object = _objectToRDF(item, issuer, dataset, graphTerm); + const next = {termType: 'BlankNode', value: issuer.getId()}; dataset.push({ subject, - predicate, - object: blankNode, + predicate: first, + object: object, graph: graphTerm }); + dataset.push({ + subject, + predicate: rest, + object: next, + graph: graphTerm + }); + subject = next; + } - subject = blankNode; - predicate = first; - const object = _objectToRDF(item); - - // skip null objects (they are relative IRIs) - if(object) { - dataset.push({ - subject, - predicate, - object, - graph: graphTerm - }); - } - - predicate = rest; + // Tail of list + if(last) { + const object = _objectToRDF(last, issuer, dataset, graphTerm); + dataset.push({ + subject, + predicate: first, + object: object, + graph: graphTerm + }); + dataset.push({ + subject, + predicate: rest, + object: nil, + graph: graphTerm + }); } - dataset.push({ - subject, - predicate, - object: nil, - graph: graphTerm - }); + return result; } /** - * Converts a JSON-LD value object to an RDF literal or a JSON-LD string or - * node object to an RDF resource. + * Converts a JSON-LD value object to an RDF literal or a JSON-LD string, + * node object to an RDF resource, + * or adds a list. * * @param item the JSON-LD value or node object. + * @param issuer a IdentifierIssuer for assigning blank node names. + * @param dataset the dataset to append RDF quads to. + * @param graphTerm the graph term for each quad. * * @return the RDF literal or RDF resource. */ -function _objectToRDF(item) { +function _objectToRDF(item, issuer, dataset, graphTerm) { const object = {}; // convert value object to RDF @@ -242,8 +248,9 @@ function _objectToRDF(item) { object.datatype.value = datatype || XSD_STRING; } } else if(graphTypes.isList(item)) { - //_listToRDF(item, issuer, subject, predicate, dataset, graphTerm); - _listToRDF(item['@list'], issuer, subject, predicate, dataset, graphTerm); + const _list = _listToRDF(item['@list'], issuer, dataset, graphTerm); + object.termType = _list.termType; + object.value = _list.value; } else { // convert string/node object to RDF const id = types.isObject(item) ? item['@id'] : item; From 0743093c448a4fa656982216ce0e0f60ce62e4d6 Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Fri, 30 Aug 2019 12:25:17 -0400 Subject: [PATCH 5/9] Fix linting issues. --- lib/nodeMap.js | 4 ++-- lib/toRdf.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/nodeMap.js b/lib/nodeMap.js index d32aaf63..e0999303 100644 --- a/lib/nodeMap.js +++ b/lib/nodeMap.js @@ -64,7 +64,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { // add values to list if(graphTypes.isValue(input)) { if('@type' in input) { - const type = input['@type']; + let type = input['@type']; // rename @type blank node if(type.indexOf('_:') === 0) { input['@type'] = type = issuer.getId(type); @@ -172,7 +172,7 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { util.addValue(subject, property, [], {propertyIsArray: true}); continue; } - for(var o of objects) { + for(let o of objects) { if(property === '@type') { // rename @type blank nodes o = (o.indexOf('_:') === 0) ? issuer.getId(o) : o; diff --git a/lib/toRdf.js b/lib/toRdf.js index 1e821123..1745e11d 100644 --- a/lib/toRdf.js +++ b/lib/toRdf.js @@ -160,7 +160,7 @@ function _listToRDF(list, issuer, dataset, graphTerm) { const last = list.pop(); // Result is the head of the list const result = last ? {termType: 'BlankNode', value: issuer.getId()} : nil; - var subject = result; + let subject = result; for(const item of list) { const object = _objectToRDF(item, issuer, dataset, graphTerm); @@ -168,7 +168,7 @@ function _listToRDF(list, issuer, dataset, graphTerm) { dataset.push({ subject, predicate: first, - object: object, + object, graph: graphTerm }); dataset.push({ @@ -186,7 +186,7 @@ function _listToRDF(list, issuer, dataset, graphTerm) { dataset.push({ subject, predicate: first, - object: object, + object, graph: graphTerm }); dataset.push({ From 7538c0b144ffe591170a437a655f0a8e9070f77c Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Fri, 30 Aug 2019 12:57:23 -0400 Subject: [PATCH 6/9] Fix style. --- lib/toRdf.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/toRdf.js b/lib/toRdf.js index 1745e11d..634cc01d 100644 --- a/lib/toRdf.js +++ b/lib/toRdf.js @@ -202,8 +202,7 @@ function _listToRDF(list, issuer, dataset, graphTerm) { /** * Converts a JSON-LD value object to an RDF literal or a JSON-LD string, - * node object to an RDF resource, - * or adds a list. + * node object to an RDF resource, or adds a list. * * @param item the JSON-LD value or node object. * @param issuer a IdentifierIssuer for assigning blank node names. From a78f62448b9c988e0e9a7dbb6753ab1999e373c6 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Fri, 30 Aug 2019 11:17:38 -0700 Subject: [PATCH 7/9] Drop dead code in compact for list of lists. --- lib/compact.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/compact.js b/lib/compact.js index 78aad528..7f1e1051 100644 --- a/lib/compact.js +++ b/lib/compact.js @@ -415,8 +415,6 @@ api.compact = ({ relativeTo: {vocab: true} })] = expandedItem['@index']; } - // FIXME - //} else if(nestResult.hasOwnProperty(itemActiveProperty)) { } else { _addValue(nestResult, itemActiveProperty, compactedItem, { valueIsArray: true, From 8d3daa9d2271f74e8f587e13453c30b997503c84 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Fri, 30 Aug 2019 11:18:08 -0700 Subject: [PATCH 8/9] Drop dead code in fromRdf for list of lists. --- lib/fromRdf.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/lib/fromRdf.js b/lib/fromRdf.js index 286ef5e6..5ce1ed2e 100644 --- a/lib/fromRdf.js +++ b/lib/fromRdf.js @@ -224,25 +224,6 @@ api.fromRDF = async ( } } - // the list is nested in another list - // FIXME - //if(property === RDF_FIRST) { - // // empty list - // if(node['@id'] === RDF_NIL) { - // // can't convert rdf:nil to a @list object because it would - // // result in a list of lists which isn't supported - // continue; - // } - - // // preserve list head - // if(RDF_REST in graphObject[head['@id']]) { - // head = graphObject[head['@id']][RDF_REST][0]; - // } - - // list.pop(); - // listNodes.pop(); - //} - // transform list into @list object delete head['@id']; head['@list'] = list.reverse(); From 67a8b16a7c17b6a007536bb626a81e0a399a281b Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Fri, 30 Aug 2019 14:31:29 -0400 Subject: [PATCH 9/9] Remove unused code. --- lib/nodeMap.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/nodeMap.js b/lib/nodeMap.js index e0999303..b9e7da2b 100644 --- a/lib/nodeMap.js +++ b/lib/nodeMap.js @@ -190,9 +190,6 @@ api.createNodeMap = (input, graphs, graph, issuer, name, list) => { {propertyIsArray: true, allowDuplicate: false}); api.createNodeMap(o, graphs, graph, issuer, id); } else if(graphTypes.isValue(o)) { - //if('@type' in o) { - // o['@type'] = o['@type'][0]; - //} util.addValue( subject, property, o, {propertyIsArray: true, allowDuplicate: false});