rdflib 2.2.34 → 2.2.35-2bb9ed0b

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