rdflib 2.2.21 → 2.2.22

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