rdflib 2.2.10 → 2.2.12-5f141ca2

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