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