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