rdflib 2.2.35 → 2.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +0 -2
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +57 -82
  5. package/esm/class-order.js +1 -1
  6. package/esm/collection.js +70 -103
  7. package/esm/default-graph.js +13 -30
  8. package/esm/empty.js +8 -23
  9. package/esm/factories/canonical-data-factory.js +33 -29
  10. package/esm/factories/extended-term-factory.js +18 -13
  11. package/esm/factories/factory-types.js +1 -1
  12. package/esm/factories/rdflib-data-factory.js +9 -11
  13. package/esm/fetcher.js +1366 -1651
  14. package/esm/formula.js +631 -736
  15. package/esm/index.js +31 -48
  16. package/esm/jsonldparser.js +19 -26
  17. package/esm/jsonparser.js +1 -1
  18. package/esm/lists.js +38 -86
  19. package/esm/literal.js +120 -154
  20. package/esm/log.js +7 -7
  21. package/esm/n3parser.js +1009 -1086
  22. package/esm/named-node.js +69 -96
  23. package/esm/namespace.js +2 -4
  24. package/esm/node-internal.js +73 -96
  25. package/esm/node.js +1 -1
  26. package/esm/parse.js +3 -3
  27. package/esm/patch-parser.js +1 -1
  28. package/esm/query.js +15 -16
  29. package/esm/rdfaparser.js +775 -841
  30. package/esm/rdfxmlparser.js +348 -364
  31. package/esm/serialize.js +2 -2
  32. package/esm/serializer.js +835 -877
  33. package/esm/statement.js +52 -71
  34. package/esm/store.js +853 -957
  35. package/esm/types.js +21 -21
  36. package/esm/update-manager.js +965 -1100
  37. package/esm/updates-via.js +104 -132
  38. package/esm/uri.js +3 -3
  39. package/esm/utils/default-graph-uri.js +2 -2
  40. package/esm/utils/terms.js +4 -5
  41. package/esm/utils-js.js +5 -5
  42. package/esm/utils.js +6 -6
  43. package/esm/variable.js +32 -55
  44. package/esm/xsd.js +2 -2
  45. package/lib/blank-node.js +57 -80
  46. package/lib/class-order.js +1 -1
  47. package/lib/collection.js +70 -101
  48. package/lib/default-graph.js +14 -29
  49. package/lib/empty.js +9 -22
  50. package/lib/factories/canonical-data-factory.js +35 -31
  51. package/lib/factories/extended-term-factory.js +18 -13
  52. package/lib/factories/factory-types.js +1 -1
  53. package/lib/factories/rdflib-data-factory.js +9 -11
  54. package/lib/fetcher.js +1375 -1654
  55. package/lib/formula.js +632 -735
  56. package/lib/index.js +80 -84
  57. package/lib/jsonldparser.js +21 -32
  58. package/lib/jsonparser.js +1 -1
  59. package/lib/lists.js +47 -87
  60. package/lib/literal.js +121 -153
  61. package/lib/log.js +7 -7
  62. package/lib/n3parser.js +1012 -1090
  63. package/lib/named-node.js +70 -95
  64. package/lib/namespace.js +2 -4
  65. package/lib/node-internal.js +73 -94
  66. package/lib/node.js +1 -1
  67. package/lib/parse.js +5 -6
  68. package/lib/patch-parser.js +1 -1
  69. package/lib/query.js +20 -18
  70. package/lib/rdfaparser.js +778 -843
  71. package/lib/rdfxmlparser.js +351 -365
  72. package/lib/serialize.js +2 -2
  73. package/lib/serializer.js +840 -880
  74. package/lib/statement.js +55 -73
  75. package/lib/store.js +860 -958
  76. package/lib/types.js +21 -21
  77. package/lib/update-manager.js +970 -1102
  78. package/lib/updates-via.js +107 -132
  79. package/lib/uri.js +3 -3
  80. package/lib/utils/default-graph-uri.js +2 -2
  81. package/lib/utils/terms.js +4 -6
  82. package/lib/utils-js.js +8 -9
  83. package/lib/utils.js +6 -6
  84. package/lib/variable.js +35 -57
  85. package/lib/xsd.js +2 -2
  86. package/package.json +2 -2
  87. package/src/n3parser.js +1 -1
  88. package/src/serializer.js +1 -1
  89. package/src/update-manager.ts +2 -1
  90. package/.babelrc +0 -20
package/esm/rdfaparser.js CHANGED
@@ -1,5 +1,3 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
1
  // RDFa Parser for rdflib.js
4
2
 
5
3
  // Originally by: Alex Milowski
@@ -37,9 +35,8 @@ if (typeof Node === 'undefined') {
37
35
  NOTATION_NODE: 12
38
36
  };
39
37
  }
40
- var RDFaProcessor = /*#__PURE__*/function () {
41
- function RDFaProcessor(kb, options) {
42
- _classCallCheck(this, RDFaProcessor);
38
+ export default class RDFaProcessor {
39
+ constructor(kb, options) {
43
40
  this.options = options || {};
44
41
  this.kb = kb;
45
42
  this.target = options.target || {
@@ -68,958 +65,895 @@ var RDFaProcessor = /*#__PURE__*/function () {
68
65
  this.finishedHandlers = [];
69
66
  this.init();
70
67
  }
71
- return _createClass(RDFaProcessor, [{
72
- key: "addTriple",
73
- value: function addTriple(origin, subject, predicate, object) {
74
- var su, ob, pr, or;
75
- if (typeof subject === 'undefined') {
76
- su = rdf.namedNode(this.options.base);
77
- } else {
78
- su = this.toRDFNodeObject(subject);
79
- }
80
- pr = this.toRDFNodeObject(predicate);
81
- ob = this.toRDFNodeObject(object);
82
- or = rdf.namedNode(this.options.base);
83
- // console.log('Adding { ' + su + ' ' + pr + ' ' + ob + ' ' + or + ' }')
84
- this.kb.add(su, pr, ob, or);
68
+ addTriple(origin, subject, predicate, object) {
69
+ var su, ob, pr, or;
70
+ if (typeof subject === 'undefined') {
71
+ su = rdf.namedNode(this.options.base);
72
+ } else {
73
+ su = this.toRDFNodeObject(subject);
85
74
  }
86
- }, {
87
- key: "ancestorPath",
88
- value: function ancestorPath(node) {
89
- var path = '';
90
- while (node && node.nodeType !== Node.DOCUMENT_NODE) {
91
- path = '/' + node.localName + path;
92
- node = node.parentNode;
93
- }
94
- return path;
75
+ pr = this.toRDFNodeObject(predicate);
76
+ ob = this.toRDFNodeObject(object);
77
+ or = rdf.namedNode(this.options.base);
78
+ // console.log('Adding { ' + su + ' ' + pr + ' ' + ob + ' ' + or + ' }')
79
+ this.kb.add(su, pr, ob, or);
80
+ }
81
+ ancestorPath(node) {
82
+ var path = '';
83
+ while (node && node.nodeType !== Node.DOCUMENT_NODE) {
84
+ path = '/' + node.localName + path;
85
+ node = node.parentNode;
95
86
  }
96
- }, {
97
- key: "copyMappings",
98
- value: function copyMappings(mappings) {
99
- var newMappings = {};
100
- for (var k in mappings) {
101
- newMappings[k] = mappings[k];
87
+ return path;
88
+ }
89
+ copyMappings(mappings) {
90
+ var newMappings = {};
91
+ for (var k in mappings) {
92
+ newMappings[k] = mappings[k];
93
+ }
94
+ return newMappings;
95
+ }
96
+ copyProperties() {}
97
+ deriveDateTimeType(value) {
98
+ for (var i = 0; i < RDFaProcessor.dateTimeTypes.length; i++) {
99
+ // console.log("Checking "+value+" against "+RDFaProcessor.dateTimeTypes[i].type)
100
+ var matched = RDFaProcessor.dateTimeTypes[i].pattern.exec(value);
101
+ if (matched && matched[0].length === value.length) {
102
+ // console.log("Matched!")
103
+ return RDFaProcessor.dateTimeTypes[i].type;
102
104
  }
103
- return newMappings;
104
105
  }
105
- }, {
106
- key: "copyProperties",
107
- value: function copyProperties() {}
108
- }, {
109
- key: "deriveDateTimeType",
110
- value: function deriveDateTimeType(value) {
111
- for (var i = 0; i < RDFaProcessor.dateTimeTypes.length; i++) {
112
- // console.log("Checking "+value+" against "+RDFaProcessor.dateTimeTypes[i].type)
113
- var matched = RDFaProcessor.dateTimeTypes[i].pattern.exec(value);
114
- if (matched && matched[0].length === value.length) {
115
- // console.log("Matched!")
116
- return RDFaProcessor.dateTimeTypes[i].type;
106
+ return null;
107
+ }
108
+ init() {}
109
+ newBlankNode() {
110
+ this.blankCounter++;
111
+ return '_:' + this.blankCounter;
112
+ }
113
+ newSubjectOrigin(origin, subject) {}
114
+ parseCURIE(value, prefixes, base) {
115
+ var colon = value.indexOf(':');
116
+ var uri;
117
+ if (colon >= 0) {
118
+ var prefix = value.substring(0, colon);
119
+ if (prefix === '') {
120
+ // default prefix
121
+ uri = prefixes[''];
122
+ return uri ? uri + value.substring(colon + 1) : null;
123
+ } else if (prefix === '_') {
124
+ // blank node
125
+ return '_:' + value.substring(colon + 1);
126
+ } else if (RDFaProcessor.NCNAME.test(prefix)) {
127
+ uri = prefixes[prefix];
128
+ if (uri) {
129
+ return uri + value.substring(colon + 1);
117
130
  }
118
131
  }
119
- return null;
120
132
  }
121
- }, {
122
- key: "init",
123
- value: function init() {}
124
- }, {
125
- key: "newBlankNode",
126
- value: function newBlankNode() {
127
- this.blankCounter++;
128
- return '_:' + this.blankCounter;
133
+ return null;
134
+ }
135
+ parseCURIEOrURI(value, prefixes, base) {
136
+ var curie = this.parseCURIE(value, prefixes, base);
137
+ if (curie) {
138
+ return curie;
129
139
  }
130
- }, {
131
- key: "newSubjectOrigin",
132
- value: function newSubjectOrigin(origin, subject) {}
133
- }, {
134
- key: "parseCURIE",
135
- value: function parseCURIE(value, prefixes, base) {
136
- var colon = value.indexOf(':');
137
- var uri;
138
- if (colon >= 0) {
139
- var prefix = value.substring(0, colon);
140
- if (prefix === '') {
141
- // default prefix
142
- uri = prefixes[''];
143
- return uri ? uri + value.substring(colon + 1) : null;
144
- } else if (prefix === '_') {
145
- // blank node
146
- return '_:' + value.substring(colon + 1);
147
- } else if (RDFaProcessor.NCNAME.test(prefix)) {
148
- uri = prefixes[prefix];
149
- if (uri) {
150
- return uri + value.substring(colon + 1);
151
- }
152
- }
153
- }
140
+ return this.resolveAndNormalize(base, value);
141
+ }
142
+ parsePredicate(value, defaultVocabulary, terms, prefixes, base, ignoreTerms) {
143
+ if (value === '') {
144
+ return null;
145
+ }
146
+ var predicate = this.parseTermOrCURIEOrAbsURI(value, defaultVocabulary, ignoreTerms ? null : terms, prefixes, base);
147
+ if (predicate && predicate.indexOf('_:') === 0) {
154
148
  return null;
155
149
  }
156
- }, {
157
- key: "parseCURIEOrURI",
158
- value: function parseCURIEOrURI(value, prefixes, base) {
159
- var curie = this.parseCURIE(value, prefixes, base);
160
- if (curie) {
161
- return curie;
150
+ return predicate;
151
+ }
152
+ parsePrefixMappings(str, target) {
153
+ var values = this.tokenize(str);
154
+ var prefix = null;
155
+ // var uri = null
156
+ for (var i = 0; i < values.length; i++) {
157
+ if (values[i][values[i].length - 1] === ':') {
158
+ prefix = values[i].substring(0, values[i].length - 1);
159
+ } else if (prefix) {
160
+ target[prefix] = this.options.base ? Uri.join(values[i], this.options.base) : values[i];
161
+ prefix = null;
162
162
  }
163
- return this.resolveAndNormalize(base, value);
164
163
  }
165
- }, {
166
- key: "parsePredicate",
167
- value: function parsePredicate(value, defaultVocabulary, terms, prefixes, base, ignoreTerms) {
168
- if (value === '') {
164
+ }
165
+ static parseRDFaDOM(dom, kb, base) {
166
+ var p = new RDFaProcessor(kb, {
167
+ 'base': base
168
+ });
169
+ // Cannot assign to read only property 'baseURI' of object '#<XMLDocument>':
170
+ if (!dom.baseURI) {
171
+ // Note this became a read-only attribute some time before 2018
172
+ dom.baseURI = base; // oinly set if not already set
173
+ }
174
+ p.process(dom, {
175
+ baseURI: base
176
+ });
177
+ }
178
+ parseSafeCURIEOrCURIEOrURI(value, prefixes, base) {
179
+ value = this.trim(value);
180
+ if (value.charAt(0) === '[' && value.charAt(value.length - 1) === ']') {
181
+ value = value.substring(1, value.length - 1);
182
+ value = value.trim(value);
183
+ if (value.length === 0) {
169
184
  return null;
170
185
  }
171
- var predicate = this.parseTermOrCURIEOrAbsURI(value, defaultVocabulary, ignoreTerms ? null : terms, prefixes, base);
172
- if (predicate && predicate.indexOf('_:') === 0) {
173
- return null;
186
+ if (value === '_:') {
187
+ // the one node
188
+ return this.theOne;
174
189
  }
175
- return predicate;
190
+ return this.parseCURIE(value, prefixes, base);
191
+ } else {
192
+ return this.parseCURIEOrURI(value, prefixes, base);
176
193
  }
177
- }, {
178
- key: "parsePrefixMappings",
179
- value: function parsePrefixMappings(str, target) {
180
- var values = this.tokenize(str);
181
- var prefix = null;
182
- // var uri = null
183
- for (var i = 0; i < values.length; i++) {
184
- if (values[i][values[i].length - 1] === ':') {
185
- prefix = values[i].substring(0, values[i].length - 1);
186
- } else if (prefix) {
187
- target[prefix] = this.options.base ? Uri.join(values[i], this.options.base) : values[i];
188
- prefix = null;
189
- }
194
+ }
195
+ parseTermOrCURIEOrAbsURI(value, defaultVocabulary, terms, prefixes, base) {
196
+ // alert("Parsing "+value+" with default vocab "+defaultVocabulary)
197
+ value = this.trim(value);
198
+ var curie = this.parseCURIE(value, prefixes, base);
199
+ if (curie) {
200
+ return curie;
201
+ } else if (terms) {
202
+ if (defaultVocabulary && !this.absURIRE.exec(value)) {
203
+ return defaultVocabulary + value;
190
204
  }
191
- }
192
- }, {
193
- key: "parseSafeCURIEOrCURIEOrURI",
194
- value: function parseSafeCURIEOrCURIEOrURI(value, prefixes, base) {
195
- value = this.trim(value);
196
- if (value.charAt(0) === '[' && value.charAt(value.length - 1) === ']') {
197
- value = value.substring(1, value.length - 1);
198
- value = value.trim(value);
199
- if (value.length === 0) {
200
- return null;
201
- }
202
- if (value === '_:') {
203
- // the one node
204
- return this.theOne;
205
- }
206
- return this.parseCURIE(value, prefixes, base);
207
- } else {
208
- return this.parseCURIEOrURI(value, prefixes, base);
205
+ var term = terms[value];
206
+ if (term) {
207
+ return term;
208
+ }
209
+ var lcvalue = value.toLowerCase();
210
+ term = terms[lcvalue];
211
+ if (term) {
212
+ return term;
209
213
  }
210
214
  }
211
- }, {
212
- key: "parseTermOrCURIEOrAbsURI",
213
- value: function parseTermOrCURIEOrAbsURI(value, defaultVocabulary, terms, prefixes, base) {
214
- // alert("Parsing "+value+" with default vocab "+defaultVocabulary)
215
- value = this.trim(value);
216
- var curie = this.parseCURIE(value, prefixes, base);
217
- if (curie) {
218
- return curie;
219
- } else if (terms) {
220
- if (defaultVocabulary && !this.absURIRE.exec(value)) {
221
- return defaultVocabulary + value;
222
- }
223
- var term = terms[value];
224
- if (term) {
225
- return term;
226
- }
227
- var lcvalue = value.toLowerCase();
228
- term = terms[lcvalue];
229
- if (term) {
230
- return term;
231
- }
215
+ if (this.absURIRE.exec(value)) {
216
+ return this.resolveAndNormalize(base, value);
217
+ }
218
+ return null;
219
+ }
220
+ parseTermOrCURIEOrURI(value, defaultVocabulary, terms, prefixes, base) {
221
+ // alert("Parsing "+value+" with default vocab "+defaultVocabulary)
222
+ value = this.trim(value);
223
+ var curie = this.parseCURIE(value, prefixes, base);
224
+ if (curie) {
225
+ return curie;
226
+ } else {
227
+ var term = terms[value];
228
+ if (term) {
229
+ return term;
232
230
  }
233
- if (this.absURIRE.exec(value)) {
234
- return this.resolveAndNormalize(base, value);
231
+ var lcvalue = value.toLowerCase();
232
+ term = terms[lcvalue];
233
+ if (term) {
234
+ return term;
235
235
  }
236
- return null;
237
- }
238
- }, {
239
- key: "parseTermOrCURIEOrURI",
240
- value: function parseTermOrCURIEOrURI(value, defaultVocabulary, terms, prefixes, base) {
241
- // alert("Parsing "+value+" with default vocab "+defaultVocabulary)
242
- value = this.trim(value);
243
- var curie = this.parseCURIE(value, prefixes, base);
244
- if (curie) {
245
- return curie;
246
- } else {
247
- var term = terms[value];
248
- if (term) {
249
- return term;
250
- }
251
- var lcvalue = value.toLowerCase();
252
- term = terms[lcvalue];
253
- if (term) {
254
- return term;
255
- }
256
- if (defaultVocabulary && !this.absURIRE.exec(value)) {
257
- return defaultVocabulary + value;
258
- }
236
+ if (defaultVocabulary && !this.absURIRE.exec(value)) {
237
+ return defaultVocabulary + value;
259
238
  }
260
- return this.resolveAndNormalize(base, value);
261
239
  }
262
- }, {
263
- key: "parseURI",
264
- value: function parseURI(uri) {
265
- return uri; // We just use strings as URIs, not objects now.
240
+ return this.resolveAndNormalize(base, value);
241
+ }
242
+ parseURI(uri) {
243
+ return uri; // We just use strings as URIs, not objects now.
244
+ }
245
+ process(node, options) {
246
+ /*
247
+ if (!window.console) {
248
+ window.console = { log: function() {} }
249
+ } */
250
+ options = options || {};
251
+ var base;
252
+ if (node.nodeType === Node.DOCUMENT_NODE) {
253
+ if (node.baseURI && !options.baseURI) {
254
+ options.baseURI = node.baseURI; // be defensive as DOM implementations vary
255
+ }
256
+ base = node.baseURI;
257
+ node = node.documentElement;
258
+ if (!node.baseURI) {
259
+ node.baseURI = base;
260
+ }
261
+ this.setContext(node);
262
+ } else if (node.parentNode.nodeType === Node.DOCUMENT_NODE) {
263
+ this.setContext(node);
266
264
  }
267
- }, {
268
- key: "process",
269
- value: function process(node, options) {
270
- /*
271
- if (!window.console) {
272
- window.console = { log: function() {} }
273
- } */
274
- options = options || {};
275
- var base;
276
- if (node.nodeType === Node.DOCUMENT_NODE) {
277
- if (node.baseURI && !options.baseURI) {
278
- options.baseURI = node.baseURI; // be defensive as DOM implementations vary
279
- }
280
- base = node.baseURI;
281
- node = node.documentElement;
282
- if (!node.baseURI) {
283
- node.baseURI = base;
284
- }
285
- this.setContext(node);
286
- } else if (node.parentNode.nodeType === Node.DOCUMENT_NODE) {
287
- this.setContext(node);
265
+ var queue = [];
266
+ // Fix for Firefox that includes the hash in the base URI
267
+ var removeHash = function (baseURI) {
268
+ // Fix for undefined baseURI property
269
+ if (!baseURI && options && options.baseURI) {
270
+ return options.baseURI;
288
271
  }
289
- var queue = [];
290
- // Fix for Firefox that includes the hash in the base URI
291
- var removeHash = function removeHash(baseURI) {
292
- // Fix for undefined baseURI property
293
- if (!baseURI && options && options.baseURI) {
294
- return options.baseURI;
295
- }
296
- var hash = baseURI.indexOf('#');
297
- if (hash >= 0) {
298
- baseURI = baseURI.substring(0, hash);
299
- }
300
- if (options && options.baseURIMap) {
301
- baseURI = options.baseURIMap(baseURI);
272
+ var hash = baseURI.indexOf('#');
273
+ if (hash >= 0) {
274
+ baseURI = baseURI.substring(0, hash);
275
+ }
276
+ if (options && options.baseURIMap) {
277
+ baseURI = options.baseURIMap(baseURI);
278
+ }
279
+ return baseURI;
280
+ };
281
+ queue.push({
282
+ current: node,
283
+ context: this.push(null, removeHash(node.baseURI))
284
+ });
285
+ while (queue.length > 0) {
286
+ var item = queue.shift();
287
+ if (item.parent) {
288
+ // Sequence Step 14: list triple generation
289
+ if (item.context.parent && item.context.parent.listMapping === item.listMapping) {
290
+ // Skip a child context with exactly the same mapping
291
+ continue;
302
292
  }
303
- return baseURI;
304
- };
305
- queue.push({
306
- current: node,
307
- context: this.push(null, removeHash(node.baseURI))
308
- });
309
- while (queue.length > 0) {
310
- var item = queue.shift();
311
- if (item.parent) {
312
- // Sequence Step 14: list triple generation
313
- if (item.context.parent && item.context.parent.listMapping === item.listMapping) {
314
- // Skip a child context with exactly the same mapping
315
- continue;
316
- }
317
- // console.log("Generating lists for "+item.subject+", tag "+item.parent.localName)
318
- for (var _predicate in item.listMapping) {
319
- var list = item.listMapping[_predicate];
320
- if (list.length === 0) {
321
- this.addTriple(item.parent, item.subject, _predicate, {
322
- type: RDFaProcessor.objectURI,
323
- value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
324
- });
325
- continue;
326
- }
327
- var bnodes = [];
328
- for (var _i = 0; _i < list.length; _i++) {
329
- bnodes.push(this.newBlankNode());
330
- // this.newSubject(item.parent,bnodes[i])
331
- }
332
- for (var _i2 = 0; _i2 < bnodes.length; _i2++) {
333
- this.addTriple(item.parent, bnodes[_i2], 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', list[_i2]);
334
- this.addTriple(item.parent, bnodes[_i2], 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', {
335
- type: RDFaProcessor.objectURI,
336
- value: _i2 + 1 < bnodes.length ? bnodes[_i2 + 1] : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
337
- });
338
- }
339
- this.addTriple(item.parent, item.subject, _predicate, {
293
+ // console.log("Generating lists for "+item.subject+", tag "+item.parent.localName)
294
+ for (let predicate in item.listMapping) {
295
+ var list = item.listMapping[predicate];
296
+ if (list.length === 0) {
297
+ this.addTriple(item.parent, item.subject, predicate, {
340
298
  type: RDFaProcessor.objectURI,
341
- value: bnodes[0]
299
+ value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
342
300
  });
301
+ continue;
343
302
  }
344
- continue;
345
- }
346
- var current = item.current;
347
- var context = item.context;
348
- // console.log("Tag: "+current.localName+", listMapping="+JSON.stringify(context.listMapping))
349
- // Sequence Step 1
350
- var skip = false;
351
- var newSubject = null;
352
- var currentObjectResource = null;
353
- var typedResource = null;
354
- var prefixes = context.prefixes;
355
- var prefixesCopied = false;
356
- var incomplete = [];
357
- var listMapping = context.listMapping;
358
- var listMappingDifferent = !context.parent;
359
- var language = context.language;
360
- var vocabulary = context.vocabulary;
361
- // TODO: the "base" element may be used for HTML+RDFa 1.1
362
- base = this.parseURI(removeHash(current.baseURI));
363
- current.item = null;
364
- // Sequence Step 2: set the default vocabulary
365
- var vocabAtt = current.getAttributeNode('vocab');
366
- if (vocabAtt) {
367
- var value = this.trim(vocabAtt.value);
368
- if (value.length > 0) {
369
- vocabulary = value;
370
- var baseSubject = base.spec;
371
- // this.newSubject(current,baseSubject)
372
- this.addTriple(current, baseSubject, 'http://www.w3.org/ns/rdfa#usesVocabulary', {
303
+ var bnodes = [];
304
+ for (let i = 0; i < list.length; i++) {
305
+ bnodes.push(this.newBlankNode());
306
+ // this.newSubject(item.parent,bnodes[i])
307
+ }
308
+ for (let i = 0; i < bnodes.length; i++) {
309
+ this.addTriple(item.parent, bnodes[i], 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', list[i]);
310
+ this.addTriple(item.parent, bnodes[i], 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', {
373
311
  type: RDFaProcessor.objectURI,
374
- value: vocabulary
312
+ value: i + 1 < bnodes.length ? bnodes[i + 1] : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
375
313
  });
376
- } else {
377
- vocabulary = this.vocabulary;
378
314
  }
315
+ this.addTriple(item.parent, item.subject, predicate, {
316
+ type: RDFaProcessor.objectURI,
317
+ value: bnodes[0]
318
+ });
379
319
  }
380
- // Sequence Step 3: IRI mappings
381
- // handle xmlns attributes
382
- for (var i = 0; i < current.attributes.length; i++) {
383
- var att = current.attributes[i];
384
- // if (att.namespaceURI=="http://www.w3.org/2000/xmlns/") {
385
- if (att.nodeName.charAt(0) === 'x' && att.nodeName.indexOf('xmlns:') === 0) {
386
- if (!prefixesCopied) {
387
- prefixes = this.copyMappings(prefixes);
388
- prefixesCopied = true;
389
- }
390
- var prefix = att.nodeName.substring(6);
391
- // TODO: resolve relative?
392
- var ref = RDFaProcessor.trim(att.value);
393
- prefixes[prefix] = this.options.base ? Uri.join(ref, this.options.base) : ref;
394
- }
320
+ continue;
321
+ }
322
+ var current = item.current;
323
+ var context = item.context;
324
+ // console.log("Tag: "+current.localName+", listMapping="+JSON.stringify(context.listMapping))
325
+ // Sequence Step 1
326
+ var skip = false;
327
+ var newSubject = null;
328
+ var currentObjectResource = null;
329
+ var typedResource = null;
330
+ var prefixes = context.prefixes;
331
+ var prefixesCopied = false;
332
+ var incomplete = [];
333
+ var listMapping = context.listMapping;
334
+ var listMappingDifferent = !context.parent;
335
+ var language = context.language;
336
+ var vocabulary = context.vocabulary;
337
+ // TODO: the "base" element may be used for HTML+RDFa 1.1
338
+ base = this.parseURI(removeHash(current.baseURI));
339
+ current.item = null;
340
+ // Sequence Step 2: set the default vocabulary
341
+ var vocabAtt = current.getAttributeNode('vocab');
342
+ if (vocabAtt) {
343
+ let value = this.trim(vocabAtt.value);
344
+ if (value.length > 0) {
345
+ vocabulary = value;
346
+ var baseSubject = base.spec;
347
+ // this.newSubject(current,baseSubject)
348
+ this.addTriple(current, baseSubject, 'http://www.w3.org/ns/rdfa#usesVocabulary', {
349
+ type: RDFaProcessor.objectURI,
350
+ value: vocabulary
351
+ });
352
+ } else {
353
+ vocabulary = this.vocabulary;
395
354
  }
396
- // Handle prefix mappings (@prefix)
397
- var prefixAtt = current.getAttributeNode('prefix');
398
- if (prefixAtt) {
355
+ }
356
+ // Sequence Step 3: IRI mappings
357
+ // handle xmlns attributes
358
+ for (var i = 0; i < current.attributes.length; i++) {
359
+ var att = current.attributes[i];
360
+ // if (att.namespaceURI=="http://www.w3.org/2000/xmlns/") {
361
+ if (att.nodeName.charAt(0) === 'x' && att.nodeName.indexOf('xmlns:') === 0) {
399
362
  if (!prefixesCopied) {
400
363
  prefixes = this.copyMappings(prefixes);
401
364
  prefixesCopied = true;
402
365
  }
403
- this.parsePrefixMappings(prefixAtt.value, prefixes);
366
+ var prefix = att.nodeName.substring(6);
367
+ // TODO: resolve relative?
368
+ var ref = RDFaProcessor.trim(att.value);
369
+ prefixes[prefix] = this.options.base ? Uri.join(ref, this.options.base) : ref;
404
370
  }
405
- // Sequence Step 4: language
406
- var xmlLangAtt = null;
407
- for (var _i3 = 0; !xmlLangAtt && _i3 < this.langAttributes.length; _i3++) {
408
- xmlLangAtt = current.getAttributeNodeNS(this.langAttributes[_i3].namespaceURI, this.langAttributes[_i3].localName);
371
+ }
372
+ // Handle prefix mappings (@prefix)
373
+ var prefixAtt = current.getAttributeNode('prefix');
374
+ if (prefixAtt) {
375
+ if (!prefixesCopied) {
376
+ prefixes = this.copyMappings(prefixes);
377
+ prefixesCopied = true;
378
+ }
379
+ this.parsePrefixMappings(prefixAtt.value, prefixes);
380
+ }
381
+ // Sequence Step 4: language
382
+ var xmlLangAtt = null;
383
+ for (let i = 0; !xmlLangAtt && i < this.langAttributes.length; i++) {
384
+ xmlLangAtt = current.getAttributeNodeNS(this.langAttributes[i].namespaceURI, this.langAttributes[i].localName);
385
+ }
386
+ if (xmlLangAtt) {
387
+ let value = RDFaProcessor.trim(xmlLangAtt.value);
388
+ if (value.length > 0) {
389
+ language = value;
390
+ } else {
391
+ language = null;
409
392
  }
410
- if (xmlLangAtt) {
411
- var _value = RDFaProcessor.trim(xmlLangAtt.value);
412
- if (_value.length > 0) {
413
- language = _value;
414
- } else {
415
- language = null;
393
+ }
394
+ var relAtt = current.getAttributeNode('rel');
395
+ var revAtt = current.getAttributeNode('rev');
396
+ var typeofAtt = current.getAttributeNode('typeof');
397
+ var propertyAtt = current.getAttributeNode('property');
398
+ var datatypeAtt = current.getAttributeNode('datatype');
399
+ var datetimeAtt = this.inHTMLMode ? current.getAttributeNode('datetime') : null;
400
+ var contentAtt = current.getAttributeNode('content');
401
+ var aboutAtt = current.getAttributeNode('about');
402
+ var srcAtt = current.getAttributeNode('src');
403
+ var resourceAtt = current.getAttributeNode('resource');
404
+ var hrefAtt = current.getAttributeNode('href');
405
+ var inlistAtt = current.getAttributeNode('inlist');
406
+ var relAttPredicates = [];
407
+ var predicate, values;
408
+ if (relAtt) {
409
+ values = this.tokenize(relAtt.value);
410
+ for (let i = 0; i < values.length; i++) {
411
+ predicate = this.parsePredicate(values[i], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt !== null);
412
+ if (predicate) {
413
+ relAttPredicates.push(predicate);
416
414
  }
417
415
  }
418
- var relAtt = current.getAttributeNode('rel');
419
- var revAtt = current.getAttributeNode('rev');
420
- var typeofAtt = current.getAttributeNode('typeof');
421
- var propertyAtt = current.getAttributeNode('property');
422
- var datatypeAtt = current.getAttributeNode('datatype');
423
- var datetimeAtt = this.inHTMLMode ? current.getAttributeNode('datetime') : null;
424
- var contentAtt = current.getAttributeNode('content');
425
- var aboutAtt = current.getAttributeNode('about');
426
- var srcAtt = current.getAttributeNode('src');
427
- var resourceAtt = current.getAttributeNode('resource');
428
- var hrefAtt = current.getAttributeNode('href');
429
- var inlistAtt = current.getAttributeNode('inlist');
430
- var relAttPredicates = [];
431
- var predicate, values;
432
- if (relAtt) {
433
- values = this.tokenize(relAtt.value);
434
- for (var _i4 = 0; _i4 < values.length; _i4++) {
435
- predicate = this.parsePredicate(values[_i4], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt !== null);
436
- if (predicate) {
437
- relAttPredicates.push(predicate);
438
- }
416
+ }
417
+ var revAttPredicates = [];
418
+ if (revAtt) {
419
+ values = this.tokenize(revAtt.value);
420
+ for (let i = 0; i < values.length; i++) {
421
+ predicate = this.parsePredicate(values[i], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt);
422
+ if (predicate) {
423
+ revAttPredicates.push(predicate);
439
424
  }
440
425
  }
441
- var revAttPredicates = [];
442
- if (revAtt) {
443
- values = this.tokenize(revAtt.value);
444
- for (var _i5 = 0; _i5 < values.length; _i5++) {
445
- predicate = this.parsePredicate(values[_i5], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt);
446
- if (predicate) {
447
- revAttPredicates.push(predicate);
448
- }
449
- }
426
+ }
427
+ // Section 3.1, bullet 7
428
+ if (this.inHTMLMode && (relAtt || revAtt) && propertyAtt) {
429
+ if (relAttPredicates.length === 0) {
430
+ relAtt = null;
450
431
  }
451
- // Section 3.1, bullet 7
452
- if (this.inHTMLMode && (relAtt || revAtt) && propertyAtt) {
453
- if (relAttPredicates.length === 0) {
454
- relAtt = null;
455
- }
456
- if (revAttPredicates.length === 0) {
457
- revAtt = null;
432
+ if (revAttPredicates.length === 0) {
433
+ revAtt = null;
434
+ }
435
+ }
436
+ if (relAtt || revAtt) {
437
+ // Sequence Step 6: establish new subject and value
438
+ if (aboutAtt) {
439
+ newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
440
+ }
441
+ if (typeofAtt) {
442
+ typedResource = newSubject;
443
+ }
444
+ if (!newSubject) {
445
+ if (current.parentNode.nodeType === Node.DOCUMENT_NODE) {
446
+ newSubject = removeHash(current.baseURI);
447
+ } else if (context.parentObject) {
448
+ // TODO: Verify: If the xml:base has been set and the parentObject is the baseURI of the parent, then the subject needs to be the new base URI
449
+ newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
458
450
  }
459
451
  }
460
- if (relAtt || revAtt) {
461
- // Sequence Step 6: establish new subject and value
462
- if (aboutAtt) {
463
- newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
452
+ if (resourceAtt) {
453
+ currentObjectResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
454
+ }
455
+ if (!currentObjectResource) {
456
+ if (hrefAtt) {
457
+ currentObjectResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
458
+ } else if (srcAtt) {
459
+ currentObjectResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
460
+ } else if (typeofAtt && !aboutAtt && !(this.inXHTMLMode && (current.localName === 'head' || current.localName === 'body'))) {
461
+ currentObjectResource = this.newBlankNode();
464
462
  }
463
+ }
464
+ if (typeofAtt && !aboutAtt && this.inXHTMLMode && (current.localName === 'head' || current.localName === 'body')) {
465
+ typedResource = newSubject;
466
+ } else if (typeofAtt && !aboutAtt) {
467
+ typedResource = currentObjectResource;
468
+ }
469
+ } else if (propertyAtt && !contentAtt && !datatypeAtt) {
470
+ // Sequence Step 5.1: establish a new subject
471
+ if (aboutAtt) {
472
+ newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
465
473
  if (typeofAtt) {
466
474
  typedResource = newSubject;
467
475
  }
468
- if (!newSubject) {
469
- if (current.parentNode.nodeType === Node.DOCUMENT_NODE) {
470
- newSubject = removeHash(current.baseURI);
471
- } else if (context.parentObject) {
472
- // TODO: Verify: If the xml:base has been set and the parentObject is the baseURI of the parent, then the subject needs to be the new base URI
473
- newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
474
- }
476
+ }
477
+ if (!newSubject && current.parentNode.nodeType === Node.DOCUMENT_NODE) {
478
+ newSubject = removeHash(current.baseURI);
479
+ if (typeofAtt) {
480
+ typedResource = newSubject;
475
481
  }
482
+ } else if (!newSubject && context.parentObject) {
483
+ // TODO: Verify: If the xml:base has been set and the parentObject is the baseURI of the parent, then the subject needs to be the new base URI
484
+ newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
485
+ }
486
+ if (typeofAtt && !typedResource) {
476
487
  if (resourceAtt) {
477
- currentObjectResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
488
+ typedResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
478
489
  }
479
- if (!currentObjectResource) {
480
- if (hrefAtt) {
481
- currentObjectResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
482
- } else if (srcAtt) {
483
- currentObjectResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
484
- } else if (typeofAtt && !aboutAtt && !(this.inXHTMLMode && (current.localName === 'head' || current.localName === 'body'))) {
485
- currentObjectResource = this.newBlankNode();
486
- }
490
+ if (!typedResource && hrefAtt) {
491
+ typedResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
487
492
  }
488
- if (typeofAtt && !aboutAtt && this.inXHTMLMode && (current.localName === 'head' || current.localName === 'body')) {
493
+ if (!typedResource && srcAtt) {
494
+ typedResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
495
+ }
496
+ if (!typedResource && (this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
489
497
  typedResource = newSubject;
490
- } else if (typeofAtt && !aboutAtt) {
491
- typedResource = currentObjectResource;
492
498
  }
493
- } else if (propertyAtt && !contentAtt && !datatypeAtt) {
494
- // Sequence Step 5.1: establish a new subject
495
- if (aboutAtt) {
496
- newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
497
- if (typeofAtt) {
498
- typedResource = newSubject;
499
- }
499
+ if (!typedResource) {
500
+ typedResource = this.newBlankNode();
500
501
  }
501
- if (!newSubject && current.parentNode.nodeType === Node.DOCUMENT_NODE) {
502
+ currentObjectResource = typedResource;
503
+ }
504
+ // console.log(current.localName+", newSubject="+newSubject+", typedResource="+typedResource+", currentObjectResource="+currentObjectResource)
505
+ } else {
506
+ // Sequence Step 5.2: establish a new subject
507
+ if (aboutAtt) {
508
+ newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
509
+ }
510
+ if (!newSubject && resourceAtt) {
511
+ newSubject = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
512
+ }
513
+ if (!newSubject && hrefAtt) {
514
+ newSubject = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
515
+ }
516
+ if (!newSubject && srcAtt) {
517
+ newSubject = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
518
+ }
519
+ if (!newSubject) {
520
+ if (current.parentNode.nodeType === Node.DOCUMENT_NODE) {
502
521
  newSubject = removeHash(current.baseURI);
503
- if (typeofAtt) {
504
- typedResource = newSubject;
505
- }
506
- } else if (!newSubject && context.parentObject) {
522
+ } else if ((this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
523
+ newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
524
+ } else if (typeofAtt) {
525
+ newSubject = this.newBlankNode();
526
+ } else if (context.parentObject) {
507
527
  // TODO: Verify: If the xml:base has been set and the parentObject is the baseURI of the parent, then the subject needs to be the new base URI
508
528
  newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
509
- }
510
- if (typeofAtt && !typedResource) {
511
- if (resourceAtt) {
512
- typedResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
513
- }
514
- if (!typedResource && hrefAtt) {
515
- typedResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
516
- }
517
- if (!typedResource && srcAtt) {
518
- typedResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
529
+ if (!propertyAtt) {
530
+ skip = true;
519
531
  }
520
- if (!typedResource && (this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
521
- typedResource = newSubject;
522
- }
523
- if (!typedResource) {
524
- typedResource = this.newBlankNode();
525
- }
526
- currentObjectResource = typedResource;
527
- }
528
- // console.log(current.localName+", newSubject="+newSubject+", typedResource="+typedResource+", currentObjectResource="+currentObjectResource)
529
- } else {
530
- // Sequence Step 5.2: establish a new subject
531
- if (aboutAtt) {
532
- newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
533
532
  }
534
- if (!newSubject && resourceAtt) {
535
- newSubject = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
536
- }
537
- if (!newSubject && hrefAtt) {
538
- newSubject = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
539
- }
540
- if (!newSubject && srcAtt) {
541
- newSubject = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
533
+ }
534
+ if (typeofAtt) {
535
+ typedResource = newSubject;
536
+ }
537
+ }
538
+ // console.log(current.tagName+": newSubject="+newSubject+", currentObjectResource="+currentObjectResource+", typedResource="+typedResource+", skip="+skip)
539
+ // var rdfaData = null
540
+ if (newSubject) {
541
+ // this.newSubject(current,newSubject)
542
+ if (aboutAtt || resourceAtt || typedResource) {
543
+ var id = newSubject;
544
+ if (typeofAtt && !aboutAtt && !resourceAtt && currentObjectResource) {
545
+ id = currentObjectResource;
546
+ }
547
+ // console.log("Setting data attribute for "+current.localName+" for subject "+id)
548
+ this.newSubjectOrigin(current, id);
549
+ }
550
+ }
551
+ // Sequence Step 7: generate type triple
552
+ if (typedResource) {
553
+ values = this.tokenize(typeofAtt.value);
554
+ for (let i = 0; i < values.length; i++) {
555
+ var object = this.parseTermOrCURIEOrAbsURI(values[i], vocabulary, context.terms, prefixes, base);
556
+ if (object) {
557
+ this.addTriple(current, typedResource, RDFaProcessor.typeURI, {
558
+ type: RDFaProcessor.objectURI,
559
+ value: object
560
+ });
542
561
  }
543
- if (!newSubject) {
544
- if (current.parentNode.nodeType === Node.DOCUMENT_NODE) {
545
- newSubject = removeHash(current.baseURI);
546
- } else if ((this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
547
- newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
548
- } else if (typeofAtt) {
549
- newSubject = this.newBlankNode();
550
- } else if (context.parentObject) {
551
- // TODO: Verify: If the xml:base has been set and the parentObject is the baseURI of the parent, then the subject needs to be the new base URI
552
- newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
553
- if (!propertyAtt) {
554
- skip = true;
555
- }
556
- }
562
+ }
563
+ }
564
+ // Sequence Step 8: new list mappings if there is a new subject
565
+ // console.log("Step 8: newSubject="+newSubject+", context.parentObject="+context.parentObject)
566
+ if (newSubject && newSubject !== context.parentObject) {
567
+ // console.log("Generating new list mapping for "+newSubject)
568
+ listMapping = {};
569
+ listMappingDifferent = true;
570
+ }
571
+ // Sequence Step 9: generate object triple
572
+ if (currentObjectResource) {
573
+ if (relAtt && inlistAtt) {
574
+ for (let i = 0; i < relAttPredicates.length; i++) {
575
+ let list = listMapping[relAttPredicates[i]];
576
+ if (!list) {
577
+ list = [];
578
+ listMapping[relAttPredicates[i]] = list;
579
+ }
580
+ list.push({
581
+ type: RDFaProcessor.objectURI,
582
+ value: currentObjectResource
583
+ });
557
584
  }
558
- if (typeofAtt) {
559
- typedResource = newSubject;
585
+ } else if (relAtt) {
586
+ for (let i = 0; i < relAttPredicates.length; i++) {
587
+ this.addTriple(current, newSubject, relAttPredicates[i], {
588
+ type: RDFaProcessor.objectURI,
589
+ value: currentObjectResource
590
+ });
560
591
  }
561
592
  }
562
- // console.log(current.tagName+": newSubject="+newSubject+", currentObjectResource="+currentObjectResource+", typedResource="+typedResource+", skip="+skip)
563
- // var rdfaData = null
564
- if (newSubject) {
565
- // this.newSubject(current,newSubject)
566
- if (aboutAtt || resourceAtt || typedResource) {
567
- var id = newSubject;
568
- if (typeofAtt && !aboutAtt && !resourceAtt && currentObjectResource) {
569
- id = currentObjectResource;
570
- }
571
- // console.log("Setting data attribute for "+current.localName+" for subject "+id)
572
- this.newSubjectOrigin(current, id);
593
+ if (revAtt) {
594
+ for (let i = 0; i < revAttPredicates.length; i++) {
595
+ this.addTriple(current, currentObjectResource, revAttPredicates[i], {
596
+ type: RDFaProcessor.objectURI,
597
+ value: newSubject
598
+ });
573
599
  }
574
600
  }
575
- // Sequence Step 7: generate type triple
576
- if (typedResource) {
577
- values = this.tokenize(typeofAtt.value);
578
- for (var _i6 = 0; _i6 < values.length; _i6++) {
579
- var object = this.parseTermOrCURIEOrAbsURI(values[_i6], vocabulary, context.terms, prefixes, base);
580
- if (object) {
581
- this.addTriple(current, typedResource, RDFaProcessor.typeURI, {
582
- type: RDFaProcessor.objectURI,
583
- value: object
584
- });
585
- }
601
+ } else {
602
+ // Sequence Step 10: incomplete triples
603
+ if (newSubject && !currentObjectResource && (relAtt || revAtt)) {
604
+ currentObjectResource = this.newBlankNode();
605
+ // alert(current.tagName+": generated blank node, newSubject="+newSubject+" currentObjectResource="+currentObjectResource)
606
+ }
607
+ if (relAtt && inlistAtt) {
608
+ for (let i = 0; i < relAttPredicates.length; i++) {
609
+ let list = listMapping[relAttPredicates[i]];
610
+ if (!list) {
611
+ list = [];
612
+ listMapping[predicate] = list;
613
+ }
614
+ // console.log("Adding incomplete list for "+predicate)
615
+ incomplete.push({
616
+ predicate: relAttPredicates[i],
617
+ list: list
618
+ });
619
+ }
620
+ } else if (relAtt) {
621
+ for (let i = 0; i < relAttPredicates.length; i++) {
622
+ incomplete.push({
623
+ predicate: relAttPredicates[i],
624
+ forward: true
625
+ });
586
626
  }
587
627
  }
588
- // Sequence Step 8: new list mappings if there is a new subject
589
- // console.log("Step 8: newSubject="+newSubject+", context.parentObject="+context.parentObject)
590
- if (newSubject && newSubject !== context.parentObject) {
591
- // console.log("Generating new list mapping for "+newSubject)
592
- listMapping = {};
593
- listMappingDifferent = true;
628
+ if (revAtt) {
629
+ for (let i = 0; i < revAttPredicates.length; i++) {
630
+ incomplete.push({
631
+ predicate: revAttPredicates[i],
632
+ forward: false
633
+ });
634
+ }
594
635
  }
595
- // Sequence Step 9: generate object triple
596
- if (currentObjectResource) {
597
- if (relAtt && inlistAtt) {
598
- for (var _i7 = 0; _i7 < relAttPredicates.length; _i7++) {
599
- var _list = listMapping[relAttPredicates[_i7]];
600
- if (!_list) {
601
- _list = [];
602
- listMapping[relAttPredicates[_i7]] = _list;
603
- }
604
- _list.push({
605
- type: RDFaProcessor.objectURI,
606
- value: currentObjectResource
607
- });
608
- }
609
- } else if (relAtt) {
610
- for (var _i8 = 0; _i8 < relAttPredicates.length; _i8++) {
611
- this.addTriple(current, newSubject, relAttPredicates[_i8], {
612
- type: RDFaProcessor.objectURI,
613
- value: currentObjectResource
614
- });
615
- }
636
+ }
637
+ // Step 11: Current property values
638
+ if (propertyAtt) {
639
+ var datatype = null;
640
+ var content = null;
641
+ if (datatypeAtt) {
642
+ datatype = datatypeAtt.value === '' ? RDFaProcessor.PlainLiteralURI : this.parseTermOrCURIEOrAbsURI(datatypeAtt.value, vocabulary, context.terms, prefixes, base);
643
+ if (datetimeAtt && !contentAtt) {
644
+ content = datetimeAtt.value;
645
+ } else {
646
+ content = datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI ? null : contentAtt ? contentAtt.value : current.textContent;
647
+ }
648
+ } else if (contentAtt) {
649
+ datatype = RDFaProcessor.PlainLiteralURI;
650
+ content = contentAtt.value;
651
+ } else if (datetimeAtt) {
652
+ content = datetimeAtt.value;
653
+ datatype = RDFaProcessor.deriveDateTimeType(content);
654
+ if (!datatype) {
655
+ datatype = RDFaProcessor.PlainLiteralURI;
616
656
  }
617
- if (revAtt) {
618
- for (var _i9 = 0; _i9 < revAttPredicates.length; _i9++) {
619
- this.addTriple(current, currentObjectResource, revAttPredicates[_i9], {
620
- type: RDFaProcessor.objectURI,
621
- value: newSubject
622
- });
623
- }
657
+ } else if (!relAtt && !revAtt) {
658
+ if (resourceAtt) {
659
+ content = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
624
660
  }
625
- } else {
626
- // Sequence Step 10: incomplete triples
627
- if (newSubject && !currentObjectResource && (relAtt || revAtt)) {
628
- currentObjectResource = this.newBlankNode();
629
- // alert(current.tagName+": generated blank node, newSubject="+newSubject+" currentObjectResource="+currentObjectResource)
661
+ if (!content && hrefAtt) {
662
+ content = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
663
+ } else if (!content && srcAtt) {
664
+ content = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
630
665
  }
631
- if (relAtt && inlistAtt) {
632
- for (var _i10 = 0; _i10 < relAttPredicates.length; _i10++) {
633
- var _list2 = listMapping[relAttPredicates[_i10]];
634
- if (!_list2) {
635
- _list2 = [];
636
- listMapping[predicate] = _list2;
637
- }
638
- // console.log("Adding incomplete list for "+predicate)
639
- incomplete.push({
640
- predicate: relAttPredicates[_i10],
641
- list: _list2
642
- });
643
- }
644
- } else if (relAtt) {
645
- for (var _i11 = 0; _i11 < relAttPredicates.length; _i11++) {
646
- incomplete.push({
647
- predicate: relAttPredicates[_i11],
648
- forward: true
649
- });
650
- }
651
- }
652
- if (revAtt) {
653
- for (var _i12 = 0; _i12 < revAttPredicates.length; _i12++) {
654
- incomplete.push({
655
- predicate: revAttPredicates[_i12],
656
- forward: false
657
- });
658
- }
666
+ if (content) {
667
+ datatype = RDFaProcessor.objectURI;
659
668
  }
660
669
  }
661
- // Step 11: Current property values
662
- if (propertyAtt) {
663
- var datatype = null;
664
- var content = null;
665
- if (datatypeAtt) {
666
- datatype = datatypeAtt.value === '' ? RDFaProcessor.PlainLiteralURI : this.parseTermOrCURIEOrAbsURI(datatypeAtt.value, vocabulary, context.terms, prefixes, base);
667
- if (datetimeAtt && !contentAtt) {
668
- content = datetimeAtt.value;
669
- } else {
670
- content = datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI ? null : contentAtt ? contentAtt.value : current.textContent;
670
+ if (!datatype) {
671
+ if (typeofAtt && !aboutAtt) {
672
+ datatype = RDFaProcessor.objectURI;
673
+ content = typedResource;
674
+ } else {
675
+ content = current.textContent;
676
+ if (this.inHTMLMode && current.localName === 'time') {
677
+ datatype = RDFaProcessor.deriveDateTimeType(content);
671
678
  }
672
- } else if (contentAtt) {
673
- datatype = RDFaProcessor.PlainLiteralURI;
674
- content = contentAtt.value;
675
- } else if (datetimeAtt) {
676
- content = datetimeAtt.value;
677
- datatype = RDFaProcessor.deriveDateTimeType(content);
678
679
  if (!datatype) {
679
680
  datatype = RDFaProcessor.PlainLiteralURI;
680
681
  }
681
- } else if (!relAtt && !revAtt) {
682
- if (resourceAtt) {
683
- content = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
684
- }
685
- if (!content && hrefAtt) {
686
- content = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
687
- } else if (!content && srcAtt) {
688
- content = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
689
- }
690
- if (content) {
691
- datatype = RDFaProcessor.objectURI;
692
- }
693
682
  }
694
- if (!datatype) {
695
- if (typeofAtt && !aboutAtt) {
696
- datatype = RDFaProcessor.objectURI;
697
- content = typedResource;
698
- } else {
699
- content = current.textContent;
700
- if (this.inHTMLMode && current.localName === 'time') {
701
- datatype = RDFaProcessor.deriveDateTimeType(content);
702
- }
703
- if (!datatype) {
704
- datatype = RDFaProcessor.PlainLiteralURI;
683
+ }
684
+ values = this.tokenize(propertyAtt.value);
685
+ for (let i = 0; i < values.length; i++) {
686
+ let predicate = this.parsePredicate(values[i], vocabulary, context.terms, prefixes, base);
687
+ if (predicate) {
688
+ if (inlistAtt) {
689
+ let list = listMapping[predicate];
690
+ if (!list) {
691
+ list = [];
692
+ listMapping[predicate] = list;
705
693
  }
706
- }
707
- }
708
- values = this.tokenize(propertyAtt.value);
709
- for (var _i13 = 0; _i13 < values.length; _i13++) {
710
- var _predicate2 = this.parsePredicate(values[_i13], vocabulary, context.terms, prefixes, base);
711
- if (_predicate2) {
712
- if (inlistAtt) {
713
- var _list3 = listMapping[_predicate2];
714
- if (!_list3) {
715
- _list3 = [];
716
- listMapping[_predicate2] = _list3;
717
- }
718
- _list3.push(datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI ? {
694
+ list.push(datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI ? {
695
+ type: datatype,
696
+ value: current.childNodes
697
+ } : {
698
+ type: datatype || RDFaProcessor.PlainLiteralURI,
699
+ value: content,
700
+ language: language
701
+ });
702
+ } else {
703
+ if (datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI) {
704
+ this.addTriple(current, newSubject, predicate, {
719
705
  type: datatype,
720
706
  value: current.childNodes
721
- } : {
707
+ });
708
+ } else {
709
+ this.addTriple(current, newSubject, predicate, {
722
710
  type: datatype || RDFaProcessor.PlainLiteralURI,
723
711
  value: content,
724
712
  language: language
725
713
  });
726
- } else {
727
- if (datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI) {
728
- this.addTriple(current, newSubject, _predicate2, {
729
- type: datatype,
730
- value: current.childNodes
731
- });
732
- } else {
733
- this.addTriple(current, newSubject, _predicate2, {
734
- type: datatype || RDFaProcessor.PlainLiteralURI,
735
- value: content,
736
- language: language
737
- });
738
- // console.log(newSubject+" "+predicate+"="+content)
739
- }
714
+ // console.log(newSubject+" "+predicate+"="+content)
740
715
  }
741
716
  }
742
717
  }
743
718
  }
744
- // Sequence Step 12: complete incomplete triples with new subject
745
- if (newSubject && !skip) {
746
- for (var _i14 = 0; _i14 < context.incomplete.length; _i14++) {
747
- if (context.incomplete[_i14].list) {
748
- // console.log("Adding subject "+newSubject+" to list for "+context.incomplete[i].predicate)
749
- // TODO: it is unclear what to do here
750
- context.incomplete[_i14].list.push({
751
- type: RDFaProcessor.objectURI,
752
- value: newSubject
753
- });
754
- } else if (context.incomplete[_i14].forward) {
755
- // console.log(current.tagName+": completing forward triple "+context.incomplete[i].predicate+" with object="+newSubject)
756
- this.addTriple(current, context.subject, context.incomplete[_i14].predicate, {
757
- type: RDFaProcessor.objectURI,
758
- value: newSubject
759
- });
760
- } else {
761
- // console.log(current.tagName+": completing reverse triple with object="+context.subject)
762
- this.addTriple(current, newSubject, context.incomplete[_i14].predicate, {
763
- type: RDFaProcessor.objectURI,
764
- value: context.subject
765
- });
766
- }
719
+ }
720
+ // Sequence Step 12: complete incomplete triples with new subject
721
+ if (newSubject && !skip) {
722
+ for (let i = 0; i < context.incomplete.length; i++) {
723
+ if (context.incomplete[i].list) {
724
+ // console.log("Adding subject "+newSubject+" to list for "+context.incomplete[i].predicate)
725
+ // TODO: it is unclear what to do here
726
+ context.incomplete[i].list.push({
727
+ type: RDFaProcessor.objectURI,
728
+ value: newSubject
729
+ });
730
+ } else if (context.incomplete[i].forward) {
731
+ // console.log(current.tagName+": completing forward triple "+context.incomplete[i].predicate+" with object="+newSubject)
732
+ this.addTriple(current, context.subject, context.incomplete[i].predicate, {
733
+ type: RDFaProcessor.objectURI,
734
+ value: newSubject
735
+ });
736
+ } else {
737
+ // console.log(current.tagName+": completing reverse triple with object="+context.subject)
738
+ this.addTriple(current, newSubject, context.incomplete[i].predicate, {
739
+ type: RDFaProcessor.objectURI,
740
+ value: context.subject
741
+ });
767
742
  }
768
743
  }
769
- var childContext = null;
770
- var listSubject = newSubject;
771
- if (skip) {
772
- // TODO: should subject be null?
773
- childContext = this.push(context, context.subject);
774
- // TODO: should the entObject be passed along? If not, then intermediary children will keep properties from being associated with incomplete triples.
775
- // TODO: Verify: if the current baseURI has changed and the parentObject is the parent's base URI, then the baseURI should change
776
- childContext.parentObject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
777
- childContext.incomplete = context.incomplete;
778
- childContext.language = language;
779
- childContext.prefixes = prefixes;
780
- childContext.vocabulary = vocabulary;
781
- } else {
782
- childContext = this.push(context, newSubject);
783
- childContext.parentObject = currentObjectResource || newSubject || context.subject;
784
- childContext.prefixes = prefixes;
785
- childContext.incomplete = incomplete;
786
- if (currentObjectResource) {
787
- // console.log("Generating new list mapping for "+currentObjectResource)
788
- listSubject = currentObjectResource;
789
- listMapping = {};
790
- listMappingDifferent = true;
791
- }
792
- childContext.listMapping = listMapping;
793
- childContext.language = language;
794
- childContext.vocabulary = vocabulary;
744
+ }
745
+ var childContext = null;
746
+ var listSubject = newSubject;
747
+ if (skip) {
748
+ // TODO: should subject be null?
749
+ childContext = this.push(context, context.subject);
750
+ // TODO: should the entObject be passed along? If not, then intermediary children will keep properties from being associated with incomplete triples.
751
+ // TODO: Verify: if the current baseURI has changed and the parentObject is the parent's base URI, then the baseURI should change
752
+ childContext.parentObject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
753
+ childContext.incomplete = context.incomplete;
754
+ childContext.language = language;
755
+ childContext.prefixes = prefixes;
756
+ childContext.vocabulary = vocabulary;
757
+ } else {
758
+ childContext = this.push(context, newSubject);
759
+ childContext.parentObject = currentObjectResource || newSubject || context.subject;
760
+ childContext.prefixes = prefixes;
761
+ childContext.incomplete = incomplete;
762
+ if (currentObjectResource) {
763
+ // console.log("Generating new list mapping for "+currentObjectResource)
764
+ listSubject = currentObjectResource;
765
+ listMapping = {};
766
+ listMappingDifferent = true;
795
767
  }
796
- if (listMappingDifferent) {
797
- // console.log("Pushing list parent "+current.localName)
768
+ childContext.listMapping = listMapping;
769
+ childContext.language = language;
770
+ childContext.vocabulary = vocabulary;
771
+ }
772
+ if (listMappingDifferent) {
773
+ // console.log("Pushing list parent "+current.localName)
774
+ queue.unshift({
775
+ parent: current,
776
+ context: context,
777
+ subject: listSubject,
778
+ listMapping: listMapping
779
+ });
780
+ }
781
+ for (var child = current.lastChild; child; child = child.previousSibling) {
782
+ if (child.nodeType === Node.ELEMENT_NODE) {
783
+ // console.log("Pushing child "+child.localName)
784
+ // child.baseURI = current.baseURI
798
785
  queue.unshift({
799
- parent: current,
800
- context: context,
801
- subject: listSubject,
802
- listMapping: listMapping
786
+ current: child,
787
+ context: childContext
803
788
  });
804
789
  }
805
- for (var child = current.lastChild; child; child = child.previousSibling) {
806
- if (child.nodeType === Node.ELEMENT_NODE) {
807
- // console.log("Pushing child "+child.localName)
808
- // child.baseURI = current.baseURI
809
- queue.unshift({
810
- current: child,
811
- context: childContext
812
- });
813
- }
814
- }
815
- }
816
- if (this.inHTMLMode) {
817
- this.copyProperties();
818
- }
819
- for (var _i15 = 0; _i15 < this.finishedHandlers.length; _i15++) {
820
- this.finishedHandlers[_i15](node);
821
790
  }
822
791
  }
823
- }, {
824
- key: "push",
825
- value: function push(parent, subject) {
826
- return {
827
- parent: parent,
828
- subject: subject || (parent ? parent.subject : null),
829
- parentObject: null,
830
- incomplete: [],
831
- listMapping: parent ? parent.listMapping : {},
832
- language: parent ? parent.language : this.language,
833
- prefixes: parent ? parent.prefixes : this.target.graph.prefixes,
834
- terms: parent ? parent.terms : this.target.graph.terms,
835
- vocabulary: parent ? parent.vocabulary : this.vocabulary
836
- };
792
+ if (this.inHTMLMode) {
793
+ this.copyProperties();
837
794
  }
838
- }, {
839
- key: "resolveAndNormalize",
840
- value: function resolveAndNormalize(base, uri) {
841
- // console.log("Joining " + uri + " to " + base + " making " + Uri.join(uri, base))
842
- return Uri.join(uri, base); // @@ normalize?
795
+ for (let i = 0; i < this.finishedHandlers.length; i++) {
796
+ this.finishedHandlers[i](node);
843
797
  }
844
- }, {
845
- key: "setContext",
846
- value: function setContext(node) {
847
- // We only recognized XHTML+RDFa 1.1 if the version is set propertyly
848
- if (node.localName === 'html' && node.getAttribute('version') === 'XHTML+RDFa 1.1') {
849
- this.setXHTMLContext();
850
- } else if (node.localName === 'html' || node.namespaceURI === 'http://www.w3.org/1999/xhtml') {
851
- if (typeof document !== 'undefined' && document.doctype) {
852
- if (document.doctype.publicId === '-//W3C//DTD XHTML+RDFa 1.0//EN' && document.doctype.systemId === 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd') {
853
- console.log('WARNING: RDF 1.0 is not supported. Defaulting to HTML5 mode.');
854
- this.setHTMLContext();
855
- } else if (document.doctype.publicId === '-//W3C//DTD XHTML+RDFa 1.1//EN' && document.doctype.systemId === 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd') {
856
- this.setXHTMLContext();
857
- } else {
858
- this.setHTMLContext();
859
- }
798
+ }
799
+ push(parent, subject) {
800
+ return {
801
+ parent: parent,
802
+ subject: subject || (parent ? parent.subject : null),
803
+ parentObject: null,
804
+ incomplete: [],
805
+ listMapping: parent ? parent.listMapping : {},
806
+ language: parent ? parent.language : this.language,
807
+ prefixes: parent ? parent.prefixes : this.target.graph.prefixes,
808
+ terms: parent ? parent.terms : this.target.graph.terms,
809
+ vocabulary: parent ? parent.vocabulary : this.vocabulary
810
+ };
811
+ }
812
+ resolveAndNormalize(base, uri) {
813
+ // console.log("Joining " + uri + " to " + base + " making " + Uri.join(uri, base))
814
+ return Uri.join(uri, base); // @@ normalize?
815
+ }
816
+ setContext(node) {
817
+ // We only recognized XHTML+RDFa 1.1 if the version is set propertyly
818
+ if (node.localName === 'html' && node.getAttribute('version') === 'XHTML+RDFa 1.1') {
819
+ this.setXHTMLContext();
820
+ } else if (node.localName === 'html' || node.namespaceURI === 'http://www.w3.org/1999/xhtml') {
821
+ if (typeof document !== 'undefined' && document.doctype) {
822
+ if (document.doctype.publicId === '-//W3C//DTD XHTML+RDFa 1.0//EN' && document.doctype.systemId === 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd') {
823
+ console.log('WARNING: RDF 1.0 is not supported. Defaulting to HTML5 mode.');
824
+ this.setHTMLContext();
825
+ } else if (document.doctype.publicId === '-//W3C//DTD XHTML+RDFa 1.1//EN' && document.doctype.systemId === 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd') {
826
+ this.setXHTMLContext();
860
827
  } else {
861
828
  this.setHTMLContext();
862
829
  }
863
830
  } else {
864
- this.setXMLContext();
865
- }
866
- }
867
- }, {
868
- key: "setHTMLContext",
869
- value: function setHTMLContext() {
870
- this.setInitialContext();
871
- this.langAttributes = [{
872
- namespaceURI: 'http://www.w3.org/XML/1998/namespace',
873
- localName: 'lang'
874
- }, {
875
- namespaceURI: null,
876
- localName: 'lang'
877
- }];
878
- this.inXHTMLMode = false;
879
- this.inHTMLMode = true;
880
- }
881
- }, {
882
- key: "setInitialContext",
883
- value: function setInitialContext() {
884
- this.vocabulary = null;
885
- // By default, the prefixes are terms are loaded to the RDFa 1.1. standard within the graph constructor
886
- this.langAttributes = [{
887
- namespaceURI: 'http://www.w3.org/XML/1998/namespace',
888
- localName: 'lang'
889
- }];
890
- }
891
- }, {
892
- key: "setXHTMLContext",
893
- value: function setXHTMLContext() {
894
- this.setInitialContext();
895
- this.inXHTMLMode = true;
896
- this.inHTMLMode = false;
897
- this.langAttributes = [{
898
- namespaceURI: 'http://www.w3.org/XML/1998/namespace',
899
- localName: 'lang'
900
- }, {
901
- namespaceURI: null,
902
- localName: 'lang'
903
- }];
904
- // From http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1
905
- this.target.graph.terms['alternate'] = 'http://www.w3.org/1999/xhtml/vocab#alternate';
906
- this.target.graph.terms['appendix'] = 'http://www.w3.org/1999/xhtml/vocab#appendix';
907
- this.target.graph.terms['bookmark'] = 'http://www.w3.org/1999/xhtml/vocab#bookmark';
908
- this.target.graph.terms['cite'] = 'http://www.w3.org/1999/xhtml/vocab#cite';
909
- this.target.graph.terms['chapter'] = 'http://www.w3.org/1999/xhtml/vocab#chapter';
910
- this.target.graph.terms['contents'] = 'http://www.w3.org/1999/xhtml/vocab#contents';
911
- this.target.graph.terms['copyright'] = 'http://www.w3.org/1999/xhtml/vocab#copyright';
912
- this.target.graph.terms['first'] = 'http://www.w3.org/1999/xhtml/vocab#first';
913
- this.target.graph.terms['glossary'] = 'http://www.w3.org/1999/xhtml/vocab#glossary';
914
- this.target.graph.terms['help'] = 'http://www.w3.org/1999/xhtml/vocab#help';
915
- this.target.graph.terms['icon'] = 'http://www.w3.org/1999/xhtml/vocab#icon';
916
- this.target.graph.terms['index'] = 'http://www.w3.org/1999/xhtml/vocab#index';
917
- this.target.graph.terms['last'] = 'http://www.w3.org/1999/xhtml/vocab#last';
918
- this.target.graph.terms['license'] = 'http://www.w3.org/1999/xhtml/vocab#license';
919
- this.target.graph.terms['meta'] = 'http://www.w3.org/1999/xhtml/vocab#meta';
920
- this.target.graph.terms['next'] = 'http://www.w3.org/1999/xhtml/vocab#next';
921
- this.target.graph.terms['prev'] = 'http://www.w3.org/1999/xhtml/vocab#prev';
922
- this.target.graph.terms['previous'] = 'http://www.w3.org/1999/xhtml/vocab#previous';
923
- this.target.graph.terms['section'] = 'http://www.w3.org/1999/xhtml/vocab#section';
924
- this.target.graph.terms['stylesheet'] = 'http://www.w3.org/1999/xhtml/vocab#stylesheet';
925
- this.target.graph.terms['subsection'] = 'http://www.w3.org/1999/xhtml/vocab#subsection';
926
- this.target.graph.terms['start'] = 'http://www.w3.org/1999/xhtml/vocab#start';
927
- this.target.graph.terms['top'] = 'http://www.w3.org/1999/xhtml/vocab#top';
928
- this.target.graph.terms['up'] = 'http://www.w3.org/1999/xhtml/vocab#up';
929
- this.target.graph.terms['p3pv1'] = 'http://www.w3.org/1999/xhtml/vocab#p3pv1';
930
- // other
931
- this.target.graph.terms['related'] = 'http://www.w3.org/1999/xhtml/vocab#related';
932
- this.target.graph.terms['role'] = 'http://www.w3.org/1999/xhtml/vocab#role';
933
- this.target.graph.terms['transformation'] = 'http://www.w3.org/1999/xhtml/vocab#transformation';
934
- }
935
- }, {
936
- key: "setXMLContext",
937
- value: function setXMLContext() {
938
- this.setInitialContext();
939
- this.inXHTMLMode = false;
940
- this.inHTMLMode = false;
941
- }
942
- }, {
943
- key: "tokenize",
944
- value: function tokenize(str) {
945
- return this.trim(str).split(/\s+/);
946
- }
947
- }, {
948
- key: "toRDFNodeObject",
949
- value: function toRDFNodeObject(x) {
950
- var _this = this;
951
- if (typeof x === 'undefined') return undefined;
952
- if (typeof x === 'string') {
953
- if (x.substring(0, 2) === '_:') {
954
- if (typeof this.blankNodes[x.substring(2)] === 'undefined') {
955
- this.blankNodes[x.substring(2)] = new BlankNode(x.substring(2));
956
- }
957
- return this.blankNodes[x.substring(2)];
958
- }
959
- return rdf.namedNode(x);
831
+ this.setHTMLContext();
960
832
  }
961
- switch (x.type) {
962
- case RDFaProcessor.objectURI:
963
- if (x.value.substring(0, 2) === '_:') {
964
- if (typeof this.blankNodes[x.value.substring(2)] === 'undefined') {
965
- this.blankNodes[x.value.substring(2)] = new BlankNode(x.value.substring(2));
966
- }
967
- return this.blankNodes[x.value.substring(2)];
968
- }
969
- return rdf.namedNode(x.value);
970
- case RDFaProcessor.PlainLiteralURI:
971
- return new Literal(x.value, x.language || '');
972
- case RDFaProcessor.XMLLiteralURI:
973
- case RDFaProcessor.HTMLLiteralURI:
974
- var string = '';
975
- Object.keys(x.value).forEach(function (i) {
976
- string += Util.domToString(x.value[i], _this.htmlOptions);
977
- });
978
- return new Literal(string, '', new NamedNode(x.type));
979
- default:
980
- return new Literal(x.value, '', new NamedNode(x.type));
981
- }
982
- }
983
- }, {
984
- key: "trim",
985
- value: function trim(str) {
986
- return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
833
+ } else {
834
+ this.setXMLContext();
987
835
  }
988
- }], [{
989
- key: "parseRDFaDOM",
990
- value: function parseRDFaDOM(dom, kb, base) {
991
- var p = new RDFaProcessor(kb, {
992
- 'base': base
993
- });
994
- // Cannot assign to read only property 'baseURI' of object '#<XMLDocument>':
995
- if (!dom.baseURI) {
996
- // Note this became a read-only attribute some time before 2018
997
- dom.baseURI = base; // oinly set if not already set
836
+ }
837
+ setHTMLContext() {
838
+ this.setInitialContext();
839
+ this.langAttributes = [{
840
+ namespaceURI: 'http://www.w3.org/XML/1998/namespace',
841
+ localName: 'lang'
842
+ }, {
843
+ namespaceURI: null,
844
+ localName: 'lang'
845
+ }];
846
+ this.inXHTMLMode = false;
847
+ this.inHTMLMode = true;
848
+ }
849
+ setInitialContext() {
850
+ this.vocabulary = null;
851
+ // By default, the prefixes are terms are loaded to the RDFa 1.1. standard within the graph constructor
852
+ this.langAttributes = [{
853
+ namespaceURI: 'http://www.w3.org/XML/1998/namespace',
854
+ localName: 'lang'
855
+ }];
856
+ }
857
+ setXHTMLContext() {
858
+ this.setInitialContext();
859
+ this.inXHTMLMode = true;
860
+ this.inHTMLMode = false;
861
+ this.langAttributes = [{
862
+ namespaceURI: 'http://www.w3.org/XML/1998/namespace',
863
+ localName: 'lang'
864
+ }, {
865
+ namespaceURI: null,
866
+ localName: 'lang'
867
+ }];
868
+ // From http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1
869
+ this.target.graph.terms['alternate'] = 'http://www.w3.org/1999/xhtml/vocab#alternate';
870
+ this.target.graph.terms['appendix'] = 'http://www.w3.org/1999/xhtml/vocab#appendix';
871
+ this.target.graph.terms['bookmark'] = 'http://www.w3.org/1999/xhtml/vocab#bookmark';
872
+ this.target.graph.terms['cite'] = 'http://www.w3.org/1999/xhtml/vocab#cite';
873
+ this.target.graph.terms['chapter'] = 'http://www.w3.org/1999/xhtml/vocab#chapter';
874
+ this.target.graph.terms['contents'] = 'http://www.w3.org/1999/xhtml/vocab#contents';
875
+ this.target.graph.terms['copyright'] = 'http://www.w3.org/1999/xhtml/vocab#copyright';
876
+ this.target.graph.terms['first'] = 'http://www.w3.org/1999/xhtml/vocab#first';
877
+ this.target.graph.terms['glossary'] = 'http://www.w3.org/1999/xhtml/vocab#glossary';
878
+ this.target.graph.terms['help'] = 'http://www.w3.org/1999/xhtml/vocab#help';
879
+ this.target.graph.terms['icon'] = 'http://www.w3.org/1999/xhtml/vocab#icon';
880
+ this.target.graph.terms['index'] = 'http://www.w3.org/1999/xhtml/vocab#index';
881
+ this.target.graph.terms['last'] = 'http://www.w3.org/1999/xhtml/vocab#last';
882
+ this.target.graph.terms['license'] = 'http://www.w3.org/1999/xhtml/vocab#license';
883
+ this.target.graph.terms['meta'] = 'http://www.w3.org/1999/xhtml/vocab#meta';
884
+ this.target.graph.terms['next'] = 'http://www.w3.org/1999/xhtml/vocab#next';
885
+ this.target.graph.terms['prev'] = 'http://www.w3.org/1999/xhtml/vocab#prev';
886
+ this.target.graph.terms['previous'] = 'http://www.w3.org/1999/xhtml/vocab#previous';
887
+ this.target.graph.terms['section'] = 'http://www.w3.org/1999/xhtml/vocab#section';
888
+ this.target.graph.terms['stylesheet'] = 'http://www.w3.org/1999/xhtml/vocab#stylesheet';
889
+ this.target.graph.terms['subsection'] = 'http://www.w3.org/1999/xhtml/vocab#subsection';
890
+ this.target.graph.terms['start'] = 'http://www.w3.org/1999/xhtml/vocab#start';
891
+ this.target.graph.terms['top'] = 'http://www.w3.org/1999/xhtml/vocab#top';
892
+ this.target.graph.terms['up'] = 'http://www.w3.org/1999/xhtml/vocab#up';
893
+ this.target.graph.terms['p3pv1'] = 'http://www.w3.org/1999/xhtml/vocab#p3pv1';
894
+ // other
895
+ this.target.graph.terms['related'] = 'http://www.w3.org/1999/xhtml/vocab#related';
896
+ this.target.graph.terms['role'] = 'http://www.w3.org/1999/xhtml/vocab#role';
897
+ this.target.graph.terms['transformation'] = 'http://www.w3.org/1999/xhtml/vocab#transformation';
898
+ }
899
+ setXMLContext() {
900
+ this.setInitialContext();
901
+ this.inXHTMLMode = false;
902
+ this.inHTMLMode = false;
903
+ }
904
+ tokenize(str) {
905
+ return this.trim(str).split(/\s+/);
906
+ }
907
+ static tokenize(str) {
908
+ return this.trim(str).split(/\s+/);
909
+ }
910
+ toRDFNodeObject(x) {
911
+ if (typeof x === 'undefined') return undefined;
912
+ if (typeof x === 'string') {
913
+ if (x.substring(0, 2) === '_:') {
914
+ if (typeof this.blankNodes[x.substring(2)] === 'undefined') {
915
+ this.blankNodes[x.substring(2)] = new BlankNode(x.substring(2));
916
+ }
917
+ return this.blankNodes[x.substring(2)];
998
918
  }
999
- p.process(dom, {
1000
- baseURI: base
1001
- });
1002
- }
1003
- }, {
1004
- key: "tokenize",
1005
- value: function tokenize(str) {
1006
- return this.trim(str).split(/\s+/);
919
+ return rdf.namedNode(x);
1007
920
  }
1008
- }, {
1009
- key: "trim",
1010
- value: function trim(str) {
1011
- return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
921
+ switch (x.type) {
922
+ case RDFaProcessor.objectURI:
923
+ if (x.value.substring(0, 2) === '_:') {
924
+ if (typeof this.blankNodes[x.value.substring(2)] === 'undefined') {
925
+ this.blankNodes[x.value.substring(2)] = new BlankNode(x.value.substring(2));
926
+ }
927
+ return this.blankNodes[x.value.substring(2)];
928
+ }
929
+ return rdf.namedNode(x.value);
930
+ case RDFaProcessor.PlainLiteralURI:
931
+ return new Literal(x.value, x.language || '');
932
+ case RDFaProcessor.XMLLiteralURI:
933
+ case RDFaProcessor.HTMLLiteralURI:
934
+ var string = '';
935
+ Object.keys(x.value).forEach(i => {
936
+ string += Util.domToString(x.value[i], this.htmlOptions);
937
+ });
938
+ return new Literal(string, '', new NamedNode(x.type));
939
+ default:
940
+ return new Literal(x.value, '', new NamedNode(x.type));
1012
941
  }
1013
- }]);
1014
- }();
1015
- export { RDFaProcessor as default };
942
+ }
943
+ trim(str) {
944
+ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
945
+ }
946
+ static trim(str) {
947
+ return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
948
+ }
949
+ }
1016
950
  RDFaProcessor.XMLLiteralURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral';
1017
951
  RDFaProcessor.HTMLLiteralURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML';
1018
952
  RDFaProcessor.PlainLiteralURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral';
1019
953
  RDFaProcessor.objectURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#object';
1020
954
  RDFaProcessor.typeURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
1021
- RDFaProcessor.nameChar = "[-A-Z_a-z\xC0-\xD6\xD8-\xF6\xF8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF.0-9\xB7\u0300-\u036F\u203F-\u2040]";
1022
- RDFaProcessor.nameStartChar = "[A-Za-z\xC0-\xD6\xD8-\xF6\xF8-\xFF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-\u0556\u0559\u0561-\u0586\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0641-\u064A\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D3\u06D5\u06E5-\u06E6\u0905-\u0939\u093D\u0958-\u0961\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8B\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AE0\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B36-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB5\u0BB7-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CDE\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39\u0D60-\u0D61\u0E01-\u0E2E\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EAE\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0F40-\u0F47\u0F49-\u0F69\u10A0-\u10C5\u10D0-\u10F6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110B-\u110C\u110E-\u1112\u113C\u113E\u1140\u114C\u114E\u1150\u1154-\u1155\u1159\u115F-\u1161\u1163\u1165\u1167\u1169\u116D-\u116E\u1172-\u1173\u1175\u119E\u11A8\u11AB\u11AE-\u11AF\u11B7-\u11B8\u11BA\u11BC-\u11C2\u11EB\u11F0\u11F9\u1E00-\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u212E\u2180-\u2182\u3041-\u3094\u30A1-\u30FA\u3105-\u312C\uAC00-\uD7A3\u4E00-\u9FA5\u3007\u3021-\u3029_]";
955
+ RDFaProcessor.nameChar = '[-A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF\.0-9\u00B7\u0300-\u036F\u203F-\u2040]';
956
+ RDFaProcessor.nameStartChar = '[\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-\u0556\u0559\u0561-\u0586\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0641-\u064A\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D3\u06D5\u06E5-\u06E6\u0905-\u0939\u093D\u0958-\u0961\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8B\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AE0\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B36-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB5\u0BB7-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CDE\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39\u0D60-\u0D61\u0E01-\u0E2E\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EAE\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0F40-\u0F47\u0F49-\u0F69\u10A0-\u10C5\u10D0-\u10F6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110B-\u110C\u110E-\u1112\u113C\u113E\u1140\u114C\u114E\u1150\u1154-\u1155\u1159\u115F-\u1161\u1163\u1165\u1167\u1169\u116D-\u116E\u1172-\u1173\u1175\u119E\u11A8\u11AB\u11AE-\u11AF\u11B7-\u11B8\u11BA\u11BC-\u11C2\u11EB\u11F0\u11F9\u1E00-\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u212E\u2180-\u2182\u3041-\u3094\u30A1-\u30FA\u3105-\u312C\uAC00-\uD7A3\u4E00-\u9FA5\u3007\u3021-\u3029_]';
1023
957
  RDFaProcessor.NCNAME = new RegExp('^' + RDFaProcessor.nameStartChar + RDFaProcessor.nameChar + '*$');
1024
958
 
1025
959
  /*
@@ -1050,5 +984,5 @@ RDFaProcessor.dateTimeTypes = [{
1050
984
  pattern: /-?[1-9][0-9][0-9][0-9]|0[1-9][0-9][0-9]|00[1-9][0-9]|000[1-9]/,
1051
985
  type: 'http://www.w3.org/2001/XMLSchema#gYear'
1052
986
  }];
1053
- var parseRDFaDOM = RDFaProcessor.parseRDFaDOM;
987
+ const parseRDFaDOM = RDFaProcessor.parseRDFaDOM;
1054
988
  export { parseRDFaDOM };