rdflib 2.2.22-4e175603 → 2.2.22-53d65d90
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 +4 -0
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +90 -61
- package/esm/class-order.js +1 -1
- package/esm/collection.js +106 -70
- package/esm/default-graph.js +33 -13
- package/esm/empty.js +26 -8
- package/esm/factories/canonical-data-factory.js +30 -33
- package/esm/factories/extended-term-factory.js +14 -18
- package/esm/factories/factory-types.js +1 -1
- package/esm/factories/rdflib-data-factory.js +11 -9
- package/esm/fetcher.js +1644 -1355
- package/esm/formula.js +740 -632
- package/esm/index.js +51 -31
- package/esm/jsonldparser.js +26 -19
- package/esm/jsonparser.js +1 -1
- package/esm/lists.js +86 -38
- package/esm/literal.js +157 -120
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1085 -1008
- package/esm/named-node.js +99 -69
- package/esm/namespace.js +4 -2
- package/esm/node-internal.js +98 -74
- package/esm/node.js +1 -1
- package/esm/parse.js +3 -3
- package/esm/patch-parser.js +1 -1
- package/esm/query.js +16 -15
- package/esm/rdfaparser.js +846 -781
- package/esm/rdfxmlparser.js +365 -348
- package/esm/serialize.js +4 -20
- package/esm/serializer.js +886 -821
- package/esm/statement.js +72 -52
- package/esm/store.js +924 -822
- package/esm/types.js +21 -21
- package/esm/update-manager.js +983 -882
- package/esm/updates-via.js +134 -104
- package/esm/uri.js +3 -3
- package/esm/utils/default-graph-uri.js +2 -2
- package/esm/utils/terms.js +5 -4
- package/esm/utils-js.js +5 -5
- package/esm/utils.js +6 -6
- package/esm/variable.js +58 -32
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +88 -60
- package/lib/class-order.js +1 -1
- package/lib/collection.js +104 -69
- package/lib/default-graph.js +32 -13
- package/lib/empty.js +25 -8
- package/lib/factories/canonical-data-factory.js +32 -35
- package/lib/factories/extended-term-factory.js +14 -18
- package/lib/factories/factory-types.js +1 -1
- package/lib/factories/rdflib-data-factory.js +11 -9
- package/lib/fetcher.js +1646 -1385
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +739 -632
- package/lib/index.js +87 -66
- package/lib/jsonldparser.js +26 -19
- package/lib/jsonparser.js +1 -1
- package/lib/lists.js +86 -54
- package/lib/literal.js +156 -120
- package/lib/log.js +7 -7
- package/lib/n3parser.js +1089 -1010
- package/lib/named-node.js +98 -69
- package/lib/namespace.js +4 -2
- package/lib/node-internal.js +96 -73
- package/lib/node.js +1 -1
- package/lib/parse.js +6 -5
- package/lib/patch-parser.js +1 -1
- package/lib/query.js +18 -19
- package/lib/rdfaparser.js +848 -783
- package/lib/rdfxmlparser.js +366 -350
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +4 -21
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +890 -825
- package/lib/statement.js +74 -54
- package/lib/store.d.ts +1 -1
- package/lib/store.js +926 -844
- package/lib/types.js +21 -21
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +959 -865
- package/lib/updates-via.js +134 -105
- package/lib/uri.js +3 -3
- package/lib/utils/default-graph-uri.js +2 -2
- package/lib/utils/terms.js +6 -4
- package/lib/utils-js.js +9 -8
- package/lib/utils.js +6 -6
- package/lib/variable.js +60 -34
- package/lib/xsd.js +2 -2
- package/package.json +6 -6
- package/src/jsonldparser.js +1 -1
- package/src/serialize.ts +4 -14
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +8 -2
package/lib/rdfxmlparser.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.default = void 0;
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
12
|
var uriUtil = _interopRequireWildcard(require("./uri"));
|
|
10
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
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); }
|
|
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; }
|
|
12
15
|
/**
|
|
13
16
|
* RDF/XML PARSER
|
|
14
17
|
*
|
|
@@ -66,13 +69,13 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
66
69
|
* @author David Sheets <dsheets@mit.edu>
|
|
67
70
|
*
|
|
68
71
|
*/
|
|
69
|
-
|
|
70
|
-
class RDFParser {
|
|
72
|
+
var RDFParser = /*#__PURE__*/function () {
|
|
71
73
|
/*
|
|
72
74
|
* @constructor
|
|
73
75
|
* @param {RDFStore} store An RDFStore object
|
|
74
76
|
*/
|
|
75
|
-
|
|
77
|
+
function RDFParser(store) {
|
|
78
|
+
(0, _classCallCheck2.default)(this, RDFParser);
|
|
76
79
|
/** Our triple store reference @private */
|
|
77
80
|
|
|
78
81
|
this.store = store; /** Our identified blank nodes @private */
|
|
@@ -84,386 +87,399 @@ class RDFParser {
|
|
|
84
87
|
/** Standard namespaces that we know how to handle @final
|
|
85
88
|
* @member RDFParser
|
|
86
89
|
*/
|
|
90
|
+
(0, _createClass2.default)(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
|
+
*/
|
|
87
100
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
/** Add a symbol of a certain type to the this frame */'addSymbol': function (type, uri) {
|
|
120
|
-
uri = uriUtil.join(uri, this.base);
|
|
121
|
-
this.node = this.store.sym(uri);
|
|
122
|
-
this.nodeType = type;
|
|
123
|
-
},
|
|
124
|
-
/** Load any constructed triples into the store */'loadTriple': function () {
|
|
125
|
-
if (this.parent.parent.collection) {
|
|
126
|
-
this.parent.parent.node.append(this.node);
|
|
127
|
-
} else {
|
|
128
|
-
this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
|
|
129
|
-
}
|
|
130
|
-
if (this.parent.rdfid != null) {
|
|
131
|
-
// reify
|
|
132
|
-
var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
|
|
133
|
-
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(RDFParser.ns.RDF + 'Statement'), this.parser.why);
|
|
134
|
-
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'subject'), this.parent.parent.node, this.parser.why);
|
|
135
|
-
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'predicate'), this.parent.node, this.parser.why);
|
|
136
|
-
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
/** Check if it's OK to load a triple */'isTripleToLoad': function () {
|
|
140
|
-
return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
|
|
141
|
-
},
|
|
142
|
-
/** Add a symbolic node to this frame */'addNode': function (uri) {
|
|
143
|
-
this.addSymbol(this.NODE, uri);
|
|
144
|
-
if (this.isTripleToLoad()) {
|
|
145
|
-
this.loadTriple();
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
/** Add a collection node to this frame */'addCollection': function () {
|
|
149
|
-
this.nodeType = this.NODE;
|
|
150
|
-
this.node = this.store.collection();
|
|
151
|
-
this.collection = true;
|
|
152
|
-
if (this.isTripleToLoad()) {
|
|
153
|
-
this.loadTriple();
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
/** Add a collection arc to this frame */'addCollectionArc': function () {
|
|
157
|
-
this.nodeType = this.ARC;
|
|
158
|
-
},
|
|
159
|
-
/** Add a bnode to this frame */'addBNode': function (id) {
|
|
160
|
-
if (id != null) {
|
|
161
|
-
if (this.parser.bnodes[id] != null) {
|
|
162
|
-
this.node = this.parser.bnodes[id];
|
|
101
|
+
function frameFactory(parser, parent, element) {
|
|
102
|
+
return {
|
|
103
|
+
'NODE': 1,
|
|
104
|
+
'ARC': 2,
|
|
105
|
+
'parent': parent,
|
|
106
|
+
'parser': parser,
|
|
107
|
+
'store': parser.store,
|
|
108
|
+
'element': element,
|
|
109
|
+
'lastChild': 0,
|
|
110
|
+
'base': null,
|
|
111
|
+
'lang': null,
|
|
112
|
+
'node': null,
|
|
113
|
+
'nodeType': null,
|
|
114
|
+
'listIndex': 1,
|
|
115
|
+
'rdfid': null,
|
|
116
|
+
'datatype': null,
|
|
117
|
+
'collection': false,
|
|
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
|
+
/** Add a symbol of a certain type to the this frame */'addSymbol': function addSymbol(type, uri) {
|
|
125
|
+
uri = uriUtil.join(uri, this.base);
|
|
126
|
+
this.node = this.store.sym(uri);
|
|
127
|
+
this.nodeType = type;
|
|
128
|
+
},
|
|
129
|
+
/** Load any constructed triples into the store */'loadTriple': function loadTriple() {
|
|
130
|
+
if (this.parent.parent.collection) {
|
|
131
|
+
this.parent.parent.node.append(this.node);
|
|
163
132
|
} else {
|
|
164
|
-
this.node
|
|
133
|
+
this.store.add(this.parent.parent.node, this.parent.node, this.node, this.parser.why);
|
|
134
|
+
}
|
|
135
|
+
if (this.parent.rdfid != null) {
|
|
136
|
+
// reify
|
|
137
|
+
var triple = this.store.sym(uriUtil.join('#' + this.parent.rdfid, this.base));
|
|
138
|
+
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(RDFParser.ns.RDF + 'Statement'), this.parser.why);
|
|
139
|
+
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'subject'), this.parent.parent.node, this.parser.why);
|
|
140
|
+
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'predicate'), this.parent.node, this.parser.why);
|
|
141
|
+
this.store.add(triple, this.store.sym(RDFParser.ns.RDF + 'object'), this.node, this.parser.why);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
/** Check if it's OK to load a triple */'isTripleToLoad': function isTripleToLoad() {
|
|
145
|
+
return this.parent != null && this.parent.parent != null && this.nodeType === this.NODE && this.parent.nodeType === this.ARC && this.parent.parent.nodeType === this.NODE;
|
|
146
|
+
},
|
|
147
|
+
/** Add a symbolic node to this frame */'addNode': function addNode(uri) {
|
|
148
|
+
this.addSymbol(this.NODE, uri);
|
|
149
|
+
if (this.isTripleToLoad()) {
|
|
150
|
+
this.loadTriple();
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
/** Add a collection node to this frame */'addCollection': function addCollection() {
|
|
154
|
+
this.nodeType = this.NODE;
|
|
155
|
+
this.node = this.store.collection();
|
|
156
|
+
this.collection = true;
|
|
157
|
+
if (this.isTripleToLoad()) {
|
|
158
|
+
this.loadTriple();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
/** Add a collection arc to this frame */'addCollectionArc': function addCollectionArc() {
|
|
162
|
+
this.nodeType = this.ARC;
|
|
163
|
+
},
|
|
164
|
+
/** Add a bnode to this frame */'addBNode': function addBNode(id) {
|
|
165
|
+
if (id != null) {
|
|
166
|
+
if (this.parser.bnodes[id] != null) {
|
|
167
|
+
this.node = this.parser.bnodes[id];
|
|
168
|
+
} else {
|
|
169
|
+
this.node = this.parser.bnodes[id] = this.store.bnode();
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
this.node = this.store.bnode();
|
|
173
|
+
}
|
|
174
|
+
this.nodeType = this.NODE;
|
|
175
|
+
if (this.isTripleToLoad()) {
|
|
176
|
+
this.loadTriple();
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
/** Add an arc or property to this frame */'addArc': function addArc(uri) {
|
|
180
|
+
if (uri === RDFParser.ns.RDF + 'li') {
|
|
181
|
+
uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
|
|
182
|
+
this.parent.listIndex++;
|
|
183
|
+
}
|
|
184
|
+
this.addSymbol(this.ARC, uri);
|
|
185
|
+
},
|
|
186
|
+
/** Add a literal to this frame */'addLiteral': function addLiteral(value) {
|
|
187
|
+
if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
|
|
188
|
+
this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
|
|
189
|
+
} else {
|
|
190
|
+
this.node = this.store.literal(value, this.lang);
|
|
191
|
+
}
|
|
192
|
+
this.nodeType = this.NODE;
|
|
193
|
+
if (this.isTripleToLoad()) {
|
|
194
|
+
this.loadTriple();
|
|
165
195
|
}
|
|
166
|
-
} else {
|
|
167
|
-
this.node = this.store.bnode();
|
|
168
|
-
}
|
|
169
|
-
this.nodeType = this.NODE;
|
|
170
|
-
if (this.isTripleToLoad()) {
|
|
171
|
-
this.loadTriple();
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
/** Add an arc or property to this frame */'addArc': function (uri) {
|
|
175
|
-
if (uri === RDFParser.ns.RDF + 'li') {
|
|
176
|
-
uri = RDFParser.ns.RDF + '_' + this.parent.listIndex;
|
|
177
|
-
this.parent.listIndex++;
|
|
178
|
-
}
|
|
179
|
-
this.addSymbol(this.ARC, uri);
|
|
180
|
-
},
|
|
181
|
-
/** Add a literal to this frame */'addLiteral': function (value) {
|
|
182
|
-
if (this.parent.datatype && this.parent.datatype !== RDFParser.ns.RDF + 'langString') {
|
|
183
|
-
this.node = this.store.literal(value, this.store.sym(this.parent.datatype));
|
|
184
|
-
} else {
|
|
185
|
-
this.node = this.store.literal(value, this.lang);
|
|
186
|
-
}
|
|
187
|
-
this.nodeType = this.NODE;
|
|
188
|
-
if (this.isTripleToLoad()) {
|
|
189
|
-
this.loadTriple();
|
|
190
196
|
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
194
199
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
attributeNode =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
potentialNode
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
200
|
+
// from the OpenLayers source .. needed to get around IE problems.
|
|
201
|
+
}, {
|
|
202
|
+
key: "getAttributeNodeNS",
|
|
203
|
+
value: function getAttributeNodeNS(node, uri, name) {
|
|
204
|
+
var attributeNode = null;
|
|
205
|
+
if (node.getAttributeNodeNS) {
|
|
206
|
+
attributeNode = node.getAttributeNodeNS(uri, name);
|
|
207
|
+
} else {
|
|
208
|
+
var attributes = node.attributes;
|
|
209
|
+
var potentialNode, fullName;
|
|
210
|
+
for (var i = 0; i < attributes.length; ++i) {
|
|
211
|
+
potentialNode = attributes[i];
|
|
212
|
+
if (potentialNode.namespaceURI === uri) {
|
|
213
|
+
fullName = potentialNode.prefix ? potentialNode.prefix + ':' + name : name;
|
|
214
|
+
if (fullName === potentialNode.nodeName) {
|
|
215
|
+
attributeNode = potentialNode;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
210
218
|
}
|
|
211
219
|
}
|
|
212
220
|
}
|
|
221
|
+
return attributeNode;
|
|
213
222
|
}
|
|
214
|
-
return attributeNode;
|
|
215
|
-
}
|
|
216
223
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Build our initial scope frame and parse the DOM into triples
|
|
226
|
+
* @param {HTMLDocument} document The DOM to parse
|
|
227
|
+
* @param {String} base The base URL to use
|
|
228
|
+
* @param {Object} why The context to which this resource belongs
|
|
229
|
+
*/
|
|
230
|
+
}, {
|
|
231
|
+
key: "parse",
|
|
232
|
+
value: function parse(document, base, why) {
|
|
233
|
+
var children = document.childNodes; // clean up for the next run
|
|
234
|
+
this.cleanParser(); // figure out the root element
|
|
235
|
+
var root;
|
|
236
|
+
if (document.nodeType === RDFParser.nodeType.DOCUMENT) {
|
|
237
|
+
for (var c = 0; c < children.length; c++) {
|
|
238
|
+
if (children[c].nodeType === RDFParser.nodeType.ELEMENT) {
|
|
239
|
+
root = children[c];
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
233
242
|
}
|
|
243
|
+
} else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
|
|
244
|
+
root = document;
|
|
245
|
+
} else {
|
|
246
|
+
throw new Error("RDFParser: can't find root in " + base + '. Halting. ');
|
|
247
|
+
// return false
|
|
234
248
|
}
|
|
235
|
-
} else if (document.nodeType === RDFParser.nodeType.ELEMENT) {
|
|
236
|
-
root = document;
|
|
237
|
-
} else {
|
|
238
|
-
throw new Error("RDFParser: can't find root in " + base + '. Halting. ');
|
|
239
|
-
// return false
|
|
240
|
-
}
|
|
241
249
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
var
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
result = result + el.namespaceURI;
|
|
260
|
-
}
|
|
261
|
-
if (el.localName) {
|
|
262
|
-
result = result + el.localName;
|
|
263
|
-
} else if (el.nodeName) {
|
|
264
|
-
if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
|
|
265
|
-
}
|
|
266
|
-
return result;
|
|
267
|
-
}.bind(this);
|
|
268
|
-
var dig = true; // if we'll dig down in the tree on the next iter
|
|
269
|
-
while (frame.parent) {
|
|
270
|
-
var dom = frame.element;
|
|
271
|
-
var attrs = dom.attributes;
|
|
272
|
-
if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
|
|
273
|
-
// we have a literal
|
|
274
|
-
if (frame.parent.nodeType === frame.NODE) {
|
|
275
|
-
// must have had attributes, store as rdf:value
|
|
276
|
-
frame.addArc(RDFParser.ns.RDF + 'value');
|
|
277
|
-
frame = this.buildFrame(frame);
|
|
250
|
+
this.why = why; // our topmost frame
|
|
251
|
+
var f = this.frameFactory(this);
|
|
252
|
+
this.base = base;
|
|
253
|
+
f.base = base;
|
|
254
|
+
f.lang = null; // was '' but can't have langs like that 2015 (!)
|
|
255
|
+
this.parseDOM(this.buildFrame(f, root));
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "parseDOM",
|
|
260
|
+
value: function parseDOM(frame) {
|
|
261
|
+
// a DOM utility function used in parsing
|
|
262
|
+
var rdfid;
|
|
263
|
+
var elementURI = function (el) {
|
|
264
|
+
var result = '';
|
|
265
|
+
if (el.namespaceURI == null) {
|
|
266
|
+
throw new Error('RDF/XML syntax error: No namespace for ' + el.localName + ' in ' + this.base);
|
|
278
267
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
// not root
|
|
282
|
-
if (frame.parent && frame.parent.collection) {
|
|
283
|
-
// we're a collection element
|
|
284
|
-
frame.addCollectionArc();
|
|
285
|
-
frame = this.buildFrame(frame, frame.element);
|
|
286
|
-
frame.parent.element = null;
|
|
268
|
+
if (el.namespaceURI) {
|
|
269
|
+
result = result + el.namespaceURI;
|
|
287
270
|
}
|
|
288
|
-
if (
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
} else {
|
|
307
|
-
frame.addNode(about.nodeValue);
|
|
308
|
-
dom.removeAttributeNode(about);
|
|
309
|
-
}
|
|
310
|
-
// Typed nodes
|
|
311
|
-
var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
|
|
312
|
-
if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
|
|
313
|
-
rdftype = {
|
|
314
|
-
'nodeValue': elementURI(dom)
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
if (rdftype != null) {
|
|
318
|
-
this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
|
|
319
|
-
if (rdftype.nodeName) {
|
|
320
|
-
dom.removeAttributeNode(rdftype);
|
|
321
|
-
}
|
|
271
|
+
if (el.localName) {
|
|
272
|
+
result = result + el.localName;
|
|
273
|
+
} else if (el.nodeName) {
|
|
274
|
+
if (el.nodeName.indexOf(':') >= 0) result = result + el.nodeName.split(':')[1];else result = result + el.nodeName;
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
}.bind(this);
|
|
278
|
+
var dig = true; // if we'll dig down in the tree on the next iter
|
|
279
|
+
while (frame.parent) {
|
|
280
|
+
var dom = frame.element;
|
|
281
|
+
var attrs = dom.attributes;
|
|
282
|
+
if (dom.nodeType === RDFParser.nodeType.TEXT || dom.nodeType === RDFParser.nodeType.CDATA_SECTION) {
|
|
283
|
+
// we have a literal
|
|
284
|
+
if (frame.parent.nodeType === frame.NODE) {
|
|
285
|
+
// must have had attributes, store as rdf:value
|
|
286
|
+
frame.addArc(RDFParser.ns.RDF + 'value');
|
|
287
|
+
frame = this.buildFrame(frame);
|
|
322
288
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
289
|
+
frame.addLiteral(dom.nodeValue);
|
|
290
|
+
} else if (elementURI(dom) !== RDFParser.ns.RDF + 'RDF') {
|
|
291
|
+
// not root
|
|
292
|
+
if (frame.parent && frame.parent.collection) {
|
|
293
|
+
// we're a collection element
|
|
294
|
+
frame.addCollectionArc();
|
|
295
|
+
frame = this.buildFrame(frame, frame.element);
|
|
296
|
+
frame.parent.element = null;
|
|
326
297
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (this.reify) {
|
|
298
|
+
if (!frame.parent || !frame.parent.nodeType || frame.parent.nodeType === frame.ARC) {
|
|
299
|
+
// we need a node
|
|
300
|
+
var about = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'about');
|
|
331
301
|
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
332
|
-
if (rdfid) {
|
|
333
|
-
|
|
302
|
+
if (about && rdfid) {
|
|
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.');
|
|
304
|
+
}
|
|
305
|
+
if (!about && rdfid) {
|
|
306
|
+
frame.addNode('#' + rdfid.nodeValue);
|
|
334
307
|
dom.removeAttributeNode(rdfid);
|
|
308
|
+
} else if (about == null && rdfid == null) {
|
|
309
|
+
var bnid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
|
|
310
|
+
if (bnid) {
|
|
311
|
+
frame.addBNode(bnid.nodeValue);
|
|
312
|
+
dom.removeAttributeNode(bnid);
|
|
313
|
+
} else {
|
|
314
|
+
frame.addBNode();
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
frame.addNode(about.nodeValue);
|
|
318
|
+
dom.removeAttributeNode(about);
|
|
335
319
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
if (parsetype) {
|
|
344
|
-
var nv = parsetype.nodeValue;
|
|
345
|
-
if (nv === 'Literal') {
|
|
346
|
-
frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
|
|
347
|
-
frame = this.buildFrame(frame);
|
|
348
|
-
// Don't include the literal node, only its children
|
|
349
|
-
frame.addLiteral(dom.childNodes);
|
|
350
|
-
dig = false;
|
|
351
|
-
} else if (nv === 'Resource') {
|
|
352
|
-
frame = this.buildFrame(frame, frame.element);
|
|
353
|
-
frame.parent.element = null;
|
|
354
|
-
frame.addBNode();
|
|
355
|
-
} else if (nv === 'Collection') {
|
|
356
|
-
frame = this.buildFrame(frame, frame.element);
|
|
357
|
-
frame.parent.element = null;
|
|
358
|
-
frame.addCollection();
|
|
320
|
+
// Typed nodes
|
|
321
|
+
var rdftype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'type');
|
|
322
|
+
if (RDFParser.ns.RDF + 'Description' !== elementURI(dom)) {
|
|
323
|
+
rdftype = {
|
|
324
|
+
'nodeValue': elementURI(dom)
|
|
325
|
+
};
|
|
359
326
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
327
|
+
if (rdftype != null) {
|
|
328
|
+
this.store.add(frame.node, this.store.sym(RDFParser.ns.RDF + 'type'), this.store.sym(uriUtil.join(rdftype.nodeValue, frame.base)), this.why);
|
|
329
|
+
if (rdftype.nodeName) {
|
|
330
|
+
dom.removeAttributeNode(rdftype);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
// Property Attributes
|
|
334
|
+
for (var x = attrs.length - 1; x >= 0; x--) {
|
|
335
|
+
this.store.add(frame.node, this.store.sym(elementURI(attrs[x])), this.store.literal(attrs[x].nodeValue, frame.lang), this.why);
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
// we should add an arc (or implicit bnode+arc)
|
|
339
|
+
frame.addArc(elementURI(dom)); // save the arc's rdf:ID if it has one
|
|
340
|
+
if (this.reify) {
|
|
341
|
+
rdfid = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'ID');
|
|
342
|
+
if (rdfid) {
|
|
343
|
+
frame.rdfid = rdfid.nodeValue;
|
|
344
|
+
dom.removeAttributeNode(rdfid);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
var parsetype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'parseType');
|
|
348
|
+
var datatype = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'datatype');
|
|
349
|
+
if (datatype) {
|
|
350
|
+
frame.datatype = datatype.nodeValue;
|
|
351
|
+
dom.removeAttributeNode(datatype);
|
|
352
|
+
}
|
|
353
|
+
if (parsetype) {
|
|
354
|
+
var nv = parsetype.nodeValue;
|
|
355
|
+
if (nv === 'Literal') {
|
|
356
|
+
frame.datatype = RDFParser.ns.RDF + 'XMLLiteral';
|
|
357
|
+
frame = this.buildFrame(frame);
|
|
358
|
+
// Don't include the literal node, only its children
|
|
359
|
+
frame.addLiteral(dom.childNodes);
|
|
360
|
+
dig = false;
|
|
361
|
+
} else if (nv === 'Resource') {
|
|
362
|
+
frame = this.buildFrame(frame, frame.element);
|
|
363
|
+
frame.parent.element = null;
|
|
374
364
|
frame.addBNode();
|
|
365
|
+
} else if (nv === 'Collection') {
|
|
366
|
+
frame = this.buildFrame(frame, frame.element);
|
|
367
|
+
frame.parent.element = null;
|
|
368
|
+
frame.addCollection();
|
|
375
369
|
}
|
|
370
|
+
dom.removeAttributeNode(parsetype);
|
|
376
371
|
}
|
|
377
|
-
|
|
378
|
-
var
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
372
|
+
if (attrs.length !== 0) {
|
|
373
|
+
var resource = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'resource');
|
|
374
|
+
var bnid2 = this.getAttributeNodeNS(dom, RDFParser.ns.RDF, 'nodeID');
|
|
375
|
+
frame = this.buildFrame(frame);
|
|
376
|
+
if (resource) {
|
|
377
|
+
frame.addNode(resource.nodeValue);
|
|
378
|
+
dom.removeAttributeNode(resource);
|
|
382
379
|
} else {
|
|
383
|
-
|
|
380
|
+
if (bnid2) {
|
|
381
|
+
frame.addBNode(bnid2.nodeValue);
|
|
382
|
+
dom.removeAttributeNode(bnid2);
|
|
383
|
+
} else {
|
|
384
|
+
frame.addBNode();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
for (var x1 = attrs.length - 1; x1 >= 0; x1--) {
|
|
388
|
+
var f = this.buildFrame(frame);
|
|
389
|
+
f.addArc(elementURI(attrs[x1]));
|
|
390
|
+
if (elementURI(attrs[x1]) === RDFParser.ns.RDF + 'type') {
|
|
391
|
+
this.buildFrame(f).addNode(attrs[x1].nodeValue);
|
|
392
|
+
} else {
|
|
393
|
+
this.buildFrame(f).addLiteral(attrs[x1].nodeValue);
|
|
394
|
+
}
|
|
384
395
|
}
|
|
396
|
+
} else if (dom.childNodes.length === 0) {
|
|
397
|
+
this.buildFrame(frame).addLiteral('');
|
|
385
398
|
}
|
|
386
|
-
} else if (dom.childNodes.length === 0) {
|
|
387
|
-
this.buildFrame(frame).addLiteral('');
|
|
388
399
|
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
} // rdf:RDF
|
|
401
|
+
// dig dug
|
|
402
|
+
dom = frame.element;
|
|
403
|
+
while (frame.parent) {
|
|
404
|
+
var pframe = frame;
|
|
405
|
+
while (dom == null) {
|
|
406
|
+
frame = frame.parent;
|
|
407
|
+
dom = frame.element;
|
|
408
|
+
}
|
|
409
|
+
var candidate = dom.childNodes && dom.childNodes[frame.lastChild];
|
|
410
|
+
if (!candidate || !dig) {
|
|
411
|
+
frame.terminateFrame();
|
|
412
|
+
if (!(frame = frame.parent)) {
|
|
413
|
+
break;
|
|
414
|
+
} // done
|
|
415
|
+
dom = frame.element;
|
|
416
|
+
dig = true;
|
|
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) {
|
|
418
|
+
frame.lastChild++;
|
|
419
|
+
} else {
|
|
420
|
+
// not a leaf
|
|
421
|
+
frame.lastChild++;
|
|
422
|
+
frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]);
|
|
403
423
|
break;
|
|
404
|
-
}
|
|
405
|
-
dom = frame.element;
|
|
406
|
-
dig = true;
|
|
407
|
-
} 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) {
|
|
408
|
-
frame.lastChild++;
|
|
409
|
-
} else {
|
|
410
|
-
// not a leaf
|
|
411
|
-
frame.lastChild++;
|
|
412
|
-
frame = this.buildFrame(pframe, dom.childNodes[frame.lastChild - 1]);
|
|
413
|
-
break;
|
|
424
|
+
}
|
|
414
425
|
}
|
|
415
|
-
}
|
|
416
|
-
} // while
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Cleans out state from a previous parse run
|
|
421
|
-
* @private
|
|
422
|
-
*/
|
|
423
|
-
cleanParser() {
|
|
424
|
-
this.bnodes = {};
|
|
425
|
-
this.why = null;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Builds scope frame
|
|
430
|
-
* @private
|
|
431
|
-
*/
|
|
432
|
-
buildFrame(parent, element) {
|
|
433
|
-
var frame = this.frameFactory(this, parent, element);
|
|
434
|
-
if (parent) {
|
|
435
|
-
frame.base = parent.base;
|
|
436
|
-
frame.lang = parent.lang;
|
|
426
|
+
} // while
|
|
437
427
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (lang != null) {
|
|
449
|
-
frame.lang = lang.nodeValue;
|
|
450
|
-
element.removeAttribute('xml:lang');
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Cleans out state from a previous parse run
|
|
431
|
+
* @private
|
|
432
|
+
*/
|
|
433
|
+
}, {
|
|
434
|
+
key: "cleanParser",
|
|
435
|
+
value: function cleanParser() {
|
|
436
|
+
this.bnodes = {};
|
|
437
|
+
this.why = null;
|
|
451
438
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Builds scope frame
|
|
442
|
+
* @private
|
|
443
|
+
*/
|
|
444
|
+
}, {
|
|
445
|
+
key: "buildFrame",
|
|
446
|
+
value: function buildFrame(parent, element) {
|
|
447
|
+
var frame = this.frameFactory(this, parent, element);
|
|
448
|
+
if (parent) {
|
|
449
|
+
frame.base = parent.base;
|
|
450
|
+
frame.lang = parent.lang;
|
|
451
|
+
}
|
|
452
|
+
if (!element || element.nodeType === RDFParser.nodeType.TEXT || element.nodeType === RDFParser.nodeType.CDATA_SECTION) {
|
|
453
|
+
return frame;
|
|
454
|
+
}
|
|
455
|
+
var attrs = element.attributes;
|
|
456
|
+
var base = element.getAttributeNode('xml:base');
|
|
457
|
+
if (base != null) {
|
|
458
|
+
frame.base = base.nodeValue;
|
|
459
|
+
element.removeAttribute('xml:base');
|
|
460
|
+
}
|
|
461
|
+
var lang = element.getAttributeNode('xml:lang');
|
|
462
|
+
if (lang != null) {
|
|
463
|
+
frame.lang = lang.nodeValue;
|
|
464
|
+
element.removeAttribute('xml:lang');
|
|
465
|
+
}
|
|
466
|
+
// remove all extraneous xml and xmlns attributes
|
|
467
|
+
for (var x = attrs.length - 1; x >= 0; x--) {
|
|
468
|
+
if (attrs[x].nodeName.substr(0, 3) === 'xml') {
|
|
469
|
+
if (attrs[x].name.slice(0, 6) === 'xmlns:') {
|
|
470
|
+
var uri = attrs[x].nodeValue; // alert('base for namespac attr:'+this.base)
|
|
471
|
+
if (this.base) uri = uriUtil.join(uri, this.base);
|
|
472
|
+
this.store.setPrefixForURI(attrs[x].name.slice(6), uri);
|
|
473
|
+
}
|
|
474
|
+
// alert('rdfparser: xml atribute: '+attrs[x].name) //@@
|
|
475
|
+
element.removeAttributeNode(attrs[x]);
|
|
459
476
|
}
|
|
460
|
-
// alert('rdfparser: xml atribute: '+attrs[x].name) //@@
|
|
461
|
-
element.removeAttributeNode(attrs[x]);
|
|
462
477
|
}
|
|
478
|
+
return frame;
|
|
463
479
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
}
|
|
480
|
+
}]);
|
|
481
|
+
return RDFParser;
|
|
482
|
+
}();
|
|
467
483
|
exports.default = RDFParser;
|
|
468
484
|
(0, _defineProperty2.default)(RDFParser, "ns", {
|
|
469
485
|
'RDF': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|