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