rdflib 2.2.35 → 2.2.36

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