rdflib 2.2.34 → 2.2.35-2bb9ed0b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/515.rdflib.min.js +3 -0
- package/dist/515.rdflib.min.js.map +1 -0
- package/dist/789.rdflib.min.js +1 -0
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +0 -2
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +57 -85
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -106
- package/esm/default-graph.js +13 -33
- package/esm/empty.js +8 -26
- package/esm/factories/canonical-data-factory.js +33 -30
- package/esm/factories/extended-term-factory.js +18 -14
- package/esm/factories/factory-types.js +1 -1
- package/esm/factories/rdflib-data-factory.js +9 -11
- package/esm/fetcher.js +1364 -1668
- package/esm/formula.js +631 -739
- package/esm/index.js +31 -51
- package/esm/jsonldparser.js +19 -26
- package/esm/jsonparser.js +1 -1
- package/esm/lists.js +41 -86
- package/esm/literal.js +120 -157
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1008 -1090
- package/esm/named-node.js +69 -99
- package/esm/namespace.js +2 -4
- package/esm/node-internal.js +73 -97
- package/esm/node.js +1 -2
- package/esm/parse.js +3 -3
- package/esm/patch-parser.js +1 -2
- package/esm/query.js +15 -30
- package/esm/rdfaparser.js +775 -846
- package/esm/rdfxmlparser.js +348 -365
- package/esm/serialize.js +2 -3
- package/esm/serializer.js +834 -889
- package/esm/sparql-to-query.js +0 -2
- package/esm/statement.js +52 -72
- package/esm/store.js +852 -963
- package/esm/types.js +26 -21
- package/esm/update-manager.js +963 -1104
- package/esm/updates-via.js +104 -134
- package/esm/uri.js +3 -3
- package/esm/utils/default-graph-uri.js +2 -2
- package/esm/utils/terms.js +4 -5
- package/esm/utils-js.js +5 -6
- package/esm/utils.js +7 -6
- package/esm/variable.js +32 -58
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +56 -83
- package/lib/class-order.js +2 -3
- package/lib/collection.js +69 -104
- package/lib/default-graph.js +13 -32
- package/lib/empty.js +8 -25
- package/lib/factories/canonical-data-factory.js +36 -34
- package/lib/factories/extended-term-factory.js +19 -16
- package/lib/factories/factory-types.js +2 -3
- package/lib/factories/rdflib-data-factory.js +10 -13
- package/lib/fetcher.js +1394 -1693
- package/lib/formula.js +631 -738
- package/lib/index.js +66 -89
- package/lib/jsonldparser.js +21 -32
- package/lib/jsonparser.js +3 -4
- package/lib/lists.js +47 -87
- package/lib/literal.js +120 -156
- package/lib/log.js +8 -9
- package/lib/n3parser.js +1011 -1096
- package/lib/named-node.js +69 -98
- package/lib/namespace.js +2 -4
- package/lib/node-internal.js +72 -95
- package/lib/node.js +2 -4
- package/lib/parse.js +5 -6
- package/lib/patch-parser.js +1 -2
- package/lib/query.js +19 -32
- package/lib/rdfaparser.js +777 -849
- package/lib/rdfxmlparser.js +350 -366
- package/lib/serialize.js +2 -3
- package/lib/serializer.js +838 -892
- package/lib/sparql-to-query.js +0 -2
- package/lib/statement.js +54 -74
- package/lib/store.js +873 -978
- package/lib/types.js +22 -43
- package/lib/update-manager.js +972 -1111
- package/lib/updates-via.js +105 -134
- package/lib/uri.js +3 -3
- package/lib/utils/default-graph-uri.js +2 -4
- package/lib/utils/terms.js +4 -6
- package/lib/utils-js.js +11 -13
- package/lib/utils.js +6 -7
- package/lib/variable.js +34 -60
- package/lib/xsd-internal.js +2 -3
- package/lib/xsd.js +3 -4
- package/package.json +31 -31
- package/src/n3parser.js +1 -1
- package/src/rdfxmlparser.js +2 -1
- package/src/serializer.js +1 -1
- package/.babelrc +0 -20
- package/dist/670.rdflib.min.js +0 -1
- package/dist/730.rdflib.min.js +0 -3
- package/dist/730.rdflib.min.js.map +0 -1
- /package/dist/{730.rdflib.min.js.LICENSE.txt → 515.rdflib.min.js.LICENSE.txt} +0 -0
package/lib/formula.js
CHANGED
|
@@ -5,12 +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 _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
9
|
var _classOrder = _interopRequireDefault(require("./class-order"));
|
|
16
10
|
var _collection = _interopRequireDefault(require("./collection"));
|
|
@@ -18,23 +12,16 @@ var _canonicalDataFactory = _interopRequireDefault(require("./factories/canonica
|
|
|
18
12
|
var _log = _interopRequireDefault(require("./log"));
|
|
19
13
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
20
14
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
21
|
-
var
|
|
15
|
+
var _serialize = _interopRequireDefault(require("./serialize"));
|
|
22
16
|
var _types = require("./types");
|
|
23
17
|
var _terms = require("./utils/terms");
|
|
24
18
|
var _variable = _interopRequireDefault(require("./variable"));
|
|
25
19
|
var _utils = require("./utils");
|
|
26
20
|
var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
27
|
-
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; } } }; }
|
|
28
|
-
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); }
|
|
29
|
-
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; }
|
|
30
|
-
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); }; }
|
|
31
|
-
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; } }
|
|
32
21
|
/**
|
|
33
22
|
* A formula, or store of RDF statements
|
|
34
23
|
*/
|
|
35
|
-
|
|
36
|
-
(0, _inherits2.default)(Formula, _Node);
|
|
37
|
-
var _super = _createSuper(Formula);
|
|
24
|
+
class Formula extends _nodeInternal.default {
|
|
38
25
|
/**
|
|
39
26
|
* Initializes this formula
|
|
40
27
|
* @constructor
|
|
@@ -45,56 +32,42 @@ var Formula = /*#__PURE__*/function (_Node) {
|
|
|
45
32
|
* @param opts
|
|
46
33
|
* @param opts.rdfFactory - The rdf factory that should be used by the store
|
|
47
34
|
*/
|
|
48
|
-
|
|
35
|
+
constructor() {
|
|
49
36
|
var _this;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
(
|
|
56
|
-
_this =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(0, _defineProperty2.default)(
|
|
62
|
-
(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);
|
|
63
50
|
/**
|
|
64
51
|
* The accompanying fetcher instance.
|
|
65
52
|
*
|
|
66
53
|
* Is set by the fetcher when initialized.
|
|
67
54
|
*/
|
|
68
|
-
(0, _defineProperty2.default)(
|
|
69
|
-
(0, _defineProperty2.default)(
|
|
55
|
+
(0, _defineProperty2.default)(this, "fetcher", void 0);
|
|
56
|
+
(0, _defineProperty2.default)(this, "isVar", 0);
|
|
70
57
|
/**
|
|
71
58
|
* A namespace for the specified namespace's URI
|
|
72
59
|
* @param nsuri The URI for the namespace
|
|
73
60
|
*/
|
|
74
|
-
(0, _defineProperty2.default)(
|
|
61
|
+
(0, _defineProperty2.default)(this, "ns", _namespace.default);
|
|
75
62
|
/** The factory used to generate statements and terms */
|
|
76
|
-
(0, _defineProperty2.default)(
|
|
77
|
-
|
|
63
|
+
(0, _defineProperty2.default)(this, "rdfFactory", void 0);
|
|
64
|
+
this.rdfFactory = opts && opts.rdfFactory || _canonicalDataFactory.default;
|
|
78
65
|
// Enable default factory methods on this while preserving factory context.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var _loop = function _loop() {
|
|
83
|
-
var factoryMethod = _step.value;
|
|
84
|
-
_this[factoryMethod] = function () {
|
|
85
|
-
var _this$rdfFactory;
|
|
86
|
-
return (_this$rdfFactory = _this.rdfFactory)[factoryMethod].apply(_this$rdfFactory, arguments);
|
|
87
|
-
};
|
|
66
|
+
for (const factoryMethod of _utils.appliedFactoryMethods) {
|
|
67
|
+
this[factoryMethod] = function () {
|
|
68
|
+
return _this.rdfFactory[factoryMethod](...arguments);
|
|
88
69
|
};
|
|
89
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
90
|
-
_loop();
|
|
91
|
-
}
|
|
92
|
-
} catch (err) {
|
|
93
|
-
_iterator.e(err);
|
|
94
|
-
} finally {
|
|
95
|
-
_iterator.f();
|
|
96
70
|
}
|
|
97
|
-
return _this;
|
|
98
71
|
}
|
|
99
72
|
|
|
100
73
|
/** Add a statement from its parts
|
|
@@ -103,764 +76,684 @@ var Formula = /*#__PURE__*/function (_Node) {
|
|
|
103
76
|
* @param object - the third part of the statement
|
|
104
77
|
* @param graph - the last part of the statement
|
|
105
78
|
*/
|
|
106
|
-
(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var _this2 = this;
|
|
110
|
-
if (arguments.length === 1) {
|
|
111
|
-
subject.forEach(function (st) {
|
|
112
|
-
return _this2.add(st.subject, st.predicate, st.object, st.graph);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
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));
|
|
116
82
|
}
|
|
83
|
+
return this.statements.push(this.rdfFactory.quad(subject, predicate, object, graph));
|
|
84
|
+
}
|
|
117
85
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return this.add(statement);
|
|
125
|
-
}
|
|
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
|
+
}
|
|
126
92
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return this.rdfFactory.blankNode(id);
|
|
135
|
-
}
|
|
93
|
+
/**
|
|
94
|
+
* Shortcut for adding blankNodes
|
|
95
|
+
* @param [id]
|
|
96
|
+
*/
|
|
97
|
+
bnode(id) {
|
|
98
|
+
return this.rdfFactory.blankNode(id);
|
|
99
|
+
}
|
|
136
100
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
_this3.add(quad.subject, quad.predicate, quad.object, quad.graph);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
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
|
+
}
|
|
149
110
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
var st = this.anyStatementMatching(s, p, o, g);
|
|
166
|
-
if (st == null) {
|
|
167
|
-
return null;
|
|
168
|
-
} else if (s == null) {
|
|
169
|
-
return st.subject;
|
|
170
|
-
} else if (p == null) {
|
|
171
|
-
return st.predicate;
|
|
172
|
-
} else if (o == null) {
|
|
173
|
-
return st.object;
|
|
174
|
-
}
|
|
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) {
|
|
175
126
|
return null;
|
|
176
|
-
}
|
|
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
|
+
}
|
|
177
136
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return y ? y.value : void 0;
|
|
190
|
-
}
|
|
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
|
+
}
|
|
191
148
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return y ? _nodeInternal.default.toJS(y) : void 0;
|
|
204
|
-
}
|
|
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
|
+
}
|
|
205
160
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (!x || x.length === 0) {
|
|
214
|
-
return undefined;
|
|
215
|
-
}
|
|
216
|
-
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;
|
|
217
168
|
}
|
|
169
|
+
return x[0];
|
|
170
|
+
}
|
|
218
171
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return this.rdfFactory.id(term);
|
|
228
|
-
}
|
|
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
|
+
}
|
|
229
180
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return (!s || s.equals(st.subject)) && (!p || p.equals(st.predicate)) && (!o || o.equals(st.object)) && (!g || g.equals(st.graph));
|
|
246
|
-
});
|
|
247
|
-
if (justOne) {
|
|
248
|
-
return sts.length === 0 ? [] : [sts[0]];
|
|
249
|
-
}
|
|
250
|
-
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]];
|
|
251
196
|
}
|
|
197
|
+
return sts;
|
|
198
|
+
}
|
|
252
199
|
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
bottom = false;
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (bottom) {
|
|
288
|
-
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;
|
|
289
230
|
}
|
|
290
231
|
}
|
|
291
|
-
|
|
232
|
+
if (bottom) {
|
|
233
|
+
bots[k] = v;
|
|
234
|
+
}
|
|
292
235
|
}
|
|
236
|
+
return bots;
|
|
237
|
+
}
|
|
293
238
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return new _collection.default();
|
|
299
|
-
}
|
|
239
|
+
/** Creates a new collection */
|
|
240
|
+
collection() {
|
|
241
|
+
return new _collection.default();
|
|
242
|
+
}
|
|
300
243
|
|
|
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
|
-
|
|
330
|
-
|
|
331
|
-
for (var _q = 0, len3 = sts.length; _q < len3; _q++) {
|
|
332
|
-
results.push(new _namedNode.default(sts[_q].graph.value));
|
|
333
|
-
}
|
|
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));
|
|
334
274
|
}
|
|
335
|
-
return results;
|
|
336
275
|
}
|
|
276
|
+
return results;
|
|
277
|
+
}
|
|
337
278
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (!other) {
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
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;
|
|
349
286
|
}
|
|
287
|
+
return this.hashString() === other.hashString();
|
|
288
|
+
}
|
|
350
289
|
|
|
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
|
-
|
|
384
|
-
|
|
385
|
-
|
|
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];
|
|
386
331
|
members[st.subject.toNT()] = st;
|
|
387
332
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
ref4 = this.each(void 0, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#range'), this.fromNT(t));
|
|
398
|
-
for (var _q2 = 0, len3 = ref4.length; _q2 < len3; _q2++) {
|
|
399
|
-
pred = ref4[_q2];
|
|
400
|
-
ref5 = this.statementsMatching(void 0, pred);
|
|
401
|
-
for (u = 0, len4 = ref5.length; u < len4; u++) {
|
|
402
|
-
st = ref5[u];
|
|
403
|
-
members[st.object.toNT()] = st;
|
|
404
|
-
}
|
|
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;
|
|
405
341
|
}
|
|
406
342
|
}
|
|
407
|
-
return members;
|
|
408
343
|
}
|
|
344
|
+
return members;
|
|
345
|
+
}
|
|
409
346
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return this.NTtoURI(this.findMembersNT(subject));
|
|
423
|
-
}
|
|
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
|
+
}
|
|
424
359
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), true);
|
|
438
|
-
}
|
|
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
|
+
}
|
|
439
372
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
454
|
-
}
|
|
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
|
+
}
|
|
455
386
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
st =
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
range = ref1[l];
|
|
488
|
-
types[range.toNT()] = st;
|
|
489
|
-
}
|
|
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;
|
|
490
418
|
}
|
|
491
419
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
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;
|
|
500
428
|
}
|
|
501
|
-
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
502
429
|
}
|
|
430
|
+
return this.transitiveClosure(types, this.rdfFactory.namedNode('http://www.w3.org/2000/01/rdf-schema#subClassOf'), false);
|
|
431
|
+
}
|
|
503
432
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return this.NTtoURI(this.findTypesNT(subject));
|
|
518
|
-
}
|
|
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
|
+
}
|
|
519
446
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
todo.push(x);
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
var sts = self.statementsMatching(null, null, x, doc).concat(self.statementsMatching(x, null, null, doc));
|
|
543
|
-
sts = sts.filter(function (st) {
|
|
544
|
-
if (excludePredicateURIs[st.predicate.value]) return false;
|
|
545
|
-
var hash = st.toNT();
|
|
546
|
-
if (doneArcs[hash]) return false;
|
|
547
|
-
doneArcs[hash] = true;
|
|
548
|
-
return true;
|
|
549
|
-
});
|
|
550
|
-
sts.forEach(function (st) {
|
|
551
|
-
queue(st.subject);
|
|
552
|
-
queue(st.object);
|
|
553
|
-
});
|
|
554
|
-
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
|
+
}
|
|
555
466
|
};
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
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());
|
|
560
483
|
}
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
561
486
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
return new Formula();
|
|
571
|
-
}
|
|
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
|
+
}
|
|
572
495
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
k
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
} else {
|
|
596
|
-
throw new Error("Can't convert string from NT: " + str);
|
|
597
|
-
}
|
|
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);
|
|
598
518
|
}
|
|
599
|
-
str = str.slice(1, k);
|
|
600
|
-
str = str.replace(/\\"/g, '"');
|
|
601
|
-
str = str.replace(/\\n/g, '\n');
|
|
602
|
-
str = str.replace(/\\\\/g, '\\');
|
|
603
|
-
return this.rdfFactory.literal(str, lang || dt);
|
|
604
|
-
case '_':
|
|
605
|
-
return this.rdfFactory.blankNode(str.slice(2));
|
|
606
|
-
case '?':
|
|
607
|
-
return new _variable.default(str.slice(1));
|
|
608
|
-
}
|
|
609
|
-
throw new Error("Can't convert from NT: " + str);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/** Returns true if this formula holds the specified statement(s) */
|
|
613
|
-
}, {
|
|
614
|
-
key: "holds",
|
|
615
|
-
value: function holds(s, p, o, g) {
|
|
616
|
-
var i;
|
|
617
|
-
if (arguments.length === 1) {
|
|
618
|
-
if (!s) {
|
|
619
|
-
return true;
|
|
620
519
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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;
|
|
626
544
|
}
|
|
627
|
-
return true;
|
|
628
|
-
} else if ((0, _terms.isStatement)(s)) {
|
|
629
|
-
return this.holds(s.subject, s.predicate, s.object, s.graph);
|
|
630
|
-
} else if (s.statements) {
|
|
631
|
-
return this.holds(s.statements);
|
|
632
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);
|
|
633
551
|
}
|
|
634
|
-
var st = this.anyStatementMatching(s, p, o, g);
|
|
635
|
-
return st != null;
|
|
636
552
|
}
|
|
553
|
+
let st = this.anyStatementMatching(s, p, o, g);
|
|
554
|
+
return st != null;
|
|
555
|
+
}
|
|
637
556
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
return this.holds(statement.subject, statement.predicate, statement.object, statement.graph);
|
|
645
|
-
}
|
|
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
|
+
}
|
|
646
563
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
context.addAll(statements);
|
|
666
|
-
return node;
|
|
667
|
-
}
|
|
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;
|
|
668
582
|
}
|
|
583
|
+
}
|
|
669
584
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
if (k[0] === '<') {
|
|
685
|
-
uris[k.slice(1, -1)] = v;
|
|
686
|
-
}
|
|
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;
|
|
687
599
|
}
|
|
688
|
-
return uris;
|
|
689
600
|
}
|
|
601
|
+
return uris;
|
|
602
|
+
}
|
|
690
603
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
return (0, _serialize2.default)(provenance, this, base, contentType, undefined, options);
|
|
703
|
-
}
|
|
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
|
+
}
|
|
704
615
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
key: "sym",
|
|
723
|
-
value: function sym(uri, name) {
|
|
724
|
-
if (name) {
|
|
725
|
-
throw new Error('This feature (kb.sym with 2 args) is removed. Do not assume prefix mappings.');
|
|
726
|
-
}
|
|
727
|
-
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.');
|
|
728
633
|
}
|
|
634
|
+
return this.rdfFactory.namedNode(uri);
|
|
635
|
+
}
|
|
729
636
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
if (x == null) {
|
|
742
|
-
_log.default.error('No value found for the() {' + s + ' ' + p + ' ' + o + '}.');
|
|
743
|
-
}
|
|
744
|
-
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 + '}.');
|
|
745
648
|
}
|
|
649
|
+
return x;
|
|
650
|
+
}
|
|
746
651
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
if (!agenda.hasOwnProperty(p)) continue;
|
|
766
|
-
return p;
|
|
767
|
-
}
|
|
768
|
-
}();
|
|
769
|
-
if (t == null) {
|
|
770
|
-
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;
|
|
771
670
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
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;
|
|
783
684
|
}
|
|
784
|
-
|
|
785
|
-
delete agenda[t];
|
|
685
|
+
agenda[s] = agenda[t];
|
|
786
686
|
}
|
|
687
|
+
done[t] = agenda[t];
|
|
688
|
+
delete agenda[t];
|
|
787
689
|
}
|
|
690
|
+
}
|
|
788
691
|
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
n++;
|
|
816
|
-
break;
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
if (!n) {
|
|
820
|
-
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;
|
|
821
718
|
}
|
|
822
719
|
}
|
|
823
|
-
if (
|
|
824
|
-
|
|
825
|
-
}
|
|
826
|
-
if (tops['http://www.w3.org/2002/07/owl#Thing']) {
|
|
827
|
-
delete tops['http://www.w3.org/2002/07/owl#Thing'];
|
|
720
|
+
if (!n) {
|
|
721
|
+
tops[k] = v;
|
|
828
722
|
}
|
|
829
|
-
return tops;
|
|
830
723
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
* Serializes this formula to a string
|
|
834
|
-
*/
|
|
835
|
-
}, {
|
|
836
|
-
key: "toString",
|
|
837
|
-
value: function toString() {
|
|
838
|
-
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'];
|
|
839
726
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
* Gets a new variable
|
|
843
|
-
* @param name - The variable's name
|
|
844
|
-
*/
|
|
845
|
-
}, {
|
|
846
|
-
key: "variable",
|
|
847
|
-
value: function variable(name) {
|
|
848
|
-
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'];
|
|
849
729
|
}
|
|
730
|
+
return tops;
|
|
731
|
+
}
|
|
850
732
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
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
|
+
}
|
|
866
759
|
exports.default = Formula;
|