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