rdflib 2.2.34 → 2.2.35-2bb9ed0b

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 (100) hide show
  1. package/dist/515.rdflib.min.js +3 -0
  2. package/dist/515.rdflib.min.js.map +1 -0
  3. package/dist/789.rdflib.min.js +1 -0
  4. package/dist/rdflib.min.js +1 -1
  5. package/dist/rdflib.min.js.LICENSE.txt +0 -2
  6. package/dist/rdflib.min.js.map +1 -1
  7. package/esm/blank-node.js +57 -85
  8. package/esm/class-order.js +1 -1
  9. package/esm/collection.js +70 -106
  10. package/esm/default-graph.js +13 -33
  11. package/esm/empty.js +8 -26
  12. package/esm/factories/canonical-data-factory.js +33 -30
  13. package/esm/factories/extended-term-factory.js +18 -14
  14. package/esm/factories/factory-types.js +1 -1
  15. package/esm/factories/rdflib-data-factory.js +9 -11
  16. package/esm/fetcher.js +1364 -1668
  17. package/esm/formula.js +631 -739
  18. package/esm/index.js +31 -51
  19. package/esm/jsonldparser.js +19 -26
  20. package/esm/jsonparser.js +1 -1
  21. package/esm/lists.js +41 -86
  22. package/esm/literal.js +120 -157
  23. package/esm/log.js +7 -7
  24. package/esm/n3parser.js +1008 -1090
  25. package/esm/named-node.js +69 -99
  26. package/esm/namespace.js +2 -4
  27. package/esm/node-internal.js +73 -97
  28. package/esm/node.js +1 -2
  29. package/esm/parse.js +3 -3
  30. package/esm/patch-parser.js +1 -2
  31. package/esm/query.js +15 -30
  32. package/esm/rdfaparser.js +775 -846
  33. package/esm/rdfxmlparser.js +348 -365
  34. package/esm/serialize.js +2 -3
  35. package/esm/serializer.js +834 -889
  36. package/esm/sparql-to-query.js +0 -2
  37. package/esm/statement.js +52 -72
  38. package/esm/store.js +852 -963
  39. package/esm/types.js +26 -21
  40. package/esm/update-manager.js +963 -1104
  41. package/esm/updates-via.js +104 -134
  42. package/esm/uri.js +3 -3
  43. package/esm/utils/default-graph-uri.js +2 -2
  44. package/esm/utils/terms.js +4 -5
  45. package/esm/utils-js.js +5 -6
  46. package/esm/utils.js +7 -6
  47. package/esm/variable.js +32 -58
  48. package/esm/xsd.js +2 -2
  49. package/lib/blank-node.js +56 -83
  50. package/lib/class-order.js +2 -3
  51. package/lib/collection.js +69 -104
  52. package/lib/default-graph.js +13 -32
  53. package/lib/empty.js +8 -25
  54. package/lib/factories/canonical-data-factory.js +36 -34
  55. package/lib/factories/extended-term-factory.js +19 -16
  56. package/lib/factories/factory-types.js +2 -3
  57. package/lib/factories/rdflib-data-factory.js +10 -13
  58. package/lib/fetcher.js +1394 -1693
  59. package/lib/formula.js +631 -738
  60. package/lib/index.js +66 -89
  61. package/lib/jsonldparser.js +21 -32
  62. package/lib/jsonparser.js +3 -4
  63. package/lib/lists.js +47 -87
  64. package/lib/literal.js +120 -156
  65. package/lib/log.js +8 -9
  66. package/lib/n3parser.js +1011 -1096
  67. package/lib/named-node.js +69 -98
  68. package/lib/namespace.js +2 -4
  69. package/lib/node-internal.js +72 -95
  70. package/lib/node.js +2 -4
  71. package/lib/parse.js +5 -6
  72. package/lib/patch-parser.js +1 -2
  73. package/lib/query.js +19 -32
  74. package/lib/rdfaparser.js +777 -849
  75. package/lib/rdfxmlparser.js +350 -366
  76. package/lib/serialize.js +2 -3
  77. package/lib/serializer.js +838 -892
  78. package/lib/sparql-to-query.js +0 -2
  79. package/lib/statement.js +54 -74
  80. package/lib/store.js +873 -978
  81. package/lib/types.js +22 -43
  82. package/lib/update-manager.js +972 -1111
  83. package/lib/updates-via.js +105 -134
  84. package/lib/uri.js +3 -3
  85. package/lib/utils/default-graph-uri.js +2 -4
  86. package/lib/utils/terms.js +4 -6
  87. package/lib/utils-js.js +11 -13
  88. package/lib/utils.js +6 -7
  89. package/lib/variable.js +34 -60
  90. package/lib/xsd-internal.js +2 -3
  91. package/lib/xsd.js +3 -4
  92. package/package.json +31 -31
  93. package/src/n3parser.js +1 -1
  94. package/src/rdfxmlparser.js +2 -1
  95. package/src/serializer.js +1 -1
  96. package/.babelrc +0 -20
  97. package/dist/670.rdflib.min.js +0 -1
  98. package/dist/730.rdflib.min.js +0 -3
  99. package/dist/730.rdflib.min.js.map +0 -1
  100. /package/dist/{730.rdflib.min.js.LICENSE.txt → 515.rdflib.min.js.LICENSE.txt} +0 -0
package/esm/store.js CHANGED
@@ -1,17 +1,4 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
2
  /* Identity management and indexing for RDF
16
3
  *
17
4
  * This file provides IndexedFormula a formula (set of triples) which
@@ -47,11 +34,11 @@ import { Query, indexedFormulaQuery } from './query';
47
34
  import { BlankNodeTermType, CollectionTermType, DefaultGraphTermType, EmptyTermType, GraphTermType, LiteralTermType, NamedNodeTermType, VariableTermType } from './types';
48
35
  import NamedNode from './named-node';
49
36
  import { namedNode } from './index';
50
- import _serialize from "./serialize";
37
+ import serialize from "./serialize";
51
38
  import BlankNode from './blank-node';
52
39
  import DefaultGraph from './default-graph';
53
40
  import Literal from './literal';
54
- var owlNamespaceURI = 'http://www.w3.org/2002/07/owl#';
41
+ const owlNamespaceURI = 'http://www.w3.org/2002/07/owl#';
55
42
  export { defaultGraphURI };
56
43
  // var link_ns = 'http://www.w3.org/2007/ont/link#'
57
44
 
@@ -95,9 +82,7 @@ function handleRDFType(formula, subj, pred, obj, why) {
95
82
  /**
96
83
  * Indexed Formula aka Store
97
84
  */
98
- var IndexedFormula = /*#__PURE__*/function (_Formula) {
99
- _inherits(IndexedFormula, _Formula);
100
- var _super = _createSuper(IndexedFormula);
85
+ export default class IndexedFormula extends Formula {
101
86
  /**
102
87
  * Creates a new formula
103
88
  * @param features - What sort of automatic processing to do? Array of string
@@ -107,1085 +92,989 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
107
92
  * @param [opts.rdfArrayRemove] - Function which removes statements from the store
108
93
  * @param [opts.dataCallback] - Callback when a statement is added to the store, will not trigger when adding duplicates
109
94
  */
110
- function IndexedFormula(features) {
111
- var _this;
112
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
113
- _classCallCheck(this, IndexedFormula);
114
- _this = _super.call(this, 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);
115
98
  // IN future - allow pass array of statements to constructor
116
99
  /**
117
100
  * An UpdateManager initialised to this store
118
101
  */
119
- _defineProperty(_assertThisInitialized(_this), "updater", void 0);
102
+ _defineProperty(this, "updater", void 0);
120
103
  /**
121
104
  * Dictionary of namespace prefixes
122
105
  */
123
- _defineProperty(_assertThisInitialized(_this), "namespaces", void 0);
106
+ _defineProperty(this, "namespaces", void 0);
124
107
  /** Map of iri predicates to functions to call when adding { s type X } */
125
- _defineProperty(_assertThisInitialized(_this), "classActions", void 0);
108
+ _defineProperty(this, "classActions", void 0);
126
109
  /** Map of iri predicates to functions to call when getting statement with {s X o} */
127
- _defineProperty(_assertThisInitialized(_this), "propertyActions", void 0);
110
+ _defineProperty(this, "propertyActions", void 0);
128
111
  /** Redirect to lexically smaller equivalent symbol */
129
- _defineProperty(_assertThisInitialized(_this), "redirections", void 0);
112
+ _defineProperty(this, "redirections", void 0);
130
113
  /** Reverse mapping to redirection: aliases for this */
131
- _defineProperty(_assertThisInitialized(_this), "aliases", void 0);
114
+ _defineProperty(this, "aliases", void 0);
132
115
  /** Redirections we got from HTTP */
133
- _defineProperty(_assertThisInitialized(_this), "HTTPRedirects", void 0);
116
+ _defineProperty(this, "HTTPRedirects", void 0);
134
117
  /** Array of statements with this X as subject */
135
- _defineProperty(_assertThisInitialized(_this), "subjectIndex", void 0);
118
+ _defineProperty(this, "subjectIndex", void 0);
136
119
  /** Array of statements with this X as predicate */
137
- _defineProperty(_assertThisInitialized(_this), "predicateIndex", void 0);
120
+ _defineProperty(this, "predicateIndex", void 0);
138
121
  /** Array of statements with this X as object */
139
- _defineProperty(_assertThisInitialized(_this), "objectIndex", void 0);
122
+ _defineProperty(this, "objectIndex", void 0);
140
123
  /** Array of statements with X as provenance */
141
- _defineProperty(_assertThisInitialized(_this), "whyIndex", void 0);
142
- _defineProperty(_assertThisInitialized(_this), "index", void 0);
143
- _defineProperty(_assertThisInitialized(_this), "features", void 0);
144
- _defineProperty(_assertThisInitialized(_this), "_universalVariables", void 0);
145
- _defineProperty(_assertThisInitialized(_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);
146
129
  /** Function to remove quads from the store arrays with */
147
- _defineProperty(_assertThisInitialized(_this), "rdfArrayRemove", void 0);
130
+ _defineProperty(this, "rdfArrayRemove", void 0);
148
131
  /** Callbacks which are triggered after a statement has been added to the store */
149
- _defineProperty(_assertThisInitialized(_this), "dataCallbacks", void 0);
150
- _this.propertyActions = {};
151
- _this.classActions = {};
152
- _this.redirections = [];
153
- _this.aliases = [];
154
- _this.HTTPRedirects = [];
155
- _this.subjectIndex = [];
156
- _this.predicateIndex = [];
157
- _this.objectIndex = [];
158
- _this.whyIndex = [];
159
- _this.index = [_this.subjectIndex, _this.predicateIndex, _this.objectIndex, _this.whyIndex];
160
- _this.namespaces = {}; // Dictionary of namespace prefixes
161
- _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.
162
145
  // See https://github.com/linkeddata/rdflib.js/issues/458
163
146
  // 'sameAs',
164
147
  // 'InverseFunctionalProperty',
165
148
  // 'FunctionalProperty',
166
149
  ];
167
- _this.rdfArrayRemove = opts.rdfArrayRemove || RDFArrayRemove;
150
+ this.rdfArrayRemove = opts.rdfArrayRemove || RDFArrayRemove;
168
151
  if (opts.dataCallback) {
169
- _this.dataCallbacks = [opts.dataCallback];
152
+ this.dataCallbacks = [opts.dataCallback];
170
153
  }
171
- _this.initPropertyActions(_this.features);
172
- return _this;
154
+ this.initPropertyActions(this.features);
173
155
  }
174
156
 
175
157
  /**
176
158
  * Gets the URI of the default graph
177
159
  */
178
- _createClass(IndexedFormula, [{
179
- key: "substitute",
180
- value:
181
- /**
182
- * Gets this graph with the bindings substituted
183
- * @param bindings The bindings
184
- */
185
- function substitute(bindings) {
186
- var statementsCopy = this.statements.map(function (ea) {
187
- return ea.substitute(bindings);
188
- });
189
- var y = new IndexedFormula();
190
- y.add(statementsCopy);
191
- return y;
192
- }
160
+ static get defaultGraphURI() {
161
+ return defaultGraphURI;
162
+ }
193
163
 
194
- /**
195
- * Add a callback which will be triggered after a statement has been added to the store.
196
- * @param cb
197
- */
198
- }, {
199
- key: "addDataCallback",
200
- value: function addDataCallback(cb) {
201
- if (!this.dataCallbacks) {
202
- this.dataCallbacks = [];
203
- }
204
- 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 = [];
205
184
  }
185
+ this.dataCallbacks.push(cb);
186
+ }
206
187
 
207
- /**
208
- * Apply a set of statements to be deleted and to be inserted
209
- *
210
- * @param patch - The set of statements to be deleted and to be inserted
211
- * @param target - The name of the document to patch
212
- * @param patchCallback - Callback to be called when patching is complete
213
- */
214
- }, {
215
- key: "applyPatch",
216
- value: function applyPatch(patch, target, patchCallback) {
217
- var targetKB = this;
218
- var ds;
219
- var binding = null;
220
- function doPatch(onDonePatch) {
221
- if (patch['delete']) {
222
- ds = patch['delete'];
223
- // console.log(bindingDebug(binding))
224
- // console.log('ds before substitute: ' + ds)
225
- if (binding) ds = ds.substitute(binding);
226
- // console.log('applyPatch: delete: ' + ds)
227
- ds = ds.statements;
228
- var bad = [];
229
- var ds2 = ds.map(function (st) {
230
- // Find the actual statements in the store
231
- var sts = targetKB.statementsMatching(st.subject, st.predicate, st.object, target);
232
- if (sts.length === 0) {
233
- // log.info("NOT FOUND deletable " + st)
234
- bad.push(st);
235
- return null;
236
- } else {
237
- // log.info("Found deletable " + st)
238
- return sts[0];
239
- }
240
- });
241
- if (bad.length) {
242
- // console.log('Could not find to delete ' + bad.length + 'statements')
243
- // console.log('despite ' + targetKB.statementsMatching(bad[0].subject, bad[0].predicate)[0])
244
- 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];
245
218
  }
246
- ds2.map(function (st) {
247
- targetKB.remove(st);
248
- });
249
- }
250
- if (patch['insert']) {
251
- // log.info("doPatch insert "+patch['insert'])
252
- ds = patch['insert'];
253
- if (binding) ds = ds.substitute(binding);
254
- ds = ds.statements;
255
- ds.map(function (st) {
256
- st.graph = target;
257
- targetKB.add(st.subject, st.predicate, st.object, st.graph);
258
- });
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 '));
259
224
  }
260
- onDonePatch();
261
- }
262
- if (patch.where) {
263
- // log.info("Processing WHERE: " + patch.where + '\n')
264
- var query = new Query('patch');
265
- query.pat = patch.where;
266
- query.pat.statements.map(function (st) {
267
- st.graph = namedNode(target.value);
225
+ ds2.map(function (st) {
226
+ targetKB.remove(st);
268
227
  });
269
- //@ts-ignore TODO: add sync property to Query when converting Query to typescript
270
- query.sync = true;
271
- var bindingsFound = [];
272
- targetKB.query(query, function onBinding(binding) {
273
- bindingsFound.push(binding);
274
- // console.log(' got a binding: ' + bindingDebug(binding))
275
- }, targetKB.fetcher, function onDone() {
276
- if (bindingsFound.length === 0) {
277
- return patchCallback('No match found to be patched:' + patch.where);
278
- }
279
- if (bindingsFound.length > 1) {
280
- return patchCallback('Patch ambiguous. No patch done.');
281
- }
282
- binding = bindingsFound[0];
283
- 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);
284
237
  });
285
- } else {
286
- doPatch(patchCallback);
287
238
  }
239
+ onDonePatch();
288
240
  }
289
-
290
- /**
291
- * N3 allows for declaring blank nodes, this function enables that support
292
- *
293
- * @param x The blank node to be declared, supported in N3
294
- */
295
- }, {
296
- key: "declareExistential",
297
- value: function declareExistential(x) {
298
- if (!this._existentialVariables) this._existentialVariables = [];
299
- this._existentialVariables.push(x);
300
- 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);
301
266
  }
267
+ }
302
268
 
303
- /**
304
- * @param features
305
- */
306
- }, {
307
- key: "initPropertyActions",
308
- value: function initPropertyActions(features) {
309
- // If the predicate is #type, use handleRDFType to create a typeCallback on the object
310
- this.propertyActions[this.rdfFactory.id(this.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'))] = [handleRDFType];
311
-
312
- // Assumption: these terms are not redirected @@fixme
313
- if (ArrayIndexOf(features, 'sameAs') >= 0) {
314
- this.propertyActions[this.rdfFactory.id(this.rdfFactory.namedNode("".concat(owlNamespaceURI, "sameAs")))] = [function (formula, subj, pred, obj, why) {
315
- // log.warn("Equating "+subj.uri+" sameAs "+obj.uri); //@@
316
- formula.equate(subj, obj);
317
- return true; // true if statement given is NOT needed in the store
318
- }]; // sameAs -> equate & don't add to index
319
- }
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
+ }
320
279
 
321
- if (ArrayIndexOf(features, 'InverseFunctionalProperty') >= 0) {
322
- this.classActions[this.rdfFactory.id(this.rdfFactory.namedNode("".concat(owlNamespaceURI, "InverseFunctionalProperty")))] = [function (formula, subj, pred, obj, addFn) {
323
- // yes subj not pred!
324
- return formula.newPropertyAction(subj, handleIFP);
325
- }]; // IFP -> handleIFP, do add to index
326
- }
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];
327
286
 
328
- if (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
- }
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
333
294
  }
334
-
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
+ 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
341
305
  }
306
+ }
342
307
 
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 (isQuad(subj)) {
363
- this.add(subj.subject, subj.predicate, subj.object, subj.graph);
364
- } else if (isStore(subj)) {
365
- 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]);
366
330
  }
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.fromValue(pred);
379
- var objNode = Node.fromValue(obj);
380
- why = Node.fromValue(why);
381
- if (!isRDFlibSubject(subj)) {
382
- throw new Error('Subject is not a subject type');
383
- }
384
- if (!isRDFlibPredicate(pred)) {
385
- throw new Error("Predicate ".concat(pred, " is not a predicate type"));
386
- }
387
- if (!isRDFlibObject(objNode)) {
388
- throw new Error("Object ".concat(objNode, " is not an object type"));
389
- }
390
- if (!isGraph(why)) {
391
- 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);
392
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) {
393
364
  //@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?
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);
412
375
  }
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
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] = [];
427
394
  }
395
+ ix[h].push(st); // Set of things with this as subject, etc
396
+ }
428
397
 
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
- }
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);
444
403
  }
445
- return st;
446
404
  }
405
+ return st;
406
+ }
447
407
 
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
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:
457
425
  return term;
458
- }
459
- var y = this.redirections[this.id(term)];
460
- if (y) {
461
- return y;
462
- }
463
- switch (term.termType) {
464
- case BlankNodeTermType:
465
- return new BlankNode(term.value);
466
- case CollectionTermType:
467
- return term;
426
+ // non-RDF/JS type, should just need to cast
427
+ case DefaultGraphTermType:
428
+ return new DefaultGraph();
429
+ case EmptyTermType:
468
430
  // non-RDF/JS type, should just need to cast
469
- case DefaultGraphTermType:
470
- return new DefaultGraph();
471
- case EmptyTermType:
472
- // non-RDF/JS type, should just need to cast
473
- return term;
474
- case GraphTermType:
475
- // non-RDF/JS type, should just need to cast
476
- return term;
477
- case LiteralTermType:
478
- return new Literal(term.value, term.language, term.datatype);
479
- case NamedNodeTermType:
480
- return new NamedNode(term.value);
481
- case VariableTermType:
482
- return new Variable(term.value);
483
- default:
484
- throw new Error("Term Type not recognized for canonization: ".concat(term.termType));
485
- }
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}`);
486
443
  }
444
+ }
487
445
 
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
- }
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);
502
457
  }
503
458
  }
504
459
  }
460
+ }
505
461
 
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
- }
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;
539
481
  }
540
482
  }
541
- if (!arrayContains(this.statements, st)) {
542
- 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
+ }
543
493
  }
544
494
  }
495
+ if (!arrayContains(this.statements, st)) {
496
+ throw new Error('Statement list does not statement ' + st + '@' + st.graph + origin);
497
+ }
545
498
  }
499
+ }
546
500
 
547
- /**
548
- * Closes this formula (and return it)
549
- */
550
- }, {
551
- key: "close",
552
- value: function close() {
553
- 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);
554
511
  }
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[u1.termType] < ClassOrder[u2.termType]) {
563
- return -1;
564
- }
565
- if (ClassOrder[u1.termType] > ClassOrder[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;
512
+ if (ClassOrder[u1.termType] < ClassOrder[u2.termType]) {
513
+ return -1;
575
514
  }
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 (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 (ArrayIndexOf(flags, 'delete') !== -1) {
606
- this.remove(st);
607
- }
608
- }
515
+ if (ClassOrder[u1.termType] > ClassOrder[u2.termType]) {
516
+ return +1;
517
+ }
518
+ if (u1.value < u2.value) {
519
+ return -1;
520
+ }
521
+ if (u1.value > u2.value) {
522
+ return +1;
609
523
  }
524
+ return 0;
525
+ }
610
526
 
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}
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));
628
552
  }
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);
553
+ if (ArrayIndexOf(flags, 'delete') !== -1) {
554
+ this.remove(st);
636
555
  }
637
556
  }
557
+ }
638
558
 
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);
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}
648
574
  }
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;
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);
664
582
  }
583
+ }
665
584
 
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.fromValue(subject), Node.fromValue(predicate), Node.fromValue(object), Node.fromValue(graph));
679
- }
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
+ }
680
593
 
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
- }
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
+ }
691
607
 
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
- }
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
+ }
704
620
 
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
- }
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
+ }
728
629
 
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
- }
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
+ }
742
640
 
743
- // convenience function used by N3 parser
744
- }, {
745
- key: "variable",
746
- value: function variable(name) {
747
- 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] = [];
748
651
  }
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
- }
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);
762
659
  }
660
+ return done;
661
+ }
763
662
 
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 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);
776
689
  }
690
+ }
777
691
 
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
- 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;
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);
801
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');
723
+ }
724
+ return results;
725
+ }
802
726
 
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 (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);
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]);
822
735
  }
823
- this.removeStatement(sts[0]);
824
736
  return this;
825
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
+ }
826
748
 
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;
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]);
842
759
  }
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
- }
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]);
872
779
  }
873
- // request triples
874
- 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();
875
785
  for (var i = 0; i < sts.length; i++) {
876
786
  this.removeStatement(sts[i]);
877
787
  }
878
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
+ }
879
794
  }
880
- this.removeMatches(this.sym(doc.value), null, null, meta); // content-type
881
- return this;
882
795
  }
796
+ this.removeMatches(this.sym(doc.value), null, null, meta); // content-type
797
+ return this;
798
+ }
883
799
 
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
- }
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
+ }
906
820
 
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
- }
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
+ }
920
832
 
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
- }
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);
941
850
  }
942
- this.rdfArrayRemove(this.statements, st);
943
- return this;
944
851
  }
852
+ this.rdfArrayRemove(this.statements, st);
853
+ return this;
854
+ }
945
855
 
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;
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]);
957
863
  }
864
+ return this;
865
+ }
958
866
 
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
-
974
- var newlist = ix[newhash];
975
- if (!newlist) {
976
- ix[newhash] = oldlist;
977
- } else {
978
- ix[newhash] = oldlist.concat(newlist);
979
- }
980
- delete ix[oldhash];
981
- };
982
- // the canonical one carries all the indexes
983
- for (var i = 0; i < 4; i++) {
984
- 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
985
878
  }
986
- this.redirections[oldhash] = small;
987
- if (big.value) {
988
- // @@JAMBO: must update redirections,aliases from sub-items, too.
989
- if (!this.aliases[newhash]) {
990
- this.aliases[newhash] = [];
991
- }
992
- this.aliases[newhash].push(big); // Back link
993
- if (this.aliases[oldhash]) {
994
- for (i = 0; i < this.aliases[oldhash].length; i++) {
995
- this.redirections[this.id(this.aliases[oldhash][i])] = small;
996
- this.aliases[newhash].push(this.aliases[oldhash][i]);
997
- }
998
- }
999
- this.add(small, this.sym('http://www.w3.org/2007/ont/link#uri'), big);
1000
- // If two things are equal, and one is requested, we should request the other.
1001
- if (this.fetcher) {
1002
- 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]);
1003
902
  }
1004
903
  }
1005
- moveIndex(this.classActions);
1006
- moveIndex(this.propertyActions);
1007
- // log.debug("Equate done. "+big+" to be known as "+small)
1008
- 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
+ }
1009
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
+ }
1010
915
 
1011
- /**
1012
- * Return all equivalent URIs by which this is known
1013
- * @param x A named node
1014
- */
1015
- }, {
1016
- key: "allAliases",
1017
- value: function allAliases(x) {
1018
- var a = this.aliases[this.id(this.canon(x))] || [];
1019
- a.push(this.canon(x));
1020
- 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;
1021
952
  }
1022
953
 
1023
- /**
1024
- * Compare by canonical URI as smushed
1025
- * @param x A named node
1026
- * @param y Another named node
1027
- */
1028
- }, {
1029
- key: "sameThings",
1030
- value: function sameThings(x, y) {
1031
- if (x.equals(y)) {
1032
- return true;
1033
- }
1034
- var x1 = this.canon(x);
1035
- // alert('x1='+x1)
1036
- if (!x1) return false;
1037
- var y1 = this.canon(y);
1038
- // alert('y1='+y1); //@@
1039
- if (!y1) return false;
1040
- 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];
1041
957
  }
1042
- }, {
1043
- key: "setPrefixForURI",
1044
- value: function setPrefixForURI(prefix, nsuri) {
1045
- // TODO: This is a hack for our own issues, which ought to be fixed
1046
- // post-release
1047
- // See http://dig.csail.mit.edu/cgi-bin/roundup.cgi/$rdf/issue227
1048
- if (prefix === 'tab' && this.namespaces['tab']) {
1049
- return;
1050
- } // There are files around with long badly generated prefixes like this
1051
- if (prefix.slice(0, 2) === 'ns' || prefix.slice(0, 7) === 'default') {
1052
- return;
1053
- }
958
+ this.namespaces[prefix] = nsuri;
959
+ }
1054
960
 
1055
- // remove any prefix that currently targets nsuri
1056
- for (var existingPrefix in this.namespaces) {
1057
- 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]);
1058
987
  }
1059
- this.namespaces[prefix] = nsuri;
1060
988
  }
1061
-
1062
- /** Search the Store
1063
- *
1064
- * ALL CONVENIENCE LOOKUP FUNCTIONS RELY ON THIS!
1065
- * @param subj - A node to search for as subject, or if null, a wildcard
1066
- * @param pred - A node to search for as predicate, or if null, a wildcard
1067
- * @param obj - A node to search for as object, or if null, a wildcard
1068
- * @param why - A node to search for as graph, or if null, a wildcard
1069
- * @param justOne - flag - stop when found one rather than get all of them?
1070
- * @returns An array of nodes which match the wildcard position
1071
- */
1072
- }, {
1073
- key: "statementsMatching",
1074
- value: function statementsMatching(subj, pred, obj, why, justOne) {
1075
- // log.debug("Matching {"+subj+" "+pred+" "+obj+"}")
1076
- var pat = [subj, pred, obj, why];
1077
- var pattern = [];
1078
- var hash = [];
1079
- var wild = []; // wildcards
1080
- var given = []; // Not wild
1081
- var p;
1082
- var list;
1083
- for (p = 0; p < 4; p++) {
1084
- pattern[p] = this.canon(Node.fromValue(pat[p]));
1085
- if (!pattern[p]) {
1086
- wild.push(p);
1087
- } else {
1088
- given.push(p);
1089
- 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);
1090
999
  }
1091
1000
  }
1092
- if (given.length === 0) {
1093
- 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
1094
1015
  }
1095
- if (given.length === 1) {
1096
- // Easy too, we have an index for that
1097
- p = given[0];
1098
- list = this.index[p][hash[p]];
1099
- if (list && justOne) {
1100
- if (list.length > 1) {
1101
- list = list.slice(0, 1);
1102
- }
1103
- }
1104
- list = list || [];
1105
- return list;
1016
+ if (list.length < best) {
1017
+ best = list.length;
1018
+ iBest = i; // (not p!)
1106
1019
  }
1107
- // Now given.length is 2, 3 or 4.
1108
- // We hope that the scale-free nature of the data will mean we tend to get
1109
- // a short index in there somewhere!
1110
- var best = 1e10; // really bad
1111
- var iBest;
1112
- var i;
1113
- for (i = 0; i < given.length; i++) {
1114
- p = given[i]; // Which part we are dealing with
1115
- list = this.index[p][hash[p]];
1116
- if (!list) {
1117
- return []; // No occurrences
1118
- }
1119
-
1120
- if (list.length < best) {
1121
- best = list.length;
1122
- 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;
1123
1035
  }
1124
1036
  }
1125
- // Ok, we have picked the shortest index but now we have to filter it
1126
- var pBest = given[iBest];
1127
- var possibles = this.index[pBest][hash[pBest]];
1128
- var check = given.slice(0, iBest).concat(given.slice(iBest + 1)); // remove iBest
1129
- var results = [];
1130
- var parts = ['subject', 'predicate', 'object', 'why'];
1131
- for (var j = 0; j < possibles.length; j++) {
1132
- var st = possibles[j];
1133
- for (i = 0; i < check.length; i++) {
1134
- // for each position to be checked
1135
- p = check[i];
1136
- if (!this.canon(st[parts[p]]).equals(pattern[p])) {
1137
- st = null;
1138
- break;
1139
- }
1140
- }
1141
- if (st != null) {
1142
- results.push(st);
1143
- if (justOne) break;
1144
- }
1037
+ if (st != null) {
1038
+ results.push(st);
1039
+ if (justOne) break;
1145
1040
  }
1146
- return results;
1147
1041
  }
1042
+ return results;
1043
+ }
1148
1044
 
1149
- /**
1150
- * A list of all the URIs by which this thing is known
1151
- * @param term
1152
- */
1153
- }, {
1154
- key: "uris",
1155
- value: function uris(term) {
1156
- var cterm = this.canon(term);
1157
- var terms = this.aliases[this.id(cterm)];
1158
- if (!cterm.value) return [];
1159
- var res = [cterm.value];
1160
- if (terms) {
1161
- for (var i = 0; i < terms.length; i++) {
1162
- res.push(terms[i].uri);
1163
- }
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);
1164
1057
  }
1165
- return res;
1166
1058
  }
1167
- }, {
1168
- key: "serialize",
1169
- value: function serialize(base, contentType, provenance, options) {
1170
- var _options;
1171
- // override Formula.serialize to force the serializer namespace prefixes
1172
- // 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
1173
1064
 
1174
- // if namespaces are explicitly passed in options, let them override the existing namespaces in this formula
1175
- var namespaces = (_options = options) !== null && _options !== void 0 && _options.namespaces ? _objectSpread(_objectSpread({}, this.namespaces), options.namespaces) : _objectSpread({}, this.namespaces);
1176
- options = _objectSpread(_objectSpread({}, options || {}), {}, {
1177
- namespaces: namespaces
1178
- });
1179
- return _serialize(provenance, this, base, contentType, undefined, options);
1180
- }
1181
- }], [{
1182
- key: "defaultGraphURI",
1183
- get: function get() {
1184
- return defaultGraphURI;
1185
- }
1186
- }]);
1187
- return IndexedFormula;
1188
- }(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
+ }
1189
1079
  _defineProperty(IndexedFormula, "handleRDFType", void 0);
1190
- export { IndexedFormula as default };
1191
1080
  IndexedFormula.handleRDFType = handleRDFType;