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
@@ -0,0 +1,348 @@
1
+ /**
2
+ * Utility functions for $rdf
3
+ * @module util
4
+ */
5
+ import { docpart } from './uri';
6
+ import log from './log';
7
+ import * as uri from './uri';
8
+ import NamedNode from './named-node';
9
+ var string = {
10
+ template: stringTemplate
11
+ };
12
+ export { log, uri, string };
13
+ export function mediaTypeClass(mediaType) {
14
+ mediaType = mediaType.split(';')[0].trim(); // remove media type parameters
15
+
16
+ return new NamedNode('http://www.w3.org/ns/iana/media-types/' + mediaType + '#Resource');
17
+ }
18
+ export function linkRelationProperty(relation) {
19
+ return new NamedNode('http://www.w3.org/ns/iana/link-relations/relation#' + relation.trim());
20
+ }
21
+ /**
22
+ * Adds callback functionality to an object.
23
+ * Callback functions are indexed by a 'hook' string.
24
+ * They return true if they want to be called again.
25
+ * @method callbackify
26
+ * @param obj {Object}
27
+ * @param callbacks {Array<string>}
28
+ */
29
+
30
+ export function callbackify(obj, callbacks) {
31
+ obj.callbacks = {};
32
+
33
+ for (var x = callbacks.length - 1; x >= 0; x--) {
34
+ obj.callbacks[callbacks[x]] = [];
35
+ }
36
+
37
+ obj.addHook = function (hook) {
38
+ if (!obj.callbacks[hook]) {
39
+ obj.callbacks[hook] = [];
40
+ }
41
+ };
42
+
43
+ obj.addCallback = function (hook, func) {
44
+ obj.callbacks[hook].push(func);
45
+ };
46
+
47
+ obj.removeCallback = function (hook, funcName) {
48
+ for (var i = 0; i < obj.callbacks[hook].length; i++) {
49
+ if (obj.callbacks[hook][i].name === funcName) {
50
+ obj.callbacks[hook].splice(i, 1);
51
+ return true;
52
+ }
53
+ }
54
+
55
+ return false;
56
+ };
57
+
58
+ obj.insertCallback = function (hook, func) {
59
+ obj.callbacks[hook].unshift(func);
60
+ };
61
+
62
+ obj.fireCallbacks = function fireCallbacks(hook, args) {
63
+ var newCallbacks = [];
64
+ var replaceCallbacks = [];
65
+ var len = obj.callbacks[hook].length;
66
+ var x;
67
+ var callback; // log.info('!@$ Firing '+hook+' call back with length'+len)
68
+
69
+ for (x = len - 1; x >= 0; x--) {
70
+ // log.info('@@ Firing '+hook+' callback '+ obj.callbacks[hook][x])
71
+ callback = obj.callbacks[hook][x];
72
+
73
+ if (callback && callback.apply(obj, args)) {
74
+ newCallbacks.push(callback);
75
+ }
76
+ }
77
+
78
+ for (x = newCallbacks.length - 1; x >= 0; x--) {
79
+ replaceCallbacks.push(newCallbacks[x]);
80
+ }
81
+
82
+ for (x = len; x < obj.callbacks[hook].length; x++) {
83
+ replaceCallbacks.push(obj.callbacks[hook][x]);
84
+ }
85
+
86
+ obj.callbacks[hook] = replaceCallbacks;
87
+ };
88
+ }
89
+ /**
90
+ * Returns a DOM parser based on current runtime environment.
91
+ */
92
+
93
+ export function DOMParserFactory() {
94
+ if (window.DOMParser) {
95
+ return new DOMParser();
96
+ } else if (window.ActiveXObject) {
97
+ return new ActiveXObject('Microsoft.XMLDOM');
98
+ } else {
99
+ return false;
100
+ }
101
+ } // From https://github.com/linkeddata/dokieli
102
+
103
+ export function domToString(node, options) {
104
+ options = options || {};
105
+ var selfClosing = [];
106
+
107
+ if (options && options.selfClosing) {
108
+ options.selfClosing.split(' ').forEach(function (n) {
109
+ selfClosing[n] = true;
110
+ });
111
+ }
112
+
113
+ var skipAttributes = [];
114
+
115
+ if (options && options.skipAttributes) {
116
+ options.skipAttributes.split(' ').forEach(function (n) {
117
+ skipAttributes[n] = true;
118
+ });
119
+ }
120
+
121
+ return dumpNode(node, options, selfClosing, skipAttributes);
122
+ }
123
+ export function dumpNode(node, options, selfClosing, skipAttributes) {
124
+ var i;
125
+ var out = '';
126
+ var noEsc = [false];
127
+ if (typeof node.nodeType === 'undefined') return out;
128
+
129
+ if (node.nodeType === 1) {
130
+ if (node.hasAttribute('class') && options && options.classWithChildText && node.matches(options.classWithChildText.class)) {
131
+ out += node.querySelector(options.classWithChildText.element).textContent;
132
+ } else if (!(options && options.skipNodeWithClass && node.matches('.' + options.skipNodeWithClass))) {
133
+ var ename = node.nodeName.toLowerCase();
134
+ out += '<' + ename;
135
+ var attrList = [];
136
+
137
+ for (i = node.attributes.length - 1; i >= 0; i--) {
138
+ var atn = node.attributes[i];
139
+ if (skipAttributes && skipAttributes.length > 0 && skipAttributes[atn.name]) continue;
140
+ if (/^\d+$/.test(atn.name)) continue;
141
+
142
+ if (atn.name === 'class' && options && options.replaceClassItemWith && atn.value.split(' ').indexOf(options.replaceClassItemWith.source) > -1) {
143
+ var re = new RegExp(options.replaceClassItemWith.source, 'g');
144
+ atn.value = atn.value.replace(re, options.replaceClassItemWith.target).trim();
145
+ }
146
+
147
+ if (!(atn.name === 'class' && options && options.skipClassWithValue && options.skipClassWithValue === atn.value)) {
148
+ attrList.push(atn.name + '=\'' + atn.value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/'/g, '&quot;') + '\'');
149
+ }
150
+ }
151
+
152
+ if (attrList.length > 0) {
153
+ if (options && options.sortAttributes) {
154
+ attrList.sort(function (a, b) {
155
+ return a.toLowerCase().localeCompare(b.toLowerCase());
156
+ });
157
+ }
158
+
159
+ out += ' ' + attrList.join(' ');
160
+ }
161
+
162
+ if (selfClosing && selfClosing.ename) {
163
+ out += ' />';
164
+ } else {
165
+ out += '>';
166
+ out += ename === 'html' ? '\n ' : '';
167
+ noEsc.push(ename === 'style' || ename === 'script');
168
+
169
+ for (i = 0; i < node.childNodes.length; i++) {
170
+ out += dumpNode(node.childNodes[i]);
171
+ }
172
+
173
+ noEsc.pop();
174
+ out += ename === 'body' ? '</' + ename + '>' + '\n' : '</' + ename + '>';
175
+ }
176
+ }
177
+ } else if (node.nodeType === 8) {
178
+ // FIXME: If comments are not tabbed in source, a new line is not prepended
179
+ out += '<!--' + node.nodeValue + '-->';
180
+ } else if (node.nodeType === 3 || node.nodeType === 4) {
181
+ // XXX: Remove new lines which were added after DOM ready
182
+ var nl = node.nodeValue.replace(/\n+$/, '');
183
+ out += noEsc[noEsc.length - 1] ? nl : nl.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
184
+ } else {
185
+ console.log('Warning; Cannot handle serialising nodes of type: ' + node.nodeType);
186
+ console.log(node);
187
+ }
188
+
189
+ return out;
190
+ }
191
+ export function dtstamp() {
192
+ var now = new Date();
193
+ var year = now.getYear() + 1900;
194
+ var month = now.getMonth() + 1;
195
+ var day = now.getDate();
196
+ var hour = now.getUTCHours();
197
+ var minute = now.getUTCMinutes();
198
+ var second = now.getSeconds();
199
+ if (month < 10) month = '0' + month;
200
+ if (day < 10) day = '0' + day;
201
+ if (hour < 10) hour = '0' + hour;
202
+ if (minute < 10) minute = '0' + minute;
203
+ if (second < 10) second = '0' + second;
204
+ return year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + 'Z';
205
+ }
206
+ /**
207
+ * Compares statements (heavy comparison for repeatable canonical ordering)
208
+ */
209
+
210
+ export function heavyCompare(x, y, g, uriMap) {
211
+ var nonBlank = function nonBlank(x) {
212
+ return x.termType === 'BlankNode' ? null : x;
213
+ };
214
+
215
+ var signature = function signature(x) {
216
+ var lis = g.statementsMatching(x).map(function (st) {
217
+ return '' + nonBlank(st.subject) + ' ' + nonBlank(st.predicate) + ' ' + nonBlank(st.object);
218
+ }).concat(g.statementsMatching(undefined, undefined, x).map(function (st) {
219
+ return '' + nonBlank(st.subject) + ' ' + nonBlank(st.predicate) + ' ' + nonBlank(st.object);
220
+ }));
221
+ lis.sort();
222
+ return lis.join('\n');
223
+ };
224
+
225
+ var comparison = Object.prototype.hasOwnProperty.call(g, "compareTerms") ? g.compareTerms(x, y) : x.compareTerm(y);
226
+
227
+ if (x.termType === 'BlankNode' && y.termType === 'BlankNode') {
228
+ if (comparison === 0) return 0; // Same
229
+
230
+ if (signature(x) > signature(y)) return +1;
231
+ if (signature(x) < signature(y)) return -1;
232
+ return comparison; // Too bad -- this order not canonical.
233
+ // throw "different bnodes indistinquishable for sorting"
234
+ } else {
235
+ if (uriMap && x.uri && y.uri) {
236
+ return (uriMap[x.uri] || x.uri).localeCompare(uriMap[y.uri] || y.uri);
237
+ }
238
+
239
+ return comparison;
240
+ }
241
+ }
242
+ export function heavyCompareSPO(x, y, g, uriMap) {
243
+ return heavyCompare(x.subject, y.subject, g, uriMap) || heavyCompare(x.predicate, y.predicate, g, uriMap) || heavyCompare(x.object, y.object, g, uriMap);
244
+ }
245
+ /**
246
+ * Defines a simple debugging function
247
+ * @method output
248
+ * @param o {String}
249
+ */
250
+
251
+ export function output(o) {
252
+ var k = document.createElement('div');
253
+ k.textContent = o;
254
+ document.body.appendChild(k);
255
+ }
256
+ import { DOMParser } from 'xmldom';
257
+ /**
258
+ * Returns a DOM from parsex XML.
259
+ */
260
+
261
+ export function parseXML(str, options) {
262
+ var dparser;
263
+ options = options || {};
264
+
265
+ if (typeof module !== 'undefined' && module && module.exports) {
266
+ // Node.js
267
+ var dom = new DOMParser().parseFromString(str, options.contentType || 'application/xhtml+xml');
268
+ return dom;
269
+ } else {
270
+ if (typeof window !== 'undefined' && window.DOMParser) {
271
+ dparser = new window.DOMParser(); // seems to actually work
272
+ } else {
273
+ dparser = new DOMParser(); // Doc says this works
274
+ }
275
+ }
276
+
277
+ return dparser.parseFromString(str, 'application/xml');
278
+ }
279
+ /**
280
+ * Removes all statements equal to x from a
281
+ */
282
+
283
+ export function RDFArrayRemove(a, x) {
284
+ for (var i = 0; i < a.length; i++) {
285
+ // TODO: This used to be the following, which didnt always work..why
286
+ // if(a[i] === x)
287
+ if (a[i].subject.equals(x.subject) && a[i].predicate.equals(x.predicate) && a[i].object.equals(x.object) && a[i].why.equals(x.why)) {
288
+ a.splice(i, 1);
289
+ return;
290
+ }
291
+ }
292
+
293
+ throw new Error('RDFArrayRemove: Array did not contain ' + x + ' ' + x.why);
294
+ }
295
+ export function string_startswith(str, pref) {
296
+ // missing library routines
297
+ return str.slice(0, pref.length) === pref;
298
+ }
299
+ /**
300
+ * C++, python style %s -> subs
301
+ */
302
+
303
+ function stringTemplate(base, subs) {
304
+ var baseA = base.split('%s');
305
+ var result = '';
306
+
307
+ for (var i = 0; i < subs.length; i++) {
308
+ subs[i] += '';
309
+ result += baseA[i] + subs[i];
310
+ }
311
+
312
+ return result + baseA.slice(subs.length).join();
313
+ } // Stack dump on errors - to pass errors back
314
+
315
+
316
+ export function stackString(e) {
317
+ var str = '' + e + '\n';
318
+
319
+ if (!e.stack) {
320
+ return str + 'No stack available.\n';
321
+ }
322
+
323
+ var lines = e.stack.toString().split('\n');
324
+ var toprint = [];
325
+
326
+ for (var i = 0; i < lines.length; i++) {
327
+ var line = lines[i];
328
+
329
+ if (line.indexOf('ecmaunit.js') > -1) {
330
+ // remove useless bit of traceback
331
+ break;
332
+ }
333
+
334
+ if (line.charAt(0) == '(') {
335
+ line = 'function' + line;
336
+ }
337
+
338
+ var chunks = line.split('@');
339
+ toprint.push(chunks);
340
+ } // toprint.reverse(); No - I prefer the latest at the top by the error message -tbl
341
+
342
+
343
+ for (var i = 0; i < toprint.length; i++) {
344
+ str += ' ' + toprint[i][1] + '\n ' + toprint[i][0];
345
+ }
346
+
347
+ return str;
348
+ }
package/esm/utils.js ADDED
@@ -0,0 +1,103 @@
1
+ import log from './log';
2
+ import { docpart } from './uri';
3
+ import { string_startswith } from './utils-js';
4
+
5
+ /** RDF/JS spec Typeguards */
6
+
7
+ /**
8
+ * Loads ontologies of the data we load (this is the callback from the kb to
9
+ * the fetcher).
10
+ */
11
+ export function AJAR_handleNewTerm(kb, p, requestedBy) {
12
+ var sf = null;
13
+
14
+ if (typeof kb.fetcher !== 'undefined') {
15
+ sf = kb.fetcher;
16
+ } else {
17
+ return;
18
+ }
19
+
20
+ if (p.termType !== 'NamedNode') return;
21
+ var docuri = docpart(p.uri);
22
+ var fixuri;
23
+
24
+ if (p.uri.indexOf('#') < 0) {
25
+ // No hash
26
+ // @@ major hack for dbpedia Categories, which spread indefinitely
27
+ if (string_startswith(p.uri, 'http://dbpedia.org/resource/Category:')) return;
28
+ /*
29
+ if (string_startswith(p.uri, 'http://xmlns.com/foaf/0.1/')) {
30
+ fixuri = "http://dig.csail.mit.edu/2005/ajar/ajaw/test/foaf"
31
+ // should give HTTP 303 to ontology -- now is :-)
32
+ } else
33
+ */
34
+
35
+ if (string_startswith(p.uri, 'http://purl.org/dc/elements/1.1/') || string_startswith(p.uri, 'http://purl.org/dc/terms/')) {
36
+ fixuri = 'http://dublincore.org/2005/06/13/dcq'; // dc fetched multiple times
37
+ } else if (string_startswith(p.uri, 'http://xmlns.com/wot/0.1/')) {
38
+ fixuri = 'http://xmlns.com/wot/0.1/index.rdf';
39
+ } else if (string_startswith(p.uri, 'http://web.resource.org/cc/')) {
40
+ // log.warn("creative commons links to html instead of rdf. doesn't seem to content-negotiate.")
41
+ fixuri = 'http://web.resource.org/cc/schema.rdf';
42
+ }
43
+ }
44
+
45
+ if (fixuri) {
46
+ docuri = fixuri;
47
+ }
48
+
49
+ if (sf && sf.getState(docuri) !== 'unrequested') return;
50
+
51
+ if (fixuri) {
52
+ // only give warning once: else happens too often
53
+ log.warn('Assuming server still broken, faking redirect of <' + p.uri + '> to <' + docuri + '>');
54
+ }
55
+
56
+ return sf.fetch(docuri, {
57
+ referringTerm: requestedBy
58
+ });
59
+ }
60
+ export var appliedFactoryMethods = ['blankNode', 'defaultGraph', 'literal', 'namedNode', 'quad', 'variable', 'supports'];
61
+ var rdf = {
62
+ first: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first',
63
+ rest: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest',
64
+ nil: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
65
+ };
66
+ /**
67
+ * Expands an array of Terms to a set of statements representing the rdf:list.
68
+ * @param rdfFactory - The factory to use
69
+ * @param subject - The iri of the first list item.
70
+ * @param data - The terms to expand into the list.
71
+ * @return The {data} as a set of statements.
72
+ */
73
+
74
+ export function arrayToStatements(rdfFactory, subject, data) {
75
+ var statements = [];
76
+ data.reduce(function (id, _listObj, i, listData) {
77
+ statements.push(rdfFactory.quad(id, rdfFactory.namedNode(rdf.first), listData[i]));
78
+ var nextNode;
79
+
80
+ if (i < listData.length - 1) {
81
+ nextNode = rdfFactory.blankNode();
82
+ statements.push(rdfFactory.quad(id, rdfFactory.namedNode(rdf.rest), nextNode));
83
+ } else {
84
+ statements.push(rdfFactory.quad(id, rdfFactory.namedNode(rdf.rest), rdfFactory.namedNode(rdf.nil)));
85
+ }
86
+
87
+ return nextNode;
88
+ }, subject);
89
+ return statements;
90
+ }
91
+ export function ArrayIndexOf(arr, item) {
92
+ var i = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
93
+ var length = arr.length;
94
+ if (i < 0) i = length + i;
95
+
96
+ for (; i < length; i++) {
97
+ if (arr[i] === item) {
98
+ return i;
99
+ }
100
+ }
101
+
102
+ return -1;
103
+ }
@@ -0,0 +1,101 @@
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 _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); }; }
10
+
11
+ 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; } }
12
+
13
+ import ClassOrder from './class-order';
14
+ import Node from './node-internal';
15
+ import { VariableTermType } from './types';
16
+ import * as Uri from './uri';
17
+
18
+ /**
19
+ * Variables are placeholders used in patterns to be matched.
20
+ * In cwm they are symbols which are the formula's list of quantified variables.
21
+ * In sparql they are not visibly URIs. Here we compromise, by having
22
+ * a common special base URI for variables. Their names are uris,
23
+ * but the ? notation has an implicit base uri of 'varid:'
24
+ */
25
+ var Variable = /*#__PURE__*/function (_Node) {
26
+ _inherits(Variable, _Node);
27
+
28
+ var _super = _createSuper(Variable);
29
+
30
+ /** The base string for a variable's name */
31
+
32
+ /** The unique identifier of this variable */
33
+
34
+ /**
35
+ * Initializes this variable
36
+ * @param name The variable's name
37
+ */
38
+ function Variable() {
39
+ var _this;
40
+
41
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
42
+
43
+ _classCallCheck(this, Variable);
44
+
45
+ _this = _super.call(this, name);
46
+
47
+ _defineProperty(_assertThisInitialized(_this), "termType", VariableTermType);
48
+
49
+ _defineProperty(_assertThisInitialized(_this), "base", 'varid:');
50
+
51
+ _defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.Variable);
52
+
53
+ _defineProperty(_assertThisInitialized(_this), "isVar", 1);
54
+
55
+ _defineProperty(_assertThisInitialized(_this), "uri", void 0);
56
+
57
+ _this.base = 'varid:';
58
+ _this.uri = Uri.join(name, _this.base);
59
+ return _this;
60
+ }
61
+
62
+ _createClass(Variable, [{
63
+ key: "equals",
64
+ value: function equals(other) {
65
+ if (!other) {
66
+ return false;
67
+ }
68
+
69
+ return this.termType === other.termType && this.value === other.value;
70
+ }
71
+ }, {
72
+ key: "hashString",
73
+ value: function hashString() {
74
+ return this.toString();
75
+ }
76
+ }, {
77
+ key: "substitute",
78
+ value: function substitute(bindings) {
79
+ var ref;
80
+ return (ref = bindings[this.toNT()]) != null ? ref : this;
81
+ }
82
+ }, {
83
+ key: "toString",
84
+ value: function toString() {
85
+ return Variable.toString(this);
86
+ }
87
+ }], [{
88
+ key: "toString",
89
+ value: function toString(variable) {
90
+ if (variable.uri.slice(0, variable.base.length) === variable.base) {
91
+ return "?".concat(variable.uri.slice(variable.base.length));
92
+ }
93
+
94
+ return "?".concat(variable.uri);
95
+ }
96
+ }]);
97
+
98
+ return Variable;
99
+ }(Node);
100
+
101
+ export { Variable as default };
@@ -0,0 +1,10 @@
1
+ import NamedNode from './named-node';
2
+ export default {
3
+ boolean: new NamedNode('http://www.w3.org/2001/XMLSchema#boolean'),
4
+ dateTime: new NamedNode('http://www.w3.org/2001/XMLSchema#dateTime'),
5
+ decimal: new NamedNode('http://www.w3.org/2001/XMLSchema#decimal'),
6
+ double: new NamedNode('http://www.w3.org/2001/XMLSchema#double'),
7
+ integer: new NamedNode('http://www.w3.org/2001/XMLSchema#integer'),
8
+ langString: new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString'),
9
+ string: new NamedNode('http://www.w3.org/2001/XMLSchema#string')
10
+ };
package/esm/xsd.js ADDED
@@ -0,0 +1,15 @@
1
+ import CanonicalDataFactory from "./factories/canonical-data-factory";
2
+ export function createXSD() {
3
+ var localFactory = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CanonicalDataFactory;
4
+ return {
5
+ boolean: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#boolean"),
6
+ dateTime: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime"),
7
+ decimal: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#decimal"),
8
+ double: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#double"),
9
+ integer: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#integer"),
10
+ langString: localFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString"),
11
+ string: localFactory.namedNode("http://www.w3.org/2001/XMLSchema#string")
12
+ };
13
+ }
14
+ var defaultXSD = createXSD(CanonicalDataFactory);
15
+ export default defaultXSD;
@@ -0,0 +1,44 @@
1
+ import Node from './node-internal';
2
+ import IndexedFormula from './store';
3
+ import { BlankNodeTermType } from './types';
4
+ import { BlankNode as TFBlankNode } from './tf-types';
5
+ /**
6
+ * An RDF blank node is a Node without a URI
7
+ * @link https://rdf.js.org/data-model-spec/#blanknode-interface
8
+ */
9
+ export default class BlankNode extends Node implements TFBlankNode {
10
+ termType: typeof BlankNodeTermType;
11
+ /**
12
+ * The next unique identifier for blank nodes
13
+ */
14
+ static nextId: number;
15
+ static NTAnonymousNodePrefix: '_:';
16
+ private static getId;
17
+ classOrder: number;
18
+ /** Whether this is a blank node */
19
+ isBlank: number;
20
+ /**
21
+ * This type of node is a variable.
22
+ *
23
+ * Note that the existence of this property already indicates that it is a variable.
24
+ */
25
+ isVar: number;
26
+ /**
27
+ * Initializes this node
28
+ * @param [id] The identifier for the blank node
29
+ */
30
+ constructor(id?: string | unknown);
31
+ /**
32
+ * The identifier for the blank node
33
+ */
34
+ get id(): string;
35
+ set id(value: string);
36
+ compareTerm(other: BlankNode): number;
37
+ /**
38
+ * Gets a copy of this blank node in the specified formula
39
+ * @param formula The formula
40
+ */
41
+ copy(formula: IndexedFormula): BlankNode;
42
+ toCanonical(): string;
43
+ toString(): string;
44
+ }
package/lib/blank-node.js CHANGED
File without changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Class orders
3
+ */
4
+ declare const ClassOrder: {
5
+ [id: string]: number;
6
+ };
7
+ export default ClassOrder;
File without changes