rdflib 2.2.22-4e175603 → 2.2.22-53d65d90

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