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