rdflib 2.2.35 → 2.2.36

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