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