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