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