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