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,588 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+
5
+ /**
6
+ * RDF/XML PARSER
7
+ *
8
+ * Parser believed to be in full positive RDF/XML parsing compliance
9
+ * with the possible exception of handling deprecated RDF attributes
10
+ * appropriately. Parser is believed to comply fully with other W3C
11
+ * and industry standards where appropriate (DOM, ECMAScript, &c.)
12
+ *
13
+ * Author: David Sheets <dsheets@mit.edu>
14
+ *
15
+ * W3C® SOFTWARE NOTICE AND LICENSE
16
+ * http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
17
+ * This work (and included software, documentation such as READMEs, or
18
+ * other related items) is being provided by the copyright holders under
19
+ * the following license. By obtaining, using and/or copying this work,
20
+ * you (the licensee) agree that you have read, understood, and will
21
+ * comply with the following terms and conditions.
22
+ *
23
+ * Permission to copy, modify, and distribute this software and its
24
+ * documentation, with or without modification, for any purpose and
25
+ * without fee or royalty is hereby granted, provided that you include
26
+ * the following on ALL copies of the software and documentation or
27
+ * portions thereof, including modifications:
28
+ *
29
+ * 1. The full text of this NOTICE in a location viewable to users of
30
+ * the redistributed or derivative work.
31
+ * 2. Any pre-existing intellectual property disclaimers, notices, or terms and
32
+ * conditions. If none exist, the W3C Software Short Notice should be
33
+ * included (hypertext is preferred, text is permitted) within the body
34
+ * of any redistributed or derivative code.
35
+ * 3. Notice of any changes or modifications to the files, including the
36
+ * date changes were made. (We recommend you provide URIs to the location
37
+ * from which the code is derived.)
38
+ *
39
+ * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
40
+ * HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
41
+ * INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
42
+ * FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR
43
+ * DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
44
+ * TRADEMARKS OR OTHER RIGHTS.
45
+ *
46
+ * COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL
47
+ * OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR
48
+ * DOCUMENTATION.
49
+ *
50
+ * The name and trademarks of copyright holders may NOT be used in
51
+ * advertising or publicity pertaining to the software without specific,
52
+ * written prior permission. Title to copyright in this software and any
53
+ * associated documentation will at all times remain with copyright
54
+ * holders.
55
+ */
56
+
57
+ /**
58
+ * @class RDFParser resource object tied to an RDFStore
59
+ *
60
+ * @author David Sheets <dsheets@mit.edu>
61
+ *
62
+ */
63
+ import * as uriUtil from './uri';
64
+
65
+ var RDFParser = /*#__PURE__*/function () {
66
+ /*
67
+ * @constructor
68
+ * @param {RDFStore} store An RDFStore object
69
+ */
70
+ function RDFParser(store) {
71
+ _classCallCheck(this, RDFParser);
72
+
73
+ /** Our triple store reference @private */
74
+ this.store = store;
75
+ /** Our identified blank nodes @private */
76
+
77
+ this.bnodes = {};
78
+ /** A context for context-aware stores @private */
79
+
80
+ this.why = null;
81
+ /** Reification flag */
82
+
83
+ this.reify = false;
84
+ }
85
+ /** Standard namespaces that we know how to handle @final
86
+ * @member RDFParser
87
+ */
88
+
89
+
90
+ _createClass(RDFParser, [{
91
+ key: "frameFactory",
92
+ value:
93
+ /**
94
+ * Frame class for namespace and base URI lookups
95
+ * Base lookups will always resolve because the parser knows
96
+ * the default base.
97
+ *
98
+ * @private
99
+ */
100
+ function frameFactory(parser, parent, element) {
101
+ return {
102
+ 'NODE': 1,
103
+ 'ARC': 2,
104
+ 'parent': parent,
105
+ 'parser': parser,
106
+ 'store': parser.store,
107
+ 'element': element,
108
+ 'lastChild': 0,
109
+ 'base': null,
110
+ 'lang': null,
111
+ 'node': null,
112
+ 'nodeType': null,
113
+ 'listIndex': 1,
114
+ 'rdfid': null,
115
+ 'datatype': null,
116
+ 'collection': false,
117
+
118
+ /** Terminate the frame and notify the store that we're done */
119
+ 'terminateFrame': function terminateFrame() {
120
+ if (this.collection) {
121
+ this.node.close();
122
+ }
123
+ },
124
+
125
+ /** Add a symbol of a certain type to the this frame */
126
+ 'addSymbol': function addSymbol(type, uri) {
127
+ uri = uriUtil.join(uri, this.base);
128
+ this.node = this.store.sym(uri);
129
+ this.nodeType = type;
130
+ },
131
+
132
+ /** Load any constructed triples into the store */
133
+ 'loadTriple': function loadTriple() {
134
+ if (this.parent.parent.collection) {
135
+ this.parent.parent.node.append(this.node);
136
+ } else {
137
+ this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
138
+ }
139
+
140
+ if (this.parent.rdfid != null) {
141
+ // reify
142
+ var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
143
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(RDFParser.ns.RDF + 'Statement'), this.parser.why);
144
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'subject'), this.parent.parent.node, this.parser.why);
145
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'predicate'), this.parent.node, this.parser.why);
146
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
147
+ }
148
+ },
149
+
150
+ /** Check if it's OK to load a triple */
151
+ 'isTripleToLoad': function isTripleToLoad() {
152
+ return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
153
+ },
154
+
155
+ /** Add a symbolic node to this frame */
156
+ 'addNode': function addNode(uri) {
157
+ this.addSymbol(this.NODE, uri);
158
+
159
+ if (this.isTripleToLoad()) {
160
+ this.loadTriple();
161
+ }
162
+ },
163
+
164
+ /** Add a collection node to this frame */
165
+ 'addCollection': function addCollection() {
166
+ this.nodeType = this.NODE;
167
+ this.node = this.store.collection();
168
+ this.collection = true;
169
+
170
+ if (this.isTripleToLoad()) {
171
+ this.loadTriple();
172
+ }
173
+ },
174
+
175
+ /** Add a collection arc to this frame */
176
+ 'addCollectionArc': function addCollectionArc() {
177
+ this.nodeType = this.ARC;
178
+ },
179
+
180
+ /** Add a bnode to this frame */
181
+ 'addBNode': function addBNode(id) {
182
+ if (id != null) {
183
+ if (this.parser.bnodes[id] != null) {
184
+ this.node = this.parser.bnodes[id];
185
+ } else {
186
+ this.node = this.parser.bnodes[id] = this.store.bnode();
187
+ }
188
+ } else {
189
+ this.node = this.store.bnode();
190
+ }
191
+
192
+ this.nodeType = this.NODE;
193
+
194
+ if (this.isTripleToLoad()) {
195
+ this.loadTriple();
196
+ }
197
+ },
198
+
199
+ /** Add an arc or property to this frame */
200
+ 'addArc': function addArc(uri) {
201
+ if (uri === RDFParser.ns.RDF + 'li') {
202
+ uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
203
+ this.parent.listIndex++;
204
+ }
205
+
206
+ this.addSymbol(this.ARC, uri);
207
+ },
208
+
209
+ /** Add a literal to this frame */
210
+ 'addLiteral': function addLiteral(value) {
211
+ if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
212
+ this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
213
+ } else {
214
+ this.node = this.store.literal(value, this.lang);
215
+ }
216
+
217
+ this.nodeType = this.NODE;
218
+
219
+ if (this.isTripleToLoad()) {
220
+ this.loadTriple();
221
+ }
222
+ }
223
+ };
224
+ } // from the OpenLayers source .. needed to get around IE problems.
225
+
226
+ }, {
227
+ key: "getAttributeNodeNS",
228
+ value: function getAttributeNodeNS(node, uri, name) {
229
+ var attributeNode = null;
230
+
231
+ if (node.getAttributeNodeNS) {
232
+ attributeNode = node.getAttributeNodeNS(uri, name);
233
+ } else {
234
+ var attributes = node.attributes;
235
+ var potentialNode, fullName;
236
+
237
+ for (var i = 0; i < attributes.length; ++i) {
238
+ potentialNode = attributes[i];
239
+
240
+ if (potentialNode.namespaceURI === uri) {
241
+ fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
242
+
243
+ if (fullName === potentialNode.nodeName) {
244
+ attributeNode = potentialNode;
245
+ break;
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ return attributeNode;
252
+ }
253
+ /**
254
+ * Build our initial scope frame and parse the DOM into triples
255
+ * @param {DOMTree} document The DOM to parse
256
+ * @param {String} base The base URL to use
257
+ * @param {Object} why The context to which this resource belongs
258
+ */
259
+
260
+ }, {
261
+ key: "parse",
262
+ value: function parse(document, base, why) {
263
+ var children = document.childNodes; // clean up for the next run
264
+
265
+ this.cleanParser(); // figure out the root element
266
+
267
+ var root;
268
+
269
+ if (document.nodeType === RDFParser.nodeType.DOCUMENT) {
270
+ for (var c = 0; c < children.length; c++) {
271
+ if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
272
+ root = children[c];
273
+ break;
274
+ }
275
+ }
276
+ } else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
277
+ root = document;
278
+ } else {
279
+ throw new Error("RDFParser: can't find root in " + base + '. Halting. '); // return false
280
+ }
281
+
282
+ this.why = why; // our topmost frame
283
+
284
+ var f = this.frameFactory(this);
285
+ this.base = base;
286
+ f.base = base;
287
+ f.lang = null; // was '' but can't have langs like that 2015 (!)
288
+
289
+ this.parseDOM(this.buildFrame(f, root));
290
+ return true;
291
+ }
292
+ }, {
293
+ key: "parseDOM",
294
+ value: function parseDOM(frame) {
295
+ // a DOM utility function used in parsing
296
+ var rdfid;
297
+
298
+ var elementURI = function (el) {
299
+ var result = '';
300
+
301
+ if (el.namespaceURI == null) {
302
+ throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
303
+ }
304
+
305
+ if (el.namespaceURI) {
306
+ result = result + el.namespaceURI;
307
+ }
308
+
309
+ if (el.localName) {
310
+ result = result + el.localName;
311
+ } else if (el.nodeName) {
312
+ if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
313
+ }
314
+
315
+ return result;
316
+ }.bind(this);
317
+
318
+ var dig = true; // if we'll dig down in the tree on the next iter
319
+
320
+ while (frame.parent) {
321
+ var dom = frame.element;
322
+ var attrs = dom.attributes;
323
+
324
+ if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
325
+ // we have a literal
326
+ if (frame.parent.nodeType === frame.NODE) {
327
+ // must have had attributes, store as rdf:value
328
+ frame.addArc(RDFParser.ns.RDF + 'value');
329
+ frame = this.buildFrame(frame);
330
+ }
331
+
332
+ frame.addLiteral(dom.nodeValue);
333
+ } else if (elementURI(dom) !== RDFParser.ns.RDF + 'RDF') {
334
+ // not root
335
+ if (frame.parent && frame.parent.collection) {
336
+ // we're a collection element
337
+ frame.addCollectionArc();
338
+ frame = this.buildFrame(frame, frame.element);
339
+ frame.parent.element = null;
340
+ }
341
+
342
+ if (!frame.parent || !frame.parent.nodeType || frame.parent.nodeType === frame.ARC) {
343
+ // we need a node
344
+ var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
345
+ rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
346
+
347
+ if (about && rdfid) {
348
+ throw new Error('RDFParser: ' + dom.nodeName + ' has both rdf:id and rdf:about.' + ' Halting. Only one of these' + ' properties may be specified on a' + ' node.');
349
+ }
350
+
351
+ if (!about && rdfid) {
352
+ frame.addNode('#' + rdfid.nodeValue);
353
+ dom.removeAttributeNode(rdfid);
354
+ } else if (about == null && rdfid == null) {
355
+ var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
356
+
357
+ if (bnid) {
358
+ frame.addBNode(bnid.nodeValue);
359
+ dom.removeAttributeNode(bnid);
360
+ } else {
361
+ frame.addBNode();
362
+ }
363
+ } else {
364
+ frame.addNode(about.nodeValue);
365
+ dom.removeAttributeNode(about);
366
+ } // Typed nodes
367
+
368
+
369
+ var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
370
+
371
+ if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
372
+ rdftype = {
373
+ 'nodeValue': elementURI(dom)
374
+ };
375
+ }
376
+
377
+ if (rdftype != null) {
378
+ this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
379
+
380
+ if (rdftype.nodeName) {
381
+ dom.removeAttributeNode(rdftype);
382
+ }
383
+ } // Property Attributes
384
+
385
+
386
+ for (var x = attrs.length - 1; x >= 0; x--) {
387
+ this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, frame.lang), this.why);
388
+ }
389
+ } else {
390
+ // we should add an arc (or implicit bnode+arc)
391
+ frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
392
+
393
+ if (this.reify) {
394
+ rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
395
+
396
+ if (rdfid) {
397
+ frame.rdfid = rdfid.nodeValue;
398
+ dom.removeAttributeNode(rdfid);
399
+ }
400
+ }
401
+
402
+ var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
403
+ var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
404
+
405
+ if (datatype) {
406
+ frame.datatype = datatype.nodeValue;
407
+ dom.removeAttributeNode(datatype);
408
+ }
409
+
410
+ if (parsetype) {
411
+ var nv = parsetype.nodeValue;
412
+
413
+ if (nv === 'Literal') {
414
+ frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
415
+ frame = this.buildFrame(frame); // Don't include the literal node, only its children
416
+
417
+ frame.addLiteral(dom.childNodes);
418
+ dig = false;
419
+ } else if (nv === 'Resource') {
420
+ frame = this.buildFrame(frame, frame.element);
421
+ frame.parent.element = null;
422
+ frame.addBNode();
423
+ } else if (nv === 'Collection') {
424
+ frame = this.buildFrame(frame, frame.element);
425
+ frame.parent.element = null;
426
+ frame.addCollection();
427
+ }
428
+
429
+ dom.removeAttributeNode(parsetype);
430
+ }
431
+
432
+ if (attrs.length !== 0) {
433
+ var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'resource');
434
+ var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
435
+ frame = this.buildFrame(frame);
436
+
437
+ if (resource) {
438
+ frame.addNode(resource.nodeValue);
439
+ dom.removeAttributeNode(resource);
440
+ } else {
441
+ if (bnid2) {
442
+ frame.addBNode(bnid2.nodeValue);
443
+ dom.removeAttributeNode(bnid2);
444
+ } else {
445
+ frame.addBNode();
446
+ }
447
+ }
448
+
449
+ for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
450
+ var f = this.buildFrame(frame);
451
+ f.addArc(elementURI(attrs[x1]));
452
+
453
+ if (elementURI(attrs[x1]) === RDFParser.ns.RDF + 'type') {
454
+ this.buildFrame(f).addNode(attrs[x1].nodeValue);
455
+ } else {
456
+ this.buildFrame(f).addLiteral(attrs[x1].nodeValue);
457
+ }
458
+ }
459
+ } else if (dom.childNodes.length === 0) {
460
+ this.buildFrame(frame).addLiteral('');
461
+ }
462
+ }
463
+ } // rdf:RDF
464
+ // dig dug
465
+
466
+
467
+ dom = frame.element;
468
+
469
+ while (frame.parent) {
470
+ var pframe = frame;
471
+
472
+ while (dom == null) {
473
+ frame = frame.parent;
474
+ dom = frame.element;
475
+ }
476
+
477
+ var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
478
+
479
+ if (!candidate || !dig) {
480
+ frame.terminateFrame();
481
+
482
+ if (!(frame = frame.parent)) {
483
+ break;
484
+ } // done
485
+
486
+
487
+ dom = frame.element;
488
+ dig = true;
489
+ } else if (candidate.nodeType !== RDFParser.nodeType.ELEMENT && candidate.nodeType !== RDFParser.nodeType.TEXT && candidate.nodeType !== RDFParser.nodeType.CDATA_SECTION || (candidate.nodeType === RDFParser.nodeType.TEXT || candidate.nodeType === RDFParser.nodeType.CDATA_SECTION) && dom.childNodes.length !== 1) {
490
+ frame.lastChild++;
491
+ } else {
492
+ // not a leaf
493
+ frame.lastChild++;
494
+ frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]);
495
+ break;
496
+ }
497
+ }
498
+ } // while
499
+
500
+ }
501
+ /**
502
+ * Cleans out state from a previous parse run
503
+ * @private
504
+ */
505
+
506
+ }, {
507
+ key: "cleanParser",
508
+ value: function cleanParser() {
509
+ this.bnodes = {};
510
+ this.why = null;
511
+ }
512
+ /**
513
+ * Builds scope frame
514
+ * @private
515
+ */
516
+
517
+ }, {
518
+ key: "buildFrame",
519
+ value: function buildFrame(parent, element) {
520
+ var frame = this.frameFactory(this, parent, element);
521
+
522
+ if (parent) {
523
+ frame.base = parent.base;
524
+ frame.lang = parent.lang;
525
+ }
526
+
527
+ if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
528
+ return frame;
529
+ }
530
+
531
+ var attrs = element.attributes;
532
+ var base = element.getAttributeNode('xml:base');
533
+
534
+ if (base != null) {
535
+ frame.base = base.nodeValue;
536
+ element.removeAttribute('xml:base');
537
+ }
538
+
539
+ var lang = element.getAttributeNode('xml:lang');
540
+
541
+ if (lang != null) {
542
+ frame.lang = lang.nodeValue;
543
+ element.removeAttribute('xml:lang');
544
+ } // remove all extraneous xml and xmlns attributes
545
+
546
+
547
+ for (var x = attrs.length - 1; x >= 0; x--) {
548
+ if (attrs[x].nodeName.substr(0, 3) === 'xml') {
549
+ if (attrs[x].name.slice(0, 6) === 'xmlns:') {
550
+ var uri = attrs[x].nodeValue; // alert('base for namespac attr:'+this.base)
551
+
552
+ if (this.base) uri = uriUtil.join(uri, this.base);
553
+ this.store.setPrefixForURI(attrs[x].name.slice(6), uri);
554
+ } // alert('rdfparser: xml atribute: '+attrs[x].name) //@@
555
+
556
+
557
+ element.removeAttributeNode(attrs[x]);
558
+ }
559
+ }
560
+
561
+ return frame;
562
+ }
563
+ }]);
564
+
565
+ return RDFParser;
566
+ }();
567
+
568
+ _defineProperty(RDFParser, "ns", {
569
+ 'RDF': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
570
+ 'RDFS': 'http://www.w3.org/2000/01/rdf-schema#'
571
+ });
572
+
573
+ _defineProperty(RDFParser, "nodeType", {
574
+ 'ELEMENT': 1,
575
+ 'ATTRIBUTE': 2,
576
+ 'TEXT': 3,
577
+ 'CDATA_SECTION': 4,
578
+ 'ENTITY_REFERENCE': 5,
579
+ 'ENTITY': 6,
580
+ 'PROCESSING_INSTRUCTION': 7,
581
+ 'COMMENT': 8,
582
+ 'DOCUMENT': 9,
583
+ 'DOCUMENT_TYPE': 10,
584
+ 'DOCUMENT_FRAGMENT': 11,
585
+ 'NOTATION': 12
586
+ });
587
+
588
+ export { RDFParser as default };
@@ -0,0 +1,95 @@
1
+ import * as convert from './convert';
2
+ import Serializer from './serializer';
3
+ import { JSONLDContentType, N3ContentType, N3LegacyContentType, NQuadsAltContentType, NQuadsContentType, NTriplesContentType, RDFXMLContentType, TurtleContentType, TurtleLegacyContentType } from './types';
4
+
5
+ /**
6
+ * Serialize to the appropriate format
7
+ */
8
+ export default function serialize(
9
+ /** The graph or nodes that should be serialized */
10
+ target,
11
+ /** The store */
12
+ kb, base,
13
+ /**
14
+ * The mime type.
15
+ * Defaults to Turtle.
16
+ */
17
+ contentType, callback, options) {
18
+ base = base || target.value;
19
+ var opts = options || {};
20
+ contentType = contentType || TurtleContentType; // text/n3 if complex?
21
+
22
+ var documentString = undefined;
23
+
24
+ try {
25
+ var sz = Serializer(kb);
26
+ if (opts.flags) sz.setFlags(opts.flags);
27
+ var newSts = kb.statementsMatching(undefined, undefined, undefined, target);
28
+ var n3String;
29
+ sz.suggestNamespaces(kb.namespaces);
30
+ sz.setBase(base);
31
+
32
+ switch (contentType) {
33
+ case RDFXMLContentType:
34
+ documentString = sz.statementsToXML(newSts);
35
+ return executeCallback(null, documentString);
36
+
37
+ case N3ContentType:
38
+ case N3LegacyContentType:
39
+ documentString = sz.statementsToN3(newSts);
40
+ return executeCallback(null, documentString);
41
+
42
+ case TurtleContentType:
43
+ case TurtleLegacyContentType:
44
+ sz.setFlags('si'); // Suppress = for sameAs and => for implies
45
+
46
+ documentString = sz.statementsToN3(newSts);
47
+ return executeCallback(null, documentString);
48
+
49
+ case NTriplesContentType:
50
+ sz.setFlags('deinprstux'); // Suppress nice parts of N3 to make ntriples
51
+
52
+ documentString = sz.statementsToNTriples(newSts);
53
+ return executeCallback(null, documentString);
54
+
55
+ case JSONLDContentType:
56
+ sz.setFlags('deinprstux'); // Use adapters to connect to incmpatible parser
57
+
58
+ n3String = sz.statementsToNTriples(newSts); // n3String = sz.statementsToN3(newSts)
59
+
60
+ convert.convertToJson(n3String, callback);
61
+ break;
62
+
63
+ case NQuadsContentType:
64
+ case NQuadsAltContentType:
65
+ // @@@ just outpout the quads? Does not work for collections
66
+ sz.setFlags('deinprstux q'); // Suppress nice parts of N3 to make ntriples
67
+
68
+ documentString = sz.statementsToNTriples(newSts); // q in flag means actually quads
69
+
70
+ return executeCallback(null, documentString);
71
+ // n3String = sz.statementsToN3(newSts)
72
+ // documentString = convert.convertToNQuads(n3String, callback)
73
+ // break
74
+
75
+ default:
76
+ throw new Error('Serialize: Content-type ' + contentType + ' not supported for data write.');
77
+ }
78
+ } catch (err) {
79
+ if (callback) {
80
+ // @ts-ignore
81
+ return callback(err, undefined);
82
+ }
83
+
84
+ throw err; // Don't hide problems from caller in sync mode
85
+ }
86
+
87
+ function executeCallback(err, result) {
88
+ if (callback) {
89
+ callback(err, result);
90
+ return;
91
+ } else {
92
+ return result;
93
+ }
94
+ }
95
+ }