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