rdflib 2.2.34 → 2.2.35-2bb9ed0b

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