rdflib 2.2.9 → 2.2.10-4fa7e876
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 +6 -6
- package/dist/rdflib.min.js.map +1 -1
- package/esm/n3parser.js +1330 -1286
- package/esm/rdfxmlparser.js +429 -412
- package/esm/serialize.js +1 -1
- package/esm/serializer.js +849 -821
- package/esm/xsd.js +9 -14
- package/lib/convert.d.ts +2 -0
- package/lib/jsonldparser.d.ts +13 -0
- package/lib/jsonparser.d.ts +4 -0
- package/lib/log.d.ts +15 -0
- package/lib/n3parser.d.ts +62 -0
- package/lib/n3parser.js +1334 -1289
- package/lib/patch-parser.d.ts +3 -0
- package/lib/query-to-sparql.d.ts +1 -0
- package/lib/query.d.ts +27 -0
- package/lib/rdfaparser.d.ts +78 -0
- package/lib/rdfxmlparser.d.ts +60 -0
- package/lib/rdfxmlparser.js +430 -413
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +1 -1
- package/lib/serializer.d.ts +54 -0
- package/lib/serializer.js +851 -824
- package/lib/sparql-to-query.d.ts +6 -0
- package/lib/updates-via.d.ts +26 -0
- package/lib/utils-js.d.ts +50 -0
- package/lib/xsd-internal.d.ts +11 -0
- package/lib/xsd.d.ts +19 -0
- package/lib/xsd.js +8 -14
- package/package.json +18 -18
- package/src/n3parser.js +1114 -1110
- package/src/rdfxmlparser.js +22 -21
- package/src/serialize.ts +3 -3
- package/src/serializer.js +74 -62
- package/src/xsd.js +16 -14
package/esm/rdfxmlparser.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
/**
|
|
2
6
|
* RDF/XML PARSER
|
|
3
7
|
*
|
|
@@ -57,515 +61,528 @@
|
|
|
57
61
|
*
|
|
58
62
|
*/
|
|
59
63
|
import * as uriUtil from './uri';
|
|
60
|
-
/*
|
|
61
|
-
* @constructor
|
|
62
|
-
* @param {RDFStore} store An RDFStore object
|
|
63
|
-
*/
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
65
|
+
var RDFParser = /*#__PURE__*/function () {
|
|
66
|
+
/*
|
|
67
|
+
* @constructor
|
|
68
|
+
* @param {RDFStore} store An RDFStore object
|
|
69
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 */
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
/** DOM Level 2 node type magic numbers @final
|
|
83
|
+
this.reify = false;
|
|
84
|
+
}
|
|
85
|
+
/** Standard namespaces that we know how to handle @final
|
|
76
86
|
* @member RDFParser
|
|
77
87
|
*/
|
|
78
88
|
|
|
79
|
-
RDFParser.nodeType = {
|
|
80
|
-
'ELEMENT': 1,
|
|
81
|
-
'ATTRIBUTE': 2,
|
|
82
|
-
'TEXT': 3,
|
|
83
|
-
'CDATA_SECTION': 4,
|
|
84
|
-
'ENTITY_REFERENCE': 5,
|
|
85
|
-
'ENTITY': 6,
|
|
86
|
-
'PROCESSING_INSTRUCTION': 7,
|
|
87
|
-
'COMMENT': 8,
|
|
88
|
-
'DOCUMENT': 9,
|
|
89
|
-
'DOCUMENT_TYPE': 10,
|
|
90
|
-
'DOCUMENT_FRAGMENT': 11,
|
|
91
|
-
'NOTATION': 12
|
|
92
|
-
};
|
|
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
89
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
}
|
|
140
139
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
},
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
},
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
/** Add a symbolic node to this frame */
|
|
156
|
+
'addNode': function addNode(uri) {
|
|
157
|
+
this.addSymbol(this.NODE, uri);
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
if (this.isTripleToLoad()) {
|
|
160
|
+
this.loadTriple();
|
|
161
|
+
}
|
|
162
|
+
},
|
|
164
163
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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;
|
|
170
169
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
186
188
|
} else {
|
|
187
|
-
this.node = this.
|
|
189
|
+
this.node = this.store.bnode();
|
|
188
190
|
}
|
|
189
|
-
} else {
|
|
190
|
-
this.node = this.store.bnode();
|
|
191
|
-
}
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
this.nodeType = this.NODE;
|
|
194
193
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
if (this.isTripleToLoad()) {
|
|
195
|
+
this.loadTriple();
|
|
196
|
+
}
|
|
197
|
+
},
|
|
199
198
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
+
}
|
|
206
205
|
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
this.addSymbol(this.ARC, uri);
|
|
207
|
+
},
|
|
209
208
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
}
|
|
217
216
|
|
|
218
|
-
|
|
217
|
+
this.nodeType = this.NODE;
|
|
219
218
|
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
if (this.isTripleToLoad()) {
|
|
220
|
+
this.loadTriple();
|
|
221
|
+
}
|
|
222
222
|
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}; // from the OpenLayers source .. needed to get around IE problems.
|
|
223
|
+
};
|
|
224
|
+
} // from the OpenLayers source .. needed to get around IE problems.
|
|
226
225
|
|
|
226
|
+
}, {
|
|
227
|
+
key: "getAttributeNodeNS",
|
|
228
|
+
value: function getAttributeNodeNS(node, uri, name) {
|
|
229
|
+
var attributeNode = null;
|
|
227
230
|
|
|
228
|
-
|
|
229
|
-
|
|
231
|
+
if (node.getAttributeNodeNS) {
|
|
232
|
+
attributeNode = node.getAttributeNodeNS(uri, name);
|
|
233
|
+
} else {
|
|
234
|
+
var attributes = node.attributes;
|
|
235
|
+
var potentialNode, fullName;
|
|
230
236
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} else {
|
|
234
|
-
var attributes = node.attributes;
|
|
235
|
-
var potentialNode, fullName;
|
|
237
|
+
for (var i = 0; i < attributes.length; ++i) {
|
|
238
|
+
potentialNode = attributes[i];
|
|
236
239
|
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
if (potentialNode.namespaceURI === uri) {
|
|
241
|
+
fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
|
|
239
242
|
|
|
240
|
-
|
|
241
|
-
|
|
243
|
+
if (fullName === potentialNode.nodeName) {
|
|
244
|
+
attributeNode = potentialNode;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
242
250
|
|
|
243
|
-
|
|
244
|
-
|
|
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];
|
|
245
273
|
break;
|
|
246
274
|
}
|
|
247
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
|
|
248
280
|
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return attributeNode;
|
|
252
|
-
};
|
|
253
|
-
/** Our triple store reference @private */
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.store = store;
|
|
257
|
-
/** Our identified blank nodes @private */
|
|
258
281
|
|
|
259
|
-
|
|
260
|
-
/** A context for context-aware stores @private */
|
|
261
|
-
|
|
262
|
-
this.why = null;
|
|
263
|
-
/** Reification flag */
|
|
264
|
-
|
|
265
|
-
this.reify = false;
|
|
266
|
-
/**
|
|
267
|
-
* Build our initial scope frame and parse the DOM into triples
|
|
268
|
-
* @param {DOMTree} document The DOM to parse
|
|
269
|
-
* @param {String} base The base URL to use
|
|
270
|
-
* @param {Object} why The context to which this resource belongs
|
|
271
|
-
*/
|
|
282
|
+
this.why = why; // our topmost frame
|
|
272
283
|
|
|
273
|
-
|
|
274
|
-
|
|
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 (!)
|
|
275
288
|
|
|
276
|
-
|
|
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;
|
|
277
297
|
|
|
278
|
-
|
|
298
|
+
var elementURI = function (el) {
|
|
299
|
+
var result = '';
|
|
279
300
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
|
|
283
|
-
root = children[c];
|
|
284
|
-
break;
|
|
301
|
+
if (el.namespaceURI == null) {
|
|
302
|
+
throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
|
|
285
303
|
}
|
|
286
|
-
}
|
|
287
|
-
} else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
|
|
288
|
-
root = document;
|
|
289
|
-
} else {
|
|
290
|
-
throw new Error("RDFParser: can't find root in " + base + '. Halting. '); // return false
|
|
291
|
-
}
|
|
292
304
|
|
|
293
|
-
|
|
305
|
+
if (el.namespaceURI) {
|
|
306
|
+
result = result + el.namespaceURI;
|
|
307
|
+
}
|
|
294
308
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
+
}
|
|
299
314
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
};
|
|
315
|
+
return result;
|
|
316
|
+
}.bind(this);
|
|
303
317
|
|
|
304
|
-
|
|
305
|
-
// a DOM utility function used in parsing
|
|
306
|
-
var rdfid;
|
|
318
|
+
var dig = true; // if we'll dig down in the tree on the next iter
|
|
307
319
|
|
|
308
|
-
|
|
309
|
-
|
|
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
|
+
}
|
|
310
331
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
+
}
|
|
314
341
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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');
|
|
318
346
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
|
|
323
|
-
}
|
|
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
|
+
}
|
|
324
350
|
|
|
325
|
-
|
|
326
|
-
|
|
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');
|
|
327
356
|
|
|
328
|
-
|
|
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
|
|
329
367
|
|
|
330
|
-
while (frame.parent) {
|
|
331
|
-
var dom = frame.element;
|
|
332
|
-
var attrs = dom.attributes;
|
|
333
368
|
|
|
334
|
-
|
|
335
|
-
// we have a literal
|
|
336
|
-
if (frame.parent.nodeType === frame.NODE) {
|
|
337
|
-
// must have had attributes, store as rdf:value
|
|
338
|
-
frame.addArc(RDFParser.ns.RDF + 'value');
|
|
339
|
-
frame = this.buildFrame(frame);
|
|
340
|
-
}
|
|
369
|
+
var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
|
|
341
370
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
frame.addCollectionArc();
|
|
348
|
-
frame = this.buildFrame(frame, frame.element);
|
|
349
|
-
frame.parent.element = null;
|
|
350
|
-
}
|
|
371
|
+
if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
|
|
372
|
+
rdftype = {
|
|
373
|
+
'nodeValue': elementURI(dom)
|
|
374
|
+
};
|
|
375
|
+
}
|
|
351
376
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
|
|
355
|
-
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
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);
|
|
356
379
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
380
|
+
if (rdftype.nodeName) {
|
|
381
|
+
dom.removeAttributeNode(rdftype);
|
|
382
|
+
}
|
|
383
|
+
} // Property Attributes
|
|
360
384
|
|
|
361
|
-
if (!about && rdfid) {
|
|
362
|
-
frame.addNode('#' + rdfid.nodeValue);
|
|
363
|
-
dom.removeAttributeNode(rdfid);
|
|
364
|
-
} else if (about == null && rdfid == null) {
|
|
365
|
-
var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
|
|
366
385
|
|
|
367
|
-
|
|
368
|
-
frame.
|
|
369
|
-
dom.removeAttributeNode(bnid);
|
|
370
|
-
} else {
|
|
371
|
-
frame.addBNode();
|
|
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);
|
|
372
388
|
}
|
|
373
389
|
} else {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
} // Typed nodes
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
|
|
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
|
|
380
392
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
'nodeValue': elementURI(dom)
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (rdftype != null) {
|
|
388
|
-
this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
|
|
393
|
+
if (this.reify) {
|
|
394
|
+
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
389
395
|
|
|
390
|
-
|
|
391
|
-
|
|
396
|
+
if (rdfid) {
|
|
397
|
+
frame.rdfid = rdfid.nodeValue;
|
|
398
|
+
dom.removeAttributeNode(rdfid);
|
|
399
|
+
}
|
|
392
400
|
}
|
|
393
|
-
} // Property Attributes
|
|
394
401
|
|
|
402
|
+
var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
|
|
403
|
+
var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
|
|
395
404
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
} else {
|
|
400
|
-
// we should add an arc (or implicit bnode+arc)
|
|
401
|
-
frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
|
|
402
|
-
|
|
403
|
-
if (this.reify) {
|
|
404
|
-
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
405
|
-
|
|
406
|
-
if (rdfid) {
|
|
407
|
-
frame.rdfid = rdfid.nodeValue;
|
|
408
|
-
dom.removeAttributeNode(rdfid);
|
|
405
|
+
if (datatype) {
|
|
406
|
+
frame.datatype = datatype.nodeValue;
|
|
407
|
+
dom.removeAttributeNode(datatype);
|
|
409
408
|
}
|
|
410
|
-
}
|
|
411
409
|
|
|
412
|
-
|
|
413
|
-
|
|
410
|
+
if (parsetype) {
|
|
411
|
+
var nv = parsetype.nodeValue;
|
|
414
412
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
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
|
|
419
416
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
frame.parent.element = null;
|
|
432
|
-
frame.addBNode();
|
|
433
|
-
} else if (nv === 'Collection') {
|
|
434
|
-
frame = this.buildFrame(frame, frame.element);
|
|
435
|
-
frame.parent.element = null;
|
|
436
|
-
frame.addCollection();
|
|
437
|
-
}
|
|
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
|
+
}
|
|
438
428
|
|
|
439
|
-
|
|
440
|
-
|
|
429
|
+
dom.removeAttributeNode(parsetype);
|
|
430
|
+
}
|
|
441
431
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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);
|
|
446
436
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
} else {
|
|
451
|
-
if (bnid2) {
|
|
452
|
-
frame.addBNode(bnid2.nodeValue);
|
|
453
|
-
dom.removeAttributeNode(bnid2);
|
|
437
|
+
if (resource) {
|
|
438
|
+
frame.addNode(resource.nodeValue);
|
|
439
|
+
dom.removeAttributeNode(resource);
|
|
454
440
|
} else {
|
|
455
|
-
|
|
441
|
+
if (bnid2) {
|
|
442
|
+
frame.addBNode(bnid2.nodeValue);
|
|
443
|
+
dom.removeAttributeNode(bnid2);
|
|
444
|
+
} else {
|
|
445
|
+
frame.addBNode();
|
|
446
|
+
}
|
|
456
447
|
}
|
|
457
|
-
}
|
|
458
448
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
449
|
+
for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
|
|
450
|
+
var f = this.buildFrame(frame);
|
|
451
|
+
f.addArc(elementURI(attrs[x1]));
|
|
462
452
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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
|
+
}
|
|
467
458
|
}
|
|
459
|
+
} else if (dom.childNodes.length === 0) {
|
|
460
|
+
this.buildFrame(frame).addLiteral('');
|
|
468
461
|
}
|
|
469
|
-
} else if (dom.childNodes.length === 0) {
|
|
470
|
-
this.buildFrame(frame).addLiteral('');
|
|
471
462
|
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// dig dug
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
dom = frame.element;
|
|
463
|
+
} // rdf:RDF
|
|
464
|
+
// dig dug
|
|
478
465
|
|
|
479
|
-
while (frame.parent) {
|
|
480
|
-
var pframe = frame;
|
|
481
|
-
|
|
482
|
-
while (dom == null) {
|
|
483
|
-
frame = frame.parent;
|
|
484
|
-
dom = frame.element;
|
|
485
|
-
}
|
|
486
466
|
|
|
487
|
-
|
|
467
|
+
dom = frame.element;
|
|
488
468
|
|
|
489
|
-
|
|
490
|
-
frame
|
|
469
|
+
while (frame.parent) {
|
|
470
|
+
var pframe = frame;
|
|
491
471
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
dom = frame.element;
|
|
498
|
-
dig = true;
|
|
499
|
-
} 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) {
|
|
500
|
-
frame.lastChild++;
|
|
501
|
-
} else {
|
|
502
|
-
// not a leaf
|
|
503
|
-
frame.lastChild++;
|
|
504
|
-
frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]);
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
} // while
|
|
472
|
+
while (dom == null) {
|
|
473
|
+
frame = frame.parent;
|
|
474
|
+
dom = frame.element;
|
|
475
|
+
}
|
|
509
476
|
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Cleans out state from a previous parse run
|
|
513
|
-
* @private
|
|
514
|
-
*/
|
|
477
|
+
var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
|
|
515
478
|
|
|
479
|
+
if (!candidate || !dig) {
|
|
480
|
+
frame.terminateFrame();
|
|
516
481
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
};
|
|
521
|
-
/**
|
|
522
|
-
* Builds scope frame
|
|
523
|
-
* @private
|
|
524
|
-
*/
|
|
482
|
+
if (!(frame = frame.parent)) {
|
|
483
|
+
break;
|
|
484
|
+
} // done
|
|
525
485
|
|
|
526
486
|
|
|
527
|
-
|
|
528
|
-
|
|
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
|
|
529
499
|
|
|
530
|
-
if (parent) {
|
|
531
|
-
frame.base = parent.base;
|
|
532
|
-
frame.lang = parent.lang;
|
|
533
500
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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;
|
|
537
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
|
+
}
|
|
538
526
|
|
|
539
|
-
|
|
540
|
-
|
|
527
|
+
if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
|
|
528
|
+
return frame;
|
|
529
|
+
}
|
|
541
530
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
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
|
+
}
|
|
546
538
|
|
|
547
|
-
|
|
539
|
+
var lang = element.getAttributeNode('xml:lang');
|
|
548
540
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
541
|
+
if (lang != null) {
|
|
542
|
+
frame.lang = lang.nodeValue;
|
|
543
|
+
element.removeAttribute('xml:lang');
|
|
544
|
+
} // remove all extraneous xml and xmlns attributes
|
|
553
545
|
|
|
554
546
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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)
|
|
559
551
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
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) //@@
|
|
563
555
|
|
|
564
556
|
|
|
565
|
-
|
|
557
|
+
element.removeAttributeNode(attrs[x]);
|
|
558
|
+
}
|
|
566
559
|
}
|
|
567
|
-
}
|
|
568
560
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
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 };
|