rdflib 2.2.21 → 2.2.22-0de51c50

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.
Files changed (115) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +13 -1
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +3 -27
  5. package/esm/collection.js +7 -29
  6. package/esm/default-graph.js +1 -15
  7. package/esm/empty.js +0 -13
  8. package/esm/factories/canonical-data-factory.js +5 -40
  9. package/esm/factories/extended-term-factory.js +0 -11
  10. package/esm/factories/factory-types.js +2 -1
  11. package/esm/factories/rdflib-data-factory.js +0 -8
  12. package/esm/fetcher.js +257 -481
  13. package/esm/formula.js +43 -142
  14. package/esm/index.js +19 -36
  15. package/esm/jsonldparser.js +20 -29
  16. package/esm/jsonparser.js +0 -7
  17. package/esm/lists.js +18 -33
  18. package/esm/literal.js +10 -42
  19. package/esm/n3parser.js +38 -351
  20. package/esm/named-node.js +8 -27
  21. package/esm/namespace.js +0 -1
  22. package/esm/node-internal.js +11 -24
  23. package/esm/node.js +1 -6
  24. package/esm/parse.js +10 -17
  25. package/esm/patch-parser.js +9 -29
  26. package/esm/query-to-sparql.js +0 -18
  27. package/esm/query.js +50 -133
  28. package/esm/rdfaparser.js +72 -210
  29. package/esm/rdfxmlparser.js +31 -128
  30. package/esm/serialize.js +8 -33
  31. package/esm/serializer.js +122 -286
  32. package/esm/sparql-to-query.js +44 -134
  33. package/esm/statement.js +8 -19
  34. package/esm/store.js +109 -280
  35. package/esm/types.js +3 -2
  36. package/esm/update-manager.js +110 -246
  37. package/esm/updates-via.js +0 -27
  38. package/esm/uri.js +6 -50
  39. package/esm/utils/default-graph-uri.js +1 -0
  40. package/esm/utils/termValue.js +0 -1
  41. package/esm/utils/terms.js +15 -16
  42. package/esm/utils-js.js +16 -57
  43. package/esm/utils.js +4 -15
  44. package/esm/variable.js +0 -20
  45. package/lib/blank-node.js +3 -28
  46. package/lib/class-order.js +0 -1
  47. package/lib/collection.js +7 -34
  48. package/lib/default-graph.js +0 -20
  49. package/lib/empty.js +0 -18
  50. package/lib/factories/canonical-data-factory.js +4 -51
  51. package/lib/factories/extended-term-factory.js +0 -18
  52. package/lib/factories/factory-types.d.ts +6 -6
  53. package/lib/factories/factory-types.js +0 -3
  54. package/lib/factories/rdflib-data-factory.js +0 -12
  55. package/lib/fetcher.d.ts +6 -6
  56. package/lib/fetcher.js +258 -470
  57. package/lib/formula.d.ts +1 -1
  58. package/lib/formula.js +43 -151
  59. package/lib/index.d.ts +1 -2
  60. package/lib/index.js +14 -82
  61. package/lib/jsonldparser.js +19 -33
  62. package/lib/jsonparser.js +0 -9
  63. package/lib/lists.js +14 -39
  64. package/lib/literal.js +10 -49
  65. package/lib/log.d.ts +0 -6
  66. package/lib/log.js +0 -1
  67. package/lib/n3parser.d.ts +1 -0
  68. package/lib/n3parser.js +39 -359
  69. package/lib/named-node.js +7 -35
  70. package/lib/namespace.js +0 -3
  71. package/lib/node-internal.js +11 -21
  72. package/lib/node.js +1 -11
  73. package/lib/parse.d.ts +1 -1
  74. package/lib/parse.js +8 -27
  75. package/lib/patch-parser.js +10 -33
  76. package/lib/query-to-sparql.js +0 -23
  77. package/lib/query.js +46 -152
  78. package/lib/rdfaparser.js +72 -220
  79. package/lib/rdfxmlparser.js +31 -132
  80. package/lib/serialize.d.ts +1 -1
  81. package/lib/serialize.js +8 -43
  82. package/lib/serializer.d.ts +1 -0
  83. package/lib/serializer.js +121 -297
  84. package/lib/sparql-to-query.js +42 -167
  85. package/lib/statement.js +8 -24
  86. package/lib/store.d.ts +2 -2
  87. package/lib/store.js +102 -282
  88. package/lib/tf-types.d.ts +4 -4
  89. package/lib/types.d.ts +8 -8
  90. package/lib/types.js +3 -3
  91. package/lib/update-manager.d.ts +2 -2
  92. package/lib/update-manager.js +110 -254
  93. package/lib/updates-via.js +0 -30
  94. package/lib/uri.js +5 -58
  95. package/lib/utils/default-graph-uri.js +1 -3
  96. package/lib/utils/termValue.js +0 -2
  97. package/lib/utils/terms.js +15 -34
  98. package/lib/utils-js.js +16 -80
  99. package/lib/utils.js +4 -21
  100. package/lib/variable.js +0 -25
  101. package/lib/xsd-internal.js +0 -3
  102. package/lib/xsd.js +0 -4
  103. package/package.json +40 -39
  104. package/src/fetcher.ts +2 -2
  105. package/src/index.ts +0 -2
  106. package/src/jsonldparser.js +13 -4
  107. package/src/n3parser.js +12 -4
  108. package/src/serialize.ts +4 -11
  109. package/src/serializer.js +24 -0
  110. package/src/update-manager.ts +18 -7
  111. package/changes.txt +0 -59
  112. package/esm/convert.js +0 -61
  113. package/lib/convert.d.ts +0 -2
  114. package/lib/convert.js +0 -77
  115. package/src/convert.js +0 -70
@@ -1,7 +1,6 @@
1
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
-
5
4
  /**
6
5
  * RDF/XML PARSER
7
6
  *
@@ -53,7 +52,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
53
52
  * associated documentation will at all times remain with copyright
54
53
  * holders.
55
54
  */
56
-
57
55
  /**
58
56
  * @class RDFParser resource object tied to an RDFStore
59
57
  *
@@ -61,7 +59,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
61
59
  *
62
60
  */
63
61
  import * as uriUtil from './uri';
64
-
65
62
  var RDFParser = /*#__PURE__*/function () {
66
63
  /*
67
64
  * @constructor
@@ -69,24 +66,17 @@ var RDFParser = /*#__PURE__*/function () {
69
66
  */
70
67
  function RDFParser(store) {
71
68
  _classCallCheck(this, RDFParser);
72
-
73
69
  /** Our triple store reference @private */
74
- this.store = store;
75
- /** Our identified blank nodes @private */
76
-
77
- this.bnodes = {};
78
- /** A context for context-aware stores @private */
79
-
80
- this.why = null;
81
- /** Reification flag */
82
70
 
71
+ this.store = store; /** Our identified blank nodes @private */
72
+ this.bnodes = {}; /** A context for context-aware stores @private */
73
+ this.why = null; /** Reification flag */
83
74
  this.reify = false;
84
75
  }
76
+
85
77
  /** Standard namespaces that we know how to handle @final
86
78
  * @member RDFParser
87
79
  */
88
-
89
-
90
80
  _createClass(RDFParser, [{
91
81
  key: "frameFactory",
92
82
  value:
@@ -97,6 +87,7 @@ var RDFParser = /*#__PURE__*/function () {
97
87
  *
98
88
  * @private
99
89
  */
90
+
100
91
  function frameFactory(parser, parent, element) {
101
92
  return {
102
93
  'NODE': 1,
@@ -114,29 +105,23 @@ var RDFParser = /*#__PURE__*/function () {
114
105
  'rdfid': null,
115
106
  'datatype': null,
116
107
  'collection': false,
117
-
118
108
  /** Terminate the frame and notify the store that we're done */
119
109
  'terminateFrame': function terminateFrame() {
120
110
  if (this.collection) {
121
111
  this.node.close();
122
112
  }
123
113
  },
124
-
125
- /** Add a symbol of a certain type to the this frame */
126
- 'addSymbol': function addSymbol(type, uri) {
114
+ /** Add a symbol of a certain type to the this frame */'addSymbol': function addSymbol(type, uri) {
127
115
  uri = uriUtil.join(uri, this.base);
128
116
  this.node = this.store.sym(uri);
129
117
  this.nodeType = type;
130
118
  },
131
-
132
- /** Load any constructed triples into the store */
133
- 'loadTriple': function loadTriple() {
119
+ /** Load any constructed triples into the store */'loadTriple': function loadTriple() {
134
120
  if (this.parent.parent.collection) {
135
121
  this.parent.parent.node.append(this.node);
136
122
  } else {
137
123
  this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
138
124
  }
139
-
140
125
  if (this.parent.rdfid != null) {
141
126
  // reify
142
127
  var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
@@ -146,39 +131,27 @@ var RDFParser = /*#__PURE__*/function () {
146
131
  this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
147
132
  }
148
133
  },
149
-
150
- /** Check if it's OK to load a triple */
151
- 'isTripleToLoad': function isTripleToLoad() {
134
+ /** Check if it's OK to load a triple */'isTripleToLoad': function isTripleToLoad() {
152
135
  return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
153
136
  },
154
-
155
- /** Add a symbolic node to this frame */
156
- 'addNode': function addNode(uri) {
137
+ /** Add a symbolic node to this frame */'addNode': function addNode(uri) {
157
138
  this.addSymbol(this.NODE, uri);
158
-
159
139
  if (this.isTripleToLoad()) {
160
140
  this.loadTriple();
161
141
  }
162
142
  },
163
-
164
- /** Add a collection node to this frame */
165
- 'addCollection': function addCollection() {
143
+ /** Add a collection node to this frame */'addCollection': function addCollection() {
166
144
  this.nodeType = this.NODE;
167
145
  this.node = this.store.collection();
168
146
  this.collection = true;
169
-
170
147
  if (this.isTripleToLoad()) {
171
148
  this.loadTriple();
172
149
  }
173
150
  },
174
-
175
- /** Add a collection arc to this frame */
176
- 'addCollectionArc': function addCollectionArc() {
151
+ /** Add a collection arc to this frame */'addCollectionArc': function addCollectionArc() {
177
152
  this.nodeType = this.ARC;
178
153
  },
179
-
180
- /** Add a bnode to this frame */
181
- 'addBNode': function addBNode(id) {
154
+ /** Add a bnode to this frame */'addBNode': function addBNode(id) {
182
155
  if (id != null) {
183
156
  if (this.parser.bnodes[id] != null) {
184
157
  this.node = this.parser.bnodes[id];
@@ -188,58 +161,46 @@ var RDFParser = /*#__PURE__*/function () {
188
161
  } else {
189
162
  this.node = this.store.bnode();
190
163
  }
191
-
192
164
  this.nodeType = this.NODE;
193
-
194
165
  if (this.isTripleToLoad()) {
195
166
  this.loadTriple();
196
167
  }
197
168
  },
198
-
199
- /** Add an arc or property to this frame */
200
- 'addArc': function addArc(uri) {
169
+ /** Add an arc or property to this frame */'addArc': function addArc(uri) {
201
170
  if (uri === RDFParser.ns.RDF + 'li') {
202
171
  uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
203
172
  this.parent.listIndex++;
204
173
  }
205
-
206
174
  this.addSymbol(this.ARC, uri);
207
175
  },
208
-
209
- /** Add a literal to this frame */
210
- 'addLiteral': function addLiteral(value) {
176
+ /** Add a literal to this frame */'addLiteral': function addLiteral(value) {
211
177
  if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
212
178
  this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
213
179
  } else {
214
180
  this.node = this.store.literal(value, this.lang);
215
181
  }
216
-
217
182
  this.nodeType = this.NODE;
218
-
219
183
  if (this.isTripleToLoad()) {
220
184
  this.loadTriple();
221
185
  }
222
186
  }
223
187
  };
224
- } // from the OpenLayers source .. needed to get around IE problems.
188
+ }
225
189
 
190
+ // from the OpenLayers source .. needed to get around IE problems.
226
191
  }, {
227
192
  key: "getAttributeNodeNS",
228
193
  value: function getAttributeNodeNS(node, uri, name) {
229
194
  var attributeNode = null;
230
-
231
195
  if (node.getAttributeNodeNS) {
232
196
  attributeNode = node.getAttributeNodeNS(uri, name);
233
197
  } else {
234
198
  var attributes = node.attributes;
235
199
  var potentialNode, fullName;
236
-
237
200
  for (var i = 0; i < attributes.length; ++i) {
238
201
  potentialNode = attributes[i];
239
-
240
202
  if (potentialNode.namespaceURI === uri) {
241
203
  fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
242
-
243
204
  if (fullName === potentialNode.nodeName) {
244
205
  attributeNode = potentialNode;
245
206
  break;
@@ -247,25 +208,21 @@ var RDFParser = /*#__PURE__*/function () {
247
208
  }
248
209
  }
249
210
  }
250
-
251
211
  return attributeNode;
252
212
  }
213
+
253
214
  /**
254
215
  * Build our initial scope frame and parse the DOM into triples
255
216
  * @param {HTMLDocument} document The DOM to parse
256
217
  * @param {String} base The base URL to use
257
218
  * @param {Object} why The context to which this resource belongs
258
219
  */
259
-
260
220
  }, {
261
221
  key: "parse",
262
222
  value: function parse(document, base, why) {
263
223
  var children = document.childNodes; // clean up for the next run
264
-
265
224
  this.cleanParser(); // figure out the root element
266
-
267
225
  var root;
268
-
269
226
  if (document.nodeType === RDFParser.nodeType.DOCUMENT) {
270
227
  for (var c = 0; c < children.length; c++) {
271
228
  if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
@@ -276,16 +233,15 @@ var RDFParser = /*#__PURE__*/function () {
276
233
  } else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
277
234
  root = document;
278
235
  } else {
279
- throw new Error("RDFParser: can't find root in " + base + '. Halting. '); // return false
236
+ throw new Error("RDFParser: can't find root in " + base + '. Halting. ');
237
+ // return false
280
238
  }
281
239
 
282
240
  this.why = why; // our topmost frame
283
-
284
241
  var f = this.frameFactory(this);
285
242
  this.base = base;
286
243
  f.base = base;
287
244
  f.lang = null; // was '' but can't have langs like that 2015 (!)
288
-
289
245
  this.parseDOM(this.buildFrame(f, root));
290
246
  return true;
291
247
  }
@@ -294,33 +250,25 @@ var RDFParser = /*#__PURE__*/function () {
294
250
  value: function parseDOM(frame) {
295
251
  // a DOM utility function used in parsing
296
252
  var rdfid;
297
-
298
253
  var elementURI = function (el) {
299
254
  var result = '';
300
-
301
255
  if (el.namespaceURI == null) {
302
256
  throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
303
257
  }
304
-
305
258
  if (el.namespaceURI) {
306
259
  result = result + el.namespaceURI;
307
260
  }
308
-
309
261
  if (el.localName) {
310
262
  result = result + el.localName;
311
263
  } else if (el.nodeName) {
312
264
  if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
313
265
  }
314
-
315
266
  return result;
316
267
  }.bind(this);
317
-
318
268
  var dig = true; // if we'll dig down in the tree on the next iter
319
-
320
269
  while (frame.parent) {
321
270
  var dom = frame.element;
322
271
  var attrs = dom.attributes;
323
-
324
272
  if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
325
273
  // we have a literal
326
274
  if (frame.parent.nodeType === frame.NODE) {
@@ -328,7 +276,6 @@ var RDFParser = /*#__PURE__*/function () {
328
276
  frame.addArc(RDFParser.ns.RDF + 'value');
329
277
  frame = this.buildFrame(frame);
330
278
  }
331
-
332
279
  frame.addLiteral(dom.nodeValue);
333
280
  } else if (elementURI(dom) !== RDFParser.ns.RDF + 'RDF') {
334
281
  // not root
@@ -338,22 +285,18 @@ var RDFParser = /*#__PURE__*/function () {
338
285
  frame = this.buildFrame(frame, frame.element);
339
286
  frame.parent.element = null;
340
287
  }
341
-
342
288
  if (!frame.parent || !frame.parent.nodeType || frame.parent.nodeType === frame.ARC) {
343
289
  // we need a node
344
290
  var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
345
291
  rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
346
-
347
292
  if (about && rdfid) {
348
293
  throw new Error('RDFParser: ' + dom.nodeName + ' has both rdf:id and rdf:about.' + ' Halting. Only one of these' + ' properties may be specified on a' + ' node.');
349
294
  }
350
-
351
295
  if (!about && rdfid) {
352
296
  frame.addNode('#' + rdfid.nodeValue);
353
297
  dom.removeAttributeNode(rdfid);
354
298
  } else if (about == null && rdfid == null) {
355
299
  var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
356
-
357
300
  if (bnid) {
358
301
  frame.addBNode(bnid.nodeValue);
359
302
  dom.removeAttributeNode(bnid);
@@ -363,57 +306,46 @@ var RDFParser = /*#__PURE__*/function () {
363
306
  } else {
364
307
  frame.addNode(about.nodeValue);
365
308
  dom.removeAttributeNode(about);
366
- } // Typed nodes
367
-
368
-
309
+ }
310
+ // Typed nodes
369
311
  var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
370
-
371
312
  if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
372
313
  rdftype = {
373
314
  'nodeValue': elementURI(dom)
374
315
  };
375
316
  }
376
-
377
317
  if (rdftype != null) {
378
318
  this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
379
-
380
319
  if (rdftype.nodeName) {
381
320
  dom.removeAttributeNode(rdftype);
382
321
  }
383
- } // Property Attributes
384
-
385
-
322
+ }
323
+ // Property Attributes
386
324
  for (var x = attrs.length - 1; x >= 0; x--) {
387
325
  this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, frame.lang), this.why);
388
326
  }
389
327
  } else {
390
328
  // we should add an arc (or implicit bnode+arc)
391
329
  frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
392
-
393
330
  if (this.reify) {
394
331
  rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
395
-
396
332
  if (rdfid) {
397
333
  frame.rdfid = rdfid.nodeValue;
398
334
  dom.removeAttributeNode(rdfid);
399
335
  }
400
336
  }
401
-
402
337
  var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
403
338
  var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
404
-
405
339
  if (datatype) {
406
340
  frame.datatype = datatype.nodeValue;
407
341
  dom.removeAttributeNode(datatype);
408
342
  }
409
-
410
343
  if (parsetype) {
411
344
  var nv = parsetype.nodeValue;
412
-
413
345
  if (nv === 'Literal') {
414
346
  frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
415
- frame = this.buildFrame(frame); // Don't include the literal node, only its children
416
-
347
+ frame = this.buildFrame(frame);
348
+ // Don't include the literal node, only its children
417
349
  frame.addLiteral(dom.childNodes);
418
350
  dig = false;
419
351
  } else if (nv === 'Resource') {
@@ -425,15 +357,12 @@ var RDFParser = /*#__PURE__*/function () {
425
357
  frame.parent.element = null;
426
358
  frame.addCollection();
427
359
  }
428
-
429
360
  dom.removeAttributeNode(parsetype);
430
361
  }
431
-
432
362
  if (attrs.length !== 0) {
433
363
  var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'resource');
434
364
  var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
435
365
  frame = this.buildFrame(frame);
436
-
437
366
  if (resource) {
438
367
  frame.addNode(resource.nodeValue);
439
368
  dom.removeAttributeNode(resource);
@@ -445,11 +374,9 @@ var RDFParser = /*#__PURE__*/function () {
445
374
  frame.addBNode();
446
375
  }
447
376
  }
448
-
449
377
  for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
450
378
  var f = this.buildFrame(frame);
451
379
  f.addArc(elementURI(attrs[x1]));
452
-
453
380
  if (elementURI(attrs[x1]) === RDFParser.ns.RDF + 'type') {
454
381
  this.buildFrame(f).addNode(attrs[x1].nodeValue);
455
382
  } else {
@@ -462,28 +389,19 @@ var RDFParser = /*#__PURE__*/function () {
462
389
  }
463
390
  } // rdf:RDF
464
391
  // dig dug
465
-
466
-
467
392
  dom = frame.element;
468
-
469
393
  while (frame.parent) {
470
394
  var pframe = frame;
471
-
472
395
  while (dom == null) {
473
396
  frame = frame.parent;
474
397
  dom = frame.element;
475
398
  }
476
-
477
399
  var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
478
-
479
400
  if (!candidate || !dig) {
480
401
  frame.terminateFrame();
481
-
482
402
  if (!(frame = frame.parent)) {
483
403
  break;
484
404
  } // done
485
-
486
-
487
405
  dom = frame.element;
488
406
  dig = true;
489
407
  } else if (candidate.nodeType !== RDFParser.nodeType.ELEMENT && candidate.nodeType !== RDFParser.nodeType.TEXT && candidate.nodeType !== RDFParser.nodeType.CDATA_SECTION || (candidate.nodeType === RDFParser.nodeType.TEXT || candidate.nodeType === RDFParser.nodeType.CDATA_SECTION) && dom.childNodes.length !== 1) {
@@ -496,80 +414,66 @@ var RDFParser = /*#__PURE__*/function () {
496
414
  }
497
415
  }
498
416
  } // while
499
-
500
417
  }
418
+
501
419
  /**
502
420
  * Cleans out state from a previous parse run
503
421
  * @private
504
422
  */
505
-
506
423
  }, {
507
424
  key: "cleanParser",
508
425
  value: function cleanParser() {
509
426
  this.bnodes = {};
510
427
  this.why = null;
511
428
  }
429
+
512
430
  /**
513
431
  * Builds scope frame
514
432
  * @private
515
433
  */
516
-
517
434
  }, {
518
435
  key: "buildFrame",
519
436
  value: function buildFrame(parent, element) {
520
437
  var frame = this.frameFactory(this, parent, element);
521
-
522
438
  if (parent) {
523
439
  frame.base = parent.base;
524
440
  frame.lang = parent.lang;
525
441
  }
526
-
527
442
  if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
528
443
  return frame;
529
444
  }
530
-
531
445
  var attrs = element.attributes;
532
446
  var base = element.getAttributeNode('xml:base');
533
-
534
447
  if (base != null) {
535
448
  frame.base = base.nodeValue;
536
449
  element.removeAttribute('xml:base');
537
450
  }
538
-
539
451
  var lang = element.getAttributeNode('xml:lang');
540
-
541
452
  if (lang != null) {
542
453
  frame.lang = lang.nodeValue;
543
454
  element.removeAttribute('xml:lang');
544
- } // remove all extraneous xml and xmlns attributes
545
-
546
-
455
+ }
456
+ // remove all extraneous xml and xmlns attributes
547
457
  for (var x = attrs.length - 1; x >= 0; x--) {
548
458
  if (attrs[x].nodeName.substr(0, 3) === 'xml') {
549
459
  if (attrs[x].name.slice(0, 6) === 'xmlns:') {
550
460
  var uri = attrs[x].nodeValue; // alert('base for namespac attr:'+this.base)
551
-
552
461
  if (this.base) uri = uriUtil.join(uri, this.base);
553
462
  this.store.setPrefixForURI(attrs[x].name.slice(6), uri);
554
- } // alert('rdfparser: xml atribute: '+attrs[x].name) //@@
555
-
556
-
463
+ }
464
+ // alert('rdfparser: xml atribute: '+attrs[x].name) //@@
557
465
  element.removeAttributeNode(attrs[x]);
558
466
  }
559
467
  }
560
-
561
468
  return frame;
562
469
  }
563
470
  }]);
564
-
565
471
  return RDFParser;
566
472
  }();
567
-
568
473
  _defineProperty(RDFParser, "ns", {
569
474
  'RDF': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
570
475
  'RDFS': 'http://www.w3.org/2000/01/rdf-schema#'
571
476
  });
572
-
573
477
  _defineProperty(RDFParser, "nodeType", {
574
478
  'ELEMENT': 1,
575
479
  'ATTRIBUTE': 2,
@@ -584,5 +488,4 @@ _defineProperty(RDFParser, "nodeType", {
584
488
  'DOCUMENT_FRAGMENT': 11,
585
489
  'NOTATION': 12
586
490
  });
587
-
588
491
  export { RDFParser as default };
package/esm/serialize.js CHANGED
@@ -1,14 +1,10 @@
1
- import * as convert from './convert';
2
1
  import Serializer from './serializer';
3
2
  import { JSONLDContentType, N3ContentType, N3LegacyContentType, NQuadsAltContentType, NQuadsContentType, NTriplesContentType, RDFXMLContentType, TurtleContentType, TurtleLegacyContentType } from './types';
4
-
5
3
  /**
6
4
  * Serialize to the appropriate format
7
5
  */
8
- export default function serialize(
9
- /** The graph or nodes that should be serialized */
10
- target,
11
- /** The store */
6
+ export default function serialize( /** The graph or nodes that should be serialized */
7
+ target, /** The store */
12
8
  kb, base,
13
9
  /**
14
10
  * The mime type.
@@ -18,69 +14,49 @@ contentType, callback, options) {
18
14
  base = base || (target === null || target === void 0 ? void 0 : target.value);
19
15
  var opts = options || {};
20
16
  contentType = contentType || TurtleContentType; // text/n3 if complex?
21
-
22
17
  var documentString = undefined;
23
-
24
18
  try {
25
19
  var sz = Serializer(kb);
26
20
  if (opts.flags) sz.setFlags(opts.flags);
27
21
  var newSts = kb.statementsMatching(undefined, undefined, undefined, target);
28
- var n3String; // If an IndexedFormula, use the namespaces from the given graph as suggestions
29
22
 
23
+ // If an IndexedFormula, use the namespaces from the given graph as suggestions
30
24
  if ('namespaces' in kb) {
31
25
  sz.suggestNamespaces(kb.namespaces);
32
- } // use the provided options.namespaces are mandatory prefixes
33
-
26
+ }
34
27
 
28
+ // use the provided options.namespaces are mandatory prefixes
35
29
  if (opts.namespaces) {
36
30
  sz.setNamespaces(opts.namespaces);
37
31
  }
38
-
39
32
  sz.setBase(base);
40
-
41
33
  switch (contentType) {
42
34
  case RDFXMLContentType:
43
35
  documentString = sz.statementsToXML(newSts);
44
36
  return executeCallback(null, documentString);
45
-
46
37
  case N3ContentType:
47
38
  case N3LegacyContentType:
48
39
  documentString = sz.statementsToN3(newSts);
49
40
  return executeCallback(null, documentString);
50
-
51
41
  case TurtleContentType:
52
42
  case TurtleLegacyContentType:
53
43
  sz.setFlags('si'); // Suppress = for sameAs and => for implies
54
-
55
44
  documentString = sz.statementsToN3(newSts);
56
45
  return executeCallback(null, documentString);
57
-
58
46
  case NTriplesContentType:
59
47
  sz.setFlags('deinprstux'); // Suppress nice parts of N3 to make ntriples
60
-
61
48
  documentString = sz.statementsToNTriples(newSts);
62
49
  return executeCallback(null, documentString);
63
-
64
50
  case JSONLDContentType:
65
- sz.setFlags('deinprstux'); // Use adapters to connect to incmpatible parser
66
-
67
- n3String = sz.statementsToNTriples(newSts); // n3String = sz.statementsToN3(newSts)
68
-
69
- convert.convertToJson(n3String, callback);
70
- break;
71
-
51
+ sz.setFlags('si'); // use turtle parameters
52
+ documentString = sz.statementsToJsonld(newSts); // convert via turtle
53
+ return executeCallback(null, documentString);
72
54
  case NQuadsContentType:
73
55
  case NQuadsAltContentType:
74
56
  // @@@ just outpout the quads? Does not work for collections
75
57
  sz.setFlags('deinprstux q'); // Suppress nice parts of N3 to make ntriples
76
-
77
58
  documentString = sz.statementsToNTriples(newSts); // q in flag means actually quads
78
-
79
59
  return executeCallback(null, documentString);
80
- // n3String = sz.statementsToN3(newSts)
81
- // documentString = convert.convertToNQuads(n3String, callback)
82
- // break
83
-
84
60
  default:
85
61
  throw new Error('Serialize: Content-type ' + contentType + ' not supported for data write.');
86
62
  }
@@ -89,7 +65,6 @@ contentType, callback, options) {
89
65
  // @ts-ignore
90
66
  return callback(err, undefined);
91
67
  }
92
-
93
68
  throw err; // Don't hide problems from caller in sync mode
94
69
  }
95
70