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/store.js CHANGED
@@ -5,21 +5,13 @@ 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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
-
11
9
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
-
13
10
  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; } } }; }
14
-
15
11
  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); }
16
-
17
- 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; }
18
-
12
+ 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; }
19
13
  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); }; }
20
-
21
14
  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; } }
22
-
23
15
  /* Identity management and indexing for RDF
24
16
  *
25
17
  * This file provides IndexedFormula a formula (set of triples) which
@@ -38,13 +30,16 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
38
30
  */
39
31
 
40
32
  /** @module store */
33
+
41
34
  import ClassOrder from './class-order';
42
35
  import { defaultGraphURI } from './factories/canonical-data-factory';
43
36
  import Formula from './formula';
44
37
  import { ArrayIndexOf } from './utils';
45
38
  import { RDFArrayRemove } from './utils-js';
46
- import { isRDFlibSubject, isRDFlibPredicate, isRDFlibObject, isStore, isGraph, // isPredicate,
47
- isQuad // isSubject
39
+ import { isRDFlibSubject, isRDFlibPredicate, isRDFlibObject, isStore, isGraph,
40
+ // isPredicate,
41
+ isQuad
42
+ // isSubject
48
43
  } from './utils/terms';
49
44
  import Node from './node';
50
45
  import Variable from './variable';
@@ -57,65 +52,53 @@ import BlankNode from './blank-node';
57
52
  import DefaultGraph from './default-graph';
58
53
  import Literal from './literal';
59
54
  var owlNamespaceURI = 'http://www.w3.org/2002/07/owl#';
60
- export { defaultGraphURI }; // var link_ns = 'http://www.w3.org/2007/ont/link#'
61
- // Handle Functional Property
55
+ export { defaultGraphURI };
56
+ // var link_ns = 'http://www.w3.org/2007/ont/link#'
62
57
 
58
+ // Handle Functional Property
63
59
  function handleFP(formula, subj, pred, obj) {
64
60
  var o1 = formula.any(subj, pred, undefined);
65
-
66
61
  if (!o1) {
67
62
  return false; // First time with this value
68
- } // log.warn("Equating "+o1.uri+" and "+obj.uri + " because FP "+pred.uri); //@@
69
-
70
-
63
+ }
64
+ // log.warn("Equating "+o1.uri+" and "+obj.uri + " because FP "+pred.uri); //@@
71
65
  formula.equate(o1, obj);
72
66
  return true;
73
67
  } // handleFP
74
- // Handle Inverse Functional Property
75
-
76
68
 
69
+ // Handle Inverse Functional Property
77
70
  function handleIFP(formula, subj, pred, obj) {
78
71
  var s1 = formula.any(undefined, pred, obj);
79
-
80
72
  if (!s1) {
81
73
  return false; // First time with this value
82
- } // log.warn("Equating "+s1.uri+" and "+subj.uri + " because IFP "+pred.uri); //@@
83
-
84
-
74
+ }
75
+ // log.warn("Equating "+s1.uri+" and "+subj.uri + " because IFP "+pred.uri); //@@
85
76
  formula.equate(s1, subj);
86
77
  return true;
87
78
  } // handleIFP
88
79
 
89
-
90
80
  function handleRDFType(formula, subj, pred, obj, why) {
91
81
  //@ts-ignore this method does not seem to exist in this library
92
82
  if (formula.typeCallback) {
93
83
  formula.typeCallback(formula, obj, why);
94
84
  }
95
-
96
85
  var x = formula.classActions[formula.id(obj)];
97
86
  var done = false;
98
-
99
87
  if (x) {
100
88
  for (var i = 0; i < x.length; i++) {
101
89
  done = done || x[i](formula, subj, pred, obj, why);
102
90
  }
103
91
  }
104
-
105
92
  return done; // statement given is not needed if true
106
93
  }
94
+
107
95
  /**
108
96
  * Indexed Formula aka Store
109
97
  */
110
-
111
-
112
98
  var IndexedFormula = /*#__PURE__*/function (_Formula) {
113
99
  _inherits(IndexedFormula, _Formula);
114
-
115
100
  var _super = _createSuper(IndexedFormula);
116
-
117
101
  // IN future - allow pass array of statements to constructor
118
-
119
102
  /**
120
103
  * An UpdateManager initialised to this store
121
104
  */
@@ -157,47 +140,26 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
157
140
  */
158
141
  function IndexedFormula(features) {
159
142
  var _this;
160
-
161
143
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
162
-
163
144
  _classCallCheck(this, IndexedFormula);
164
-
165
145
  _this = _super.call(this, undefined, undefined, undefined, undefined, opts);
166
-
167
146
  _defineProperty(_assertThisInitialized(_this), "updater", void 0);
168
-
169
147
  _defineProperty(_assertThisInitialized(_this), "namespaces", void 0);
170
-
171
148
  _defineProperty(_assertThisInitialized(_this), "classActions", void 0);
172
-
173
149
  _defineProperty(_assertThisInitialized(_this), "propertyActions", void 0);
174
-
175
150
  _defineProperty(_assertThisInitialized(_this), "redirections", void 0);
176
-
177
151
  _defineProperty(_assertThisInitialized(_this), "aliases", void 0);
178
-
179
152
  _defineProperty(_assertThisInitialized(_this), "HTTPRedirects", void 0);
180
-
181
153
  _defineProperty(_assertThisInitialized(_this), "subjectIndex", void 0);
182
-
183
154
  _defineProperty(_assertThisInitialized(_this), "predicateIndex", void 0);
184
-
185
155
  _defineProperty(_assertThisInitialized(_this), "objectIndex", void 0);
186
-
187
156
  _defineProperty(_assertThisInitialized(_this), "whyIndex", void 0);
188
-
189
157
  _defineProperty(_assertThisInitialized(_this), "index", void 0);
190
-
191
158
  _defineProperty(_assertThisInitialized(_this), "features", void 0);
192
-
193
159
  _defineProperty(_assertThisInitialized(_this), "_universalVariables", void 0);
194
-
195
160
  _defineProperty(_assertThisInitialized(_this), "_existentialVariables", void 0);
196
-
197
161
  _defineProperty(_assertThisInitialized(_this), "rdfArrayRemove", void 0);
198
-
199
162
  _defineProperty(_assertThisInitialized(_this), "dataCallbacks", void 0);
200
-
201
163
  _this.propertyActions = {};
202
164
  _this.classActions = {};
203
165
  _this.redirections = [];
@@ -209,7 +171,6 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
209
171
  _this.whyIndex = [];
210
172
  _this.index = [_this.subjectIndex, _this.predicateIndex, _this.objectIndex, _this.whyIndex];
211
173
  _this.namespaces = {}; // Dictionary of namespace prefixes
212
-
213
174
  _this.features = features || [// By default, devs do not expect these features.
214
175
  // See https://github.com/linkeddata/rdflib.js/issues/458
215
176
  // 'sameAs',
@@ -217,20 +178,16 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
217
178
  // 'FunctionalProperty',
218
179
  ];
219
180
  _this.rdfArrayRemove = opts.rdfArrayRemove || RDFArrayRemove;
220
-
221
181
  if (opts.dataCallback) {
222
182
  _this.dataCallbacks = [opts.dataCallback];
223
183
  }
224
-
225
184
  _this.initPropertyActions(_this.features);
226
-
227
185
  return _this;
228
186
  }
187
+
229
188
  /**
230
189
  * Gets the URI of the default graph
231
190
  */
232
-
233
-
234
191
  _createClass(IndexedFormula, [{
235
192
  key: "substitute",
236
193
  value:
@@ -246,20 +203,20 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
246
203
  y.add(statementsCopy);
247
204
  return y;
248
205
  }
206
+
249
207
  /**
250
208
  * Add a callback which will be triggered after a statement has been added to the store.
251
209
  * @param cb
252
210
  */
253
-
254
211
  }, {
255
212
  key: "addDataCallback",
256
213
  value: function addDataCallback(cb) {
257
214
  if (!this.dataCallbacks) {
258
215
  this.dataCallbacks = [];
259
216
  }
260
-
261
217
  this.dataCallbacks.push(cb);
262
218
  }
219
+
263
220
  /**
264
221
  * Apply a set of statements to be deleted and to be inserted
265
222
  *
@@ -267,27 +224,24 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
267
224
  * @param target - The name of the document to patch
268
225
  * @param patchCallback - Callback to be called when patching is complete
269
226
  */
270
-
271
227
  }, {
272
228
  key: "applyPatch",
273
229
  value: function applyPatch(patch, target, patchCallback) {
274
230
  var targetKB = this;
275
231
  var ds;
276
232
  var binding = null;
277
-
278
233
  function doPatch(onDonePatch) {
279
234
  if (patch['delete']) {
280
- ds = patch['delete']; // console.log(bindingDebug(binding))
235
+ ds = patch['delete'];
236
+ // console.log(bindingDebug(binding))
281
237
  // console.log('ds before substitute: ' + ds)
282
-
283
- if (binding) ds = ds.substitute(binding); // console.log('applyPatch: delete: ' + ds)
284
-
238
+ if (binding) ds = ds.substitute(binding);
239
+ // console.log('applyPatch: delete: ' + ds)
285
240
  ds = ds.statements;
286
241
  var bad = [];
287
242
  var ds2 = ds.map(function (st) {
288
243
  // Find the actual statements in the store
289
244
  var sts = targetKB.statementsMatching(st.subject, st.predicate, st.object, target);
290
-
291
245
  if (sts.length === 0) {
292
246
  // log.info("NOT FOUND deletable " + st)
293
247
  bad.push(st);
@@ -297,18 +251,15 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
297
251
  return sts[0];
298
252
  }
299
253
  });
300
-
301
254
  if (bad.length) {
302
255
  // console.log('Could not find to delete ' + bad.length + 'statements')
303
256
  // console.log('despite ' + targetKB.statementsMatching(bad[0].subject, bad[0].predicate)[0])
304
257
  return patchCallback('Could not find to delete: ' + bad.join('\n or '));
305
258
  }
306
-
307
259
  ds2.map(function (st) {
308
260
  targetKB.remove(st);
309
261
  });
310
262
  }
311
-
312
263
  if (patch['insert']) {
313
264
  // log.info("doPatch insert "+patch['insert'])
314
265
  ds = patch['insert'];
@@ -319,31 +270,28 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
319
270
  targetKB.add(st.subject, st.predicate, st.object, st.graph);
320
271
  });
321
272
  }
322
-
323
273
  onDonePatch();
324
274
  }
325
-
326
275
  if (patch.where) {
327
276
  // log.info("Processing WHERE: " + patch.where + '\n')
328
277
  var query = new Query('patch');
329
278
  query.pat = patch.where;
330
279
  query.pat.statements.map(function (st) {
331
280
  st.graph = namedNode(target.value);
332
- }); //@ts-ignore TODO: add sync property to Query when converting Query to typescript
333
-
281
+ });
282
+ //@ts-ignore TODO: add sync property to Query when converting Query to typescript
334
283
  query.sync = true;
335
284
  var bindingsFound = [];
336
285
  targetKB.query(query, function onBinding(binding) {
337
- bindingsFound.push(binding); // console.log(' got a binding: ' + bindingDebug(binding))
286
+ bindingsFound.push(binding);
287
+ // console.log(' got a binding: ' + bindingDebug(binding))
338
288
  }, targetKB.fetcher, function onDone() {
339
289
  if (bindingsFound.length === 0) {
340
290
  return patchCallback('No match found to be patched:' + patch.where);
341
291
  }
342
-
343
292
  if (bindingsFound.length > 1) {
344
293
  return patchCallback('Patch ambiguous. No patch done.');
345
294
  }
346
-
347
295
  binding = bindingsFound[0];
348
296
  doPatch(patchCallback);
349
297
  });
@@ -351,31 +299,30 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
351
299
  doPatch(patchCallback);
352
300
  }
353
301
  }
302
+
354
303
  /**
355
304
  * N3 allows for declaring blank nodes, this function enables that support
356
305
  *
357
306
  * @param x The blank node to be declared, supported in N3
358
307
  */
359
-
360
308
  }, {
361
309
  key: "declareExistential",
362
310
  value: function declareExistential(x) {
363
311
  if (!this._existentialVariables) this._existentialVariables = [];
364
-
365
312
  this._existentialVariables.push(x);
366
-
367
313
  return x;
368
314
  }
315
+
369
316
  /**
370
317
  * @param features
371
318
  */
372
-
373
319
  }, {
374
320
  key: "initPropertyActions",
375
321
  value: function initPropertyActions(features) {
376
322
  // If the predicate is #type, use handleRDFType to create a typeCallback on the object
377
- this.propertyActions[this.rdfFactory.id(this.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'))] = [handleRDFType]; // Assumption: these terms are not redirected @@fixme
323
+ this.propertyActions[this.rdfFactory.id(this.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'))] = [handleRDFType];
378
324
 
325
+ // Assumption: these terms are not redirected @@fixme
379
326
  if (ArrayIndexOf(features, 'sameAs') >= 0) {
380
327
  this.propertyActions[this.rdfFactory.id(this.rdfFactory.namedNode("".concat(owlNamespaceURI, "sameAs")))] = [function (formula, subj, pred, obj, why) {
381
328
  // log.warn("Equating "+subj.uri+" sameAs "+obj.uri); //@@
@@ -397,14 +344,15 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
397
344
  }]; // FP => handleFP, do add to index
398
345
  }
399
346
  }
400
- /** @deprecated Use {add} instead */
401
347
 
348
+ /** @deprecated Use {add} instead */
402
349
  }, {
403
350
  key: "addStatement",
404
351
  value: function addStatement(st) {
405
352
  this.add(st.subject, st.predicate, st.object, st.graph);
406
353
  return this.statements.length;
407
354
  }
355
+
408
356
  /**
409
357
  * Adds a triple (quad) to the store.
410
358
  *
@@ -415,12 +363,10 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
415
363
  * @param why - The document in which the triple (S,P,O) was or will be stored on the web
416
364
  * @returns The statement added to the store, or the store
417
365
  */
418
-
419
366
  }, {
420
367
  key: "add",
421
368
  value: function add(subj, pred, obj, why) {
422
369
  var i;
423
-
424
370
  if (arguments.length === 1) {
425
371
  if (subj instanceof Array) {
426
372
  for (i = 0; i < subj.length; i++) {
@@ -431,93 +377,73 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
431
377
  } else if (isStore(subj)) {
432
378
  this.add(subj.statements);
433
379
  }
434
-
435
380
  return this;
436
381
  }
437
-
438
382
  var actions;
439
383
  var st;
440
-
441
384
  if (!why) {
442
385
  // system generated
443
386
  why = this.fetcher ? this.fetcher.appNode : this.rdfFactory.defaultGraph();
444
387
  }
445
-
446
388
  if (typeof subj == 'string') {
447
389
  subj = this.rdfFactory.namedNode(subj);
448
390
  }
449
-
450
391
  pred = Node.fromValue(pred);
451
392
  var objNode = Node.fromValue(obj);
452
393
  why = Node.fromValue(why);
453
-
454
394
  if (!isRDFlibSubject(subj)) {
455
395
  throw new Error('Subject is not a subject type');
456
396
  }
457
-
458
397
  if (!isRDFlibPredicate(pred)) {
459
398
  throw new Error("Predicate ".concat(pred, " is not a predicate type"));
460
399
  }
461
-
462
400
  if (!isRDFlibObject(objNode)) {
463
401
  throw new Error("Object ".concat(objNode, " is not an object type"));
464
402
  }
465
-
466
403
  if (!isGraph(why)) {
467
404
  throw new Error("Why is not a graph type");
468
- } //@ts-ignore This is not used internally
469
-
470
-
405
+ }
406
+ //@ts-ignore This is not used internally
471
407
  if (this.predicateCallback) {
472
408
  //@ts-ignore This is not used internally
473
409
  this.predicateCallback(this, pred, why);
474
- } // Action return true if the statement does not need to be added
475
-
476
-
410
+ }
411
+ // Action return true if the statement does not need to be added
477
412
  var predHash = this.id(this.canon(pred));
478
413
  actions = this.propertyActions[predHash]; // Predicate hash
479
-
480
414
  var done = false;
481
-
482
415
  if (actions) {
483
416
  // alert('type: '+typeof actions +' @@ actions='+actions)
484
417
  for (i = 0; i < actions.length; i++) {
485
418
  done = done || actions[i](this, subj, pred, objNode, why);
486
419
  }
487
420
  }
488
-
489
421
  if (this.holds(subj, pred, objNode, why)) {
490
422
  // Takes time but saves duplicates
491
423
  // console.log('rdflib: Ignoring dup! {' + subj + ' ' + pred + ' ' + obj + ' ' + why + '}')
492
424
  return null; // @@better to return self in all cases?
493
- } // If we are tracking provenance, every thing should be loaded into the store
425
+ }
426
+ // If we are tracking provenance, every thing should be loaded into the store
494
427
  // if (done) return this.rdfFactory.quad(subj, pred, obj, why)
495
428
  // Don't put it in the store
496
429
  // still return this statement for owl:sameAs input
497
-
498
-
499
- var hash = [this.id(this.canon(subj)), predHash, this.id(this.canon(objNode)), this.id(this.canon(why))]; // @ts-ignore this will fail if you pass a collection and the factory does not allow Collections
500
-
430
+ var hash = [this.id(this.canon(subj)), predHash, this.id(this.canon(objNode)), this.id(this.canon(why))];
431
+ // @ts-ignore this will fail if you pass a collection and the factory does not allow Collections
501
432
  st = this.rdfFactory.quad(subj, pred, objNode, why);
502
-
503
433
  for (i = 0; i < 4; i++) {
504
434
  var ix = this.index[i];
505
435
  var h = hash[i];
506
-
507
436
  if (!ix[h]) {
508
437
  ix[h] = [];
509
438
  }
510
-
511
439
  ix[h].push(st); // Set of things with this as subject, etc
512
- } // log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
513
-
440
+ }
514
441
 
442
+ // log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
515
443
  this.statements.push(st);
516
-
517
444
  if (this.dataCallbacks) {
518
445
  var _iterator = _createForOfIteratorHelper(this.dataCallbacks),
519
- _step;
520
-
446
+ _step;
521
447
  try {
522
448
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
523
449
  var callback = _step.value;
@@ -529,14 +455,13 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
529
455
  _iterator.f();
530
456
  }
531
457
  }
532
-
533
458
  return st;
534
459
  }
460
+
535
461
  /**
536
462
  * Returns the symbol with canonical URI as smushed
537
463
  * @param term - An RDF node
538
464
  */
539
-
540
465
  }, {
541
466
  key: "canon",
542
467
  value: function canon(term) {
@@ -544,57 +469,44 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
544
469
  // @@ TODO Should improve this to return proper value - doing this to keep it backward compatible
545
470
  return term;
546
471
  }
547
-
548
472
  var y = this.redirections[this.id(term)];
549
-
550
473
  if (y) {
551
474
  return y;
552
475
  }
553
-
554
476
  switch (term.termType) {
555
477
  case BlankNodeTermType:
556
478
  return new BlankNode(term.value);
557
-
558
479
  case CollectionTermType:
559
480
  return term;
560
481
  // non-RDF/JS type, should just need to cast
561
-
562
482
  case DefaultGraphTermType:
563
483
  return new DefaultGraph();
564
-
565
484
  case EmptyTermType:
566
485
  // non-RDF/JS type, should just need to cast
567
486
  return term;
568
-
569
487
  case GraphTermType:
570
488
  // non-RDF/JS type, should just need to cast
571
489
  return term;
572
-
573
490
  case LiteralTermType:
574
491
  return new Literal(term.value, term.language, term.datatype);
575
-
576
492
  case NamedNodeTermType:
577
493
  return new NamedNode(term.value);
578
-
579
494
  case VariableTermType:
580
495
  return new Variable(term.value);
581
-
582
496
  default:
583
497
  throw new Error("Term Type not recognized for canonization: ".concat(term.termType));
584
498
  }
585
499
  }
500
+
586
501
  /**
587
502
  * Checks this formula for consistency
588
503
  */
589
-
590
504
  }, {
591
505
  key: "check",
592
506
  value: function check() {
593
507
  this.checkStatementList(this.statements);
594
-
595
508
  for (var p = 0; p < 4; p++) {
596
509
  var ix = this.index[p];
597
-
598
510
  for (var key in ix) {
599
511
  if (ix.hasOwnProperty(key)) {
600
512
  // @ts-ignore should this pass an array or a single statement? checkStateMentsList expects an array.
@@ -603,27 +515,24 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
603
515
  }
604
516
  }
605
517
  }
518
+
606
519
  /**
607
520
  * Checks a list of statements for consistency
608
521
  * @param sts - The list of statements to check
609
522
  * @param from - An index with the array ['subject', 'predicate', 'object', 'why']
610
523
  */
611
-
612
524
  }, {
613
525
  key: "checkStatementList",
614
526
  value: function checkStatementList(sts, from) {
615
527
  if (from === undefined) {
616
528
  from = 0;
617
529
  }
618
-
619
530
  var names = ['subject', 'predicate', 'object', 'why'];
620
531
  var origin = ' found in ' + names[from] + ' index.';
621
532
  var st;
622
-
623
533
  for (var j = 0; j < sts.length; j++) {
624
534
  st = sts[j];
625
535
  var term = [st.subject, st.predicate, st.object, st.graph];
626
-
627
536
  var arrayContains = function arrayContains(a, x) {
628
537
  for (var i = 0; i < a.length; i++) {
629
538
  if (a[i].subject.equals(x.subject) && a[i].predicate.equals(x.predicate) && a[i].object.equals(x.object) && a[i].why.equals(x.graph)) {
@@ -631,27 +540,26 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
631
540
  }
632
541
  }
633
542
  };
634
-
635
543
  for (var p = 0; p < 4; p++) {
636
544
  var c = this.canon(term[p]);
637
545
  var h = this.id(c);
638
-
639
- if (!this.index[p][h]) {// throw new Error('No ' + name[p] + ' index for statement ' + st + '@' + st.why + origin)
546
+ if (!this.index[p][h]) {
547
+ // throw new Error('No ' + name[p] + ' index for statement ' + st + '@' + st.why + origin)
640
548
  } else {
641
- if (!arrayContains(this.index[p][h], st)) {// throw new Error('Index for ' + name[p] + ' does not have statement ' + st + '@' + st.why + origin)
549
+ if (!arrayContains(this.index[p][h], st)) {
550
+ // throw new Error('Index for ' + name[p] + ' does not have statement ' + st + '@' + st.why + origin)
642
551
  }
643
552
  }
644
553
  }
645
-
646
554
  if (!arrayContains(this.statements, st)) {
647
555
  throw new Error('Statement list does not statement ' + st + '@' + st.graph + origin);
648
556
  }
649
557
  }
650
558
  }
559
+
651
560
  /**
652
561
  * Closes this formula (and return it)
653
562
  */
654
-
655
563
  }, {
656
564
  key: "close",
657
565
  value: function close() {
@@ -664,25 +572,21 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
664
572
  if (Object.prototype.hasOwnProperty.call(u1, "compareTerm")) {
665
573
  return u1.compareTerm(u2);
666
574
  }
667
-
668
575
  if (ClassOrder[u1.termType] < ClassOrder[u2.termType]) {
669
576
  return -1;
670
577
  }
671
-
672
578
  if (ClassOrder[u1.termType] > ClassOrder[u2.termType]) {
673
579
  return +1;
674
580
  }
675
-
676
581
  if (u1.value < u2.value) {
677
582
  return -1;
678
583
  }
679
-
680
584
  if (u1.value > u2.value) {
681
585
  return +1;
682
586
  }
683
-
684
587
  return 0;
685
588
  }
589
+
686
590
  /**
687
591
  * replaces @template with @target and add appropriate triples
688
592
  * removes no triples by default and is a one-direction replication
@@ -690,45 +594,39 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
690
594
  * @param target node to copy to
691
595
  * @param flags Whether or not to do a two-directional copy and/or delete triples
692
596
  */
693
-
694
597
  }, {
695
598
  key: "copyTo",
696
599
  value: function copyTo(template, target, flags) {
697
600
  if (!flags) flags = [];
698
601
  var statList = this.statementsMatching(template);
699
-
700
602
  if (ArrayIndexOf(flags, 'two-direction') !== -1) {
701
603
  statList.concat(this.statementsMatching(undefined, undefined, template));
702
604
  }
703
-
704
605
  for (var i = 0; i < statList.length; i++) {
705
606
  var st = statList[i];
706
-
707
607
  switch (st.object.termType) {
708
608
  case 'NamedNode':
709
609
  this.add(target, st.predicate, st.object);
710
610
  break;
711
-
712
611
  case 'Literal':
713
- case 'BlankNode': // @ts-ignore Collections can appear here
714
-
612
+ case 'BlankNode':
613
+ // @ts-ignore Collections can appear here
715
614
  case 'Collection':
716
615
  // @ts-ignore Possible bug: copy is not available on Collections
717
616
  this.add(target, st.predicate, st.object.copy(this));
718
617
  }
719
-
720
618
  if (ArrayIndexOf(flags, 'delete') !== -1) {
721
619
  this.remove(st);
722
620
  }
723
621
  }
724
622
  }
623
+
725
624
  /**
726
625
  * Simplify graph in store when we realize two identifiers are equivalent
727
626
  * We replace the bigger with the smaller.
728
627
  * @param u1in The first node
729
628
  * @param u2in The second node
730
629
  */
731
-
732
630
  }, {
733
631
  key: "equate",
734
632
  value: function equate(u1in, u2in) {
@@ -738,13 +636,11 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
738
636
  var u1 = this.canon(u1in);
739
637
  var u2 = this.canon(u2in);
740
638
  var d = this.compareTerms(u1, u2);
741
-
742
639
  if (!d) {
743
640
  return true; // No information in {a = a}
744
- } // var big
641
+ }
642
+ // var big
745
643
  // var small
746
-
747
-
748
644
  if (d < 0) {
749
645
  // u1 less than u2
750
646
  return this.replaceWith(u2, u1);
@@ -752,17 +648,18 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
752
648
  return this.replaceWith(u1, u2);
753
649
  }
754
650
  }
651
+
755
652
  /**
756
653
  * Creates a new empty indexed formula
757
654
  * Only applicable for IndexedFormula, but TypeScript won't allow a subclass to override a property
758
655
  * @param features The list of features
759
656
  */
760
-
761
657
  }, {
762
658
  key: "formula",
763
659
  value: function formula(features) {
764
660
  return new IndexedFormula(features);
765
661
  }
662
+
766
663
  /**
767
664
  * Returns the number of statements contained in this IndexedFormula.
768
665
  * (Getter proxy to this.statements).
@@ -773,12 +670,12 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
773
670
  * ```
774
671
  * @returns {Number}
775
672
  */
776
-
777
673
  }, {
778
674
  key: "length",
779
675
  get: function get() {
780
676
  return this.statements.length;
781
677
  }
678
+
782
679
  /**
783
680
  * Returns any quads matching the given arguments.
784
681
  * Standard RDFJS spec method for Source objects, implemented as an
@@ -788,92 +685,86 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
788
685
  * @param object The object
789
686
  * @param graph The graph that contains the statement
790
687
  */
791
-
792
688
  }, {
793
689
  key: "match",
794
690
  value: function match(subject, predicate, object, graph) {
795
691
  return this.statementsMatching(Node.fromValue(subject), Node.fromValue(predicate), Node.fromValue(object), Node.fromValue(graph));
796
692
  }
693
+
797
694
  /**
798
695
  * Find out whether a given URI is used as symbol in the formula
799
696
  * @param uri The URI to look for
800
697
  */
801
-
802
698
  }, {
803
699
  key: "mentionsURI",
804
700
  value: function mentionsURI(uri) {
805
701
  var hash = '<' + uri + '>';
806
702
  return !!this.subjectIndex[hash] || !!this.objectIndex[hash] || !!this.predicateIndex[hash];
807
703
  }
704
+
808
705
  /**
809
706
  * Existentials are BNodes - something exists without naming
810
707
  * @param uri An URI
811
708
  */
812
-
813
709
  }, {
814
710
  key: "newExistential",
815
711
  value: function newExistential(uri) {
816
712
  if (!uri) return this.bnode();
817
- var x = this.sym(uri); // @ts-ignore x should be blanknode, but is namedNode.
818
-
713
+ var x = this.sym(uri);
714
+ // @ts-ignore x should be blanknode, but is namedNode.
819
715
  return this.declareExistential(x);
820
716
  }
717
+
821
718
  /**
822
719
  * Adds a new property action
823
720
  * @param pred the predicate that the function should be triggered on
824
721
  * @param action the function that should trigger
825
722
  */
826
-
827
723
  }, {
828
724
  key: "newPropertyAction",
829
725
  value: function newPropertyAction(pred, action) {
830
726
  // log.debug("newPropertyAction: "+pred)
831
727
  var hash = this.id(pred);
832
-
833
728
  if (!this.propertyActions[hash]) {
834
729
  this.propertyActions[hash] = [];
835
730
  }
836
-
837
- this.propertyActions[hash].push(action); // Now apply the function to to statements already in the store
838
-
731
+ this.propertyActions[hash].push(action);
732
+ // Now apply the function to to statements already in the store
839
733
  var toBeFixed = this.statementsMatching(undefined, pred, undefined);
840
734
  var done = false;
841
-
842
735
  for (var i = 0; i < toBeFixed.length; i++) {
843
736
  // NOT optimized - sort toBeFixed etc
844
737
  done = done || action(this, toBeFixed[i].subject, pred, toBeFixed[i].object);
845
738
  }
846
-
847
739
  return done;
848
740
  }
741
+
849
742
  /**
850
743
  * Creates a new universal node
851
744
  * Universals are Variables
852
745
  * @param uri An URI
853
746
  */
854
-
855
747
  }, {
856
748
  key: "newUniversal",
857
749
  value: function newUniversal(uri) {
858
750
  var x = this.sym(uri);
859
751
  if (!this._universalVariables) this._universalVariables = [];
860
-
861
752
  this._universalVariables.push(x);
862
-
863
753
  return x;
864
- } // convenience function used by N3 parser
754
+ }
865
755
 
756
+ // convenience function used by N3 parser
866
757
  }, {
867
758
  key: "variable",
868
759
  value: function variable(name) {
869
760
  return new Variable(name);
870
761
  }
762
+
871
763
  /**
872
764
  * Find an unused id for a file being edited: return a symbol
873
765
  * (Note: Slow iff a lot of them -- could be O(log(k)) )
874
766
  * @param doc A document named node
875
767
  */
876
-
877
768
  }, {
878
769
  key: "nextSymbol",
879
770
  value: function nextSymbol(doc) {
@@ -882,6 +773,7 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
882
773
  if (!this.mentionsURI(uri)) return this.sym(uri);
883
774
  }
884
775
  }
776
+
885
777
  /**
886
778
  * Query this store asynchronously, return bindings in callback
887
779
  *
@@ -890,47 +782,41 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
890
782
  * @param Fetcher | null If you want the query to do link following
891
783
  * @param onDone OBSOLETE - do not use this // @@ Why not ?? Called when query complete
892
784
  */
893
-
894
785
  }, {
895
786
  key: "query",
896
787
  value: function query(myQuery, callback, fetcher, onDone) {
897
788
  return indexedFormulaQuery.call(this, myQuery, callback, fetcher, onDone);
898
789
  }
790
+
899
791
  /**
900
792
  * Query this store synchronously and return bindings
901
793
  *
902
794
  * @param myQuery The query to be run
903
795
  */
904
-
905
796
  }, {
906
797
  key: "querySync",
907
798
  value: function querySync(myQuery) {
908
799
  var results = [];
909
-
910
800
  function saveBinginds(bindings) {
911
801
  results.push(bindings);
912
802
  }
913
-
914
803
  function onDone() {
915
804
  done = true;
916
805
  }
917
-
918
- var done = false; // @ts-ignore TODO: Add .sync to Query
919
-
806
+ var done = false;
807
+ // @ts-ignore TODO: Add .sync to Query
920
808
  myQuery.sync = true;
921
809
  indexedFormulaQuery.call(this, myQuery, saveBinginds, null, onDone);
922
-
923
810
  if (!done) {
924
811
  throw new Error('Sync query should have called done function');
925
812
  }
926
-
927
813
  return results;
928
814
  }
815
+
929
816
  /**
930
817
  * Removes one or multiple statement(s) from this formula
931
818
  * @param st - A Statement or array of Statements to remove
932
819
  */
933
-
934
820
  }, {
935
821
  key: "remove",
936
822
  value: function remove(st) {
@@ -938,39 +824,33 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
938
824
  for (var i = 0; i < st.length; i++) {
939
825
  this.remove(st[i]);
940
826
  }
941
-
942
827
  return this;
943
828
  }
944
-
945
829
  if (isStore(st)) {
946
830
  return this.remove(st.statements);
947
831
  }
948
-
949
832
  var sts = this.statementsMatching(st.subject, st.predicate, st.object, st.graph);
950
-
951
833
  if (!sts.length) {
952
834
  throw new Error('Statement to be removed is not on store: ' + st);
953
835
  }
954
-
955
836
  this.removeStatement(sts[0]);
956
837
  return this;
957
838
  }
839
+
958
840
  /**
959
841
  * Removes all statements in a doc
960
842
  * @param doc - The document / graph
961
843
  */
962
-
963
844
  }, {
964
845
  key: "removeDocument",
965
846
  value: function removeDocument(doc) {
966
847
  var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
967
-
968
848
  for (var i = 0; i < sts.length; i++) {
969
849
  this.removeStatement(sts[i]);
970
850
  }
971
-
972
851
  return this;
973
852
  }
853
+
974
854
  /**
975
855
  * Remove all statements matching args (within limit) *
976
856
  * @param subj The subject
@@ -979,28 +859,21 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
979
859
  * @param why The graph that contains the statement
980
860
  * @param limit The number of statements to remove
981
861
  */
982
-
983
862
  }, {
984
863
  key: "removeMany",
985
864
  value: function removeMany(subj, pred, obj, why, limit) {
986
865
  // log.debug("entering removeMany w/ subj,pred,obj,why,limit = " + subj +", "+ pred+", " + obj+", " + why+", " + limit)
987
- var sts = this.statementsMatching(subj, pred, obj, why, false); // This is a subtle bug that occurred in updateCenter.js too.
866
+ var sts = this.statementsMatching(subj, pred, obj, why, false);
867
+ // This is a subtle bug that occurred in updateCenter.js too.
988
868
  // The fact is, this.statementsMatching returns this.whyIndex instead of a copy of it
989
869
  // but for perfromance consideration, it's better to just do that
990
870
  // so make a copy here.
991
-
992
871
  var statements = [];
993
-
994
- for (var i = 0; i < sts.length; i++) {
995
- statements.push(sts[i]);
996
- }
997
-
872
+ for (var i = 0; i < sts.length; i++) statements.push(sts[i]);
998
873
  if (limit) statements = statements.slice(0, limit);
999
-
1000
- for (i = 0; i < statements.length; i++) {
1001
- this.remove(statements[i]);
1002
- }
874
+ for (i = 0; i < statements.length; i++) this.remove(statements[i]);
1003
875
  }
876
+
1004
877
  /**
1005
878
  * Remove all matching statements
1006
879
  * @param subject The subject
@@ -1008,13 +881,13 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1008
881
  * @param object The object
1009
882
  * @param graph The graph that contains the statement
1010
883
  */
1011
-
1012
884
  }, {
1013
885
  key: "removeMatches",
1014
886
  value: function removeMatches(subject, predicate, object, graph) {
1015
887
  this.removeMany(subject, predicate, object, graph);
1016
888
  return this;
1017
889
  }
890
+
1018
891
  /**
1019
892
  * Remove a particular statement object from the store
1020
893
  *
@@ -1022,108 +895,93 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1022
895
  * Make sure you only use this for these.
1023
896
  * Otherwise, you should use remove() above.
1024
897
  */
1025
-
1026
898
  }, {
1027
899
  key: "removeStatement",
1028
900
  value: function removeStatement(st) {
1029
901
  // log.debug("entering remove w/ st=" + st)
1030
902
  var term = [st.subject, st.predicate, st.object, st.graph];
1031
-
1032
903
  for (var p = 0; p < 4; p++) {
1033
904
  var c = this.canon(term[p]);
1034
905
  var h = this.id(c);
1035
-
1036
- if (!this.index[p][h]) {// log.warn ("Statement removal: no index '+p+': "+st)
906
+ if (!this.index[p][h]) {
907
+ // log.warn ("Statement removal: no index '+p+': "+st)
1037
908
  } else {
1038
909
  this.rdfArrayRemove(this.index[p][h], st);
1039
910
  }
1040
911
  }
1041
-
1042
912
  this.rdfArrayRemove(this.statements, st);
1043
913
  return this;
1044
914
  }
915
+
1045
916
  /**
1046
917
  * Removes statements
1047
918
  * @param sts The statements to remove
1048
919
  */
1049
-
1050
920
  }, {
1051
921
  key: "removeStatements",
1052
922
  value: function removeStatements(sts) {
1053
923
  for (var i = 0; i < sts.length; i++) {
1054
924
  this.remove(sts[i]);
1055
925
  }
1056
-
1057
926
  return this;
1058
927
  }
928
+
1059
929
  /**
1060
930
  * Replace big with small, obsoleted with obsoleting.
1061
931
  */
1062
-
1063
932
  }, {
1064
933
  key: "replaceWith",
1065
934
  value: function replaceWith(big, small) {
1066
935
  // log.debug("Replacing "+big+" with "+small) // this.id(@@
1067
936
  var oldhash = this.id(big);
1068
937
  var newhash = this.id(small);
1069
-
1070
938
  var moveIndex = function moveIndex(ix) {
1071
939
  var oldlist = ix[oldhash];
1072
-
1073
940
  if (!oldlist) {
1074
941
  return; // none to move
1075
942
  }
1076
943
 
1077
944
  var newlist = ix[newhash];
1078
-
1079
945
  if (!newlist) {
1080
946
  ix[newhash] = oldlist;
1081
947
  } else {
1082
948
  ix[newhash] = oldlist.concat(newlist);
1083
949
  }
1084
-
1085
950
  delete ix[oldhash];
1086
- }; // the canonical one carries all the indexes
1087
-
1088
-
951
+ };
952
+ // the canonical one carries all the indexes
1089
953
  for (var i = 0; i < 4; i++) {
1090
954
  moveIndex(this.index[i]);
1091
955
  }
1092
-
1093
956
  this.redirections[oldhash] = small;
1094
-
1095
957
  if (big.value) {
1096
958
  // @@JAMBO: must update redirections,aliases from sub-items, too.
1097
959
  if (!this.aliases[newhash]) {
1098
960
  this.aliases[newhash] = [];
1099
961
  }
1100
-
1101
962
  this.aliases[newhash].push(big); // Back link
1102
-
1103
963
  if (this.aliases[oldhash]) {
1104
964
  for (i = 0; i < this.aliases[oldhash].length; i++) {
1105
965
  this.redirections[this.id(this.aliases[oldhash][i])] = small;
1106
966
  this.aliases[newhash].push(this.aliases[oldhash][i]);
1107
967
  }
1108
968
  }
1109
-
1110
- this.add(small, this.sym('http://www.w3.org/2007/ont/link#uri'), big); // If two things are equal, and one is requested, we should request the other.
1111
-
969
+ this.add(small, this.sym('http://www.w3.org/2007/ont/link#uri'), big);
970
+ // If two things are equal, and one is requested, we should request the other.
1112
971
  if (this.fetcher) {
1113
972
  this.fetcher.nowKnownAs(big, small);
1114
973
  }
1115
974
  }
1116
-
1117
975
  moveIndex(this.classActions);
1118
- moveIndex(this.propertyActions); // log.debug("Equate done. "+big+" to be known as "+small)
1119
-
976
+ moveIndex(this.propertyActions);
977
+ // log.debug("Equate done. "+big+" to be known as "+small)
1120
978
  return true; // true means the statement does not need to be put in
1121
979
  }
980
+
1122
981
  /**
1123
982
  * Return all equivalent URIs by which this is known
1124
983
  * @param x A named node
1125
984
  */
1126
-
1127
985
  }, {
1128
986
  key: "allAliases",
1129
987
  value: function allAliases(x) {
@@ -1131,24 +989,23 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1131
989
  a.push(this.canon(x));
1132
990
  return a;
1133
991
  }
992
+
1134
993
  /**
1135
994
  * Compare by canonical URI as smushed
1136
995
  * @param x A named node
1137
996
  * @param y Another named node
1138
997
  */
1139
-
1140
998
  }, {
1141
999
  key: "sameThings",
1142
1000
  value: function sameThings(x, y) {
1143
1001
  if (x.equals(y)) {
1144
1002
  return true;
1145
1003
  }
1146
-
1147
- var x1 = this.canon(x); // alert('x1='+x1)
1148
-
1004
+ var x1 = this.canon(x);
1005
+ // alert('x1='+x1)
1149
1006
  if (!x1) return false;
1150
- var y1 = this.canon(y); // alert('y1='+y1); //@@
1151
-
1007
+ var y1 = this.canon(y);
1008
+ // alert('y1='+y1); //@@
1152
1009
  if (!y1) return false;
1153
1010
  return x1.value === y1.value;
1154
1011
  }
@@ -1161,19 +1018,17 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1161
1018
  if (prefix === 'tab' && this.namespaces['tab']) {
1162
1019
  return;
1163
1020
  } // There are files around with long badly generated prefixes like this
1164
-
1165
-
1166
1021
  if (prefix.slice(0, 2) === 'ns' || prefix.slice(0, 7) === 'default') {
1167
1022
  return;
1168
- } // remove any prefix that currently targets nsuri
1169
-
1023
+ }
1170
1024
 
1025
+ // remove any prefix that currently targets nsuri
1171
1026
  for (var existingPrefix in this.namespaces) {
1172
1027
  if (this.namespaces[existingPrefix] == nsuri) delete this.namespaces[existingPrefix];
1173
1028
  }
1174
-
1175
1029
  this.namespaces[prefix] = nsuri;
1176
1030
  }
1031
+
1177
1032
  /** Search the Store
1178
1033
  *
1179
1034
  * ALL CONVENIENCE LOOKUP FUNCTIONS RELY ON THIS!
@@ -1184,7 +1039,6 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1184
1039
  * @param justOne - flag - stop when found one rather than get all of them?
1185
1040
  * @returns An array of nodes which match the wildcard position
1186
1041
  */
1187
-
1188
1042
  }, {
1189
1043
  key: "statementsMatching",
1190
1044
  value: function statementsMatching(subj, pred, obj, why, justOne) {
@@ -1193,15 +1047,11 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1193
1047
  var pattern = [];
1194
1048
  var hash = [];
1195
1049
  var wild = []; // wildcards
1196
-
1197
1050
  var given = []; // Not wild
1198
-
1199
1051
  var p;
1200
1052
  var list;
1201
-
1202
1053
  for (p = 0; p < 4; p++) {
1203
1054
  pattern[p] = this.canon(Node.fromValue(pat[p]));
1204
-
1205
1055
  if (!pattern[p]) {
1206
1056
  wild.push(p);
1207
1057
  } else {
@@ -1209,39 +1059,30 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1209
1059
  hash[p] = this.id(pattern[p]);
1210
1060
  }
1211
1061
  }
1212
-
1213
1062
  if (given.length === 0) {
1214
1063
  return this.statements;
1215
1064
  }
1216
-
1217
1065
  if (given.length === 1) {
1218
1066
  // Easy too, we have an index for that
1219
1067
  p = given[0];
1220
1068
  list = this.index[p][hash[p]];
1221
-
1222
1069
  if (list && justOne) {
1223
1070
  if (list.length > 1) {
1224
1071
  list = list.slice(0, 1);
1225
1072
  }
1226
1073
  }
1227
-
1228
1074
  list = list || [];
1229
1075
  return list;
1230
- } // Now given.length is 2, 3 or 4.
1076
+ }
1077
+ // Now given.length is 2, 3 or 4.
1231
1078
  // We hope that the scale-free nature of the data will mean we tend to get
1232
1079
  // a short index in there somewhere!
1233
-
1234
-
1235
1080
  var best = 1e10; // really bad
1236
-
1237
1081
  var iBest;
1238
1082
  var i;
1239
-
1240
1083
  for (i = 0; i < given.length; i++) {
1241
1084
  p = given[i]; // Which part we are dealing with
1242
-
1243
1085
  list = this.index[p][hash[p]];
1244
-
1245
1086
  if (!list) {
1246
1087
  return []; // No occurrences
1247
1088
  }
@@ -1250,42 +1091,35 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1250
1091
  best = list.length;
1251
1092
  iBest = i; // (not p!)
1252
1093
  }
1253
- } // Ok, we have picked the shortest index but now we have to filter it
1254
-
1255
-
1094
+ }
1095
+ // Ok, we have picked the shortest index but now we have to filter it
1256
1096
  var pBest = given[iBest];
1257
1097
  var possibles = this.index[pBest][hash[pBest]];
1258
1098
  var check = given.slice(0, iBest).concat(given.slice(iBest + 1)); // remove iBest
1259
-
1260
1099
  var results = [];
1261
1100
  var parts = ['subject', 'predicate', 'object', 'why'];
1262
-
1263
1101
  for (var j = 0; j < possibles.length; j++) {
1264
1102
  var st = possibles[j];
1265
-
1266
1103
  for (i = 0; i < check.length; i++) {
1267
1104
  // for each position to be checked
1268
1105
  p = check[i];
1269
-
1270
1106
  if (!this.canon(st[parts[p]]).equals(pattern[p])) {
1271
1107
  st = null;
1272
1108
  break;
1273
1109
  }
1274
1110
  }
1275
-
1276
1111
  if (st != null) {
1277
1112
  results.push(st);
1278
1113
  if (justOne) break;
1279
1114
  }
1280
1115
  }
1281
-
1282
1116
  return results;
1283
1117
  }
1118
+
1284
1119
  /**
1285
1120
  * A list of all the URIs by which this thing is known
1286
1121
  * @param term
1287
1122
  */
1288
-
1289
1123
  }, {
1290
1124
  key: "uris",
1291
1125
  value: function uris(term) {
@@ -1293,22 +1127,20 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1293
1127
  var terms = this.aliases[this.id(cterm)];
1294
1128
  if (!cterm.value) return [];
1295
1129
  var res = [cterm.value];
1296
-
1297
1130
  if (terms) {
1298
1131
  for (var i = 0; i < terms.length; i++) {
1299
1132
  res.push(terms[i].uri);
1300
1133
  }
1301
1134
  }
1302
-
1303
1135
  return res;
1304
1136
  }
1305
1137
  }, {
1306
1138
  key: "serialize",
1307
1139
  value: function serialize(base, contentType, provenance, options) {
1308
1140
  var _options;
1309
-
1310
1141
  // override Formula.serialize to force the serializer namespace prefixes
1311
1142
  // to those of this IndexedFormula
1143
+
1312
1144
  // if namespaces are explicitly passed in options, let them override the existing namespaces in this formula
1313
1145
  var namespaces = (_options = options) !== null && _options !== void 0 && _options.namespaces ? _objectSpread(_objectSpread({}, this.namespaces), options.namespaces) : _objectSpread({}, this.namespaces);
1314
1146
  options = _objectSpread(_objectSpread({}, options || {}), {}, {
@@ -1322,11 +1154,8 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
1322
1154
  return defaultGraphURI;
1323
1155
  }
1324
1156
  }]);
1325
-
1326
1157
  return IndexedFormula;
1327
1158
  }(Formula);
1328
-
1329
1159
  _defineProperty(IndexedFormula, "handleRDFType", void 0);
1330
-
1331
1160
  export { IndexedFormula as default };
1332
1161
  IndexedFormula.handleRDFType = handleRDFType;