rdflib 2.2.22-2cea0982 → 2.2.22-4e175603
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +0 -2
- package/dist/rdflib.min.js.map +1 -1
- package/esm/jsonldparser.js +1 -1
- package/esm/serialize.js +19 -3
- package/esm/serializer.js +0 -23
- package/lib/formula.d.ts +1 -1
- package/lib/jsonldparser.js +1 -1
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +20 -3
- package/lib/serializer.d.ts +0 -1
- package/lib/serializer.js +0 -24
- package/lib/store.d.ts +1 -1
- package/package.json +4 -4
- package/src/jsonldparser.js +1 -1
- package/src/serialize.ts +14 -4
- package/src/serializer.js +0 -24
package/esm/jsonldparser.js
CHANGED
|
@@ -65,7 +65,7 @@ export default function jsonldParser(str, kb, base, callback) {
|
|
|
65
65
|
}
|
|
66
66
|
function nodeType(kb, obj) {
|
|
67
67
|
if (obj['@id'].startsWith('_:')) {
|
|
68
|
-
// This object is a Blank Node
|
|
68
|
+
// This object is a Blank Node.. pass the id without the preceding _:
|
|
69
69
|
return kb.rdfFactory.blankNode(obj['@id'].substring(2));
|
|
70
70
|
} else {
|
|
71
71
|
// This object is a Named Node
|
package/esm/serialize.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Serializer from './serializer';
|
|
2
2
|
import { JSONLDContentType, N3ContentType, N3LegacyContentType, NQuadsAltContentType, NQuadsContentType, NTriplesContentType, RDFXMLContentType, TurtleContentType, TurtleLegacyContentType } from './types';
|
|
3
|
+
import * as jsonld from 'jsonld';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Serialize to the appropriate format
|
|
5
7
|
*/
|
|
@@ -19,6 +21,7 @@ contentType, callback, options) {
|
|
|
19
21
|
var sz = Serializer(kb);
|
|
20
22
|
if (opts.flags) sz.setFlags(opts.flags);
|
|
21
23
|
var newSts = kb.statementsMatching(undefined, undefined, undefined, target);
|
|
24
|
+
var n3String;
|
|
22
25
|
|
|
23
26
|
// If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
24
27
|
if ('namespaces' in kb) {
|
|
@@ -48,9 +51,10 @@ contentType, callback, options) {
|
|
|
48
51
|
documentString = sz.statementsToNTriples(newSts);
|
|
49
52
|
return executeCallback(null, documentString);
|
|
50
53
|
case JSONLDContentType:
|
|
51
|
-
sz.setFlags('
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
sz.setFlags('deinprstux'); // Use adapters to connect to incmpatible parser
|
|
55
|
+
n3String = sz.statementsToNTriples(newSts);
|
|
56
|
+
// n3String = sz.statementsToN3(newSts)
|
|
57
|
+
return toJsonld(n3String);
|
|
54
58
|
case NQuadsContentType:
|
|
55
59
|
case NQuadsAltContentType:
|
|
56
60
|
// @@@ just outpout the quads? Does not work for collections
|
|
@@ -76,4 +80,16 @@ contentType, callback, options) {
|
|
|
76
80
|
return result;
|
|
77
81
|
}
|
|
78
82
|
}
|
|
83
|
+
function toJsonld(item) {
|
|
84
|
+
try {
|
|
85
|
+
return jsonld.fromRDF(item, {
|
|
86
|
+
format: 'application/n-quads'
|
|
87
|
+
}).then(docJsonld => {
|
|
88
|
+
return JSON.stringify(docJsonld);
|
|
89
|
+
});
|
|
90
|
+
// return JSON.stringify(await jsonld.fromRDF(item, {format: 'application/n-quads'}))
|
|
91
|
+
} catch (e) {
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
79
95
|
}
|
package/esm/serializer.js
CHANGED
|
@@ -13,8 +13,6 @@ import * as Util from './utils-js';
|
|
|
13
13
|
import CanonicalDataFactory from './factories/canonical-data-factory';
|
|
14
14
|
import { createXSD } from './xsd';
|
|
15
15
|
import solidNs from 'solid-namespace';
|
|
16
|
-
// import * as jsonld from 'jsonld'
|
|
17
|
-
import * as ttl2jsonld from '@frogcat/ttl2jsonld';
|
|
18
16
|
export default function createSerializer(store) {
|
|
19
17
|
return new Serializer(store);
|
|
20
18
|
}
|
|
@@ -964,27 +962,6 @@ export class Serializer {
|
|
|
964
962
|
var tree2 = [str, tree, '</rdf:RDF>']; // @@ namespace declrations
|
|
965
963
|
return XMLtreeToString(tree2, -1);
|
|
966
964
|
} // End @@ body
|
|
967
|
-
|
|
968
|
-
statementsToJsonld(sts) {
|
|
969
|
-
// ttl2jsonld creates context keys for all ttl prefix
|
|
970
|
-
// context keys must be full IRI
|
|
971
|
-
function findId(itemObj) {
|
|
972
|
-
if (itemObj['@id']) {
|
|
973
|
-
const item = itemObj['@id'].split(':');
|
|
974
|
-
if (keys[item[0]]) itemObj['@id'] = jsonldObj['@context'][item[0]] + item[1];
|
|
975
|
-
}
|
|
976
|
-
const itemValues = Object.values(itemObj);
|
|
977
|
-
for (const i in itemValues) {
|
|
978
|
-
if (typeof itemValues[i] !== 'string') {
|
|
979
|
-
// @list contains array
|
|
980
|
-
findId(itemValues[i]);
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
const turtleDoc = this.statementsToN3(sts);
|
|
985
|
-
const jsonldObj = ttl2jsonld.parse(turtleDoc);
|
|
986
|
-
return JSON.stringify(jsonldObj, null, 2);
|
|
987
|
-
}
|
|
988
965
|
}
|
|
989
966
|
|
|
990
967
|
// String escaping utilities
|
package/lib/formula.d.ts
CHANGED
|
@@ -270,7 +270,7 @@ export default class Formula extends Node {
|
|
|
270
270
|
* @param provenance - The provenance URI
|
|
271
271
|
* @param options - options to pass to the serializer, as defined in serialize method
|
|
272
272
|
*/
|
|
273
|
-
serialize(base: any, contentType: any, provenance: any, options?: any): string |
|
|
273
|
+
serialize(base: any, contentType: any, provenance: any, options?: any): string | undefined;
|
|
274
274
|
/**
|
|
275
275
|
* Creates a new formula with the substituting bindings applied
|
|
276
276
|
* @param bindings - The bindings to substitute
|
package/lib/jsonldparser.js
CHANGED
|
@@ -72,7 +72,7 @@ function jsonldParser(str, kb, base, callback) {
|
|
|
72
72
|
}
|
|
73
73
|
function nodeType(kb, obj) {
|
|
74
74
|
if (obj['@id'].startsWith('_:')) {
|
|
75
|
-
// This object is a Blank Node
|
|
75
|
+
// This object is a Blank Node.. pass the id without the preceding _:
|
|
76
76
|
return kb.rdfFactory.blankNode(obj['@id'].substring(2));
|
|
77
77
|
} else {
|
|
78
78
|
// This object is a Named Node
|
package/lib/serialize.d.ts
CHANGED
package/lib/serialize.js
CHANGED
|
@@ -7,6 +7,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = serialize;
|
|
8
8
|
var _serializer = _interopRequireDefault(require("./serializer"));
|
|
9
9
|
var _types = require("./types");
|
|
10
|
+
var jsonld = _interopRequireWildcard(require("jsonld"));
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
13
|
/**
|
|
11
14
|
* Serialize to the appropriate format
|
|
12
15
|
*/
|
|
@@ -26,6 +29,7 @@ contentType, callback, options) {
|
|
|
26
29
|
var sz = (0, _serializer.default)(kb);
|
|
27
30
|
if (opts.flags) sz.setFlags(opts.flags);
|
|
28
31
|
var newSts = kb.statementsMatching(undefined, undefined, undefined, target);
|
|
32
|
+
var n3String;
|
|
29
33
|
|
|
30
34
|
// If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
31
35
|
if ('namespaces' in kb) {
|
|
@@ -55,9 +59,10 @@ contentType, callback, options) {
|
|
|
55
59
|
documentString = sz.statementsToNTriples(newSts);
|
|
56
60
|
return executeCallback(null, documentString);
|
|
57
61
|
case _types.JSONLDContentType:
|
|
58
|
-
sz.setFlags('
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
sz.setFlags('deinprstux'); // Use adapters to connect to incmpatible parser
|
|
63
|
+
n3String = sz.statementsToNTriples(newSts);
|
|
64
|
+
// n3String = sz.statementsToN3(newSts)
|
|
65
|
+
return toJsonld(n3String);
|
|
61
66
|
case _types.NQuadsContentType:
|
|
62
67
|
case _types.NQuadsAltContentType:
|
|
63
68
|
// @@@ just outpout the quads? Does not work for collections
|
|
@@ -83,4 +88,16 @@ contentType, callback, options) {
|
|
|
83
88
|
return result;
|
|
84
89
|
}
|
|
85
90
|
}
|
|
91
|
+
function toJsonld(item) {
|
|
92
|
+
try {
|
|
93
|
+
return jsonld.fromRDF(item, {
|
|
94
|
+
format: 'application/n-quads'
|
|
95
|
+
}).then(docJsonld => {
|
|
96
|
+
return JSON.stringify(docJsonld);
|
|
97
|
+
});
|
|
98
|
+
// return JSON.stringify(await jsonld.fromRDF(item, {format: 'application/n-quads'}))
|
|
99
|
+
} catch (e) {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
86
103
|
}
|
package/lib/serializer.d.ts
CHANGED
package/lib/serializer.js
CHANGED
|
@@ -14,7 +14,6 @@ var Util = _interopRequireWildcard(require("./utils-js"));
|
|
|
14
14
|
var _canonicalDataFactory = _interopRequireDefault(require("./factories/canonical-data-factory"));
|
|
15
15
|
var _xsd = require("./xsd");
|
|
16
16
|
var _solidNamespace = _interopRequireDefault(require("solid-namespace"));
|
|
17
|
-
var ttl2jsonld = _interopRequireWildcard(require("@frogcat/ttl2jsonld"));
|
|
18
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
19
|
/* Serialization of RDF Graphs
|
|
@@ -25,8 +24,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
25
24
|
** Licence: MIT
|
|
26
25
|
*/
|
|
27
26
|
|
|
28
|
-
// import * as jsonld from 'jsonld'
|
|
29
|
-
|
|
30
27
|
function createSerializer(store) {
|
|
31
28
|
return new Serializer(store);
|
|
32
29
|
}
|
|
@@ -976,27 +973,6 @@ class Serializer {
|
|
|
976
973
|
var tree2 = [str, tree, '</rdf:RDF>']; // @@ namespace declrations
|
|
977
974
|
return XMLtreeToString(tree2, -1);
|
|
978
975
|
} // End @@ body
|
|
979
|
-
|
|
980
|
-
statementsToJsonld(sts) {
|
|
981
|
-
// ttl2jsonld creates context keys for all ttl prefix
|
|
982
|
-
// context keys must be full IRI
|
|
983
|
-
function findId(itemObj) {
|
|
984
|
-
if (itemObj['@id']) {
|
|
985
|
-
const item = itemObj['@id'].split(':');
|
|
986
|
-
if (keys[item[0]]) itemObj['@id'] = jsonldObj['@context'][item[0]] + item[1];
|
|
987
|
-
}
|
|
988
|
-
const itemValues = Object.values(itemObj);
|
|
989
|
-
for (const i in itemValues) {
|
|
990
|
-
if (typeof itemValues[i] !== 'string') {
|
|
991
|
-
// @list contains array
|
|
992
|
-
findId(itemValues[i]);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
const turtleDoc = this.statementsToN3(sts);
|
|
997
|
-
const jsonldObj = ttl2jsonld.parse(turtleDoc);
|
|
998
|
-
return JSON.stringify(jsonldObj, null, 2);
|
|
999
|
-
}
|
|
1000
976
|
}
|
|
1001
977
|
|
|
1002
978
|
// String escaping utilities
|
package/lib/store.d.ts
CHANGED
|
@@ -299,5 +299,5 @@ export default class IndexedFormula extends Formula {
|
|
|
299
299
|
* @param term
|
|
300
300
|
*/
|
|
301
301
|
uris(term: Quad_Subject): string[];
|
|
302
|
-
serialize(base: any, contentType: any, provenance: any, options?: any): string |
|
|
302
|
+
serialize(base: any, contentType: any, provenance: any, options?: any): string | undefined;
|
|
303
303
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rdflib",
|
|
3
3
|
"description": "an RDF library for node.js. Suitable for client and server side.",
|
|
4
|
-
"version": "2.2.22-
|
|
4
|
+
"version": "2.2.22-4e175603",
|
|
5
5
|
"private": false,
|
|
6
6
|
"browserslist": [
|
|
7
7
|
"> 0.5%"
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"bugs": "http://github.com/linkeddata/rdflib.js/issues",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/runtime": "^7.20.1",
|
|
48
|
-
"@frogcat/ttl2jsonld": "^0.0.9",
|
|
49
48
|
"@xmldom/xmldom": "^0.8.6",
|
|
50
49
|
"cross-fetch": "^3.1.5",
|
|
51
50
|
"jsonld": "^8.1.0",
|
|
@@ -85,7 +84,7 @@
|
|
|
85
84
|
"typescript": "^4.9.3",
|
|
86
85
|
"webpack": "^5.75.0",
|
|
87
86
|
"webpack-cli": "^5.0.0",
|
|
88
|
-
"webpack-dev-server": "
|
|
87
|
+
"webpack-dev-server": "4.11"
|
|
89
88
|
},
|
|
90
89
|
"scripts": {
|
|
91
90
|
"build": "babel src --extensions \".ts,.js\" -d lib",
|
|
@@ -100,7 +99,7 @@
|
|
|
100
99
|
"test": "npm run test:unit && npm run test:serialize && npm run test:types",
|
|
101
100
|
"test:clean": "rimraf tests/serialize/,*",
|
|
102
101
|
"test:serialize": "npm run build && npm run test:serialize:all && npm run test:clean",
|
|
103
|
-
"test:serialize:all": "npm run test:serialize:1 && npm run test:serialize:2 && npm run test:serialize:3 && npm run test:serialize:4 && npm run test:serialize:5 && npm run test:serialize:6 && npm run test:serialize:7 && npm run test:serialize:8 && npm run test:serialize:10 && npm run test:serialize:11 && npm run test:serialize:12 && npm run test:serialize:13 && npm run test:serialize:14
|
|
102
|
+
"test:serialize:all": "npm run test:serialize:8 && npm run test:serialize:1 && npm run test:serialize:2 && npm run test:serialize:3 && npm run test:serialize:4 && npm run test:serialize:5 && npm run test:serialize:6 && npm run test:serialize:7 && npm run test:serialize:8 && npm run test:serialize:9 && npm run test:serialize:10 && npm run test:serialize:11 && npm run test:serialize:12 && npm run test:serialize:13 && npm run test:serialize:14 && npm run test:serialize:15 && npm run test:serialize:16",
|
|
104
103
|
"test:serialize:1": "cd ./tests/serialize && node ./data.js -in=t1.ttl -format=application/rdf+xml -out=,t1.xml && fs-grep http://www.w3.org/2001/XMLSchema#integer ,t1.xml",
|
|
105
104
|
"test:serialize:2": "cd ./tests/serialize && node ./data.js -in=t2.ttl -format=application/rdf+xml -out=,t2.xml && node diff ,t2.xml t2-ref.xml",
|
|
106
105
|
"test:serialize:3": "cd ./tests/serialize && node ./data.js -in=t3.ttl -format=application/rdf+xml -out=,t3.xml && node diff ,t3.xml t3-ref.xml",
|
|
@@ -109,6 +108,7 @@
|
|
|
109
108
|
"test:serialize:6": "cd ./tests/serialize && node ./data.js -in=t5.n3 -format=text/n3 -out=,t6.n3 && node diff ,t6.n3 t6-ref.n3",
|
|
110
109
|
"test:serialize:7": "cd ./tests/serialize && node ./data.js -in=t7.n3 -format=application/n-triples -out=,t7.nt && node diff ,t7.nt t7-ref.nt",
|
|
111
110
|
"test:serialize:8": "cd ./tests/serialize && node ./data.js -in=t5.n3 -format=application/n-quads -out=,t8.nq && node diff ,t8.nq t8-ref.nq",
|
|
111
|
+
"test:serialize:9": "cd ./tests/serialize && node ./data.js -in=t7.n3 -format=application/ld+json -out=,t9.jsonld && node diff ,t9.jsonld t9-ref.jsonld",
|
|
112
112
|
"test:serialize:10": "cd ./tests/serialize && node ./data.js -in=details.ttl -format=text/turtle -out=,t10.ttl && node diff ,t10.ttl t10-ref.ttl",
|
|
113
113
|
"test:serialize:11": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=application/rdf+xml -out=,structures.xml && node diff ,structures.xml t11-ref.xml",
|
|
114
114
|
"test:serialize:12": "cd ./tests/serialize && node ./data.js -in=structures.n3 -format=text/turtle -out=,structures.ttl && node diff ,structures.ttl t12-ref.ttl",
|
package/src/jsonldparser.js
CHANGED
|
@@ -84,7 +84,7 @@ export default function jsonldParser (str, kb, base, callback) {
|
|
|
84
84
|
|
|
85
85
|
function nodeType (kb, obj) {
|
|
86
86
|
if (obj['@id'].startsWith('_:')) {
|
|
87
|
-
// This object is a Blank Node
|
|
87
|
+
// This object is a Blank Node.. pass the id without the preceding _:
|
|
88
88
|
return kb.rdfFactory.blankNode(obj['@id'].substring(2));
|
|
89
89
|
} else {
|
|
90
90
|
// This object is a Named Node
|
package/src/serialize.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from './types'
|
|
15
15
|
import IndexedFormula from './store'
|
|
16
16
|
import { BlankNode, NamedNode } from './tf-types'
|
|
17
|
+
import * as jsonld from 'jsonld'
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Serialize to the appropriate format
|
|
@@ -41,7 +42,7 @@ export default function serialize (
|
|
|
41
42
|
*/
|
|
42
43
|
namespaces?: Record<string, string>
|
|
43
44
|
}
|
|
44
|
-
): string | undefined
|
|
45
|
+
): string | undefined {
|
|
45
46
|
base = base || target?.value
|
|
46
47
|
const opts = options || {}
|
|
47
48
|
contentType = contentType || TurtleContentType // text/n3 if complex?
|
|
@@ -50,6 +51,7 @@ export default function serialize (
|
|
|
50
51
|
var sz = Serializer(kb)
|
|
51
52
|
if ((opts as any).flags) sz.setFlags((opts as any).flags)
|
|
52
53
|
var newSts = kb!.statementsMatching(undefined, undefined, undefined, target as NamedNode)
|
|
54
|
+
var n3String: string
|
|
53
55
|
|
|
54
56
|
// If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
55
57
|
if ('namespaces' in kb) {
|
|
@@ -80,9 +82,10 @@ export default function serialize (
|
|
|
80
82
|
documentString = sz.statementsToNTriples(newSts)
|
|
81
83
|
return executeCallback(null, documentString)
|
|
82
84
|
case JSONLDContentType:
|
|
83
|
-
sz.setFlags('
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
sz.setFlags('deinprstux') // Use adapters to connect to incmpatible parser
|
|
86
|
+
n3String = sz.statementsToNTriples(newSts)
|
|
87
|
+
// n3String = sz.statementsToN3(newSts)
|
|
88
|
+
return toJsonld(n3String) as any
|
|
86
89
|
case NQuadsContentType:
|
|
87
90
|
case NQuadsAltContentType: // @@@ just outpout the quads? Does not work for collections
|
|
88
91
|
sz.setFlags('deinprstux q') // Suppress nice parts of N3 to make ntriples
|
|
@@ -107,4 +110,11 @@ export default function serialize (
|
|
|
107
110
|
return result as string
|
|
108
111
|
}
|
|
109
112
|
}
|
|
113
|
+
|
|
114
|
+
function toJsonld (item ) {
|
|
115
|
+
try {
|
|
116
|
+
return jsonld.fromRDF(item, {format: 'application/n-quads'}).then( docJsonld => { return JSON.stringify(docJsonld) })
|
|
117
|
+
// return JSON.stringify(await jsonld.fromRDF(item, {format: 'application/n-quads'}))
|
|
118
|
+
} catch (e) { throw e }
|
|
119
|
+
}
|
|
110
120
|
}
|
package/src/serializer.js
CHANGED
|
@@ -12,8 +12,6 @@ import * as Util from './utils-js'
|
|
|
12
12
|
import CanonicalDataFactory from './factories/canonical-data-factory'
|
|
13
13
|
import { createXSD } from './xsd'
|
|
14
14
|
import solidNs from 'solid-namespace'
|
|
15
|
-
// import * as jsonld from 'jsonld'
|
|
16
|
-
import * as ttl2jsonld from '@frogcat/ttl2jsonld'
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
export default function createSerializer(store) {
|
|
@@ -1013,28 +1011,6 @@ export class Serializer {
|
|
|
1013
1011
|
var tree2 = [str, tree, '</rdf:RDF>'] // @@ namespace declrations
|
|
1014
1012
|
return XMLtreeToString(tree2, -1)
|
|
1015
1013
|
} // End @@ body
|
|
1016
|
-
|
|
1017
|
-
statementsToJsonld (sts) {
|
|
1018
|
-
// ttl2jsonld creates context keys for all ttl prefix
|
|
1019
|
-
// context keys must be full IRI
|
|
1020
|
-
function findId (itemObj) {
|
|
1021
|
-
if (itemObj['@id']) {
|
|
1022
|
-
const item = itemObj['@id'].split(':')
|
|
1023
|
-
if (keys[item[0]]) itemObj['@id'] = jsonldObj['@context'][item[0]] + item[1]
|
|
1024
|
-
}
|
|
1025
|
-
const itemValues = Object.values(itemObj)
|
|
1026
|
-
for (const i in itemValues) {
|
|
1027
|
-
if (typeof itemValues[i] !== 'string') { // @list contains array
|
|
1028
|
-
findId(itemValues[i])
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
const turtleDoc = this.statementsToN3(sts)
|
|
1033
|
-
const jsonldObj = ttl2jsonld.parse(turtleDoc)
|
|
1034
|
-
|
|
1035
|
-
return JSON.stringify(jsonldObj, null, 2)
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
1014
|
}
|
|
1039
1015
|
|
|
1040
1016
|
// String escaping utilities
|