rdflib 2.2.21 → 2.2.22
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 +9 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +61 -114
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -128
- package/esm/convert.js +1 -2
- package/esm/default-graph.js +14 -48
- package/esm/empty.js +8 -39
- package/esm/factories/canonical-data-factory.js +33 -65
- package/esm/factories/extended-term-factory.js +18 -25
- package/esm/factories/factory-types.js +3 -2
- package/esm/factories/rdflib-data-factory.js +9 -19
- package/esm/fetcher.js +1341 -1854
- package/esm/formula.js +639 -846
- package/esm/index.js +40 -76
- package/esm/jsonldparser.js +24 -49
- package/esm/jsonparser.js +1 -8
- package/esm/lists.js +47 -110
- package/esm/literal.js +120 -189
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1015 -1412
- package/esm/named-node.js +70 -119
- package/esm/namespace.js +2 -5
- package/esm/node-internal.js +73 -110
- package/esm/node.js +2 -7
- package/esm/parse.js +12 -19
- package/esm/patch-parser.js +10 -30
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +63 -147
- package/esm/rdfaparser.js +794 -997
- package/esm/rdfxmlparser.js +347 -461
- package/esm/serialize.js +9 -27
- package/esm/serializer.js +820 -1049
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +54 -85
- package/esm/store.js +830 -1103
- package/esm/types.js +22 -21
- package/esm/update-manager.js +869 -1106
- package/esm/updates-via.js +104 -161
- package/esm/uri.js +9 -53
- package/esm/utils/default-graph-uri.js +3 -2
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +19 -21
- package/esm/utils-js.js +20 -61
- package/esm/utils.js +10 -21
- package/esm/variable.js +32 -78
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +60 -113
- package/lib/class-order.js +1 -2
- package/lib/collection.js +69 -131
- package/lib/convert.js +3 -9
- package/lib/default-graph.js +13 -52
- package/lib/empty.js +8 -43
- package/lib/factories/canonical-data-factory.js +35 -79
- package/lib/factories/extended-term-factory.js +18 -32
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +1 -4
- package/lib/factories/rdflib-data-factory.js +9 -23
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +1370 -1843
- package/lib/formula.js +640 -855
- package/lib/index.js +66 -152
- package/lib/jsonldparser.js +23 -53
- package/lib/jsonparser.js +1 -10
- package/lib/lists.js +55 -112
- package/lib/literal.js +120 -195
- package/lib/log.d.ts +0 -6
- package/lib/log.js +7 -8
- package/lib/n3parser.js +1030 -1436
- package/lib/named-node.js +69 -126
- package/lib/namespace.js +2 -7
- package/lib/node-internal.js +74 -107
- package/lib/node.js +2 -12
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +12 -32
- package/lib/patch-parser.js +11 -34
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +62 -167
- package/lib/rdfaparser.js +796 -1009
- package/lib/rdfxmlparser.js +349 -466
- package/lib/serialize.js +11 -37
- package/lib/serializer.js +823 -1064
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +55 -91
- package/lib/store.d.ts +1 -1
- package/lib/store.js +850 -1112
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +23 -23
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +865 -1103
- package/lib/updates-via.js +105 -164
- package/lib/uri.js +8 -61
- package/lib/utils/default-graph-uri.js +3 -5
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +19 -40
- package/lib/utils-js.js +23 -88
- package/lib/utils.js +10 -27
- package/lib/variable.js +34 -85
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +2 -6
- package/package.json +36 -36
- package/src/fetcher.ts +2 -2
- package/src/update-manager.ts +12 -7
- package/changes.txt +0 -59
package/lib/formula.js
CHANGED
|
@@ -1,68 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
9
|
var _classOrder = _interopRequireDefault(require("./class-order"));
|
|
25
|
-
|
|
26
10
|
var _collection = _interopRequireDefault(require("./collection"));
|
|
27
|
-
|
|
28
11
|
var _canonicalDataFactory = _interopRequireDefault(require("./factories/canonical-data-factory"));
|
|
29
|
-
|
|
30
12
|
var _log = _interopRequireDefault(require("./log"));
|
|
31
|
-
|
|
32
13
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
33
|
-
|
|
34
14
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
35
|
-
|
|
36
|
-
var _serialize2 = _interopRequireDefault(require("./serialize"));
|
|
37
|
-
|
|
15
|
+
var _serialize = _interopRequireDefault(require("./serialize"));
|
|
38
16
|
var _types = require("./types");
|
|
39
|
-
|
|
40
17
|
var _terms = require("./utils/terms");
|
|
41
|
-
|
|
42
18
|
var _variable = _interopRequireDefault(require("./variable"));
|
|
43
|
-
|
|
44
19
|
var _utils = require("./utils");
|
|
45
|
-
|
|
46
20
|
var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
47
|
-
|
|
48
|
-
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; } } }; }
|
|
49
|
-
|
|
50
|
-
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); }
|
|
51
|
-
|
|
52
|
-
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; }
|
|
53
|
-
|
|
54
|
-
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); }; }
|
|
55
|
-
|
|
56
|
-
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; } }
|
|
57
|
-
|
|
58
21
|
/**
|
|
59
22
|
* A formula, or store of RDF statements
|
|
60
23
|
*/
|
|
61
|
-
|
|
62
|
-
(0, _inherits2.default)(Formula, _Node);
|
|
63
|
-
|
|
64
|
-
var _super = _createSuper(Formula);
|
|
65
|
-
|
|
24
|
+
class Formula extends _nodeInternal.default {
|
|
66
25
|
/**
|
|
67
26
|
* The accompanying fetcher instance.
|
|
68
27
|
*
|
|
@@ -86,893 +45,719 @@ var Formula = /*#__PURE__*/function (_Node) {
|
|
|
86
45
|
* @param opts
|
|
87
46
|
* @param opts.rdfFactory - The rdf factory that should be used by the store
|
|
88
47
|
*/
|
|
89
|
-
|
|
48
|
+
constructor() {
|
|
90
49
|
var _this;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
(0, _defineProperty2.default)(
|
|
104
|
-
(0, _defineProperty2.default)(
|
|
105
|
-
(0, _defineProperty2.default)(
|
|
106
|
-
(0, _defineProperty2.default)(
|
|
107
|
-
(0, _defineProperty2.default)(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
var _loop = function _loop() {
|
|
116
|
-
var factoryMethod = _step.value;
|
|
117
|
-
|
|
118
|
-
_this[factoryMethod] = function () {
|
|
119
|
-
var _this$rdfFactory;
|
|
120
|
-
|
|
121
|
-
return (_this$rdfFactory = _this.rdfFactory)[factoryMethod].apply(_this$rdfFactory, arguments);
|
|
122
|
-
};
|
|
50
|
+
let statements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
51
|
+
let constraints = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
52
|
+
let initBindings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
53
|
+
let optional = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
54
|
+
let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
55
|
+
super('');
|
|
56
|
+
_this = this;
|
|
57
|
+
this.statements = statements;
|
|
58
|
+
this.constraints = constraints;
|
|
59
|
+
this.initBindings = initBindings;
|
|
60
|
+
this.optional = optional;
|
|
61
|
+
(0, _defineProperty2.default)(this, "termType", _types.GraphTermType);
|
|
62
|
+
(0, _defineProperty2.default)(this, "classOrder", _classOrder.default.Graph);
|
|
63
|
+
(0, _defineProperty2.default)(this, "fetcher", void 0);
|
|
64
|
+
(0, _defineProperty2.default)(this, "isVar", 0);
|
|
65
|
+
(0, _defineProperty2.default)(this, "ns", _namespace.default);
|
|
66
|
+
(0, _defineProperty2.default)(this, "rdfFactory", void 0);
|
|
67
|
+
this.rdfFactory = opts && opts.rdfFactory || _canonicalDataFactory.default;
|
|
68
|
+
// Enable default factory methods on this while preserving factory context.
|
|
69
|
+
for (const factoryMethod of _utils.appliedFactoryMethods) {
|
|
70
|
+
this[factoryMethod] = function () {
|
|
71
|
+
return _this.rdfFactory[factoryMethod](...arguments);
|
|
123
72
|
};
|
|
124
|
-
|
|
125
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
126
|
-
_loop();
|
|
127
|
-
}
|
|
128
|
-
} catch (err) {
|
|
129
|
-
_iterator.e(err);
|
|
130
|
-
} finally {
|
|
131
|
-
_iterator.f();
|
|
132
73
|
}
|
|
133
|
-
|
|
134
|
-
return _this;
|
|
135
74
|
}
|
|
75
|
+
|
|
136
76
|
/** Add a statement from its parts
|
|
137
77
|
* @param subject - the first part of the statement
|
|
138
78
|
* @param predicate - the second part of the statement
|
|
139
79
|
* @param object - the third part of the statement
|
|
140
80
|
* @param graph - the last part of the statement
|
|
141
81
|
*/
|
|
82
|
+
add(subject, predicate, object, graph) {
|
|
83
|
+
if (arguments.length === 1) {
|
|
84
|
+
subject.forEach(st => this.add(st.subject, st.predicate, st.object, st.graph));
|
|
85
|
+
}
|
|
86
|
+
return this.statements.push(this.rdfFactory.quad(subject, predicate, object, graph));
|
|
87
|
+
}
|
|
142
88
|
|
|
89
|
+
/** Add a statment object
|
|
90
|
+
* @param {Statement} statement - An existing constructed statement to add
|
|
91
|
+
*/
|
|
92
|
+
addStatement(statement) {
|
|
93
|
+
return this.add(statement);
|
|
94
|
+
}
|
|
143
95
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return _this2.add(st.subject, st.predicate, st.object, st.graph);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
96
|
+
/**
|
|
97
|
+
* Shortcut for adding blankNodes
|
|
98
|
+
* @param [id]
|
|
99
|
+
*/
|
|
100
|
+
bnode(id) {
|
|
101
|
+
return this.rdfFactory.blankNode(id);
|
|
102
|
+
}
|
|
154
103
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return this.add(statement);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Shortcut for adding blankNodes
|
|
168
|
-
* @param [id]
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
}, {
|
|
172
|
-
key: "bnode",
|
|
173
|
-
value: function bnode(id) {
|
|
174
|
-
return this.rdfFactory.blankNode(id);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Adds all the statements to this formula
|
|
178
|
-
* @param statements - A collection of statements
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
}, {
|
|
182
|
-
key: "addAll",
|
|
183
|
-
value: function addAll(statements) {
|
|
184
|
-
var _this3 = this;
|
|
185
|
-
|
|
186
|
-
statements.forEach(function (quad) {
|
|
187
|
-
_this3.add(quad.subject, quad.predicate, quad.object, quad.graph);
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
/** Follow link from one node, using one wildcard, looking for one
|
|
191
|
-
*
|
|
192
|
-
* For example, any(me, knows, null, profile) - a person I know accoring to my profile .
|
|
193
|
-
* any(me, knows, null, null) - a person I know accoring to anything in store .
|
|
194
|
-
* any(null, knows, me, null) - a person who know me accoring to anything in store .
|
|
195
|
-
*
|
|
196
|
-
* @param s - A node to search for as subject, or if null, a wildcard
|
|
197
|
-
* @param p - A node to search for as predicate, or if null, a wildcard
|
|
198
|
-
* @param o - A node to search for as object, or if null, a wildcard
|
|
199
|
-
* @param g - A node to search for as graph, or if null, a wildcard
|
|
200
|
-
* @returns A node which match the wildcard position, or null
|
|
201
|
-
*/
|
|
202
|
-
|
|
203
|
-
}, {
|
|
204
|
-
key: "any",
|
|
205
|
-
value: function any(s, p, o, g) {
|
|
206
|
-
var st = this.anyStatementMatching(s, p, o, g);
|
|
207
|
-
|
|
208
|
-
if (st == null) {
|
|
209
|
-
return null;
|
|
210
|
-
} else if (s == null) {
|
|
211
|
-
return st.subject;
|
|
212
|
-
} else if (p == null) {
|
|
213
|
-
return st.predicate;
|
|
214
|
-
} else if (o == null) {
|
|
215
|
-
return st.object;
|
|
216
|
-
}
|
|
104
|
+
/**
|
|
105
|
+
* Adds all the statements to this formula
|
|
106
|
+
* @param statements - A collection of statements
|
|
107
|
+
*/
|
|
108
|
+
addAll(statements) {
|
|
109
|
+
statements.forEach(quad => {
|
|
110
|
+
this.add(quad.subject, quad.predicate, quad.object, quad.graph);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
217
113
|
|
|
114
|
+
/** Follow link from one node, using one wildcard, looking for one
|
|
115
|
+
*
|
|
116
|
+
* For example, any(me, knows, null, profile) - a person I know accoring to my profile .
|
|
117
|
+
* any(me, knows, null, null) - a person I know accoring to anything in store .
|
|
118
|
+
* any(null, knows, me, null) - a person who know me accoring to anything in store .
|
|
119
|
+
*
|
|
120
|
+
* @param s - A node to search for as subject, or if null, a wildcard
|
|
121
|
+
* @param p - A node to search for as predicate, or if null, a wildcard
|
|
122
|
+
* @param o - A node to search for as object, or if null, a wildcard
|
|
123
|
+
* @param g - A node to search for as graph, or if null, a wildcard
|
|
124
|
+
* @returns A node which match the wildcard position, or null
|
|
125
|
+
*/
|
|
126
|
+
any(s, p, o, g) {
|
|
127
|
+
const st = this.anyStatementMatching(s, p, o, g);
|
|
128
|
+
if (st == null) {
|
|
218
129
|
return null;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}, {
|
|
229
|
-
key: "anyValue",
|
|
230
|
-
value: function anyValue(s, p, o, g) {
|
|
231
|
-
var y = this.any(s, p, o, g);
|
|
232
|
-
return y ? y.value : void 0;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Gets the first JavaScript object equivalent to a node based on the specified pattern
|
|
236
|
-
* @param s The subject
|
|
237
|
-
* @param p The predicate
|
|
238
|
-
* @param o The object
|
|
239
|
-
* @param g The graph that contains the statement
|
|
240
|
-
*/
|
|
241
|
-
|
|
242
|
-
}, {
|
|
243
|
-
key: "anyJS",
|
|
244
|
-
value: function anyJS(s, p, o, g) {
|
|
245
|
-
var y = this.any(s, p, o, g);
|
|
246
|
-
return y ? _nodeInternal.default.toJS(y) : void 0;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Gets the first statement that matches the specified pattern
|
|
250
|
-
*/
|
|
130
|
+
} else if (s == null) {
|
|
131
|
+
return st.subject;
|
|
132
|
+
} else if (p == null) {
|
|
133
|
+
return st.predicate;
|
|
134
|
+
} else if (o == null) {
|
|
135
|
+
return st.object;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
251
139
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Gets the value of a node that matches the specified pattern
|
|
142
|
+
* @param s The subject
|
|
143
|
+
* @param p The predicate
|
|
144
|
+
* @param o The object
|
|
145
|
+
* @param g The graph that contains the statement
|
|
146
|
+
*/
|
|
147
|
+
anyValue(s, p, o, g) {
|
|
148
|
+
const y = this.any(s, p, o, g);
|
|
149
|
+
return y ? y.value : void 0;
|
|
150
|
+
}
|
|
256
151
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Gets the first JavaScript object equivalent to a node based on the specified pattern
|
|
154
|
+
* @param s The subject
|
|
155
|
+
* @param p The predicate
|
|
156
|
+
* @param o The object
|
|
157
|
+
* @param g The graph that contains the statement
|
|
158
|
+
*/
|
|
159
|
+
anyJS(s, p, o, g) {
|
|
160
|
+
const y = this.any(s, p, o, g);
|
|
161
|
+
return y ? _nodeInternal.default.toJS(y) : void 0;
|
|
162
|
+
}
|
|
260
163
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}, {
|
|
270
|
-
key: "id",
|
|
271
|
-
value: function id(term) {
|
|
272
|
-
return this.rdfFactory.id(term);
|
|
164
|
+
/**
|
|
165
|
+
* Gets the first statement that matches the specified pattern
|
|
166
|
+
*/
|
|
167
|
+
anyStatementMatching(s, p, o, g) {
|
|
168
|
+
let x = this.statementsMatching(s, p, o, g, true);
|
|
169
|
+
if (!x || x.length === 0) {
|
|
170
|
+
return undefined;
|
|
273
171
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
* This is really a teaching method as to do this properly you would use IndexedFormula
|
|
277
|
-
*
|
|
278
|
-
* @param s - A node to search for as subject, or if null, a wildcard
|
|
279
|
-
* @param p - A node to search for as predicate, or if null, a wildcard
|
|
280
|
-
* @param o - A node to search for as object, or if null, a wildcard
|
|
281
|
-
* @param g - A node to search for as graph, or if null, a wildcard
|
|
282
|
-
* @param justOne - flag - stop when found one rather than get all of them?
|
|
283
|
-
* @returns {Array<Node>} - An array of nodes which match the wildcard position
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
|
-
}, {
|
|
287
|
-
key: "statementsMatching",
|
|
288
|
-
value: function statementsMatching(s, p, o, g, justOne) {
|
|
289
|
-
var sts = this.statements.filter(function (st) {
|
|
290
|
-
return (!s || s.equals(st.subject)) && (!p || p.equals(st.predicate)) && (!o || o.equals(st.object)) && (!g || g.equals(st.graph));
|
|
291
|
-
});
|
|
172
|
+
return x[0];
|
|
173
|
+
}
|
|
292
174
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Returns a unique index-safe identifier for the given term.
|
|
177
|
+
*
|
|
178
|
+
* Falls back to the rdflib hashString implementation if the given factory doesn't support id.
|
|
179
|
+
*/
|
|
180
|
+
id(term) {
|
|
181
|
+
return this.rdfFactory.id(term);
|
|
182
|
+
}
|
|
296
183
|
|
|
297
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Search the Store
|
|
186
|
+
* This is really a teaching method as to do this properly you would use IndexedFormula
|
|
187
|
+
*
|
|
188
|
+
* @param s - A node to search for as subject, or if null, a wildcard
|
|
189
|
+
* @param p - A node to search for as predicate, or if null, a wildcard
|
|
190
|
+
* @param o - A node to search for as object, or if null, a wildcard
|
|
191
|
+
* @param g - A node to search for as graph, or if null, a wildcard
|
|
192
|
+
* @param justOne - flag - stop when found one rather than get all of them?
|
|
193
|
+
* @returns {Array<Node>} - An array of nodes which match the wildcard position
|
|
194
|
+
*/
|
|
195
|
+
statementsMatching(s, p, o, g, justOne) {
|
|
196
|
+
const sts = this.statements.filter(st => (!s || s.equals(st.subject)) && (!p || p.equals(st.predicate)) && (!o || o.equals(st.object)) && (!g || g.equals(st.graph)));
|
|
197
|
+
if (justOne) {
|
|
198
|
+
return sts.length === 0 ? [] : [sts[0]];
|
|
298
199
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
* These are a set of classes which provide by themselves complete
|
|
302
|
-
* information -- the other classes are redundant for those who
|
|
303
|
-
* know the class DAG.
|
|
304
|
-
* @param types A map of the types
|
|
305
|
-
*/
|
|
306
|
-
|
|
307
|
-
}, {
|
|
308
|
-
key: "bottomTypeURIs",
|
|
309
|
-
value: function bottomTypeURIs(types) {
|
|
310
|
-
var bots;
|
|
311
|
-
var bottom;
|
|
312
|
-
var elt;
|
|
313
|
-
var i;
|
|
314
|
-
var len;
|
|
315
|
-
var ref;
|
|
316
|
-
var subs;
|
|
317
|
-
var v;
|
|
318
|
-
bots = [];
|
|
319
|
-
|
|
320
|
-
for (var _k in types) {
|
|
321
|
-
if (!types.hasOwnProperty(_k)) continue;
|
|
322
|
-
v = types[_k];
|
|
323
|
-
subs = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), this.rdfFactory.namedNode(_k));
|
|
324
|
-
bottom = true;
|
|
325
|
-
i = 0;
|
|
326
|
-
|
|
327
|
-
for (len = subs.length; i < len; i++) {
|
|
328
|
-
elt = subs[i];
|
|
329
|
-
ref = elt.uri;
|
|
330
|
-
|
|
331
|
-
if (ref in types) {
|
|
332
|
-
// the subclass is one we know
|
|
333
|
-
bottom = false;
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
200
|
+
return sts;
|
|
201
|
+
}
|
|
337
202
|
|
|
338
|
-
|
|
339
|
-
|
|
203
|
+
/**
|
|
204
|
+
* Finds the types in the list which have no *stored* subtypes
|
|
205
|
+
* These are a set of classes which provide by themselves complete
|
|
206
|
+
* information -- the other classes are redundant for those who
|
|
207
|
+
* know the class DAG.
|
|
208
|
+
* @param types A map of the types
|
|
209
|
+
*/
|
|
210
|
+
bottomTypeURIs(types) {
|
|
211
|
+
let bots;
|
|
212
|
+
let bottom;
|
|
213
|
+
let elt;
|
|
214
|
+
let i;
|
|
215
|
+
let len;
|
|
216
|
+
let ref;
|
|
217
|
+
let subs;
|
|
218
|
+
let v;
|
|
219
|
+
bots = [];
|
|
220
|
+
for (let k in types) {
|
|
221
|
+
if (!types.hasOwnProperty(k)) continue;
|
|
222
|
+
v = types[k];
|
|
223
|
+
subs = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), this.rdfFactory.namedNode(k));
|
|
224
|
+
bottom = true;
|
|
225
|
+
i = 0;
|
|
226
|
+
for (len = subs.length; i < len; i++) {
|
|
227
|
+
elt = subs[i];
|
|
228
|
+
ref = elt.uri;
|
|
229
|
+
if (ref in types) {
|
|
230
|
+
// the subclass is one we know
|
|
231
|
+
bottom = false;
|
|
232
|
+
break;
|
|
340
233
|
}
|
|
341
234
|
}
|
|
342
|
-
|
|
343
|
-
|
|
235
|
+
if (bottom) {
|
|
236
|
+
bots[k] = v;
|
|
237
|
+
}
|
|
344
238
|
}
|
|
345
|
-
|
|
239
|
+
return bots;
|
|
240
|
+
}
|
|
346
241
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
/** Follow links from one node, using one wildcard.
|
|
353
|
-
*
|
|
354
|
-
* For example, each(me, knows, null, profile) - people I know accoring to my profile .
|
|
355
|
-
* each(me, knows, null, null) - people I know accoring to anything in store .
|
|
356
|
-
* each(null, knows, me, null) - people who know me accoring to anything in store .
|
|
357
|
-
*
|
|
358
|
-
* @param s - A node to search for as subject, or if null, a wildcard
|
|
359
|
-
* @param p - A node to search for as predicate, or if null, a wildcard
|
|
360
|
-
* @param o - A node to search for as object, or if null, a wildcard
|
|
361
|
-
* @param g - A node to search for as graph, or if null, a wildcard
|
|
362
|
-
* @returns {Array<Node>} - An array of nodes which match the wildcard position
|
|
363
|
-
*/
|
|
364
|
-
|
|
365
|
-
}, {
|
|
366
|
-
key: "each",
|
|
367
|
-
value: function each(s, p, o, g) {
|
|
368
|
-
var results = [];
|
|
369
|
-
var sts = this.statementsMatching(s, p, o, g, false);
|
|
370
|
-
|
|
371
|
-
if (s == null) {
|
|
372
|
-
for (var i = 0, len = sts.length; i < len; i++) {
|
|
373
|
-
results.push(sts[i].subject);
|
|
374
|
-
}
|
|
375
|
-
} else if (p == null) {
|
|
376
|
-
for (var l = 0, len1 = sts.length; l < len1; l++) {
|
|
377
|
-
results.push(sts[l].predicate);
|
|
378
|
-
}
|
|
379
|
-
} else if (o == null) {
|
|
380
|
-
for (var m = 0, len2 = sts.length; m < len2; m++) {
|
|
381
|
-
results.push(sts[m].object);
|
|
382
|
-
}
|
|
383
|
-
} else if (g == null) {
|
|
384
|
-
for (var _q = 0, len3 = sts.length; _q < len3; _q++) {
|
|
385
|
-
results.push(new _namedNode.default(sts[_q].graph.value));
|
|
386
|
-
}
|
|
387
|
-
}
|
|
242
|
+
/** Creates a new collection */
|
|
243
|
+
collection() {
|
|
244
|
+
return new _collection.default();
|
|
245
|
+
}
|
|
388
246
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
247
|
+
/** Follow links from one node, using one wildcard.
|
|
248
|
+
*
|
|
249
|
+
* For example, each(me, knows, null, profile) - people I know accoring to my profile .
|
|
250
|
+
* each(me, knows, null, null) - people I know accoring to anything in store .
|
|
251
|
+
* each(null, knows, me, null) - people who know me accoring to anything in store .
|
|
252
|
+
*
|
|
253
|
+
* @param s - A node to search for as subject, or if null, a wildcard
|
|
254
|
+
* @param p - A node to search for as predicate, or if null, a wildcard
|
|
255
|
+
* @param o - A node to search for as object, or if null, a wildcard
|
|
256
|
+
* @param g - A node to search for as graph, or if null, a wildcard
|
|
257
|
+
* @returns {Array<Node>} - An array of nodes which match the wildcard position
|
|
258
|
+
*/
|
|
259
|
+
each(s, p, o, g) {
|
|
260
|
+
const results = [];
|
|
261
|
+
let sts = this.statementsMatching(s, p, o, g, false);
|
|
262
|
+
if (s == null) {
|
|
263
|
+
for (let i = 0, len = sts.length; i < len; i++) {
|
|
264
|
+
results.push(sts[i].subject);
|
|
265
|
+
}
|
|
266
|
+
} else if (p == null) {
|
|
267
|
+
for (let l = 0, len1 = sts.length; l < len1; l++) {
|
|
268
|
+
results.push(sts[l].predicate);
|
|
269
|
+
}
|
|
270
|
+
} else if (o == null) {
|
|
271
|
+
for (let m = 0, len2 = sts.length; m < len2; m++) {
|
|
272
|
+
results.push(sts[m].object);
|
|
273
|
+
}
|
|
274
|
+
} else if (g == null) {
|
|
275
|
+
for (let q = 0, len3 = sts.length; q < len3; q++) {
|
|
276
|
+
results.push(new _namedNode.default(sts[q].graph.value));
|
|
401
277
|
}
|
|
402
|
-
|
|
403
|
-
return this.hashString() === other.hashString();
|
|
404
278
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
* or is the object of something which has the type as its range, or subject
|
|
408
|
-
* of something which has the type as its domain
|
|
409
|
-
* We don't bother doing subproperty (yet?)as it doesn't seeem to be used
|
|
410
|
-
* much.
|
|
411
|
-
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
412
|
-
* @return a hash of URIs
|
|
413
|
-
*/
|
|
414
|
-
|
|
415
|
-
}, {
|
|
416
|
-
key: "findMembersNT",
|
|
417
|
-
value: function findMembersNT(thisClass) {
|
|
418
|
-
var len2;
|
|
419
|
-
var len4;
|
|
420
|
-
var m;
|
|
421
|
-
var members;
|
|
422
|
-
var pred;
|
|
423
|
-
var ref;
|
|
424
|
-
var ref1;
|
|
425
|
-
var ref2;
|
|
426
|
-
var ref3;
|
|
427
|
-
var ref4;
|
|
428
|
-
var ref5;
|
|
429
|
-
var seeds;
|
|
430
|
-
var st;
|
|
431
|
-
var u;
|
|
432
|
-
seeds = {};
|
|
433
|
-
seeds[thisClass.toNT()] = true;
|
|
434
|
-
members = {};
|
|
435
|
-
ref = this.transitiveClosure(seeds, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
|
|
436
|
-
|
|
437
|
-
for (var t in ref) {
|
|
438
|
-
if (!ref.hasOwnProperty(t)) continue;
|
|
439
|
-
ref1 = this.statementsMatching(void 0, this.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), this.fromNT(t));
|
|
440
|
-
|
|
441
|
-
for (var i = 0, len = ref1.length; i < len; i++) {
|
|
442
|
-
st = ref1[i];
|
|
443
|
-
members[st.subject.toNT()] = st;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
ref2 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#domain'), this.fromNT(t));
|
|
447
|
-
|
|
448
|
-
for (var l = 0, len1 = ref2.length; l < len1; l++) {
|
|
449
|
-
pred = ref2[l];
|
|
450
|
-
ref3 = this.statementsMatching(void 0, pred);
|
|
451
|
-
|
|
452
|
-
for (m = 0, len2 = ref3.length; m < len2; m++) {
|
|
453
|
-
st = ref3[m];
|
|
454
|
-
members[st.subject.toNT()] = st;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
ref4 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#range'), this.fromNT(t));
|
|
279
|
+
return results;
|
|
280
|
+
}
|
|
459
281
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Test whether this formula is equals to {other}
|
|
284
|
+
* @param other - The other formula
|
|
285
|
+
*/
|
|
286
|
+
equals(other) {
|
|
287
|
+
if (!other) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
return this.hashString() === other.hashString();
|
|
291
|
+
}
|
|
463
292
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
293
|
+
/**
|
|
294
|
+
* For thisClass or any subclass, anything which has it is its type
|
|
295
|
+
* or is the object of something which has the type as its range, or subject
|
|
296
|
+
* of something which has the type as its domain
|
|
297
|
+
* We don't bother doing subproperty (yet?)as it doesn't seeem to be used
|
|
298
|
+
* much.
|
|
299
|
+
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
300
|
+
* @return a hash of URIs
|
|
301
|
+
*/
|
|
302
|
+
findMembersNT(thisClass) {
|
|
303
|
+
let len2;
|
|
304
|
+
let len4;
|
|
305
|
+
let m;
|
|
306
|
+
let members;
|
|
307
|
+
let pred;
|
|
308
|
+
let ref;
|
|
309
|
+
let ref1;
|
|
310
|
+
let ref2;
|
|
311
|
+
let ref3;
|
|
312
|
+
let ref4;
|
|
313
|
+
let ref5;
|
|
314
|
+
let seeds;
|
|
315
|
+
let st;
|
|
316
|
+
let u;
|
|
317
|
+
seeds = {};
|
|
318
|
+
seeds[thisClass.toNT()] = true;
|
|
319
|
+
members = {};
|
|
320
|
+
ref = this.transitiveClosure(seeds, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
|
|
321
|
+
for (let t in ref) {
|
|
322
|
+
if (!ref.hasOwnProperty(t)) continue;
|
|
323
|
+
ref1 = this.statementsMatching(void 0, this.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), this.fromNT(t));
|
|
324
|
+
for (let i = 0, len = ref1.length; i < len; i++) {
|
|
325
|
+
st = ref1[i];
|
|
326
|
+
members[st.subject.toNT()] = st;
|
|
469
327
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
* We don't bother doing subproperty (yet?)as it doesn't seeem to be used
|
|
478
|
-
* much.
|
|
479
|
-
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
480
|
-
* @param subject - A named node
|
|
481
|
-
*/
|
|
482
|
-
|
|
483
|
-
}, {
|
|
484
|
-
key: "findMemberURIs",
|
|
485
|
-
value: function findMemberURIs(subject) {
|
|
486
|
-
return this.NTtoURI(this.findMembersNT(subject));
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Get all the Classes of which we can RDFS-infer the subject is a superclass
|
|
490
|
-
* Returns a hash table where key is NT of type and value is statement why we
|
|
491
|
-
* think so.
|
|
492
|
-
* Does NOT return terms, returns URI strings.
|
|
493
|
-
* We use NT representations in this version because they handle blank nodes.
|
|
494
|
-
*/
|
|
495
|
-
|
|
496
|
-
}, {
|
|
497
|
-
key: "findSubClassesNT",
|
|
498
|
-
value: function findSubClassesNT(subject) {
|
|
499
|
-
var types = {};
|
|
500
|
-
types[subject.toNT()] = true;
|
|
501
|
-
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Get all the Classes of which we can RDFS-infer the subject is a subclass
|
|
505
|
-
* @param {RDFlibNamedNode} subject - The thing whose classes are to be found
|
|
506
|
-
* @returns a hash table where key is NT of type and value is statement why we
|
|
507
|
-
* think so.
|
|
508
|
-
* Does NOT return terms, returns URI strings.
|
|
509
|
-
* We use NT representations in this version because they handle blank nodes.
|
|
510
|
-
*/
|
|
511
|
-
|
|
512
|
-
}, {
|
|
513
|
-
key: "findSuperClassesNT",
|
|
514
|
-
value: function findSuperClassesNT(subject) {
|
|
515
|
-
var types = {};
|
|
516
|
-
types[subject.toNT()] = true;
|
|
517
|
-
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
521
|
-
* todo: This will loop is there is a class subclass loop (Sublass loops are
|
|
522
|
-
* not illegal)
|
|
523
|
-
* @param {RDFlibNamedNode} subject - The thing whose classes are to be found
|
|
524
|
-
* @returns a hash table where key is NT of type and value is statement why we think so.
|
|
525
|
-
* Does NOT return terms, returns URI strings.
|
|
526
|
-
* We use NT representations in this version because they handle blank nodes.
|
|
527
|
-
*/
|
|
528
|
-
|
|
529
|
-
}, {
|
|
530
|
-
key: "findTypesNT",
|
|
531
|
-
value: function findTypesNT(subject) {
|
|
532
|
-
var domain;
|
|
533
|
-
var range;
|
|
534
|
-
var rdftype;
|
|
535
|
-
var ref;
|
|
536
|
-
var ref1;
|
|
537
|
-
var ref2;
|
|
538
|
-
var ref3;
|
|
539
|
-
var st;
|
|
540
|
-
var types;
|
|
541
|
-
rdftype = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
|
|
542
|
-
types = [];
|
|
543
|
-
ref = this.statementsMatching(subject, void 0, void 0);
|
|
544
|
-
|
|
545
|
-
for (var i = 0, len = ref.length; i < len; i++) {
|
|
546
|
-
st = ref[i];
|
|
547
|
-
|
|
548
|
-
if (st.predicate.uri === rdftype) {
|
|
549
|
-
types[st.object.toNT()] = st;
|
|
550
|
-
} else {
|
|
551
|
-
ref1 = this.each(st.predicate, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#domain'));
|
|
552
|
-
|
|
553
|
-
for (var l = 0, len1 = ref1.length; l < len1; l++) {
|
|
554
|
-
range = ref1[l];
|
|
555
|
-
types[range.toNT()] = st;
|
|
556
|
-
}
|
|
328
|
+
ref2 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#domain'), this.fromNT(t));
|
|
329
|
+
for (let l = 0, len1 = ref2.length; l < len1; l++) {
|
|
330
|
+
pred = ref2[l];
|
|
331
|
+
ref3 = this.statementsMatching(void 0, pred);
|
|
332
|
+
for (m = 0, len2 = ref3.length; m < len2; m++) {
|
|
333
|
+
st = ref3[m];
|
|
334
|
+
members[st.subject.toNT()] = st;
|
|
557
335
|
}
|
|
558
336
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
for (var _q3 = 0, len3 = ref3.length; _q3 < len3; _q3++) {
|
|
567
|
-
domain = ref3[_q3];
|
|
568
|
-
types[domain.toNT()] = st;
|
|
337
|
+
ref4 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#range'), this.fromNT(t));
|
|
338
|
+
for (let q = 0, len3 = ref4.length; q < len3; q++) {
|
|
339
|
+
pred = ref4[q];
|
|
340
|
+
ref5 = this.statementsMatching(void 0, pred);
|
|
341
|
+
for (u = 0, len4 = ref5.length; u < len4; u++) {
|
|
342
|
+
st = ref5[u];
|
|
343
|
+
members[st.object.toNT()] = st;
|
|
569
344
|
}
|
|
570
345
|
}
|
|
571
|
-
|
|
572
|
-
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
573
346
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
* todo: This will loop is there is a class subclass loop (Sublass loops are
|
|
577
|
-
* not illegal)
|
|
578
|
-
* Returns a hash table where key is NT of type and value is statement why we
|
|
579
|
-
* think so.
|
|
580
|
-
* Does NOT return terms, returns URI strings.
|
|
581
|
-
* We use NT representations in this version because they handle blank nodes.
|
|
582
|
-
* @param subject - A subject node
|
|
583
|
-
*/
|
|
584
|
-
|
|
585
|
-
}, {
|
|
586
|
-
key: "findTypeURIs",
|
|
587
|
-
value: function findTypeURIs(subject) {
|
|
588
|
-
return this.NTtoURI(this.findTypesNT(subject));
|
|
589
|
-
}
|
|
590
|
-
/** Trace statements which connect directly, or through bnodes
|
|
591
|
-
*
|
|
592
|
-
* @param subject - The node to start looking for statments
|
|
593
|
-
* @param doc - The document to be searched, or null to search all documents
|
|
594
|
-
* @returns an array of statements, duplicate statements are suppresssed.
|
|
595
|
-
*/
|
|
596
|
-
|
|
597
|
-
}, {
|
|
598
|
-
key: "connectedStatements",
|
|
599
|
-
value: function connectedStatements(subject, doc, excludePredicateURIs) {
|
|
600
|
-
excludePredicateURIs = excludePredicateURIs || [];
|
|
601
|
-
var todo = [subject];
|
|
602
|
-
var done = {};
|
|
603
|
-
var doneArcs = {};
|
|
604
|
-
var result = [];
|
|
605
|
-
var self = this;
|
|
606
|
-
|
|
607
|
-
var follow = function follow(x) {
|
|
608
|
-
var queue = function queue(x) {
|
|
609
|
-
if (x.termType === 'BlankNode' && !done[x.value]) {
|
|
610
|
-
done[x.value] = true;
|
|
611
|
-
todo.push(x);
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
var sts = self.statementsMatching(null, null, x, doc).concat(self.statementsMatching(x, null, null, doc));
|
|
616
|
-
sts = sts.filter(function (st) {
|
|
617
|
-
if (excludePredicateURIs[st.predicate.value]) return false;
|
|
618
|
-
var hash = st.toNT();
|
|
619
|
-
if (doneArcs[hash]) return false;
|
|
620
|
-
doneArcs[hash] = true;
|
|
621
|
-
return true;
|
|
622
|
-
});
|
|
623
|
-
sts.forEach(function (st) {
|
|
624
|
-
queue(st.subject);
|
|
625
|
-
queue(st.object);
|
|
626
|
-
});
|
|
627
|
-
result = result.concat(sts);
|
|
628
|
-
};
|
|
347
|
+
return members;
|
|
348
|
+
}
|
|
629
349
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
350
|
+
/**
|
|
351
|
+
* For thisClass or any subclass, anything which has it is its type
|
|
352
|
+
* or is the object of something which has the type as its range, or subject
|
|
353
|
+
* of something which has the type as its domain
|
|
354
|
+
* We don't bother doing subproperty (yet?)as it doesn't seeem to be used
|
|
355
|
+
* much.
|
|
356
|
+
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
357
|
+
* @param subject - A named node
|
|
358
|
+
*/
|
|
359
|
+
findMemberURIs(subject) {
|
|
360
|
+
return this.NTtoURI(this.findMembersNT(subject));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Get all the Classes of which we can RDFS-infer the subject is a superclass
|
|
365
|
+
* Returns a hash table where key is NT of type and value is statement why we
|
|
366
|
+
* think so.
|
|
367
|
+
* Does NOT return terms, returns URI strings.
|
|
368
|
+
* We use NT representations in this version because they handle blank nodes.
|
|
369
|
+
*/
|
|
370
|
+
findSubClassesNT(subject) {
|
|
371
|
+
let types = {};
|
|
372
|
+
types[subject.toNT()] = true;
|
|
373
|
+
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
|
|
374
|
+
}
|
|
633
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Get all the Classes of which we can RDFS-infer the subject is a subclass
|
|
378
|
+
* @param {RDFlibNamedNode} subject - The thing whose classes are to be found
|
|
379
|
+
* @returns a hash table where key is NT of type and value is statement why we
|
|
380
|
+
* think so.
|
|
381
|
+
* Does NOT return terms, returns URI strings.
|
|
382
|
+
* We use NT representations in this version because they handle blank nodes.
|
|
383
|
+
*/
|
|
384
|
+
findSuperClassesNT(subject) {
|
|
385
|
+
let types = {};
|
|
386
|
+
types[subject.toNT()] = true;
|
|
387
|
+
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
388
|
+
}
|
|
634
389
|
|
|
635
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
392
|
+
* todo: This will loop is there is a class subclass loop (Sublass loops are
|
|
393
|
+
* not illegal)
|
|
394
|
+
* @param {RDFlibNamedNode} subject - The thing whose classes are to be found
|
|
395
|
+
* @returns a hash table where key is NT of type and value is statement why we think so.
|
|
396
|
+
* Does NOT return terms, returns URI strings.
|
|
397
|
+
* We use NT representations in this version because they handle blank nodes.
|
|
398
|
+
*/
|
|
399
|
+
findTypesNT(subject) {
|
|
400
|
+
let domain;
|
|
401
|
+
let range;
|
|
402
|
+
let rdftype;
|
|
403
|
+
let ref;
|
|
404
|
+
let ref1;
|
|
405
|
+
let ref2;
|
|
406
|
+
let ref3;
|
|
407
|
+
let st;
|
|
408
|
+
let types;
|
|
409
|
+
rdftype = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
|
|
410
|
+
types = [];
|
|
411
|
+
ref = this.statementsMatching(subject, void 0, void 0);
|
|
412
|
+
for (let i = 0, len = ref.length; i < len; i++) {
|
|
413
|
+
st = ref[i];
|
|
414
|
+
if (st.predicate.uri === rdftype) {
|
|
415
|
+
types[st.object.toNT()] = st;
|
|
416
|
+
} else {
|
|
417
|
+
ref1 = this.each(st.predicate, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#domain'));
|
|
418
|
+
for (let l = 0, len1 = ref1.length; l < len1; l++) {
|
|
419
|
+
range = ref1[l];
|
|
420
|
+
types[range.toNT()] = st;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
636
423
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
value: function formula(_features) {
|
|
646
|
-
return new Formula();
|
|
424
|
+
ref2 = this.statementsMatching(void 0, void 0, subject);
|
|
425
|
+
for (let m = 0, len2 = ref2.length; m < len2; m++) {
|
|
426
|
+
st = ref2[m];
|
|
427
|
+
ref3 = this.each(st.predicate, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#range'));
|
|
428
|
+
for (let q = 0, len3 = ref3.length; q < len3; q++) {
|
|
429
|
+
domain = ref3[q];
|
|
430
|
+
types[domain.toNT()] = st;
|
|
431
|
+
}
|
|
647
432
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
* The blank node bit should not be used on program-external values; designed
|
|
651
|
-
* for internal work such as storing a blank node id in an HTML attribute.
|
|
652
|
-
* This will only parse the strings generated by the various toNT() methods.
|
|
653
|
-
*/
|
|
654
|
-
|
|
655
|
-
}, {
|
|
656
|
-
key: "fromNT",
|
|
657
|
-
value: function fromNT(str) {
|
|
658
|
-
var dt, k, lang;
|
|
659
|
-
|
|
660
|
-
switch (str[0]) {
|
|
661
|
-
case '<':
|
|
662
|
-
return this.sym(str.slice(1, -1));
|
|
663
|
-
|
|
664
|
-
case '"':
|
|
665
|
-
lang = void 0;
|
|
666
|
-
dt = void 0;
|
|
667
|
-
k = str.lastIndexOf('"');
|
|
668
|
-
|
|
669
|
-
if (k < str.length - 1) {
|
|
670
|
-
if (str[k + 1] === '@') {
|
|
671
|
-
lang = str.slice(k + 2);
|
|
672
|
-
} else if (str.slice(k + 1, k + 3) === '^^') {
|
|
673
|
-
dt = this.fromNT(str.slice(k + 3));
|
|
674
|
-
} else {
|
|
675
|
-
throw new Error("Can't convert string from NT: " + str);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
str = str.slice(1, k);
|
|
680
|
-
str = str.replace(/\\"/g, '"');
|
|
681
|
-
str = str.replace(/\\n/g, '\n');
|
|
682
|
-
str = str.replace(/\\\\/g, '\\');
|
|
683
|
-
return this.rdfFactory.literal(str, lang || dt);
|
|
684
|
-
|
|
685
|
-
case '_':
|
|
686
|
-
return this.rdfFactory.blankNode(str.slice(2));
|
|
433
|
+
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
434
|
+
}
|
|
687
435
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
436
|
+
/**
|
|
437
|
+
* Get all the Classes of which we can RDFS-infer the subject is a member
|
|
438
|
+
* todo: This will loop is there is a class subclass loop (Sublass loops are
|
|
439
|
+
* not illegal)
|
|
440
|
+
* Returns a hash table where key is NT of type and value is statement why we
|
|
441
|
+
* think so.
|
|
442
|
+
* Does NOT return terms, returns URI strings.
|
|
443
|
+
* We use NT representations in this version because they handle blank nodes.
|
|
444
|
+
* @param subject - A subject node
|
|
445
|
+
*/
|
|
446
|
+
findTypeURIs(subject) {
|
|
447
|
+
return this.NTtoURI(this.findTypesNT(subject));
|
|
448
|
+
}
|
|
691
449
|
|
|
692
|
-
|
|
450
|
+
/** Trace statements which connect directly, or through bnodes
|
|
451
|
+
*
|
|
452
|
+
* @param subject - The node to start looking for statments
|
|
453
|
+
* @param doc - The document to be searched, or null to search all documents
|
|
454
|
+
* @returns an array of statements, duplicate statements are suppresssed.
|
|
455
|
+
*/
|
|
456
|
+
connectedStatements(subject, doc, excludePredicateURIs) {
|
|
457
|
+
excludePredicateURIs = excludePredicateURIs || [];
|
|
458
|
+
let todo = [subject];
|
|
459
|
+
let done = {};
|
|
460
|
+
let doneArcs = {};
|
|
461
|
+
let result = [];
|
|
462
|
+
let self = this;
|
|
463
|
+
let follow = function (x) {
|
|
464
|
+
let queue = function (x) {
|
|
465
|
+
if (x.termType === 'BlankNode' && !done[x.value]) {
|
|
466
|
+
done[x.value] = true;
|
|
467
|
+
todo.push(x);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
let sts = self.statementsMatching(null, null, x, doc).concat(self.statementsMatching(x, null, null, doc));
|
|
471
|
+
sts = sts.filter(function (st) {
|
|
472
|
+
if (excludePredicateURIs[st.predicate.value]) return false;
|
|
473
|
+
let hash = st.toNT();
|
|
474
|
+
if (doneArcs[hash]) return false;
|
|
475
|
+
doneArcs[hash] = true;
|
|
476
|
+
return true;
|
|
477
|
+
});
|
|
478
|
+
sts.forEach(function (st) {
|
|
479
|
+
queue(st.subject);
|
|
480
|
+
queue(st.object);
|
|
481
|
+
});
|
|
482
|
+
result = result.concat(sts);
|
|
483
|
+
};
|
|
484
|
+
while (todo.length) {
|
|
485
|
+
follow(todo.shift());
|
|
693
486
|
}
|
|
694
|
-
|
|
487
|
+
// console.log('' + result.length + ' statements about ' + subject)
|
|
488
|
+
return result;
|
|
489
|
+
}
|
|
695
490
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
491
|
+
/**
|
|
492
|
+
* Creates a new empty formula
|
|
493
|
+
*
|
|
494
|
+
* @param _features - Not applicable, but necessary for typing to pass
|
|
495
|
+
*/
|
|
496
|
+
formula(_features) {
|
|
497
|
+
return new Formula();
|
|
498
|
+
}
|
|
700
499
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
500
|
+
/**
|
|
501
|
+
* Transforms an NTriples string format into a Node.
|
|
502
|
+
* The blank node bit should not be used on program-external values; designed
|
|
503
|
+
* for internal work such as storing a blank node id in an HTML attribute.
|
|
504
|
+
* This will only parse the strings generated by the various toNT() methods.
|
|
505
|
+
*/
|
|
506
|
+
fromNT(str) {
|
|
507
|
+
let dt, k, lang;
|
|
508
|
+
switch (str[0]) {
|
|
509
|
+
case '<':
|
|
510
|
+
return this.sym(str.slice(1, -1));
|
|
511
|
+
case '"':
|
|
512
|
+
lang = void 0;
|
|
513
|
+
dt = void 0;
|
|
514
|
+
k = str.lastIndexOf('"');
|
|
515
|
+
if (k < str.length - 1) {
|
|
516
|
+
if (str[k + 1] === '@') {
|
|
517
|
+
lang = str.slice(k + 2);
|
|
518
|
+
} else if (str.slice(k + 1, k + 3) === '^^') {
|
|
519
|
+
dt = this.fromNT(str.slice(k + 3));
|
|
520
|
+
} else {
|
|
521
|
+
throw new Error("Can't convert string from NT: " + str);
|
|
522
|
+
}
|
|
704
523
|
}
|
|
524
|
+
str = str.slice(1, k);
|
|
525
|
+
str = str.replace(/\\"/g, '"');
|
|
526
|
+
str = str.replace(/\\n/g, '\n');
|
|
527
|
+
str = str.replace(/\\\\/g, '\\');
|
|
528
|
+
return this.rdfFactory.literal(str, lang || dt);
|
|
529
|
+
case '_':
|
|
530
|
+
return this.rdfFactory.blankNode(str.slice(2));
|
|
531
|
+
case '?':
|
|
532
|
+
return new _variable.default(str.slice(1));
|
|
533
|
+
}
|
|
534
|
+
throw new Error("Can't convert from NT: " + str);
|
|
535
|
+
}
|
|
705
536
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
537
|
+
/** Returns true if this formula holds the specified statement(s) */
|
|
538
|
+
holds(s, p, o, g) {
|
|
539
|
+
let i;
|
|
540
|
+
if (arguments.length === 1) {
|
|
541
|
+
if (!s) {
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
if (s instanceof Array) {
|
|
545
|
+
for (i = 0; i < s.length; i++) {
|
|
546
|
+
if (!this.holds(s[i])) {
|
|
547
|
+
return false;
|
|
711
548
|
}
|
|
712
|
-
|
|
713
|
-
return true;
|
|
714
|
-
} else if ((0, _terms.isStatement)(s)) {
|
|
715
|
-
return this.holds(s.subject, s.predicate, s.object, s.graph);
|
|
716
|
-
} else if (s.statements) {
|
|
717
|
-
return this.holds(s.statements);
|
|
718
549
|
}
|
|
550
|
+
return true;
|
|
551
|
+
} else if ((0, _terms.isStatement)(s)) {
|
|
552
|
+
return this.holds(s.subject, s.predicate, s.object, s.graph);
|
|
553
|
+
} else if (s.statements) {
|
|
554
|
+
return this.holds(s.statements);
|
|
719
555
|
}
|
|
720
|
-
|
|
721
|
-
var st = this.anyStatementMatching(s, p, o, g);
|
|
722
|
-
return st != null;
|
|
723
556
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}, {
|
|
729
|
-
key: "holdsStatement",
|
|
730
|
-
value: function holdsStatement(statement) {
|
|
731
|
-
return this.holds(statement.subject, statement.predicate, statement.object, statement.graph);
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Used by the n3parser to generate list elements
|
|
735
|
-
* @param values - The values of the collection
|
|
736
|
-
* @param context - The store
|
|
737
|
-
* @return {BlankNode|Collection} - The term for the statement
|
|
738
|
-
*/
|
|
739
|
-
|
|
740
|
-
}, {
|
|
741
|
-
key: "list",
|
|
742
|
-
value: function list(values, context) {
|
|
743
|
-
if (context.rdfFactory.supports["COLLECTIONS"]) {
|
|
744
|
-
var collection = context.rdfFactory.collection();
|
|
745
|
-
values.forEach(function (val) {
|
|
746
|
-
collection.append(val);
|
|
747
|
-
});
|
|
748
|
-
return collection;
|
|
749
|
-
} else {
|
|
750
|
-
var node = context.rdfFactory.blankNode();
|
|
751
|
-
|
|
752
|
-
var _statements = (0, _utils.arrayToStatements)(context.rdfFactory, node, values);
|
|
557
|
+
let st = this.anyStatementMatching(s, p, o, g);
|
|
558
|
+
return st != null;
|
|
559
|
+
}
|
|
753
560
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
* @param t - Some iterable collection of NTriple URI strings
|
|
761
|
-
* @return A collection of the URIs as strings
|
|
762
|
-
* todo: explain why it is important to go through NT
|
|
763
|
-
*/
|
|
764
|
-
|
|
765
|
-
}, {
|
|
766
|
-
key: "NTtoURI",
|
|
767
|
-
value: function NTtoURI(t) {
|
|
768
|
-
var k, v;
|
|
769
|
-
var uris = {};
|
|
770
|
-
|
|
771
|
-
for (k in t) {
|
|
772
|
-
if (!t.hasOwnProperty(k)) continue;
|
|
773
|
-
v = t[k];
|
|
774
|
-
|
|
775
|
-
if (k[0] === '<') {
|
|
776
|
-
uris[k.slice(1, -1)] = v;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
561
|
+
/**
|
|
562
|
+
* Returns true if this formula holds the specified {statement}
|
|
563
|
+
*/
|
|
564
|
+
holdsStatement(statement) {
|
|
565
|
+
return this.holds(statement.subject, statement.predicate, statement.object, statement.graph);
|
|
566
|
+
}
|
|
779
567
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
key: "serialize",
|
|
792
|
-
value: function serialize(base, contentType, provenance, options) {
|
|
793
|
-
// delegate the graph serialization to the implementation in ./serialize
|
|
794
|
-
return (0, _serialize2.default)(provenance, this, base, contentType, undefined, options);
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Creates a new formula with the substituting bindings applied
|
|
798
|
-
* @param bindings - The bindings to substitute
|
|
799
|
-
*/
|
|
800
|
-
|
|
801
|
-
}, {
|
|
802
|
-
key: "substitute",
|
|
803
|
-
value: function substitute(bindings) {
|
|
804
|
-
var statementsCopy = this.statements.map(function (ea) {
|
|
805
|
-
return ea.substitute(bindings);
|
|
568
|
+
/**
|
|
569
|
+
* Used by the n3parser to generate list elements
|
|
570
|
+
* @param values - The values of the collection
|
|
571
|
+
* @param context - The store
|
|
572
|
+
* @return {BlankNode|Collection} - The term for the statement
|
|
573
|
+
*/
|
|
574
|
+
list(values, context) {
|
|
575
|
+
if (context.rdfFactory.supports["COLLECTIONS"]) {
|
|
576
|
+
const collection = context.rdfFactory.collection();
|
|
577
|
+
values.forEach(function (val) {
|
|
578
|
+
collection.append(val);
|
|
806
579
|
});
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
580
|
+
return collection;
|
|
581
|
+
} else {
|
|
582
|
+
const node = context.rdfFactory.blankNode();
|
|
583
|
+
const statements = (0, _utils.arrayToStatements)(context.rdfFactory, node, values);
|
|
584
|
+
context.addAll(statements);
|
|
585
|
+
return node;
|
|
812
586
|
}
|
|
813
|
-
}
|
|
814
|
-
key: "sym",
|
|
815
|
-
value: function sym(uri, name) {
|
|
816
|
-
if (name) {
|
|
817
|
-
throw new Error('This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings.');
|
|
818
|
-
}
|
|
587
|
+
}
|
|
819
588
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
if (x == null) {
|
|
836
|
-
_log.default.error('No value found for the() {' + s + ' ' + p + ' ' + o + '}.');
|
|
589
|
+
/**
|
|
590
|
+
* Transform a collection of NTriple URIs into their URI strings
|
|
591
|
+
* @param t - Some iterable collection of NTriple URI strings
|
|
592
|
+
* @return A collection of the URIs as strings
|
|
593
|
+
* todo: explain why it is important to go through NT
|
|
594
|
+
*/
|
|
595
|
+
NTtoURI(t) {
|
|
596
|
+
let k, v;
|
|
597
|
+
let uris = {};
|
|
598
|
+
for (k in t) {
|
|
599
|
+
if (!t.hasOwnProperty(k)) continue;
|
|
600
|
+
v = t[k];
|
|
601
|
+
if (k[0] === '<') {
|
|
602
|
+
uris[k.slice(1, -1)] = v;
|
|
837
603
|
}
|
|
838
|
-
|
|
839
|
-
return x;
|
|
840
604
|
}
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
* These are hand-written implementations of a backward-chaining reasoner
|
|
844
|
-
* over the RDFS axioms.
|
|
845
|
-
* @param seeds - A hash of NTs of classes to start with
|
|
846
|
-
* @param predicate - The property to trace though
|
|
847
|
-
* @param inverse - Trace inverse direction
|
|
848
|
-
*/
|
|
849
|
-
|
|
850
|
-
}, {
|
|
851
|
-
key: "transitiveClosure",
|
|
852
|
-
value: function transitiveClosure(seeds, predicate, inverse) {
|
|
853
|
-
var elt, i, len, s, sups, t;
|
|
854
|
-
var agenda = {};
|
|
855
|
-
Object.assign(agenda, seeds); // make a copy
|
|
856
|
-
|
|
857
|
-
var done = {}; // classes we have looked up
|
|
858
|
-
|
|
859
|
-
while (true) {
|
|
860
|
-
t = function () {
|
|
861
|
-
for (var p in agenda) {
|
|
862
|
-
if (!agenda.hasOwnProperty(p)) continue;
|
|
863
|
-
return p;
|
|
864
|
-
}
|
|
865
|
-
}();
|
|
866
|
-
|
|
867
|
-
if (t == null) {
|
|
868
|
-
return done;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
sups = inverse ? this.each(void 0, predicate, this.fromNT(t)) : this.each(this.fromNT(t), predicate);
|
|
605
|
+
return uris;
|
|
606
|
+
}
|
|
872
607
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
608
|
+
/**
|
|
609
|
+
* Serializes this formula
|
|
610
|
+
* @param base - The base string
|
|
611
|
+
* @param contentType - The content type of the syntax to use
|
|
612
|
+
* @param provenance - The provenance URI
|
|
613
|
+
* @param options - options to pass to the serializer, as defined in serialize method
|
|
614
|
+
*/
|
|
615
|
+
serialize(base, contentType, provenance, options) {
|
|
616
|
+
// delegate the graph serialization to the implementation in ./serialize
|
|
617
|
+
return (0, _serialize.default)(provenance, this, base, contentType, undefined, options);
|
|
618
|
+
}
|
|
876
619
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
620
|
+
/**
|
|
621
|
+
* Creates a new formula with the substituting bindings applied
|
|
622
|
+
* @param bindings - The bindings to substitute
|
|
623
|
+
*/
|
|
624
|
+
substitute(bindings) {
|
|
625
|
+
let statementsCopy = this.statements.map(function (ea) {
|
|
626
|
+
return ea.substitute(bindings);
|
|
627
|
+
});
|
|
628
|
+
console.log('Formula subs statmnts:' + statementsCopy);
|
|
629
|
+
const y = new Formula();
|
|
630
|
+
y.addAll(statementsCopy);
|
|
631
|
+
console.log('indexed-form subs formula:' + y);
|
|
632
|
+
return y;
|
|
633
|
+
}
|
|
634
|
+
sym(uri, name) {
|
|
635
|
+
if (name) {
|
|
636
|
+
throw new Error('This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings.');
|
|
637
|
+
}
|
|
638
|
+
return this.rdfFactory.namedNode(uri);
|
|
639
|
+
}
|
|
880
640
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
641
|
+
/**
|
|
642
|
+
* Gets the node matching the specified pattern. Throws when no match could be made.
|
|
643
|
+
* @param s - The subject
|
|
644
|
+
* @param p - The predicate
|
|
645
|
+
* @param o - The object
|
|
646
|
+
* @param g - The graph that contains the statement
|
|
647
|
+
*/
|
|
648
|
+
the(s, p, o, g) {
|
|
649
|
+
let x = this.any(s, p, o, g);
|
|
650
|
+
if (x == null) {
|
|
651
|
+
_log.default.error('No value found for the() {' + s + ' ' + p + ' ' + o + '}.');
|
|
652
|
+
}
|
|
653
|
+
return x;
|
|
654
|
+
}
|
|
884
655
|
|
|
885
|
-
|
|
656
|
+
/**
|
|
657
|
+
* RDFS Inference
|
|
658
|
+
* These are hand-written implementations of a backward-chaining reasoner
|
|
659
|
+
* over the RDFS axioms.
|
|
660
|
+
* @param seeds - A hash of NTs of classes to start with
|
|
661
|
+
* @param predicate - The property to trace though
|
|
662
|
+
* @param inverse - Trace inverse direction
|
|
663
|
+
*/
|
|
664
|
+
transitiveClosure(seeds, predicate, inverse) {
|
|
665
|
+
let elt, i, len, s, sups, t;
|
|
666
|
+
let agenda = {};
|
|
667
|
+
Object.assign(agenda, seeds); // make a copy
|
|
668
|
+
let done = {}; // classes we have looked up
|
|
669
|
+
while (true) {
|
|
670
|
+
t = function () {
|
|
671
|
+
for (let p in agenda) {
|
|
672
|
+
if (!agenda.hasOwnProperty(p)) continue;
|
|
673
|
+
return p;
|
|
886
674
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
675
|
+
}();
|
|
676
|
+
if (t == null) {
|
|
677
|
+
return done;
|
|
890
678
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
*/
|
|
898
|
-
|
|
899
|
-
}, {
|
|
900
|
-
key: "topTypeURIs",
|
|
901
|
-
value: function topTypeURIs(types) {
|
|
902
|
-
var i;
|
|
903
|
-
var j;
|
|
904
|
-
var k;
|
|
905
|
-
var len;
|
|
906
|
-
var n;
|
|
907
|
-
var ref;
|
|
908
|
-
var tops;
|
|
909
|
-
var v;
|
|
910
|
-
tops = [];
|
|
911
|
-
|
|
912
|
-
for (k in types) {
|
|
913
|
-
if (!types.hasOwnProperty(k)) continue;
|
|
914
|
-
v = types[k];
|
|
915
|
-
n = 0;
|
|
916
|
-
ref = this.each(this.rdfFactory.namedNode(k), this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'));
|
|
917
|
-
|
|
918
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
|
919
|
-
j = ref[i];
|
|
920
|
-
|
|
921
|
-
if (j.uri !== 'http://www.w3.org/2000/01/rdf-schema#Resource') {
|
|
922
|
-
n++;
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
679
|
+
sups = inverse ? this.each(void 0, predicate, this.fromNT(t)) : this.each(this.fromNT(t), predicate);
|
|
680
|
+
for (i = 0, len = sups.length; i < len; i++) {
|
|
681
|
+
elt = sups[i];
|
|
682
|
+
s = elt.toNT();
|
|
683
|
+
if (s in done) {
|
|
684
|
+
continue;
|
|
925
685
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
tops[k] = v;
|
|
686
|
+
if (s in agenda) {
|
|
687
|
+
continue;
|
|
929
688
|
}
|
|
689
|
+
agenda[s] = agenda[t];
|
|
930
690
|
}
|
|
691
|
+
done[t] = agenda[t];
|
|
692
|
+
delete agenda[t];
|
|
693
|
+
}
|
|
694
|
+
}
|
|
931
695
|
|
|
932
|
-
|
|
933
|
-
|
|
696
|
+
/**
|
|
697
|
+
* Finds the types in the list which have no *stored* supertypes
|
|
698
|
+
* We exclude the universal class, owl:Things and rdf:Resource, as it is
|
|
699
|
+
* information-free.
|
|
700
|
+
* @param types - The types
|
|
701
|
+
*/
|
|
702
|
+
topTypeURIs(types) {
|
|
703
|
+
let i;
|
|
704
|
+
let j;
|
|
705
|
+
let k;
|
|
706
|
+
let len;
|
|
707
|
+
let n;
|
|
708
|
+
let ref;
|
|
709
|
+
let tops;
|
|
710
|
+
let v;
|
|
711
|
+
tops = [];
|
|
712
|
+
for (k in types) {
|
|
713
|
+
if (!types.hasOwnProperty(k)) continue;
|
|
714
|
+
v = types[k];
|
|
715
|
+
n = 0;
|
|
716
|
+
ref = this.each(this.rdfFactory.namedNode(k), this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'));
|
|
717
|
+
for (i = 0, len = ref.length; i < len; i++) {
|
|
718
|
+
j = ref[i];
|
|
719
|
+
if (j.uri !== 'http://www.w3.org/2000/01/rdf-schema#Resource') {
|
|
720
|
+
n++;
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
934
723
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
delete tops['http://www.w3.org/2002/07/owl#Thing'];
|
|
724
|
+
if (!n) {
|
|
725
|
+
tops[k] = v;
|
|
938
726
|
}
|
|
939
|
-
|
|
940
|
-
return tops;
|
|
941
|
-
}
|
|
942
|
-
/**
|
|
943
|
-
* Serializes this formula to a string
|
|
944
|
-
*/
|
|
945
|
-
|
|
946
|
-
}, {
|
|
947
|
-
key: "toString",
|
|
948
|
-
value: function toString() {
|
|
949
|
-
return '{' + this.statements.join('\n') + '}';
|
|
950
727
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
* @param name - The variable's name
|
|
954
|
-
*/
|
|
955
|
-
|
|
956
|
-
}, {
|
|
957
|
-
key: "variable",
|
|
958
|
-
value: function variable(name) {
|
|
959
|
-
return new _variable.default(name);
|
|
728
|
+
if (tops['http://www.w3.org/2000/01/rdf-schema#Resource']) {
|
|
729
|
+
delete tops['http://www.w3.org/2000/01/rdf-schema#Resource'];
|
|
960
730
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
* @param s - The subject
|
|
964
|
-
* @param p - The predicate
|
|
965
|
-
* @param o - The object
|
|
966
|
-
* @param g - The graph that contains the statement
|
|
967
|
-
*/
|
|
968
|
-
|
|
969
|
-
}, {
|
|
970
|
-
key: "whether",
|
|
971
|
-
value: function whether(s, p, o, g) {
|
|
972
|
-
return this.statementsMatching(s, p, o, g, false).length;
|
|
731
|
+
if (tops['http://www.w3.org/2002/07/owl#Thing']) {
|
|
732
|
+
delete tops['http://www.w3.org/2002/07/owl#Thing'];
|
|
973
733
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
734
|
+
return tops;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Serializes this formula to a string
|
|
739
|
+
*/
|
|
740
|
+
toString() {
|
|
741
|
+
return '{' + this.statements.join('\n') + '}';
|
|
742
|
+
}
|
|
977
743
|
|
|
744
|
+
/**
|
|
745
|
+
* Gets a new variable
|
|
746
|
+
* @param name - The variable's name
|
|
747
|
+
*/
|
|
748
|
+
variable(name) {
|
|
749
|
+
return new _variable.default(name);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Gets the number of statements in this formula that matches the specified pattern
|
|
754
|
+
* @param s - The subject
|
|
755
|
+
* @param p - The predicate
|
|
756
|
+
* @param o - The object
|
|
757
|
+
* @param g - The graph that contains the statement
|
|
758
|
+
*/
|
|
759
|
+
whether(s, p, o, g) {
|
|
760
|
+
return this.statementsMatching(s, p, o, g, false).length;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
978
763
|
exports.default = Formula;
|