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