rdflib 2.2.21 → 2.2.22-0de51c50
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.
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +13 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +3 -27
- package/esm/collection.js +7 -29
- package/esm/default-graph.js +1 -15
- package/esm/empty.js +0 -13
- package/esm/factories/canonical-data-factory.js +5 -40
- package/esm/factories/extended-term-factory.js +0 -11
- package/esm/factories/factory-types.js +2 -1
- package/esm/factories/rdflib-data-factory.js +0 -8
- package/esm/fetcher.js +257 -481
- package/esm/formula.js +43 -142
- package/esm/index.js +19 -36
- package/esm/jsonldparser.js +20 -29
- package/esm/jsonparser.js +0 -7
- package/esm/lists.js +18 -33
- package/esm/literal.js +10 -42
- package/esm/n3parser.js +38 -351
- package/esm/named-node.js +8 -27
- package/esm/namespace.js +0 -1
- package/esm/node-internal.js +11 -24
- package/esm/node.js +1 -6
- package/esm/parse.js +10 -17
- package/esm/patch-parser.js +9 -29
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +50 -133
- package/esm/rdfaparser.js +72 -210
- package/esm/rdfxmlparser.js +31 -128
- package/esm/serialize.js +8 -33
- package/esm/serializer.js +122 -286
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +8 -19
- package/esm/store.js +109 -280
- package/esm/types.js +3 -2
- package/esm/update-manager.js +110 -246
- package/esm/updates-via.js +0 -27
- package/esm/uri.js +6 -50
- package/esm/utils/default-graph-uri.js +1 -0
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +15 -16
- package/esm/utils-js.js +16 -57
- package/esm/utils.js +4 -15
- package/esm/variable.js +0 -20
- package/lib/blank-node.js +3 -28
- package/lib/class-order.js +0 -1
- package/lib/collection.js +7 -34
- package/lib/default-graph.js +0 -20
- package/lib/empty.js +0 -18
- package/lib/factories/canonical-data-factory.js +4 -51
- package/lib/factories/extended-term-factory.js +0 -18
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +0 -3
- package/lib/factories/rdflib-data-factory.js +0 -12
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +258 -470
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +43 -151
- package/lib/index.d.ts +1 -2
- package/lib/index.js +14 -82
- package/lib/jsonldparser.js +19 -33
- package/lib/jsonparser.js +0 -9
- package/lib/lists.js +14 -39
- package/lib/literal.js +10 -49
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -1
- package/lib/n3parser.d.ts +1 -0
- package/lib/n3parser.js +39 -359
- package/lib/named-node.js +7 -35
- package/lib/namespace.js +0 -3
- package/lib/node-internal.js +11 -21
- package/lib/node.js +1 -11
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +8 -27
- package/lib/patch-parser.js +10 -33
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +46 -152
- package/lib/rdfaparser.js +72 -220
- package/lib/rdfxmlparser.js +31 -132
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +8 -43
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +121 -297
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +8 -24
- package/lib/store.d.ts +2 -2
- package/lib/store.js +102 -282
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +3 -3
- package/lib/update-manager.d.ts +2 -2
- package/lib/update-manager.js +110 -254
- package/lib/updates-via.js +0 -30
- package/lib/uri.js +5 -58
- package/lib/utils/default-graph-uri.js +1 -3
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +15 -34
- package/lib/utils-js.js +16 -80
- package/lib/utils.js +4 -21
- package/lib/variable.js +0 -25
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +0 -4
- package/package.json +40 -39
- package/src/fetcher.ts +2 -2
- package/src/index.ts +0 -2
- package/src/jsonldparser.js +13 -4
- package/src/n3parser.js +12 -4
- package/src/serialize.ts +4 -11
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +18 -7
- package/changes.txt +0 -59
- package/esm/convert.js +0 -61
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -77
- package/src/convert.js +0 -70
package/lib/rdfxmlparser.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = void 0;
|
|
11
|
-
|
|
12
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
-
|
|
18
12
|
var uriUtil = _interopRequireWildcard(require("./uri"));
|
|
19
|
-
|
|
20
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* RDF/XML PARSER
|
|
26
17
|
*
|
|
@@ -72,7 +63,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
72
63
|
* associated documentation will at all times remain with copyright
|
|
73
64
|
* holders.
|
|
74
65
|
*/
|
|
75
|
-
|
|
76
66
|
/**
|
|
77
67
|
* @class RDFParser resource object tied to an RDFStore
|
|
78
68
|
*
|
|
@@ -86,24 +76,17 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
86
76
|
*/
|
|
87
77
|
function RDFParser(store) {
|
|
88
78
|
(0, _classCallCheck2.default)(this, RDFParser);
|
|
89
|
-
|
|
90
79
|
/** 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 */
|
|
96
|
-
|
|
97
|
-
this.why = null;
|
|
98
|
-
/** Reification flag */
|
|
99
80
|
|
|
81
|
+
this.store = store; /** Our identified blank nodes @private */
|
|
82
|
+
this.bnodes = {}; /** A context for context-aware stores @private */
|
|
83
|
+
this.why = null; /** Reification flag */
|
|
100
84
|
this.reify = false;
|
|
101
85
|
}
|
|
86
|
+
|
|
102
87
|
/** Standard namespaces that we know how to handle @final
|
|
103
88
|
* @member RDFParser
|
|
104
89
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
90
|
(0, _createClass2.default)(RDFParser, [{
|
|
108
91
|
key: "frameFactory",
|
|
109
92
|
value:
|
|
@@ -114,6 +97,7 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
114
97
|
*
|
|
115
98
|
* @private
|
|
116
99
|
*/
|
|
100
|
+
|
|
117
101
|
function frameFactory(parser, parent, element) {
|
|
118
102
|
return {
|
|
119
103
|
'NODE': 1,
|
|
@@ -131,29 +115,23 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
131
115
|
'rdfid': null,
|
|
132
116
|
'datatype': null,
|
|
133
117
|
'collection': false,
|
|
134
|
-
|
|
135
118
|
/** Terminate the frame and notify the store that we're done */
|
|
136
119
|
'terminateFrame': function terminateFrame() {
|
|
137
120
|
if (this.collection) {
|
|
138
121
|
this.node.close();
|
|
139
122
|
}
|
|
140
123
|
},
|
|
141
|
-
|
|
142
|
-
/** Add a symbol of a certain type to the this frame */
|
|
143
|
-
'addSymbol': function addSymbol(type, uri) {
|
|
124
|
+
/** Add a symbol of a certain type to the this frame */'addSymbol': function addSymbol(type, uri) {
|
|
144
125
|
uri = uriUtil.join(uri, this.base);
|
|
145
126
|
this.node = this.store.sym(uri);
|
|
146
127
|
this.nodeType = type;
|
|
147
128
|
},
|
|
148
|
-
|
|
149
|
-
/** Load any constructed triples into the store */
|
|
150
|
-
'loadTriple': function loadTriple() {
|
|
129
|
+
/** Load any constructed triples into the store */'loadTriple': function loadTriple() {
|
|
151
130
|
if (this.parent.parent.collection) {
|
|
152
131
|
this.parent.parent.node.append(this.node);
|
|
153
132
|
} else {
|
|
154
133
|
this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
|
|
155
134
|
}
|
|
156
|
-
|
|
157
135
|
if (this.parent.rdfid != null) {
|
|
158
136
|
// reify
|
|
159
137
|
var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
|
|
@@ -163,39 +141,27 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
163
141
|
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
|
|
164
142
|
}
|
|
165
143
|
},
|
|
166
|
-
|
|
167
|
-
/** Check if it's OK to load a triple */
|
|
168
|
-
'isTripleToLoad': function isTripleToLoad() {
|
|
144
|
+
/** Check if it's OK to load a triple */'isTripleToLoad': function isTripleToLoad() {
|
|
169
145
|
return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
|
|
170
146
|
},
|
|
171
|
-
|
|
172
|
-
/** Add a symbolic node to this frame */
|
|
173
|
-
'addNode': function addNode(uri) {
|
|
147
|
+
/** Add a symbolic node to this frame */'addNode': function addNode(uri) {
|
|
174
148
|
this.addSymbol(this.NODE, uri);
|
|
175
|
-
|
|
176
149
|
if (this.isTripleToLoad()) {
|
|
177
150
|
this.loadTriple();
|
|
178
151
|
}
|
|
179
152
|
},
|
|
180
|
-
|
|
181
|
-
/** Add a collection node to this frame */
|
|
182
|
-
'addCollection': function addCollection() {
|
|
153
|
+
/** Add a collection node to this frame */'addCollection': function addCollection() {
|
|
183
154
|
this.nodeType = this.NODE;
|
|
184
155
|
this.node = this.store.collection();
|
|
185
156
|
this.collection = true;
|
|
186
|
-
|
|
187
157
|
if (this.isTripleToLoad()) {
|
|
188
158
|
this.loadTriple();
|
|
189
159
|
}
|
|
190
160
|
},
|
|
191
|
-
|
|
192
|
-
/** Add a collection arc to this frame */
|
|
193
|
-
'addCollectionArc': function addCollectionArc() {
|
|
161
|
+
/** Add a collection arc to this frame */'addCollectionArc': function addCollectionArc() {
|
|
194
162
|
this.nodeType = this.ARC;
|
|
195
163
|
},
|
|
196
|
-
|
|
197
|
-
/** Add a bnode to this frame */
|
|
198
|
-
'addBNode': function addBNode(id) {
|
|
164
|
+
/** Add a bnode to this frame */'addBNode': function addBNode(id) {
|
|
199
165
|
if (id != null) {
|
|
200
166
|
if (this.parser.bnodes[id] != null) {
|
|
201
167
|
this.node = this.parser.bnodes[id];
|
|
@@ -205,58 +171,46 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
205
171
|
} else {
|
|
206
172
|
this.node = this.store.bnode();
|
|
207
173
|
}
|
|
208
|
-
|
|
209
174
|
this.nodeType = this.NODE;
|
|
210
|
-
|
|
211
175
|
if (this.isTripleToLoad()) {
|
|
212
176
|
this.loadTriple();
|
|
213
177
|
}
|
|
214
178
|
},
|
|
215
|
-
|
|
216
|
-
/** Add an arc or property to this frame */
|
|
217
|
-
'addArc': function addArc(uri) {
|
|
179
|
+
/** Add an arc or property to this frame */'addArc': function addArc(uri) {
|
|
218
180
|
if (uri === RDFParser.ns.RDF + 'li') {
|
|
219
181
|
uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
|
|
220
182
|
this.parent.listIndex++;
|
|
221
183
|
}
|
|
222
|
-
|
|
223
184
|
this.addSymbol(this.ARC, uri);
|
|
224
185
|
},
|
|
225
|
-
|
|
226
|
-
/** Add a literal to this frame */
|
|
227
|
-
'addLiteral': function addLiteral(value) {
|
|
186
|
+
/** Add a literal to this frame */'addLiteral': function addLiteral(value) {
|
|
228
187
|
if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
|
|
229
188
|
this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
|
|
230
189
|
} else {
|
|
231
190
|
this.node = this.store.literal(value, this.lang);
|
|
232
191
|
}
|
|
233
|
-
|
|
234
192
|
this.nodeType = this.NODE;
|
|
235
|
-
|
|
236
193
|
if (this.isTripleToLoad()) {
|
|
237
194
|
this.loadTriple();
|
|
238
195
|
}
|
|
239
196
|
}
|
|
240
197
|
};
|
|
241
|
-
}
|
|
198
|
+
}
|
|
242
199
|
|
|
200
|
+
// from the OpenLayers source .. needed to get around IE problems.
|
|
243
201
|
}, {
|
|
244
202
|
key: "getAttributeNodeNS",
|
|
245
203
|
value: function getAttributeNodeNS(node, uri, name) {
|
|
246
204
|
var attributeNode = null;
|
|
247
|
-
|
|
248
205
|
if (node.getAttributeNodeNS) {
|
|
249
206
|
attributeNode = node.getAttributeNodeNS(uri, name);
|
|
250
207
|
} else {
|
|
251
208
|
var attributes = node.attributes;
|
|
252
209
|
var potentialNode, fullName;
|
|
253
|
-
|
|
254
210
|
for (var i = 0; i < attributes.length; ++i) {
|
|
255
211
|
potentialNode = attributes[i];
|
|
256
|
-
|
|
257
212
|
if (potentialNode.namespaceURI === uri) {
|
|
258
213
|
fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
|
|
259
|
-
|
|
260
214
|
if (fullName === potentialNode.nodeName) {
|
|
261
215
|
attributeNode = potentialNode;
|
|
262
216
|
break;
|
|
@@ -264,25 +218,21 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
264
218
|
}
|
|
265
219
|
}
|
|
266
220
|
}
|
|
267
|
-
|
|
268
221
|
return attributeNode;
|
|
269
222
|
}
|
|
223
|
+
|
|
270
224
|
/**
|
|
271
225
|
* Build our initial scope frame and parse the DOM into triples
|
|
272
226
|
* @param {HTMLDocument} document The DOM to parse
|
|
273
227
|
* @param {String} base The base URL to use
|
|
274
228
|
* @param {Object} why The context to which this resource belongs
|
|
275
229
|
*/
|
|
276
|
-
|
|
277
230
|
}, {
|
|
278
231
|
key: "parse",
|
|
279
232
|
value: function parse(document, base, why) {
|
|
280
233
|
var children = document.childNodes; // clean up for the next run
|
|
281
|
-
|
|
282
234
|
this.cleanParser(); // figure out the root element
|
|
283
|
-
|
|
284
235
|
var root;
|
|
285
|
-
|
|
286
236
|
if (document.nodeType === RDFParser.nodeType.DOCUMENT) {
|
|
287
237
|
for (var c = 0; c < children.length; c++) {
|
|
288
238
|
if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
|
|
@@ -293,16 +243,15 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
293
243
|
} else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
|
|
294
244
|
root = document;
|
|
295
245
|
} else {
|
|
296
|
-
throw new Error("RDFParser: can't find root in " + base + '. Halting. ');
|
|
246
|
+
throw new Error("RDFParser: can't find root in " + base + '. Halting. ');
|
|
247
|
+
// return false
|
|
297
248
|
}
|
|
298
249
|
|
|
299
250
|
this.why = why; // our topmost frame
|
|
300
|
-
|
|
301
251
|
var f = this.frameFactory(this);
|
|
302
252
|
this.base = base;
|
|
303
253
|
f.base = base;
|
|
304
254
|
f.lang = null; // was '' but can't have langs like that 2015 (!)
|
|
305
|
-
|
|
306
255
|
this.parseDOM(this.buildFrame(f, root));
|
|
307
256
|
return true;
|
|
308
257
|
}
|
|
@@ -311,33 +260,25 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
311
260
|
value: function parseDOM(frame) {
|
|
312
261
|
// a DOM utility function used in parsing
|
|
313
262
|
var rdfid;
|
|
314
|
-
|
|
315
263
|
var elementURI = function (el) {
|
|
316
264
|
var result = '';
|
|
317
|
-
|
|
318
265
|
if (el.namespaceURI == null) {
|
|
319
266
|
throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
|
|
320
267
|
}
|
|
321
|
-
|
|
322
268
|
if (el.namespaceURI) {
|
|
323
269
|
result = result + el.namespaceURI;
|
|
324
270
|
}
|
|
325
|
-
|
|
326
271
|
if (el.localName) {
|
|
327
272
|
result = result + el.localName;
|
|
328
273
|
} else if (el.nodeName) {
|
|
329
274
|
if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
|
|
330
275
|
}
|
|
331
|
-
|
|
332
276
|
return result;
|
|
333
277
|
}.bind(this);
|
|
334
|
-
|
|
335
278
|
var dig = true; // if we'll dig down in the tree on the next iter
|
|
336
|
-
|
|
337
279
|
while (frame.parent) {
|
|
338
280
|
var dom = frame.element;
|
|
339
281
|
var attrs = dom.attributes;
|
|
340
|
-
|
|
341
282
|
if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
|
|
342
283
|
// we have a literal
|
|
343
284
|
if (frame.parent.nodeType === frame.NODE) {
|
|
@@ -345,7 +286,6 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
345
286
|
frame.addArc(RDFParser.ns.RDF + 'value');
|
|
346
287
|
frame = this.buildFrame(frame);
|
|
347
288
|
}
|
|
348
|
-
|
|
349
289
|
frame.addLiteral(dom.nodeValue);
|
|
350
290
|
} else if (elementURI(dom) !== RDFParser.ns.RDF + 'RDF') {
|
|
351
291
|
// not root
|
|
@@ -355,22 +295,18 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
355
295
|
frame = this.buildFrame(frame, frame.element);
|
|
356
296
|
frame.parent.element = null;
|
|
357
297
|
}
|
|
358
|
-
|
|
359
298
|
if (!frame.parent || !frame.parent.nodeType || frame.parent.nodeType === frame.ARC) {
|
|
360
299
|
// we need a node
|
|
361
300
|
var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
|
|
362
301
|
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
363
|
-
|
|
364
302
|
if (about && rdfid) {
|
|
365
303
|
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
304
|
}
|
|
367
|
-
|
|
368
305
|
if (!about && rdfid) {
|
|
369
306
|
frame.addNode('#' + rdfid.nodeValue);
|
|
370
307
|
dom.removeAttributeNode(rdfid);
|
|
371
308
|
} else if (about == null && rdfid == null) {
|
|
372
309
|
var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
|
|
373
|
-
|
|
374
310
|
if (bnid) {
|
|
375
311
|
frame.addBNode(bnid.nodeValue);
|
|
376
312
|
dom.removeAttributeNode(bnid);
|
|
@@ -380,57 +316,46 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
380
316
|
} else {
|
|
381
317
|
frame.addNode(about.nodeValue);
|
|
382
318
|
dom.removeAttributeNode(about);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
319
|
+
}
|
|
320
|
+
// Typed nodes
|
|
386
321
|
var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
|
|
387
|
-
|
|
388
322
|
if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
|
|
389
323
|
rdftype = {
|
|
390
324
|
'nodeValue': elementURI(dom)
|
|
391
325
|
};
|
|
392
326
|
}
|
|
393
|
-
|
|
394
327
|
if (rdftype != null) {
|
|
395
328
|
this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
|
|
396
|
-
|
|
397
329
|
if (rdftype.nodeName) {
|
|
398
330
|
dom.removeAttributeNode(rdftype);
|
|
399
331
|
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
332
|
+
}
|
|
333
|
+
// Property Attributes
|
|
403
334
|
for (var x = attrs.length - 1; x >= 0; x--) {
|
|
404
335
|
this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, frame.lang), this.why);
|
|
405
336
|
}
|
|
406
337
|
} else {
|
|
407
338
|
// we should add an arc (or implicit bnode+arc)
|
|
408
339
|
frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
|
|
409
|
-
|
|
410
340
|
if (this.reify) {
|
|
411
341
|
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
412
|
-
|
|
413
342
|
if (rdfid) {
|
|
414
343
|
frame.rdfid = rdfid.nodeValue;
|
|
415
344
|
dom.removeAttributeNode(rdfid);
|
|
416
345
|
}
|
|
417
346
|
}
|
|
418
|
-
|
|
419
347
|
var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
|
|
420
348
|
var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
|
|
421
|
-
|
|
422
349
|
if (datatype) {
|
|
423
350
|
frame.datatype = datatype.nodeValue;
|
|
424
351
|
dom.removeAttributeNode(datatype);
|
|
425
352
|
}
|
|
426
|
-
|
|
427
353
|
if (parsetype) {
|
|
428
354
|
var nv = parsetype.nodeValue;
|
|
429
|
-
|
|
430
355
|
if (nv === 'Literal') {
|
|
431
356
|
frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
|
|
432
|
-
frame = this.buildFrame(frame);
|
|
433
|
-
|
|
357
|
+
frame = this.buildFrame(frame);
|
|
358
|
+
// Don't include the literal node, only its children
|
|
434
359
|
frame.addLiteral(dom.childNodes);
|
|
435
360
|
dig = false;
|
|
436
361
|
} else if (nv === 'Resource') {
|
|
@@ -442,15 +367,12 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
442
367
|
frame.parent.element = null;
|
|
443
368
|
frame.addCollection();
|
|
444
369
|
}
|
|
445
|
-
|
|
446
370
|
dom.removeAttributeNode(parsetype);
|
|
447
371
|
}
|
|
448
|
-
|
|
449
372
|
if (attrs.length !== 0) {
|
|
450
373
|
var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'resource');
|
|
451
374
|
var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
|
|
452
375
|
frame = this.buildFrame(frame);
|
|
453
|
-
|
|
454
376
|
if (resource) {
|
|
455
377
|
frame.addNode(resource.nodeValue);
|
|
456
378
|
dom.removeAttributeNode(resource);
|
|
@@ -462,11 +384,9 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
462
384
|
frame.addBNode();
|
|
463
385
|
}
|
|
464
386
|
}
|
|
465
|
-
|
|
466
387
|
for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
|
|
467
388
|
var f = this.buildFrame(frame);
|
|
468
389
|
f.addArc(elementURI(attrs[x1]));
|
|
469
|
-
|
|
470
390
|
if (elementURI(attrs[x1]) === RDFParser.ns.RDF + 'type') {
|
|
471
391
|
this.buildFrame(f).addNode(attrs[x1].nodeValue);
|
|
472
392
|
} else {
|
|
@@ -479,28 +399,19 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
479
399
|
}
|
|
480
400
|
} // rdf:RDF
|
|
481
401
|
// dig dug
|
|
482
|
-
|
|
483
|
-
|
|
484
402
|
dom = frame.element;
|
|
485
|
-
|
|
486
403
|
while (frame.parent) {
|
|
487
404
|
var pframe = frame;
|
|
488
|
-
|
|
489
405
|
while (dom == null) {
|
|
490
406
|
frame = frame.parent;
|
|
491
407
|
dom = frame.element;
|
|
492
408
|
}
|
|
493
|
-
|
|
494
409
|
var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
|
|
495
|
-
|
|
496
410
|
if (!candidate || !dig) {
|
|
497
411
|
frame.terminateFrame();
|
|
498
|
-
|
|
499
412
|
if (!(frame = frame.parent)) {
|
|
500
413
|
break;
|
|
501
414
|
} // done
|
|
502
|
-
|
|
503
|
-
|
|
504
415
|
dom = frame.element;
|
|
505
416
|
dig = true;
|
|
506
417
|
} 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) {
|
|
@@ -513,74 +424,62 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
513
424
|
}
|
|
514
425
|
}
|
|
515
426
|
} // while
|
|
516
|
-
|
|
517
427
|
}
|
|
428
|
+
|
|
518
429
|
/**
|
|
519
430
|
* Cleans out state from a previous parse run
|
|
520
431
|
* @private
|
|
521
432
|
*/
|
|
522
|
-
|
|
523
433
|
}, {
|
|
524
434
|
key: "cleanParser",
|
|
525
435
|
value: function cleanParser() {
|
|
526
436
|
this.bnodes = {};
|
|
527
437
|
this.why = null;
|
|
528
438
|
}
|
|
439
|
+
|
|
529
440
|
/**
|
|
530
441
|
* Builds scope frame
|
|
531
442
|
* @private
|
|
532
443
|
*/
|
|
533
|
-
|
|
534
444
|
}, {
|
|
535
445
|
key: "buildFrame",
|
|
536
446
|
value: function buildFrame(parent, element) {
|
|
537
447
|
var frame = this.frameFactory(this, parent, element);
|
|
538
|
-
|
|
539
448
|
if (parent) {
|
|
540
449
|
frame.base = parent.base;
|
|
541
450
|
frame.lang = parent.lang;
|
|
542
451
|
}
|
|
543
|
-
|
|
544
452
|
if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
|
|
545
453
|
return frame;
|
|
546
454
|
}
|
|
547
|
-
|
|
548
455
|
var attrs = element.attributes;
|
|
549
456
|
var base = element.getAttributeNode('xml:base');
|
|
550
|
-
|
|
551
457
|
if (base != null) {
|
|
552
458
|
frame.base = base.nodeValue;
|
|
553
459
|
element.removeAttribute('xml:base');
|
|
554
460
|
}
|
|
555
|
-
|
|
556
461
|
var lang = element.getAttributeNode('xml:lang');
|
|
557
|
-
|
|
558
462
|
if (lang != null) {
|
|
559
463
|
frame.lang = lang.nodeValue;
|
|
560
464
|
element.removeAttribute('xml:lang');
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
|
|
465
|
+
}
|
|
466
|
+
// remove all extraneous xml and xmlns attributes
|
|
564
467
|
for (var x = attrs.length - 1; x >= 0; x--) {
|
|
565
468
|
if (attrs[x].nodeName.substr(0, 3) === 'xml') {
|
|
566
469
|
if (attrs[x].name.slice(0, 6) === 'xmlns:') {
|
|
567
470
|
var uri = attrs[x].nodeValue; // alert('base for namespac attr:'+this.base)
|
|
568
|
-
|
|
569
471
|
if (this.base) uri = uriUtil.join(uri, this.base);
|
|
570
472
|
this.store.setPrefixForURI(attrs[x].name.slice(6), uri);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
|
|
473
|
+
}
|
|
474
|
+
// alert('rdfparser: xml atribute: '+attrs[x].name) //@@
|
|
574
475
|
element.removeAttributeNode(attrs[x]);
|
|
575
476
|
}
|
|
576
477
|
}
|
|
577
|
-
|
|
578
478
|
return frame;
|
|
579
479
|
}
|
|
580
480
|
}]);
|
|
581
481
|
return RDFParser;
|
|
582
482
|
}();
|
|
583
|
-
|
|
584
483
|
exports.default = RDFParser;
|
|
585
484
|
(0, _defineProperty2.default)(RDFParser, "ns", {
|
|
586
485
|
'RDF': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
package/lib/serialize.d.ts
CHANGED
package/lib/serialize.js
CHANGED
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
4
|
Object.defineProperty(exports, "__esModule", {
|
|
8
5
|
value: true
|
|
9
6
|
});
|
|
10
7
|
exports.default = serialize;
|
|
11
|
-
|
|
12
|
-
var convert = _interopRequireWildcard(require("./convert"));
|
|
13
|
-
|
|
14
8
|
var _serializer = _interopRequireDefault(require("./serializer"));
|
|
15
|
-
|
|
16
9
|
var _types = require("./types");
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
10
|
/**
|
|
23
11
|
* Serialize to the appropriate format
|
|
24
12
|
*/
|
|
25
|
-
function serialize(
|
|
26
|
-
/** The
|
|
27
|
-
target,
|
|
28
|
-
/** The store */
|
|
13
|
+
function serialize( /** The graph or nodes that should be serialized */
|
|
14
|
+
target, /** The store */
|
|
29
15
|
kb, base,
|
|
30
16
|
/**
|
|
31
17
|
* The mime type.
|
|
@@ -35,69 +21,49 @@ contentType, callback, options) {
|
|
|
35
21
|
base = base || (target === null || target === void 0 ? void 0 : target.value);
|
|
36
22
|
var opts = options || {};
|
|
37
23
|
contentType = contentType || _types.TurtleContentType; // text/n3 if complex?
|
|
38
|
-
|
|
39
24
|
var documentString = undefined;
|
|
40
|
-
|
|
41
25
|
try {
|
|
42
26
|
var sz = (0, _serializer.default)(kb);
|
|
43
27
|
if (opts.flags) sz.setFlags(opts.flags);
|
|
44
28
|
var newSts = kb.statementsMatching(undefined, undefined, undefined, target);
|
|
45
|
-
var n3String; // If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
46
29
|
|
|
30
|
+
// If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
47
31
|
if ('namespaces' in kb) {
|
|
48
32
|
sz.suggestNamespaces(kb.namespaces);
|
|
49
|
-
}
|
|
50
|
-
|
|
33
|
+
}
|
|
51
34
|
|
|
35
|
+
// use the provided options.namespaces are mandatory prefixes
|
|
52
36
|
if (opts.namespaces) {
|
|
53
37
|
sz.setNamespaces(opts.namespaces);
|
|
54
38
|
}
|
|
55
|
-
|
|
56
39
|
sz.setBase(base);
|
|
57
|
-
|
|
58
40
|
switch (contentType) {
|
|
59
41
|
case _types.RDFXMLContentType:
|
|
60
42
|
documentString = sz.statementsToXML(newSts);
|
|
61
43
|
return executeCallback(null, documentString);
|
|
62
|
-
|
|
63
44
|
case _types.N3ContentType:
|
|
64
45
|
case _types.N3LegacyContentType:
|
|
65
46
|
documentString = sz.statementsToN3(newSts);
|
|
66
47
|
return executeCallback(null, documentString);
|
|
67
|
-
|
|
68
48
|
case _types.TurtleContentType:
|
|
69
49
|
case _types.TurtleLegacyContentType:
|
|
70
50
|
sz.setFlags('si'); // Suppress = for sameAs and => for implies
|
|
71
|
-
|
|
72
51
|
documentString = sz.statementsToN3(newSts);
|
|
73
52
|
return executeCallback(null, documentString);
|
|
74
|
-
|
|
75
53
|
case _types.NTriplesContentType:
|
|
76
54
|
sz.setFlags('deinprstux'); // Suppress nice parts of N3 to make ntriples
|
|
77
|
-
|
|
78
55
|
documentString = sz.statementsToNTriples(newSts);
|
|
79
56
|
return executeCallback(null, documentString);
|
|
80
|
-
|
|
81
57
|
case _types.JSONLDContentType:
|
|
82
|
-
sz.setFlags('
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
convert.convertToJson(n3String, callback);
|
|
87
|
-
break;
|
|
88
|
-
|
|
58
|
+
sz.setFlags('si'); // use turtle parameters
|
|
59
|
+
documentString = sz.statementsToJsonld(newSts); // convert via turtle
|
|
60
|
+
return executeCallback(null, documentString);
|
|
89
61
|
case _types.NQuadsContentType:
|
|
90
62
|
case _types.NQuadsAltContentType:
|
|
91
63
|
// @@@ just outpout the quads? Does not work for collections
|
|
92
64
|
sz.setFlags('deinprstux q'); // Suppress nice parts of N3 to make ntriples
|
|
93
|
-
|
|
94
65
|
documentString = sz.statementsToNTriples(newSts); // q in flag means actually quads
|
|
95
|
-
|
|
96
66
|
return executeCallback(null, documentString);
|
|
97
|
-
// n3String = sz.statementsToN3(newSts)
|
|
98
|
-
// documentString = convert.convertToNQuads(n3String, callback)
|
|
99
|
-
// break
|
|
100
|
-
|
|
101
67
|
default:
|
|
102
68
|
throw new Error('Serialize: Content-type ' + contentType + ' not supported for data write.');
|
|
103
69
|
}
|
|
@@ -106,7 +72,6 @@ contentType, callback, options) {
|
|
|
106
72
|
// @ts-ignore
|
|
107
73
|
return callback(err, undefined);
|
|
108
74
|
}
|
|
109
|
-
|
|
110
75
|
throw err; // Don't hide problems from caller in sync mode
|
|
111
76
|
}
|
|
112
77
|
|