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
@@ -1,11 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  var _typeof = require("@babel/runtime/helpers/typeof");
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
8
- exports.default = RDFParser;
10
+ exports.default = void 0;
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
17
 
10
18
  var uriUtil = _interopRequireWildcard(require("./uri"));
11
19
 
@@ -71,515 +79,524 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
71
79
  * @author David Sheets <dsheets@mit.edu>
72
80
  *
73
81
  */
74
-
75
- /*
76
- * @constructor
77
- * @param {RDFStore} store An RDFStore object
78
- */
79
- function RDFParser(store) {
80
- var RDFParser = {};
81
- /** Standard namespaces that we know how to handle @final
82
- * @member RDFParser
82
+ var RDFParser = /*#__PURE__*/function () {
83
+ /*
84
+ * @constructor
85
+ * @param {RDFStore} store An RDFStore object
83
86
  */
87
+ function RDFParser(store) {
88
+ (0, _classCallCheck2.default)(this, RDFParser);
89
+
90
+ /** Our triple store reference @private */
91
+ this.store = store;
92
+ /** Our identified blank nodes @private */
93
+
94
+ this.bnodes = {};
95
+ /** A context for context-aware stores @private */
84
96
 
85
- RDFParser.ns = {
86
- 'RDF': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
87
- 'RDFS': 'http://www.w3.org/2000/01/rdf-schema#'
88
- };
89
- /** DOM Level 2 node type magic numbers @final
97
+ this.why = null;
98
+ /** Reification flag */
99
+
100
+ this.reify = false;
101
+ }
102
+ /** Standard namespaces that we know how to handle @final
90
103
  * @member RDFParser
91
104
  */
92
105
 
93
- RDFParser.nodeType = {
94
- 'ELEMENT': 1,
95
- 'ATTRIBUTE': 2,
96
- 'TEXT': 3,
97
- 'CDATA_SECTION': 4,
98
- 'ENTITY_REFERENCE': 5,
99
- 'ENTITY': 6,
100
- 'PROCESSING_INSTRUCTION': 7,
101
- 'COMMENT': 8,
102
- 'DOCUMENT': 9,
103
- 'DOCUMENT_TYPE': 10,
104
- 'DOCUMENT_FRAGMENT': 11,
105
- 'NOTATION': 12
106
- };
107
- /**
108
- * Frame class for namespace and base URI lookups
109
- * Base lookups will always resolve because the parser knows
110
- * the default base.
111
- *
112
- * @private
113
- */
114
106
 
115
- this.frameFactory = function (parser, parent, element) {
116
- return {
117
- 'NODE': 1,
118
- 'ARC': 2,
119
- 'parent': parent,
120
- 'parser': parser,
121
- 'store': parser.store,
122
- 'element': element,
123
- 'lastChild': 0,
124
- 'base': null,
125
- 'lang': null,
126
- 'node': null,
127
- 'nodeType': null,
128
- 'listIndex': 1,
129
- 'rdfid': null,
130
- 'datatype': null,
131
- 'collection': false,
132
-
133
- /** Terminate the frame and notify the store that we're done */
134
- 'terminateFrame': function terminateFrame() {
135
- if (this.collection) {
136
- this.node.close();
137
- }
138
- },
139
-
140
- /** Add a symbol of a certain type to the this frame */
141
- 'addSymbol': function addSymbol(type, uri) {
142
- uri = uriUtil.join(uri, this.base);
143
- this.node = this.store.sym(uri);
144
- this.nodeType = type;
145
- },
146
-
147
- /** Load any constructed triples into the store */
148
- 'loadTriple': function loadTriple() {
149
- if (this.parent.parent.collection) {
150
- this.parent.parent.node.append(this.node);
151
- } else {
152
- this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
153
- }
107
+ (0, _createClass2.default)(RDFParser, [{
108
+ key: "frameFactory",
109
+ value:
110
+ /**
111
+ * Frame class for namespace and base URI lookups
112
+ * Base lookups will always resolve because the parser knows
113
+ * the default base.
114
+ *
115
+ * @private
116
+ */
117
+ function frameFactory(parser, parent, element) {
118
+ return {
119
+ 'NODE': 1,
120
+ 'ARC': 2,
121
+ 'parent': parent,
122
+ 'parser': parser,
123
+ 'store': parser.store,
124
+ 'element': element,
125
+ 'lastChild': 0,
126
+ 'base': null,
127
+ 'lang': null,
128
+ 'node': null,
129
+ 'nodeType': null,
130
+ 'listIndex': 1,
131
+ 'rdfid': null,
132
+ 'datatype': null,
133
+ 'collection': false,
134
+
135
+ /** Terminate the frame and notify the store that we're done */
136
+ 'terminateFrame': function terminateFrame() {
137
+ if (this.collection) {
138
+ this.node.close();
139
+ }
140
+ },
141
+
142
+ /** Add a symbol of a certain type to the this frame */
143
+ 'addSymbol': function addSymbol(type, uri) {
144
+ uri = uriUtil.join(uri, this.base);
145
+ this.node = this.store.sym(uri);
146
+ this.nodeType = type;
147
+ },
148
+
149
+ /** Load any constructed triples into the store */
150
+ 'loadTriple': function loadTriple() {
151
+ if (this.parent.parent.collection) {
152
+ this.parent.parent.node.append(this.node);
153
+ } else {
154
+ this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
155
+ }
154
156
 
155
- if (this.parent.rdfid != null) {
156
- // reify
157
- var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
158
- this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(RDFParser.ns.RDF + 'Statement'), this.parser.why);
159
- this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'subject'), this.parent.parent.node, this.parser.why);
160
- this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'predicate'), this.parent.node, this.parser.why);
161
- this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
162
- }
163
- },
157
+ if (this.parent.rdfid != null) {
158
+ // reify
159
+ var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
160
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(RDFParser.ns.RDF + 'Statement'), this.parser.why);
161
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'subject'), this.parent.parent.node, this.parser.why);
162
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'predicate'), this.parent.node, this.parser.why);
163
+ this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
164
+ }
165
+ },
164
166
 
165
- /** Check if it's OK to load a triple */
166
- 'isTripleToLoad': function isTripleToLoad() {
167
- return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
168
- },
167
+ /** Check if it's OK to load a triple */
168
+ 'isTripleToLoad': function isTripleToLoad() {
169
+ return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
170
+ },
169
171
 
170
- /** Add a symbolic node to this frame */
171
- 'addNode': function addNode(uri) {
172
- this.addSymbol(this.NODE, uri);
172
+ /** Add a symbolic node to this frame */
173
+ 'addNode': function addNode(uri) {
174
+ this.addSymbol(this.NODE, uri);
173
175
 
174
- if (this.isTripleToLoad()) {
175
- this.loadTriple();
176
- }
177
- },
176
+ if (this.isTripleToLoad()) {
177
+ this.loadTriple();
178
+ }
179
+ },
178
180
 
179
- /** Add a collection node to this frame */
180
- 'addCollection': function addCollection() {
181
- this.nodeType = this.NODE;
182
- this.node = this.store.collection();
183
- this.collection = true;
181
+ /** Add a collection node to this frame */
182
+ 'addCollection': function addCollection() {
183
+ this.nodeType = this.NODE;
184
+ this.node = this.store.collection();
185
+ this.collection = true;
184
186
 
185
- if (this.isTripleToLoad()) {
186
- this.loadTriple();
187
- }
188
- },
189
-
190
- /** Add a collection arc to this frame */
191
- 'addCollectionArc': function addCollectionArc() {
192
- this.nodeType = this.ARC;
193
- },
194
-
195
- /** Add a bnode to this frame */
196
- 'addBNode': function addBNode(id) {
197
- if (id != null) {
198
- if (this.parser.bnodes[id] != null) {
199
- this.node = this.parser.bnodes[id];
187
+ if (this.isTripleToLoad()) {
188
+ this.loadTriple();
189
+ }
190
+ },
191
+
192
+ /** Add a collection arc to this frame */
193
+ 'addCollectionArc': function addCollectionArc() {
194
+ this.nodeType = this.ARC;
195
+ },
196
+
197
+ /** Add a bnode to this frame */
198
+ 'addBNode': function addBNode(id) {
199
+ if (id != null) {
200
+ if (this.parser.bnodes[id] != null) {
201
+ this.node = this.parser.bnodes[id];
202
+ } else {
203
+ this.node = this.parser.bnodes[id] = this.store.bnode();
204
+ }
200
205
  } else {
201
- this.node = this.parser.bnodes[id] = this.store.bnode();
206
+ this.node = this.store.bnode();
202
207
  }
203
- } else {
204
- this.node = this.store.bnode();
205
- }
206
208
 
207
- this.nodeType = this.NODE;
209
+ this.nodeType = this.NODE;
208
210
 
209
- if (this.isTripleToLoad()) {
210
- this.loadTriple();
211
- }
212
- },
211
+ if (this.isTripleToLoad()) {
212
+ this.loadTriple();
213
+ }
214
+ },
213
215
 
214
- /** Add an arc or property to this frame */
215
- 'addArc': function addArc(uri) {
216
- if (uri === RDFParser.ns.RDF + 'li') {
217
- uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
218
- this.parent.listIndex++;
219
- }
216
+ /** Add an arc or property to this frame */
217
+ 'addArc': function addArc(uri) {
218
+ if (uri === RDFParser.ns.RDF + 'li') {
219
+ uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
220
+ this.parent.listIndex++;
221
+ }
220
222
 
221
- this.addSymbol(this.ARC, uri);
222
- },
223
+ this.addSymbol(this.ARC, uri);
224
+ },
223
225
 
224
- /** Add a literal to this frame */
225
- 'addLiteral': function addLiteral(value) {
226
- if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
227
- this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
228
- } else {
229
- this.node = this.store.literal(value, this.lang);
230
- }
226
+ /** Add a literal to this frame */
227
+ 'addLiteral': function addLiteral(value) {
228
+ if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
229
+ this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
230
+ } else {
231
+ this.node = this.store.literal(value, this.lang);
232
+ }
231
233
 
232
- this.nodeType = this.NODE;
234
+ this.nodeType = this.NODE;
233
235
 
234
- if (this.isTripleToLoad()) {
235
- this.loadTriple();
236
+ if (this.isTripleToLoad()) {
237
+ this.loadTriple();
238
+ }
236
239
  }
237
- }
238
- };
239
- }; // from the OpenLayers source .. needed to get around IE problems.
240
+ };
241
+ } // from the OpenLayers source .. needed to get around IE problems.
240
242
 
243
+ }, {
244
+ key: "getAttributeNodeNS",
245
+ value: function getAttributeNodeNS(node, uri, name) {
246
+ var attributeNode = null;
241
247
 
242
- this.getAttributeNodeNS = function (node, uri, name) {
243
- var attributeNode = null;
248
+ if (node.getAttributeNodeNS) {
249
+ attributeNode = node.getAttributeNodeNS(uri, name);
250
+ } else {
251
+ var attributes = node.attributes;
252
+ var potentialNode, fullName;
244
253
 
245
- if (node.getAttributeNodeNS) {
246
- attributeNode = node.getAttributeNodeNS(uri, name);
247
- } else {
248
- var attributes = node.attributes;
249
- var potentialNode, fullName;
254
+ for (var i = 0; i < attributes.length; ++i) {
255
+ potentialNode = attributes[i];
250
256
 
251
- for (var i = 0; i < attributes.length; ++i) {
252
- potentialNode = attributes[i];
257
+ if (potentialNode.namespaceURI === uri) {
258
+ fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
253
259
 
254
- if (potentialNode.namespaceURI === uri) {
255
- fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
260
+ if (fullName === potentialNode.nodeName) {
261
+ attributeNode = potentialNode;
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ }
256
267
 
257
- if (fullName === potentialNode.nodeName) {
258
- attributeNode = potentialNode;
268
+ return attributeNode;
269
+ }
270
+ /**
271
+ * Build our initial scope frame and parse the DOM into triples
272
+ * @param {DOMTree} document The DOM to parse
273
+ * @param {String} base The base URL to use
274
+ * @param {Object} why The context to which this resource belongs
275
+ */
276
+
277
+ }, {
278
+ key: "parse",
279
+ value: function parse(document, base, why) {
280
+ var children = document.childNodes; // clean up for the next run
281
+
282
+ this.cleanParser(); // figure out the root element
283
+
284
+ var root;
285
+
286
+ if (document.nodeType === RDFParser.nodeType.DOCUMENT) {
287
+ for (var c = 0; c < children.length; c++) {
288
+ if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
289
+ root = children[c];
259
290
  break;
260
291
  }
261
292
  }
293
+ } else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
294
+ root = document;
295
+ } else {
296
+ throw new Error("RDFParser: can't find root in " + base + '. Halting. '); // return false
262
297
  }
263
- }
264
-
265
- return attributeNode;
266
- };
267
- /** Our triple store reference @private */
268
-
269
-
270
- this.store = store;
271
- /** Our identified blank nodes @private */
272
298
 
273
- this.bnodes = {};
274
- /** A context for context-aware stores @private */
299
+ this.why = why; // our topmost frame
275
300
 
276
- this.why = null;
277
- /** Reification flag */
301
+ var f = this.frameFactory(this);
302
+ this.base = base;
303
+ f.base = base;
304
+ f.lang = null; // was '' but can't have langs like that 2015 (!)
278
305
 
279
- this.reify = false;
280
- /**
281
- * Build our initial scope frame and parse the DOM into triples
282
- * @param {DOMTree} document The DOM to parse
283
- * @param {String} base The base URL to use
284
- * @param {Object} why The context to which this resource belongs
285
- */
286
-
287
- this.parse = function (document, base, why) {
288
- var children = document.childNodes; // clean up for the next run
289
-
290
- this.cleanParser(); // figure out the root element
306
+ this.parseDOM(this.buildFrame(f, root));
307
+ return true;
308
+ }
309
+ }, {
310
+ key: "parseDOM",
311
+ value: function parseDOM(frame) {
312
+ // a DOM utility function used in parsing
313
+ var rdfid;
291
314
 
292
- var root;
315
+ var elementURI = function (el) {
316
+ var result = '';
293
317
 
294
- if (document.nodeType === RDFParser.nodeType.DOCUMENT) {
295
- for (var c = 0; c < children.length; c++) {
296
- if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
297
- root = children[c];
298
- break;
318
+ if (el.namespaceURI == null) {
319
+ throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
299
320
  }
300
- }
301
- } else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
302
- root = document;
303
- } else {
304
- throw new Error("RDFParser: can't find root in " + base + '. Halting. '); // return false
305
- }
306
321
 
307
- this.why = why; // our topmost frame
322
+ if (el.namespaceURI) {
323
+ result = result + el.namespaceURI;
324
+ }
308
325
 
309
- var f = this.frameFactory(this);
310
- this.base = base;
311
- f.base = base;
312
- f.lang = null; // was '' but can't have langs like that 2015 (!)
326
+ if (el.localName) {
327
+ result = result + el.localName;
328
+ } else if (el.nodeName) {
329
+ if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
330
+ }
313
331
 
314
- this.parseDOM(this.buildFrame(f, root));
315
- return true;
316
- };
332
+ return result;
333
+ }.bind(this);
317
334
 
318
- this.parseDOM = function (frame) {
319
- // a DOM utility function used in parsing
320
- var rdfid;
335
+ var dig = true; // if we'll dig down in the tree on the next iter
321
336
 
322
- var elementURI = function (el) {
323
- var result = '';
337
+ while (frame.parent) {
338
+ var dom = frame.element;
339
+ var attrs = dom.attributes;
340
+
341
+ if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
342
+ // we have a literal
343
+ if (frame.parent.nodeType === frame.NODE) {
344
+ // must have had attributes, store as rdf:value
345
+ frame.addArc(RDFParser.ns.RDF + 'value');
346
+ frame = this.buildFrame(frame);
347
+ }
324
348
 
325
- if (el.namespaceURI == null) {
326
- throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
327
- }
349
+ frame.addLiteral(dom.nodeValue);
350
+ } else if (elementURI(dom) !== RDFParser.ns.RDF + 'RDF') {
351
+ // not root
352
+ if (frame.parent && frame.parent.collection) {
353
+ // we're a collection element
354
+ frame.addCollectionArc();
355
+ frame = this.buildFrame(frame, frame.element);
356
+ frame.parent.element = null;
357
+ }
328
358
 
329
- if (el.namespaceURI) {
330
- result = result + el.namespaceURI;
331
- }
359
+ if (!frame.parent || !frame.parent.nodeType || frame.parent.nodeType === frame.ARC) {
360
+ // we need a node
361
+ var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
362
+ rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
332
363
 
333
- if (el.localName) {
334
- result = result + el.localName;
335
- } else if (el.nodeName) {
336
- if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
337
- }
364
+ if (about && rdfid) {
365
+ 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.');
366
+ }
338
367
 
339
- return result;
340
- }.bind(this);
368
+ if (!about && rdfid) {
369
+ frame.addNode('#' + rdfid.nodeValue);
370
+ dom.removeAttributeNode(rdfid);
371
+ } else if (about == null && rdfid == null) {
372
+ var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
341
373
 
342
- var dig = true; // if we'll dig down in the tree on the next iter
374
+ if (bnid) {
375
+ frame.addBNode(bnid.nodeValue);
376
+ dom.removeAttributeNode(bnid);
377
+ } else {
378
+ frame.addBNode();
379
+ }
380
+ } else {
381
+ frame.addNode(about.nodeValue);
382
+ dom.removeAttributeNode(about);
383
+ } // Typed nodes
343
384
 
344
- while (frame.parent) {
345
- var dom = frame.element;
346
- var attrs = dom.attributes;
347
385
 
348
- if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
349
- // we have a literal
350
- if (frame.parent.nodeType === frame.NODE) {
351
- // must have had attributes, store as rdf:value
352
- frame.addArc(RDFParser.ns.RDF + 'value');
353
- frame = this.buildFrame(frame);
354
- }
386
+ var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
355
387
 
356
- frame.addLiteral(dom.nodeValue);
357
- } else if (elementURI(dom) !== RDFParser.ns.RDF + 'RDF') {
358
- // not root
359
- if (frame.parent && frame.parent.collection) {
360
- // we're a collection element
361
- frame.addCollectionArc();
362
- frame = this.buildFrame(frame, frame.element);
363
- frame.parent.element = null;
364
- }
388
+ if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
389
+ rdftype = {
390
+ 'nodeValue': elementURI(dom)
391
+ };
392
+ }
365
393
 
366
- if (!frame.parent || !frame.parent.nodeType || frame.parent.nodeType === frame.ARC) {
367
- // we need a node
368
- var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
369
- rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
394
+ if (rdftype != null) {
395
+ this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
370
396
 
371
- if (about && rdfid) {
372
- 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.');
373
- }
397
+ if (rdftype.nodeName) {
398
+ dom.removeAttributeNode(rdftype);
399
+ }
400
+ } // Property Attributes
374
401
 
375
- if (!about && rdfid) {
376
- frame.addNode('#' + rdfid.nodeValue);
377
- dom.removeAttributeNode(rdfid);
378
- } else if (about == null && rdfid == null) {
379
- var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
380
402
 
381
- if (bnid) {
382
- frame.addBNode(bnid.nodeValue);
383
- dom.removeAttributeNode(bnid);
384
- } else {
385
- frame.addBNode();
403
+ for (var x = attrs.length - 1; x >= 0; x--) {
404
+ this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, frame.lang), this.why);
386
405
  }
387
406
  } else {
388
- frame.addNode(about.nodeValue);
389
- dom.removeAttributeNode(about);
390
- } // Typed nodes
391
-
392
-
393
- var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
394
-
395
- if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
396
- rdftype = {
397
- 'nodeValue': elementURI(dom)
398
- };
399
- }
407
+ // we should add an arc (or implicit bnode+arc)
408
+ frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
400
409
 
401
- if (rdftype != null) {
402
- this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
410
+ if (this.reify) {
411
+ rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
403
412
 
404
- if (rdftype.nodeName) {
405
- dom.removeAttributeNode(rdftype);
413
+ if (rdfid) {
414
+ frame.rdfid = rdfid.nodeValue;
415
+ dom.removeAttributeNode(rdfid);
416
+ }
406
417
  }
407
- } // Property Attributes
408
-
409
-
410
- for (var x = attrs.length - 1; x >= 0; x--) {
411
- this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, frame.lang), this.why);
412
- }
413
- } else {
414
- // we should add an arc (or implicit bnode+arc)
415
- frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
416
418
 
417
- if (this.reify) {
418
- rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
419
+ var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
420
+ var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
419
421
 
420
- if (rdfid) {
421
- frame.rdfid = rdfid.nodeValue;
422
- dom.removeAttributeNode(rdfid);
422
+ if (datatype) {
423
+ frame.datatype = datatype.nodeValue;
424
+ dom.removeAttributeNode(datatype);
423
425
  }
424
- }
425
426
 
426
- var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
427
- var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
427
+ if (parsetype) {
428
+ var nv = parsetype.nodeValue;
428
429
 
429
- if (datatype) {
430
- frame.datatype = datatype.nodeValue;
431
- dom.removeAttributeNode(datatype);
432
- }
430
+ if (nv === 'Literal') {
431
+ frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
432
+ frame = this.buildFrame(frame); // Don't include the literal node, only its children
433
433
 
434
- if (parsetype) {
435
- var nv = parsetype.nodeValue;
436
-
437
- if (nv === 'Literal') {
438
- frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
439
- frame = this.buildFrame(frame); // Don't include the literal node, only its children
440
-
441
- frame.addLiteral(dom.childNodes);
442
- dig = false;
443
- } else if (nv === 'Resource') {
444
- frame = this.buildFrame(frame, frame.element);
445
- frame.parent.element = null;
446
- frame.addBNode();
447
- } else if (nv === 'Collection') {
448
- frame = this.buildFrame(frame, frame.element);
449
- frame.parent.element = null;
450
- frame.addCollection();
451
- }
434
+ frame.addLiteral(dom.childNodes);
435
+ dig = false;
436
+ } else if (nv === 'Resource') {
437
+ frame = this.buildFrame(frame, frame.element);
438
+ frame.parent.element = null;
439
+ frame.addBNode();
440
+ } else if (nv === 'Collection') {
441
+ frame = this.buildFrame(frame, frame.element);
442
+ frame.parent.element = null;
443
+ frame.addCollection();
444
+ }
452
445
 
453
- dom.removeAttributeNode(parsetype);
454
- }
446
+ dom.removeAttributeNode(parsetype);
447
+ }
455
448
 
456
- if (attrs.length !== 0) {
457
- var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'resource');
458
- var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
459
- frame = this.buildFrame(frame);
449
+ if (attrs.length !== 0) {
450
+ var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'resource');
451
+ var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
452
+ frame = this.buildFrame(frame);
460
453
 
461
- if (resource) {
462
- frame.addNode(resource.nodeValue);
463
- dom.removeAttributeNode(resource);
464
- } else {
465
- if (bnid2) {
466
- frame.addBNode(bnid2.nodeValue);
467
- dom.removeAttributeNode(bnid2);
454
+ if (resource) {
455
+ frame.addNode(resource.nodeValue);
456
+ dom.removeAttributeNode(resource);
468
457
  } else {
469
- frame.addBNode();
458
+ if (bnid2) {
459
+ frame.addBNode(bnid2.nodeValue);
460
+ dom.removeAttributeNode(bnid2);
461
+ } else {
462
+ frame.addBNode();
463
+ }
470
464
  }
471
- }
472
465
 
473
- for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
474
- var f = this.buildFrame(frame);
475
- f.addArc(elementURI(attrs[x1]));
466
+ for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
467
+ var f = this.buildFrame(frame);
468
+ f.addArc(elementURI(attrs[x1]));
476
469
 
477
- if (elementURI(attrs[x1]) === RDFParser.ns.RDF + 'type') {
478
- this.buildFrame(f).addNode(attrs[x1].nodeValue);
479
- } else {
480
- this.buildFrame(f).addLiteral(attrs[x1].nodeValue);
470
+ if (elementURI(attrs[x1]) === RDFParser.ns.RDF + 'type') {
471
+ this.buildFrame(f).addNode(attrs[x1].nodeValue);
472
+ } else {
473
+ this.buildFrame(f).addLiteral(attrs[x1].nodeValue);
474
+ }
481
475
  }
476
+ } else if (dom.childNodes.length === 0) {
477
+ this.buildFrame(frame).addLiteral('');
482
478
  }
483
- } else if (dom.childNodes.length === 0) {
484
- this.buildFrame(frame).addLiteral('');
485
479
  }
486
- }
487
- } // rdf:RDF
488
- // dig dug
489
-
480
+ } // rdf:RDF
481
+ // dig dug
490
482
 
491
- dom = frame.element;
492
-
493
- while (frame.parent) {
494
- var pframe = frame;
495
-
496
- while (dom == null) {
497
- frame = frame.parent;
498
- dom = frame.element;
499
- }
500
483
 
501
- var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
484
+ dom = frame.element;
502
485
 
503
- if (!candidate || !dig) {
504
- frame.terminateFrame();
486
+ while (frame.parent) {
487
+ var pframe = frame;
505
488
 
506
- if (!(frame = frame.parent)) {
507
- break;
508
- } // done
509
-
510
-
511
- dom = frame.element;
512
- dig = true;
513
- } 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) {
514
- frame.lastChild++;
515
- } else {
516
- // not a leaf
517
- frame.lastChild++;
518
- frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]);
519
- break;
520
- }
521
- }
522
- } // while
489
+ while (dom == null) {
490
+ frame = frame.parent;
491
+ dom = frame.element;
492
+ }
523
493
 
524
- };
525
- /**
526
- * Cleans out state from a previous parse run
527
- * @private
528
- */
494
+ var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
529
495
 
496
+ if (!candidate || !dig) {
497
+ frame.terminateFrame();
530
498
 
531
- this.cleanParser = function () {
532
- this.bnodes = {};
533
- this.why = null;
534
- };
535
- /**
536
- * Builds scope frame
537
- * @private
538
- */
499
+ if (!(frame = frame.parent)) {
500
+ break;
501
+ } // done
539
502
 
540
503
 
541
- this.buildFrame = function (parent, element) {
542
- var frame = this.frameFactory(this, parent, element);
504
+ dom = frame.element;
505
+ dig = true;
506
+ } 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) {
507
+ frame.lastChild++;
508
+ } else {
509
+ // not a leaf
510
+ frame.lastChild++;
511
+ frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]);
512
+ break;
513
+ }
514
+ }
515
+ } // while
543
516
 
544
- if (parent) {
545
- frame.base = parent.base;
546
- frame.lang = parent.lang;
547
517
  }
548
-
549
- if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
550
- return frame;
518
+ /**
519
+ * Cleans out state from a previous parse run
520
+ * @private
521
+ */
522
+
523
+ }, {
524
+ key: "cleanParser",
525
+ value: function cleanParser() {
526
+ this.bnodes = {};
527
+ this.why = null;
551
528
  }
529
+ /**
530
+ * Builds scope frame
531
+ * @private
532
+ */
533
+
534
+ }, {
535
+ key: "buildFrame",
536
+ value: function buildFrame(parent, element) {
537
+ var frame = this.frameFactory(this, parent, element);
538
+
539
+ if (parent) {
540
+ frame.base = parent.base;
541
+ frame.lang = parent.lang;
542
+ }
543
+
544
+ if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
545
+ return frame;
546
+ }
552
547
 
553
- var attrs = element.attributes;
554
- var base = element.getAttributeNode('xml:base');
548
+ var attrs = element.attributes;
549
+ var base = element.getAttributeNode('xml:base');
555
550
 
556
- if (base != null) {
557
- frame.base = base.nodeValue;
558
- element.removeAttribute('xml:base');
559
- }
551
+ if (base != null) {
552
+ frame.base = base.nodeValue;
553
+ element.removeAttribute('xml:base');
554
+ }
560
555
 
561
- var lang = element.getAttributeNode('xml:lang');
556
+ var lang = element.getAttributeNode('xml:lang');
562
557
 
563
- if (lang != null) {
564
- frame.lang = lang.nodeValue;
565
- element.removeAttribute('xml:lang');
566
- } // remove all extraneous xml and xmlns attributes
558
+ if (lang != null) {
559
+ frame.lang = lang.nodeValue;
560
+ element.removeAttribute('xml:lang');
561
+ } // remove all extraneous xml and xmlns attributes
567
562
 
568
563
 
569
- for (var x = attrs.length - 1; x >= 0; x--) {
570
- if (attrs[x].nodeName.substr(0, 3) === 'xml') {
571
- if (attrs[x].name.slice(0, 6) === 'xmlns:') {
572
- var uri = attrs[x].nodeValue; // alert('base for namespac attr:'+this.base)
564
+ for (var x = attrs.length - 1; x >= 0; x--) {
565
+ if (attrs[x].nodeName.substr(0, 3) === 'xml') {
566
+ if (attrs[x].name.slice(0, 6) === 'xmlns:') {
567
+ var uri = attrs[x].nodeValue; // alert('base for namespac attr:'+this.base)
573
568
 
574
- if (this.base) uri = uriUtil.join(uri, this.base);
575
- this.store.setPrefixForURI(attrs[x].name.slice(6), uri);
576
- } // alert('rdfparser: xml atribute: '+attrs[x].name) //@@
569
+ if (this.base) uri = uriUtil.join(uri, this.base);
570
+ this.store.setPrefixForURI(attrs[x].name.slice(6), uri);
571
+ } // alert('rdfparser: xml atribute: '+attrs[x].name) //@@
577
572
 
578
573
 
579
- element.removeAttributeNode(attrs[x]);
574
+ element.removeAttributeNode(attrs[x]);
575
+ }
580
576
  }
577
+
578
+ return frame;
581
579
  }
580
+ }]);
581
+ return RDFParser;
582
+ }();
582
583
 
583
- return frame;
584
- };
585
- }
584
+ exports.default = RDFParser;
585
+ (0, _defineProperty2.default)(RDFParser, "ns", {
586
+ 'RDF': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
587
+ 'RDFS': 'http://www.w3.org/2000/01/rdf-schema#'
588
+ });
589
+ (0, _defineProperty2.default)(RDFParser, "nodeType", {
590
+ 'ELEMENT': 1,
591
+ 'ATTRIBUTE': 2,
592
+ 'TEXT': 3,
593
+ 'CDATA_SECTION': 4,
594
+ 'ENTITY_REFERENCE': 5,
595
+ 'ENTITY': 6,
596
+ 'PROCESSING_INSTRUCTION': 7,
597
+ 'COMMENT': 8,
598
+ 'DOCUMENT': 9,
599
+ 'DOCUMENT_TYPE': 10,
600
+ 'DOCUMENT_FRAGMENT': 11,
601
+ 'NOTATION': 12
602
+ });