rdflib 2.2.22-4e175603 → 2.2.22-53d65d90

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