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