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
package/esm/formula.js CHANGED
@@ -5,17 +5,11 @@ import _inherits from "@babel/runtime/helpers/inherits";
5
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
6
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
-
9
8
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
-
11
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
-
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
11
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
16
-
17
12
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
-
19
13
  import ClassOrder from './class-order';
20
14
  import Collection from './collection';
21
15
  import CanonicalDataFactory from './factories/canonical-data-factory';
@@ -28,15 +22,12 @@ import { isStatement } from './utils/terms';
28
22
  import Variable from './variable';
29
23
  import { appliedFactoryMethods, arrayToStatements } from './utils';
30
24
  import NamedNode from './named-node';
31
-
32
25
  /**
33
26
  * A formula, or store of RDF statements
34
27
  */
35
28
  var Formula = /*#__PURE__*/function (_Node) {
36
29
  _inherits(Formula, _Node);
37
-
38
30
  var _super = _createSuper(Formula);
39
-
40
31
  /**
41
32
  * The accompanying fetcher instance.
42
33
  *
@@ -62,49 +53,35 @@ var Formula = /*#__PURE__*/function (_Node) {
62
53
  */
63
54
  function Formula() {
64
55
  var _this;
65
-
66
56
  var statements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
67
57
  var constraints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
68
58
  var initBindings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
69
59
  var optional = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
70
60
  var opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
71
-
72
61
  _classCallCheck(this, Formula);
73
-
74
62
  _this = _super.call(this, '');
75
63
  _this.statements = statements;
76
64
  _this.constraints = constraints;
77
65
  _this.initBindings = initBindings;
78
66
  _this.optional = optional;
79
-
80
67
  _defineProperty(_assertThisInitialized(_this), "termType", GraphTermType);
81
-
82
68
  _defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.Graph);
83
-
84
69
  _defineProperty(_assertThisInitialized(_this), "fetcher", void 0);
85
-
86
70
  _defineProperty(_assertThisInitialized(_this), "isVar", 0);
87
-
88
71
  _defineProperty(_assertThisInitialized(_this), "ns", Namespace);
89
-
90
72
  _defineProperty(_assertThisInitialized(_this), "rdfFactory", void 0);
91
-
92
- _this.rdfFactory = opts && opts.rdfFactory || CanonicalDataFactory; // Enable default factory methods on this while preserving factory context.
93
-
73
+ _this.rdfFactory = opts && opts.rdfFactory || CanonicalDataFactory;
74
+ // Enable default factory methods on this while preserving factory context.
94
75
  var _iterator = _createForOfIteratorHelper(appliedFactoryMethods),
95
- _step;
96
-
76
+ _step;
97
77
  try {
98
78
  var _loop = function _loop() {
99
79
  var factoryMethod = _step.value;
100
-
101
80
  _this[factoryMethod] = function () {
102
81
  var _this$rdfFactory;
103
-
104
82
  return (_this$rdfFactory = _this.rdfFactory)[factoryMethod].apply(_this$rdfFactory, arguments);
105
83
  };
106
84
  };
107
-
108
85
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
109
86
  _loop();
110
87
  }
@@ -113,63 +90,59 @@ var Formula = /*#__PURE__*/function (_Node) {
113
90
  } finally {
114
91
  _iterator.f();
115
92
  }
116
-
117
93
  return _this;
118
94
  }
95
+
119
96
  /** Add a statement from its parts
120
97
  * @param subject - the first part of the statement
121
98
  * @param predicate - the second part of the statement
122
99
  * @param object - the third part of the statement
123
100
  * @param graph - the last part of the statement
124
101
  */
125
-
126
-
127
102
  _createClass(Formula, [{
128
103
  key: "add",
129
104
  value: function add(subject, predicate, object, graph) {
130
105
  var _this2 = this;
131
-
132
106
  if (arguments.length === 1) {
133
107
  subject.forEach(function (st) {
134
108
  return _this2.add(st.subject, st.predicate, st.object, st.graph);
135
109
  });
136
110
  }
137
-
138
111
  return this.statements.push(this.rdfFactory.quad(subject, predicate, object, graph));
139
112
  }
113
+
140
114
  /** Add a statment object
141
115
  * @param {Statement} statement - An existing constructed statement to add
142
116
  */
143
-
144
117
  }, {
145
118
  key: "addStatement",
146
119
  value: function addStatement(statement) {
147
120
  return this.add(statement);
148
121
  }
122
+
149
123
  /**
150
124
  * Shortcut for adding blankNodes
151
125
  * @param [id]
152
126
  */
153
-
154
127
  }, {
155
128
  key: "bnode",
156
129
  value: function bnode(id) {
157
130
  return this.rdfFactory.blankNode(id);
158
131
  }
132
+
159
133
  /**
160
134
  * Adds all the statements to this formula
161
135
  * @param statements - A collection of statements
162
136
  */
163
-
164
137
  }, {
165
138
  key: "addAll",
166
139
  value: function addAll(statements) {
167
140
  var _this3 = this;
168
-
169
141
  statements.forEach(function (quad) {
170
142
  _this3.add(quad.subject, quad.predicate, quad.object, quad.graph);
171
143
  });
172
144
  }
145
+
173
146
  /** Follow link from one node, using one wildcard, looking for one
174
147
  *
175
148
  * For example, any(me, knows, null, profile) - a person I know accoring to my profile .
@@ -182,12 +155,10 @@ var Formula = /*#__PURE__*/function (_Node) {
182
155
  * @param g - A node to search for as graph, or if null, a wildcard
183
156
  * @returns A node which match the wildcard position, or null
184
157
  */
185
-
186
158
  }, {
187
159
  key: "any",
188
160
  value: function any(s, p, o, g) {
189
161
  var st = this.anyStatementMatching(s, p, o, g);
190
-
191
162
  if (st == null) {
192
163
  return null;
193
164
  } else if (s == null) {
@@ -197,9 +168,9 @@ var Formula = /*#__PURE__*/function (_Node) {
197
168
  } else if (o == null) {
198
169
  return st.object;
199
170
  }
200
-
201
171
  return null;
202
172
  }
173
+
203
174
  /**
204
175
  * Gets the value of a node that matches the specified pattern
205
176
  * @param s The subject
@@ -207,13 +178,13 @@ var Formula = /*#__PURE__*/function (_Node) {
207
178
  * @param o The object
208
179
  * @param g The graph that contains the statement
209
180
  */
210
-
211
181
  }, {
212
182
  key: "anyValue",
213
183
  value: function anyValue(s, p, o, g) {
214
184
  var y = this.any(s, p, o, g);
215
185
  return y ? y.value : void 0;
216
186
  }
187
+
217
188
  /**
218
189
  * Gets the first JavaScript object equivalent to a node based on the specified pattern
219
190
  * @param s The subject
@@ -221,39 +192,37 @@ var Formula = /*#__PURE__*/function (_Node) {
221
192
  * @param o The object
222
193
  * @param g The graph that contains the statement
223
194
  */
224
-
225
195
  }, {
226
196
  key: "anyJS",
227
197
  value: function anyJS(s, p, o, g) {
228
198
  var y = this.any(s, p, o, g);
229
199
  return y ? Node.toJS(y) : void 0;
230
200
  }
201
+
231
202
  /**
232
203
  * Gets the first statement that matches the specified pattern
233
204
  */
234
-
235
205
  }, {
236
206
  key: "anyStatementMatching",
237
207
  value: function anyStatementMatching(s, p, o, g) {
238
208
  var x = this.statementsMatching(s, p, o, g, true);
239
-
240
209
  if (!x || x.length === 0) {
241
210
  return undefined;
242
211
  }
243
-
244
212
  return x[0];
245
213
  }
214
+
246
215
  /**
247
216
  * Returns a unique index-safe identifier for the given term.
248
217
  *
249
218
  * Falls back to the rdflib hashString implementation if the given factory doesn't support id.
250
219
  */
251
-
252
220
  }, {
253
221
  key: "id",
254
222
  value: function id(term) {
255
223
  return this.rdfFactory.id(term);
256
224
  }
225
+
257
226
  /**
258
227
  * Search the Store
259
228
  * This is really a teaching method as to do this properly you would use IndexedFormula
@@ -265,20 +234,18 @@ var Formula = /*#__PURE__*/function (_Node) {
265
234
  * @param justOne - flag - stop when found one rather than get all of them?
266
235
  * @returns {Array<Node>} - An array of nodes which match the wildcard position
267
236
  */
268
-
269
237
  }, {
270
238
  key: "statementsMatching",
271
239
  value: function statementsMatching(s, p, o, g, justOne) {
272
240
  var sts = this.statements.filter(function (st) {
273
241
  return (!s || s.equals(st.subject)) && (!p || p.equals(st.predicate)) && (!o || o.equals(st.object)) && (!g || g.equals(st.graph));
274
242
  });
275
-
276
243
  if (justOne) {
277
244
  return sts.length === 0 ? [] : [sts[0]];
278
245
  }
279
-
280
246
  return sts;
281
247
  }
248
+
282
249
  /**
283
250
  * Finds the types in the list which have no *stored* subtypes
284
251
  * These are a set of classes which provide by themselves complete
@@ -286,7 +253,6 @@ var Formula = /*#__PURE__*/function (_Node) {
286
253
  * know the class DAG.
287
254
  * @param types A map of the types
288
255
  */
289
-
290
256
  }, {
291
257
  key: "bottomTypeURIs",
292
258
  value: function bottomTypeURIs(types) {
@@ -299,39 +265,35 @@ var Formula = /*#__PURE__*/function (_Node) {
299
265
  var subs;
300
266
  var v;
301
267
  bots = [];
302
-
303
268
  for (var _k in types) {
304
269
  if (!types.hasOwnProperty(_k)) continue;
305
270
  v = types[_k];
306
271
  subs = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), this.rdfFactory.namedNode(_k));
307
272
  bottom = true;
308
273
  i = 0;
309
-
310
274
  for (len = subs.length; i < len; i++) {
311
275
  elt = subs[i];
312
276
  ref = elt.uri;
313
-
314
277
  if (ref in types) {
315
278
  // the subclass is one we know
316
279
  bottom = false;
317
280
  break;
318
281
  }
319
282
  }
320
-
321
283
  if (bottom) {
322
284
  bots[_k] = v;
323
285
  }
324
286
  }
325
-
326
287
  return bots;
327
288
  }
328
- /** Creates a new collection */
329
289
 
290
+ /** Creates a new collection */
330
291
  }, {
331
292
  key: "collection",
332
293
  value: function collection() {
333
294
  return new Collection();
334
295
  }
296
+
335
297
  /** Follow links from one node, using one wildcard.
336
298
  *
337
299
  * For example, each(me, knows, null, profile) - people I know accoring to my profile .
@@ -344,13 +306,11 @@ var Formula = /*#__PURE__*/function (_Node) {
344
306
  * @param g - A node to search for as graph, or if null, a wildcard
345
307
  * @returns {Array<Node>} - An array of nodes which match the wildcard position
346
308
  */
347
-
348
309
  }, {
349
310
  key: "each",
350
311
  value: function each(s, p, o, g) {
351
312
  var results = [];
352
313
  var sts = this.statementsMatching(s, p, o, g, false);
353
-
354
314
  if (s == null) {
355
315
  for (var i = 0, len = sts.length; i < len; i++) {
356
316
  results.push(sts[i].subject);
@@ -368,23 +328,22 @@ var Formula = /*#__PURE__*/function (_Node) {
368
328
  results.push(new NamedNode(sts[_q].graph.value));
369
329
  }
370
330
  }
371
-
372
331
  return results;
373
332
  }
333
+
374
334
  /**
375
335
  * Test whether this formula is equals to {other}
376
336
  * @param other - The other formula
377
337
  */
378
-
379
338
  }, {
380
339
  key: "equals",
381
340
  value: function equals(other) {
382
341
  if (!other) {
383
342
  return false;
384
343
  }
385
-
386
344
  return this.hashString() === other.hashString();
387
345
  }
346
+
388
347
  /**
389
348
  * For thisClass or any subclass, anything which has it is its type
390
349
  * or is the object of something which has the type as its range, or subject
@@ -394,7 +353,6 @@ var Formula = /*#__PURE__*/function (_Node) {
394
353
  * Get all the Classes of which we can RDFS-infer the subject is a member
395
354
  * @return a hash of URIs
396
355
  */
397
-
398
356
  }, {
399
357
  key: "findMembersNT",
400
358
  value: function findMembersNT(thisClass) {
@@ -416,43 +374,35 @@ var Formula = /*#__PURE__*/function (_Node) {
416
374
  seeds[thisClass.toNT()] = true;
417
375
  members = {};
418
376
  ref = this.transitiveClosure(seeds, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
419
-
420
377
  for (var t in ref) {
421
378
  if (!ref.hasOwnProperty(t)) continue;
422
379
  ref1 = this.statementsMatching(void 0, this.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), this.fromNT(t));
423
-
424
380
  for (var i = 0, len = ref1.length; i < len; i++) {
425
381
  st = ref1[i];
426
382
  members[st.subject.toNT()] = st;
427
383
  }
428
-
429
384
  ref2 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#domain'), this.fromNT(t));
430
-
431
385
  for (var l = 0, len1 = ref2.length; l < len1; l++) {
432
386
  pred = ref2[l];
433
387
  ref3 = this.statementsMatching(void 0, pred);
434
-
435
388
  for (m = 0, len2 = ref3.length; m < len2; m++) {
436
389
  st = ref3[m];
437
390
  members[st.subject.toNT()] = st;
438
391
  }
439
392
  }
440
-
441
393
  ref4 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#range'), this.fromNT(t));
442
-
443
394
  for (var _q2 = 0, len3 = ref4.length; _q2 < len3; _q2++) {
444
395
  pred = ref4[_q2];
445
396
  ref5 = this.statementsMatching(void 0, pred);
446
-
447
397
  for (u = 0, len4 = ref5.length; u < len4; u++) {
448
398
  st = ref5[u];
449
399
  members[st.object.toNT()] = st;
450
400
  }
451
401
  }
452
402
  }
453
-
454
403
  return members;
455
404
  }
405
+
456
406
  /**
457
407
  * For thisClass or any subclass, anything which has it is its type
458
408
  * or is the object of something which has the type as its range, or subject
@@ -462,12 +412,12 @@ var Formula = /*#__PURE__*/function (_Node) {
462
412
  * Get all the Classes of which we can RDFS-infer the subject is a member
463
413
  * @param subject - A named node
464
414
  */
465
-
466
415
  }, {
467
416
  key: "findMemberURIs",
468
417
  value: function findMemberURIs(subject) {
469
418
  return this.NTtoURI(this.findMembersNT(subject));
470
419
  }
420
+
471
421
  /**
472
422
  * Get all the Classes of which we can RDFS-infer the subject is a superclass
473
423
  * Returns a hash table where key is NT of type and value is statement why we
@@ -475,7 +425,6 @@ var Formula = /*#__PURE__*/function (_Node) {
475
425
  * Does NOT return terms, returns URI strings.
476
426
  * We use NT representations in this version because they handle blank nodes.
477
427
  */
478
-
479
428
  }, {
480
429
  key: "findSubClassesNT",
481
430
  value: function findSubClassesNT(subject) {
@@ -483,6 +432,7 @@ var Formula = /*#__PURE__*/function (_Node) {
483
432
  types[subject.toNT()] = true;
484
433
  return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
485
434
  }
435
+
486
436
  /**
487
437
  * Get all the Classes of which we can RDFS-infer the subject is a subclass
488
438
  * @param {RDFlibNamedNode} subject - The thing whose classes are to be found
@@ -491,7 +441,6 @@ var Formula = /*#__PURE__*/function (_Node) {
491
441
  * Does NOT return terms, returns URI strings.
492
442
  * We use NT representations in this version because they handle blank nodes.
493
443
  */
494
-
495
444
  }, {
496
445
  key: "findSuperClassesNT",
497
446
  value: function findSuperClassesNT(subject) {
@@ -499,6 +448,7 @@ var Formula = /*#__PURE__*/function (_Node) {
499
448
  types[subject.toNT()] = true;
500
449
  return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
501
450
  }
451
+
502
452
  /**
503
453
  * Get all the Classes of which we can RDFS-infer the subject is a member
504
454
  * todo: This will loop is there is a class subclass loop (Sublass loops are
@@ -508,7 +458,6 @@ var Formula = /*#__PURE__*/function (_Node) {
508
458
  * Does NOT return terms, returns URI strings.
509
459
  * We use NT representations in this version because they handle blank nodes.
510
460
  */
511
-
512
461
  }, {
513
462
  key: "findTypesNT",
514
463
  value: function findTypesNT(subject) {
@@ -524,36 +473,30 @@ var Formula = /*#__PURE__*/function (_Node) {
524
473
  rdftype = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
525
474
  types = [];
526
475
  ref = this.statementsMatching(subject, void 0, void 0);
527
-
528
476
  for (var i = 0, len = ref.length; i < len; i++) {
529
477
  st = ref[i];
530
-
531
478
  if (st.predicate.uri === rdftype) {
532
479
  types[st.object.toNT()] = st;
533
480
  } else {
534
481
  ref1 = this.each(st.predicate, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#domain'));
535
-
536
482
  for (var l = 0, len1 = ref1.length; l < len1; l++) {
537
483
  range = ref1[l];
538
484
  types[range.toNT()] = st;
539
485
  }
540
486
  }
541
487
  }
542
-
543
488
  ref2 = this.statementsMatching(void 0, void 0, subject);
544
-
545
489
  for (var m = 0, len2 = ref2.length; m < len2; m++) {
546
490
  st = ref2[m];
547
491
  ref3 = this.each(st.predicate, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#range'));
548
-
549
492
  for (var _q3 = 0, len3 = ref3.length; _q3 < len3; _q3++) {
550
493
  domain = ref3[_q3];
551
494
  types[domain.toNT()] = st;
552
495
  }
553
496
  }
554
-
555
497
  return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
556
498
  }
499
+
557
500
  /**
558
501
  * Get all the Classes of which we can RDFS-infer the subject is a member
559
502
  * todo: This will loop is there is a class subclass loop (Sublass loops are
@@ -564,19 +507,18 @@ var Formula = /*#__PURE__*/function (_Node) {
564
507
  * We use NT representations in this version because they handle blank nodes.
565
508
  * @param subject - A subject node
566
509
  */
567
-
568
510
  }, {
569
511
  key: "findTypeURIs",
570
512
  value: function findTypeURIs(subject) {
571
513
  return this.NTtoURI(this.findTypesNT(subject));
572
514
  }
515
+
573
516
  /** Trace statements which connect directly, or through bnodes
574
517
  *
575
518
  * @param subject - The node to start looking for statments
576
519
  * @param doc - The document to be searched, or null to search all documents
577
520
  * @returns an array of statements, duplicate statements are suppresssed.
578
521
  */
579
-
580
522
  }, {
581
523
  key: "connectedStatements",
582
524
  value: function connectedStatements(subject, doc, excludePredicateURIs) {
@@ -586,7 +528,6 @@ var Formula = /*#__PURE__*/function (_Node) {
586
528
  var doneArcs = {};
587
529
  var result = [];
588
530
  var self = this;
589
-
590
531
  var follow = function follow(x) {
591
532
  var queue = function queue(x) {
592
533
  if (x.termType === 'BlankNode' && !done[x.value]) {
@@ -594,7 +535,6 @@ var Formula = /*#__PURE__*/function (_Node) {
594
535
  todo.push(x);
595
536
  }
596
537
  };
597
-
598
538
  var sts = self.statementsMatching(null, null, x, doc).concat(self.statementsMatching(x, null, null, doc));
599
539
  sts = sts.filter(function (st) {
600
540
  if (excludePredicateURIs[st.predicate.value]) return false;
@@ -609,46 +549,41 @@ var Formula = /*#__PURE__*/function (_Node) {
609
549
  });
610
550
  result = result.concat(sts);
611
551
  };
612
-
613
552
  while (todo.length) {
614
553
  follow(todo.shift());
615
- } // console.log('' + result.length + ' statements about ' + subject)
616
-
617
-
554
+ }
555
+ // console.log('' + result.length + ' statements about ' + subject)
618
556
  return result;
619
557
  }
558
+
620
559
  /**
621
560
  * Creates a new empty formula
622
561
  *
623
562
  * @param _features - Not applicable, but necessary for typing to pass
624
563
  */
625
-
626
564
  }, {
627
565
  key: "formula",
628
566
  value: function formula(_features) {
629
567
  return new Formula();
630
568
  }
569
+
631
570
  /**
632
571
  * Transforms an NTriples string format into a Node.
633
572
  * The blank node bit should not be used on program-external values; designed
634
573
  * for internal work such as storing a blank node id in an HTML attribute.
635
574
  * This will only parse the strings generated by the various toNT() methods.
636
575
  */
637
-
638
576
  }, {
639
577
  key: "fromNT",
640
578
  value: function fromNT(str) {
641
579
  var dt, k, lang;
642
-
643
580
  switch (str[0]) {
644
581
  case '<':
645
582
  return this.sym(str.slice(1, -1));
646
-
647
583
  case '"':
648
584
  lang = void 0;
649
585
  dt = void 0;
650
586
  k = str.lastIndexOf('"');
651
-
652
587
  if (k < str.length - 1) {
653
588
  if (str[k + 1] === '@') {
654
589
  lang = str.slice(k + 2);
@@ -658,41 +593,34 @@ var Formula = /*#__PURE__*/function (_Node) {
658
593
  throw new Error("Can't convert string from NT: " + str);
659
594
  }
660
595
  }
661
-
662
596
  str = str.slice(1, k);
663
597
  str = str.replace(/\\"/g, '"');
664
598
  str = str.replace(/\\n/g, '\n');
665
599
  str = str.replace(/\\\\/g, '\\');
666
600
  return this.rdfFactory.literal(str, lang || dt);
667
-
668
601
  case '_':
669
602
  return this.rdfFactory.blankNode(str.slice(2));
670
-
671
603
  case '?':
672
604
  return new Variable(str.slice(1));
673
605
  }
674
-
675
606
  throw new Error("Can't convert from NT: " + str);
676
607
  }
677
- /** Returns true if this formula holds the specified statement(s) */
678
608
 
609
+ /** Returns true if this formula holds the specified statement(s) */
679
610
  }, {
680
611
  key: "holds",
681
612
  value: function holds(s, p, o, g) {
682
613
  var i;
683
-
684
614
  if (arguments.length === 1) {
685
615
  if (!s) {
686
616
  return true;
687
617
  }
688
-
689
618
  if (s instanceof Array) {
690
619
  for (i = 0; i < s.length; i++) {
691
620
  if (!this.holds(s[i])) {
692
621
  return false;
693
622
  }
694
623
  }
695
-
696
624
  return true;
697
625
  } else if (isStatement(s)) {
698
626
  return this.holds(s.subject, s.predicate, s.object, s.graph);
@@ -700,26 +628,25 @@ var Formula = /*#__PURE__*/function (_Node) {
700
628
  return this.holds(s.statements);
701
629
  }
702
630
  }
703
-
704
631
  var st = this.anyStatementMatching(s, p, o, g);
705
632
  return st != null;
706
633
  }
634
+
707
635
  /**
708
636
  * Returns true if this formula holds the specified {statement}
709
637
  */
710
-
711
638
  }, {
712
639
  key: "holdsStatement",
713
640
  value: function holdsStatement(statement) {
714
641
  return this.holds(statement.subject, statement.predicate, statement.object, statement.graph);
715
642
  }
643
+
716
644
  /**
717
645
  * Used by the n3parser to generate list elements
718
646
  * @param values - The values of the collection
719
647
  * @param context - The store
720
648
  * @return {BlankNode|Collection} - The term for the statement
721
649
  */
722
-
723
650
  }, {
724
651
  key: "list",
725
652
  value: function list(values, context) {
@@ -731,37 +658,33 @@ var Formula = /*#__PURE__*/function (_Node) {
731
658
  return collection;
732
659
  } else {
733
660
  var node = context.rdfFactory.blankNode();
734
-
735
- var _statements = arrayToStatements(context.rdfFactory, node, values);
736
-
737
- context.addAll(_statements);
661
+ var statements = arrayToStatements(context.rdfFactory, node, values);
662
+ context.addAll(statements);
738
663
  return node;
739
664
  }
740
665
  }
666
+
741
667
  /**
742
668
  * Transform a collection of NTriple URIs into their URI strings
743
669
  * @param t - Some iterable collection of NTriple URI strings
744
670
  * @return A collection of the URIs as strings
745
671
  * todo: explain why it is important to go through NT
746
672
  */
747
-
748
673
  }, {
749
674
  key: "NTtoURI",
750
675
  value: function NTtoURI(t) {
751
676
  var k, v;
752
677
  var uris = {};
753
-
754
678
  for (k in t) {
755
679
  if (!t.hasOwnProperty(k)) continue;
756
680
  v = t[k];
757
-
758
681
  if (k[0] === '<') {
759
682
  uris[k.slice(1, -1)] = v;
760
683
  }
761
684
  }
762
-
763
685
  return uris;
764
686
  }
687
+
765
688
  /**
766
689
  * Serializes this formula
767
690
  * @param base - The base string
@@ -769,18 +692,17 @@ var Formula = /*#__PURE__*/function (_Node) {
769
692
  * @param provenance - The provenance URI
770
693
  * @param options - options to pass to the serializer, as defined in serialize method
771
694
  */
772
-
773
695
  }, {
774
696
  key: "serialize",
775
697
  value: function serialize(base, contentType, provenance, options) {
776
698
  // delegate the graph serialization to the implementation in ./serialize
777
699
  return _serialize(provenance, this, base, contentType, undefined, options);
778
700
  }
701
+
779
702
  /**
780
703
  * Creates a new formula with the substituting bindings applied
781
704
  * @param bindings - The bindings to substitute
782
705
  */
783
-
784
706
  }, {
785
707
  key: "substitute",
786
708
  value: function substitute(bindings) {
@@ -799,9 +721,9 @@ var Formula = /*#__PURE__*/function (_Node) {
799
721
  if (name) {
800
722
  throw new Error('This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings.');
801
723
  }
802
-
803
724
  return this.rdfFactory.namedNode(uri);
804
725
  }
726
+
805
727
  /**
806
728
  * Gets the node matching the specified pattern. Throws when no match could be made.
807
729
  * @param s - The subject
@@ -809,18 +731,16 @@ var Formula = /*#__PURE__*/function (_Node) {
809
731
  * @param o - The object
810
732
  * @param g - The graph that contains the statement
811
733
  */
812
-
813
734
  }, {
814
735
  key: "the",
815
736
  value: function the(s, p, o, g) {
816
737
  var x = this.any(s, p, o, g);
817
-
818
738
  if (x == null) {
819
739
  log.error('No value found for the() {' + s + ' ' + p + ' ' + o + '}.');
820
740
  }
821
-
822
741
  return x;
823
742
  }
743
+
824
744
  /**
825
745
  * RDFS Inference
826
746
  * These are hand-written implementations of a backward-chaining reasoner
@@ -829,16 +749,13 @@ var Formula = /*#__PURE__*/function (_Node) {
829
749
  * @param predicate - The property to trace though
830
750
  * @param inverse - Trace inverse direction
831
751
  */
832
-
833
752
  }, {
834
753
  key: "transitiveClosure",
835
754
  value: function transitiveClosure(seeds, predicate, inverse) {
836
755
  var elt, i, len, s, sups, t;
837
756
  var agenda = {};
838
757
  Object.assign(agenda, seeds); // make a copy
839
-
840
758
  var done = {}; // classes we have looked up
841
-
842
759
  while (true) {
843
760
  t = function () {
844
761
  for (var p in agenda) {
@@ -846,39 +763,32 @@ var Formula = /*#__PURE__*/function (_Node) {
846
763
  return p;
847
764
  }
848
765
  }();
849
-
850
766
  if (t == null) {
851
767
  return done;
852
768
  }
853
-
854
769
  sups = inverse ? this.each(void 0, predicate, this.fromNT(t)) : this.each(this.fromNT(t), predicate);
855
-
856
770
  for (i = 0, len = sups.length; i < len; i++) {
857
771
  elt = sups[i];
858
772
  s = elt.toNT();
859
-
860
773
  if (s in done) {
861
774
  continue;
862
775
  }
863
-
864
776
  if (s in agenda) {
865
777
  continue;
866
778
  }
867
-
868
779
  agenda[s] = agenda[t];
869
780
  }
870
-
871
781
  done[t] = agenda[t];
872
782
  delete agenda[t];
873
783
  }
874
784
  }
785
+
875
786
  /**
876
787
  * Finds the types in the list which have no *stored* supertypes
877
788
  * We exclude the universal class, owl:Things and rdf:Resource, as it is
878
789
  * information-free.
879
790
  * @param types - The types
880
791
  */
881
-
882
792
  }, {
883
793
  key: "topTypeURIs",
884
794
  value: function topTypeURIs(types) {
@@ -891,56 +801,50 @@ var Formula = /*#__PURE__*/function (_Node) {
891
801
  var tops;
892
802
  var v;
893
803
  tops = [];
894
-
895
804
  for (k in types) {
896
805
  if (!types.hasOwnProperty(k)) continue;
897
806
  v = types[k];
898
807
  n = 0;
899
808
  ref = this.each(this.rdfFactory.namedNode(k), this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'));
900
-
901
809
  for (i = 0, len = ref.length; i < len; i++) {
902
810
  j = ref[i];
903
-
904
811
  if (j.uri !== 'http://www.w3.org/2000/01/rdf-schema#Resource') {
905
812
  n++;
906
813
  break;
907
814
  }
908
815
  }
909
-
910
816
  if (!n) {
911
817
  tops[k] = v;
912
818
  }
913
819
  }
914
-
915
820
  if (tops['http://www.w3.org/2000/01/rdf-schema#Resource']) {
916
821
  delete tops['http://www.w3.org/2000/01/rdf-schema#Resource'];
917
822
  }
918
-
919
823
  if (tops['http://www.w3.org/2002/07/owl#Thing']) {
920
824
  delete tops['http://www.w3.org/2002/07/owl#Thing'];
921
825
  }
922
-
923
826
  return tops;
924
827
  }
828
+
925
829
  /**
926
830
  * Serializes this formula to a string
927
831
  */
928
-
929
832
  }, {
930
833
  key: "toString",
931
834
  value: function toString() {
932
835
  return '{' + this.statements.join('\n') + '}';
933
836
  }
837
+
934
838
  /**
935
839
  * Gets a new variable
936
840
  * @param name - The variable's name
937
841
  */
938
-
939
842
  }, {
940
843
  key: "variable",
941
844
  value: function variable(name) {
942
845
  return new Variable(name);
943
846
  }
847
+
944
848
  /**
945
849
  * Gets the number of statements in this formula that matches the specified pattern
946
850
  * @param s - The subject
@@ -948,15 +852,12 @@ var Formula = /*#__PURE__*/function (_Node) {
948
852
  * @param o - The object
949
853
  * @param g - The graph that contains the statement
950
854
  */
951
-
952
855
  }, {
953
856
  key: "whether",
954
857
  value: function whether(s, p, o, g) {
955
858
  return this.statementsMatching(s, p, o, g, false).length;
956
859
  }
957
860
  }]);
958
-
959
861
  return Formula;
960
862
  }(Node);
961
-
962
863
  export { Formula as default };