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