rdflib 2.2.35 → 2.2.36

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