rdflib 2.2.34 → 2.2.35-0ebb696c

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 (101) hide show
  1. package/dist/515.rdflib.min.js +3 -0
  2. package/dist/515.rdflib.min.js.map +1 -0
  3. package/dist/789.rdflib.min.js +1 -0
  4. package/dist/rdflib.min.js +1 -1
  5. package/dist/rdflib.min.js.LICENSE.txt +0 -2
  6. package/dist/rdflib.min.js.map +1 -1
  7. package/esm/blank-node.js +57 -85
  8. package/esm/class-order.js +1 -1
  9. package/esm/collection.js +70 -106
  10. package/esm/default-graph.js +13 -33
  11. package/esm/empty.js +8 -26
  12. package/esm/factories/canonical-data-factory.js +33 -30
  13. package/esm/factories/extended-term-factory.js +18 -14
  14. package/esm/factories/factory-types.js +1 -1
  15. package/esm/factories/rdflib-data-factory.js +9 -11
  16. package/esm/fetcher.js +1364 -1668
  17. package/esm/formula.js +631 -739
  18. package/esm/index.js +31 -51
  19. package/esm/jsonldparser.js +19 -26
  20. package/esm/jsonparser.js +1 -1
  21. package/esm/lists.js +41 -86
  22. package/esm/literal.js +120 -157
  23. package/esm/log.js +7 -7
  24. package/esm/n3parser.js +1008 -1090
  25. package/esm/named-node.js +69 -99
  26. package/esm/namespace.js +2 -4
  27. package/esm/node-internal.js +73 -97
  28. package/esm/node.js +1 -2
  29. package/esm/parse.js +3 -3
  30. package/esm/patch-parser.js +1 -2
  31. package/esm/query.js +15 -30
  32. package/esm/rdfaparser.js +775 -846
  33. package/esm/rdfxmlparser.js +348 -365
  34. package/esm/serialize.js +2 -3
  35. package/esm/serializer.js +834 -889
  36. package/esm/sparql-to-query.js +0 -2
  37. package/esm/statement.js +52 -72
  38. package/esm/store.js +852 -963
  39. package/esm/types.js +26 -21
  40. package/esm/update-manager.js +964 -1104
  41. package/esm/updates-via.js +104 -134
  42. package/esm/uri.js +3 -3
  43. package/esm/utils/default-graph-uri.js +2 -2
  44. package/esm/utils/terms.js +4 -5
  45. package/esm/utils-js.js +5 -6
  46. package/esm/utils.js +7 -6
  47. package/esm/variable.js +32 -58
  48. package/esm/xsd.js +2 -2
  49. package/lib/blank-node.js +56 -83
  50. package/lib/class-order.js +2 -3
  51. package/lib/collection.js +69 -104
  52. package/lib/default-graph.js +13 -32
  53. package/lib/empty.js +8 -25
  54. package/lib/factories/canonical-data-factory.js +36 -34
  55. package/lib/factories/extended-term-factory.js +19 -16
  56. package/lib/factories/factory-types.js +2 -3
  57. package/lib/factories/rdflib-data-factory.js +10 -13
  58. package/lib/fetcher.js +1394 -1693
  59. package/lib/formula.js +631 -738
  60. package/lib/index.js +66 -89
  61. package/lib/jsonldparser.js +21 -32
  62. package/lib/jsonparser.js +3 -4
  63. package/lib/lists.js +47 -87
  64. package/lib/literal.js +120 -156
  65. package/lib/log.js +8 -9
  66. package/lib/n3parser.js +1011 -1096
  67. package/lib/named-node.js +69 -98
  68. package/lib/namespace.js +2 -4
  69. package/lib/node-internal.js +72 -95
  70. package/lib/node.js +2 -4
  71. package/lib/parse.js +5 -6
  72. package/lib/patch-parser.js +1 -2
  73. package/lib/query.js +19 -32
  74. package/lib/rdfaparser.js +777 -849
  75. package/lib/rdfxmlparser.js +350 -366
  76. package/lib/serialize.js +2 -3
  77. package/lib/serializer.js +838 -892
  78. package/lib/sparql-to-query.js +0 -2
  79. package/lib/statement.js +54 -74
  80. package/lib/store.js +873 -978
  81. package/lib/types.js +22 -43
  82. package/lib/update-manager.js +973 -1111
  83. package/lib/updates-via.js +105 -134
  84. package/lib/uri.js +3 -3
  85. package/lib/utils/default-graph-uri.js +2 -4
  86. package/lib/utils/terms.js +4 -6
  87. package/lib/utils-js.js +11 -13
  88. package/lib/utils.js +6 -7
  89. package/lib/variable.js +34 -60
  90. package/lib/xsd-internal.js +2 -3
  91. package/lib/xsd.js +3 -4
  92. package/package.json +31 -31
  93. package/src/n3parser.js +1 -1
  94. package/src/rdfxmlparser.js +2 -1
  95. package/src/serializer.js +1 -1
  96. package/src/update-manager.ts +2 -1
  97. package/.babelrc +0 -20
  98. package/dist/670.rdflib.min.js +0 -1
  99. package/dist/730.rdflib.min.js +0 -3
  100. package/dist/730.rdflib.min.js.map +0 -1
  101. /package/dist/{730.rdflib.min.js.LICENSE.txt → 515.rdflib.min.js.LICENSE.txt} +0 -0
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,963 +65,895 @@ var RDFaProcessor = /*#__PURE__*/function () {
68
65
  this.finishedHandlers = [];
69
66
  this.init();
70
67
  }
71
- _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
-
281
- base = node.baseURI;
282
- node = node.documentElement;
283
- if (!node.baseURI) {
284
- node.baseURI = base;
285
- }
286
- this.setContext(node);
287
- } else if (node.parentNode.nodeType === Node.DOCUMENT_NODE) {
288
- 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;
289
271
  }
290
- var queue = [];
291
- // Fix for Firefox that includes the hash in the base URI
292
- var removeHash = function removeHash(baseURI) {
293
- // Fix for undefined baseURI property
294
- if (!baseURI && options && options.baseURI) {
295
- return options.baseURI;
296
- }
297
- var hash = baseURI.indexOf('#');
298
- if (hash >= 0) {
299
- baseURI = baseURI.substring(0, hash);
300
- }
301
- if (options && options.baseURIMap) {
302
- 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;
303
292
  }
304
- return baseURI;
305
- };
306
- queue.push({
307
- current: node,
308
- context: this.push(null, removeHash(node.baseURI))
309
- });
310
- while (queue.length > 0) {
311
- var item = queue.shift();
312
- if (item.parent) {
313
- // Sequence Step 14: list triple generation
314
- if (item.context.parent && item.context.parent.listMapping === item.listMapping) {
315
- // Skip a child context with exactly the same mapping
316
- continue;
317
- }
318
- // console.log("Generating lists for "+item.subject+", tag "+item.parent.localName)
319
- for (var _predicate in item.listMapping) {
320
- var list = item.listMapping[_predicate];
321
- if (list.length === 0) {
322
- this.addTriple(item.parent, item.subject, _predicate, {
323
- type: RDFaProcessor.objectURI,
324
- value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
325
- });
326
- continue;
327
- }
328
- var bnodes = [];
329
- for (var _i = 0; _i < list.length; _i++) {
330
- bnodes.push(this.newBlankNode());
331
- // this.newSubject(item.parent,bnodes[i])
332
- }
333
-
334
- for (var _i2 = 0; _i2 < bnodes.length; _i2++) {
335
- this.addTriple(item.parent, bnodes[_i2], 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first', list[_i2]);
336
- this.addTriple(item.parent, bnodes[_i2], 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest', {
337
- type: RDFaProcessor.objectURI,
338
- value: _i2 + 1 < bnodes.length ? bnodes[_i2 + 1] : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
339
- });
340
- }
341
- 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, {
342
298
  type: RDFaProcessor.objectURI,
343
- value: bnodes[0]
299
+ value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
344
300
  });
301
+ continue;
345
302
  }
346
- continue;
347
- }
348
- var current = item.current;
349
- var context = item.context;
350
- // console.log("Tag: "+current.localName+", listMapping="+JSON.stringify(context.listMapping))
351
- // Sequence Step 1
352
- var skip = false;
353
- var newSubject = null;
354
- var currentObjectResource = null;
355
- var typedResource = null;
356
- var prefixes = context.prefixes;
357
- var prefixesCopied = false;
358
- var incomplete = [];
359
- var listMapping = context.listMapping;
360
- var listMappingDifferent = !context.parent;
361
- var language = context.language;
362
- var vocabulary = context.vocabulary;
363
- // TODO: the "base" element may be used for HTML+RDFa 1.1
364
- base = this.parseURI(removeHash(current.baseURI));
365
- current.item = null;
366
- // Sequence Step 2: set the default vocabulary
367
- var vocabAtt = current.getAttributeNode('vocab');
368
- if (vocabAtt) {
369
- var value = this.trim(vocabAtt.value);
370
- if (value.length > 0) {
371
- vocabulary = value;
372
- var baseSubject = base.spec;
373
- // this.newSubject(current,baseSubject)
374
- 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', {
375
311
  type: RDFaProcessor.objectURI,
376
- value: vocabulary
312
+ value: i + 1 < bnodes.length ? bnodes[i + 1] : 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'
377
313
  });
378
- } else {
379
- vocabulary = this.vocabulary;
380
314
  }
315
+ this.addTriple(item.parent, item.subject, predicate, {
316
+ type: RDFaProcessor.objectURI,
317
+ value: bnodes[0]
318
+ });
381
319
  }
382
- // Sequence Step 3: IRI mappings
383
- // handle xmlns attributes
384
- for (var i = 0; i < current.attributes.length; i++) {
385
- var att = current.attributes[i];
386
- // if (att.namespaceURI=="http://www.w3.org/2000/xmlns/") {
387
- if (att.nodeName.charAt(0) === 'x' && att.nodeName.indexOf('xmlns:') === 0) {
388
- if (!prefixesCopied) {
389
- prefixes = this.copyMappings(prefixes);
390
- prefixesCopied = true;
391
- }
392
- var prefix = att.nodeName.substring(6);
393
- // TODO: resolve relative?
394
- var ref = RDFaProcessor.trim(att.value);
395
- prefixes[prefix] = this.options.base ? Uri.join(ref, this.options.base) : ref;
396
- }
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;
397
354
  }
398
- // Handle prefix mappings (@prefix)
399
- var prefixAtt = current.getAttributeNode('prefix');
400
- 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) {
401
362
  if (!prefixesCopied) {
402
363
  prefixes = this.copyMappings(prefixes);
403
364
  prefixesCopied = true;
404
365
  }
405
- 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;
406
370
  }
407
- // Sequence Step 4: language
408
- var xmlLangAtt = null;
409
- for (var _i3 = 0; !xmlLangAtt && _i3 < this.langAttributes.length; _i3++) {
410
- 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;
411
392
  }
412
- if (xmlLangAtt) {
413
- var _value = RDFaProcessor.trim(xmlLangAtt.value);
414
- if (_value.length > 0) {
415
- language = _value;
416
- } else {
417
- 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);
418
414
  }
419
415
  }
420
- var relAtt = current.getAttributeNode('rel');
421
- var revAtt = current.getAttributeNode('rev');
422
- var typeofAtt = current.getAttributeNode('typeof');
423
- var propertyAtt = current.getAttributeNode('property');
424
- var datatypeAtt = current.getAttributeNode('datatype');
425
- var datetimeAtt = this.inHTMLMode ? current.getAttributeNode('datetime') : null;
426
- var contentAtt = current.getAttributeNode('content');
427
- var aboutAtt = current.getAttributeNode('about');
428
- var srcAtt = current.getAttributeNode('src');
429
- var resourceAtt = current.getAttributeNode('resource');
430
- var hrefAtt = current.getAttributeNode('href');
431
- var inlistAtt = current.getAttributeNode('inlist');
432
- var relAttPredicates = [];
433
- var predicate, values;
434
- if (relAtt) {
435
- values = this.tokenize(relAtt.value);
436
- for (var _i4 = 0; _i4 < values.length; _i4++) {
437
- predicate = this.parsePredicate(values[_i4], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt !== null);
438
- if (predicate) {
439
- relAttPredicates.push(predicate);
440
- }
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);
441
424
  }
442
425
  }
443
- var revAttPredicates = [];
444
- if (revAtt) {
445
- values = this.tokenize(revAtt.value);
446
- for (var _i5 = 0; _i5 < values.length; _i5++) {
447
- predicate = this.parsePredicate(values[_i5], vocabulary, context.terms, prefixes, base, this.inHTMLMode && propertyAtt);
448
- if (predicate) {
449
- revAttPredicates.push(predicate);
450
- }
451
- }
426
+ }
427
+ // Section 3.1, bullet 7
428
+ if (this.inHTMLMode && (relAtt || revAtt) && propertyAtt) {
429
+ if (relAttPredicates.length === 0) {
430
+ relAtt = null;
452
431
  }
453
- // Section 3.1, bullet 7
454
- if (this.inHTMLMode && (relAtt || revAtt) && propertyAtt) {
455
- if (relAttPredicates.length === 0) {
456
- relAtt = null;
457
- }
458
- if (revAttPredicates.length === 0) {
459
- 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;
460
450
  }
461
451
  }
462
- if (relAtt || revAtt) {
463
- // Sequence Step 6: establish new subject and value
464
- if (aboutAtt) {
465
- 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();
466
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);
467
473
  if (typeofAtt) {
468
474
  typedResource = newSubject;
469
475
  }
470
- if (!newSubject) {
471
- if (current.parentNode.nodeType === Node.DOCUMENT_NODE) {
472
- newSubject = removeHash(current.baseURI);
473
- } else if (context.parentObject) {
474
- // 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
475
- newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
476
- }
476
+ }
477
+ if (!newSubject && current.parentNode.nodeType === Node.DOCUMENT_NODE) {
478
+ newSubject = removeHash(current.baseURI);
479
+ if (typeofAtt) {
480
+ typedResource = newSubject;
477
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) {
478
487
  if (resourceAtt) {
479
- currentObjectResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
488
+ typedResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
480
489
  }
481
- if (!currentObjectResource) {
482
- if (hrefAtt) {
483
- currentObjectResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
484
- } else if (srcAtt) {
485
- currentObjectResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
486
- } else if (typeofAtt && !aboutAtt && !(this.inXHTMLMode && (current.localName === 'head' || current.localName === 'body'))) {
487
- currentObjectResource = this.newBlankNode();
488
- }
490
+ if (!typedResource && hrefAtt) {
491
+ typedResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
492
+ }
493
+ if (!typedResource && srcAtt) {
494
+ typedResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
489
495
  }
490
- if (typeofAtt && !aboutAtt && this.inXHTMLMode && (current.localName === 'head' || current.localName === 'body')) {
496
+ if (!typedResource && (this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
491
497
  typedResource = newSubject;
492
- } else if (typeofAtt && !aboutAtt) {
493
- typedResource = currentObjectResource;
494
498
  }
495
- } else if (propertyAtt && !contentAtt && !datatypeAtt) {
496
- // Sequence Step 5.1: establish a new subject
497
- if (aboutAtt) {
498
- newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
499
- if (typeofAtt) {
500
- typedResource = newSubject;
501
- }
499
+ if (!typedResource) {
500
+ typedResource = this.newBlankNode();
502
501
  }
503
- 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) {
504
521
  newSubject = removeHash(current.baseURI);
505
- if (typeofAtt) {
506
- typedResource = newSubject;
507
- }
508
- } 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) {
509
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
510
528
  newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
511
- }
512
- if (typeofAtt && !typedResource) {
513
- if (resourceAtt) {
514
- typedResource = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
515
- }
516
- if (!typedResource && hrefAtt) {
517
- typedResource = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
518
- }
519
- if (!typedResource && srcAtt) {
520
- typedResource = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
529
+ if (!propertyAtt) {
530
+ skip = true;
521
531
  }
522
- if (!typedResource && (this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
523
- typedResource = newSubject;
524
- }
525
- if (!typedResource) {
526
- typedResource = this.newBlankNode();
527
- }
528
- currentObjectResource = typedResource;
529
- }
530
- // console.log(current.localName+", newSubject="+newSubject+", typedResource="+typedResource+", currentObjectResource="+currentObjectResource)
531
- } else {
532
- // Sequence Step 5.2: establish a new subject
533
- if (aboutAtt) {
534
- newSubject = this.parseSafeCURIEOrCURIEOrURI(aboutAtt.value, prefixes, base);
535
532
  }
536
- if (!newSubject && resourceAtt) {
537
- newSubject = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
538
- }
539
- if (!newSubject && hrefAtt) {
540
- newSubject = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
541
- }
542
- if (!newSubject && srcAtt) {
543
- 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
+ });
544
561
  }
545
- if (!newSubject) {
546
- if (current.parentNode.nodeType === Node.DOCUMENT_NODE) {
547
- newSubject = removeHash(current.baseURI);
548
- } else if ((this.inXHTMLMode || this.inHTMLMode) && (current.localName === 'head' || current.localName === 'body')) {
549
- newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
550
- } else if (typeofAtt) {
551
- newSubject = this.newBlankNode();
552
- } else if (context.parentObject) {
553
- // 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
554
- newSubject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
555
- if (!propertyAtt) {
556
- skip = true;
557
- }
558
- }
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
+ });
559
584
  }
560
- if (typeofAtt) {
561
- 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
+ });
562
591
  }
563
592
  }
564
- // console.log(current.tagName+": newSubject="+newSubject+", currentObjectResource="+currentObjectResource+", typedResource="+typedResource+", skip="+skip)
565
- // var rdfaData = null
566
- if (newSubject) {
567
- // this.newSubject(current,newSubject)
568
- if (aboutAtt || resourceAtt || typedResource) {
569
- var id = newSubject;
570
- if (typeofAtt && !aboutAtt && !resourceAtt && currentObjectResource) {
571
- id = currentObjectResource;
572
- }
573
- // console.log("Setting data attribute for "+current.localName+" for subject "+id)
574
- 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
+ });
575
599
  }
576
600
  }
577
- // Sequence Step 7: generate type triple
578
- if (typedResource) {
579
- values = this.tokenize(typeofAtt.value);
580
- for (var _i6 = 0; _i6 < values.length; _i6++) {
581
- var object = this.parseTermOrCURIEOrAbsURI(values[_i6], vocabulary, context.terms, prefixes, base);
582
- if (object) {
583
- this.addTriple(current, typedResource, RDFaProcessor.typeURI, {
584
- type: RDFaProcessor.objectURI,
585
- value: object
586
- });
587
- }
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
+ });
588
626
  }
589
627
  }
590
- // Sequence Step 8: new list mappings if there is a new subject
591
- // console.log("Step 8: newSubject="+newSubject+", context.parentObject="+context.parentObject)
592
- if (newSubject && newSubject !== context.parentObject) {
593
- // console.log("Generating new list mapping for "+newSubject)
594
- listMapping = {};
595
- listMappingDifferent = true;
596
- }
597
- // Sequence Step 9: generate object triple
598
- if (currentObjectResource) {
599
- if (relAtt && inlistAtt) {
600
- for (var _i7 = 0; _i7 < relAttPredicates.length; _i7++) {
601
- var _list = listMapping[relAttPredicates[_i7]];
602
- if (!_list) {
603
- _list = [];
604
- listMapping[relAttPredicates[_i7]] = _list;
605
- }
606
- _list.push({
607
- type: RDFaProcessor.objectURI,
608
- value: currentObjectResource
609
- });
610
- }
611
- } else if (relAtt) {
612
- for (var _i8 = 0; _i8 < relAttPredicates.length; _i8++) {
613
- this.addTriple(current, newSubject, relAttPredicates[_i8], {
614
- type: RDFaProcessor.objectURI,
615
- value: currentObjectResource
616
- });
617
- }
628
+ if (revAtt) {
629
+ for (let i = 0; i < revAttPredicates.length; i++) {
630
+ incomplete.push({
631
+ predicate: revAttPredicates[i],
632
+ forward: false
633
+ });
618
634
  }
619
- if (revAtt) {
620
- for (var _i9 = 0; _i9 < revAttPredicates.length; _i9++) {
621
- this.addTriple(current, currentObjectResource, revAttPredicates[_i9], {
622
- type: RDFaProcessor.objectURI,
623
- value: newSubject
624
- });
625
- }
635
+ }
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;
626
656
  }
627
- } else {
628
- // Sequence Step 10: incomplete triples
629
- if (newSubject && !currentObjectResource && (relAtt || revAtt)) {
630
- currentObjectResource = this.newBlankNode();
631
- // alert(current.tagName+": generated blank node, newSubject="+newSubject+" currentObjectResource="+currentObjectResource)
657
+ } else if (!relAtt && !revAtt) {
658
+ if (resourceAtt) {
659
+ content = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
632
660
  }
633
-
634
- if (relAtt && inlistAtt) {
635
- for (var _i10 = 0; _i10 < relAttPredicates.length; _i10++) {
636
- var _list2 = listMapping[relAttPredicates[_i10]];
637
- if (!_list2) {
638
- _list2 = [];
639
- listMapping[predicate] = _list2;
640
- }
641
- // console.log("Adding incomplete list for "+predicate)
642
- incomplete.push({
643
- predicate: relAttPredicates[_i10],
644
- list: _list2
645
- });
646
- }
647
- } else if (relAtt) {
648
- for (var _i11 = 0; _i11 < relAttPredicates.length; _i11++) {
649
- incomplete.push({
650
- predicate: relAttPredicates[_i11],
651
- forward: true
652
- });
653
- }
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));
654
665
  }
655
- if (revAtt) {
656
- for (var _i12 = 0; _i12 < revAttPredicates.length; _i12++) {
657
- incomplete.push({
658
- predicate: revAttPredicates[_i12],
659
- forward: false
660
- });
661
- }
666
+ if (content) {
667
+ datatype = RDFaProcessor.objectURI;
662
668
  }
663
669
  }
664
- // Step 11: Current property values
665
- if (propertyAtt) {
666
- var datatype = null;
667
- var content = null;
668
- if (datatypeAtt) {
669
- datatype = datatypeAtt.value === '' ? RDFaProcessor.PlainLiteralURI : this.parseTermOrCURIEOrAbsURI(datatypeAtt.value, vocabulary, context.terms, prefixes, base);
670
- if (datetimeAtt && !contentAtt) {
671
- content = datetimeAtt.value;
672
- } else {
673
- 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);
674
678
  }
675
- } else if (contentAtt) {
676
- datatype = RDFaProcessor.PlainLiteralURI;
677
- content = contentAtt.value;
678
- } else if (datetimeAtt) {
679
- content = datetimeAtt.value;
680
- datatype = RDFaProcessor.deriveDateTimeType(content);
681
679
  if (!datatype) {
682
680
  datatype = RDFaProcessor.PlainLiteralURI;
683
681
  }
684
- } else if (!relAtt && !revAtt) {
685
- if (resourceAtt) {
686
- content = this.parseSafeCURIEOrCURIEOrURI(resourceAtt.value, prefixes, base);
687
- }
688
- if (!content && hrefAtt) {
689
- content = this.resolveAndNormalize(base, encodeURI(hrefAtt.value));
690
- } else if (!content && srcAtt) {
691
- content = this.resolveAndNormalize(base, encodeURI(srcAtt.value));
692
- }
693
- if (content) {
694
- datatype = RDFaProcessor.objectURI;
695
- }
696
682
  }
697
- if (!datatype) {
698
- if (typeofAtt && !aboutAtt) {
699
- datatype = RDFaProcessor.objectURI;
700
- content = typedResource;
701
- } else {
702
- content = current.textContent;
703
- if (this.inHTMLMode && current.localName === 'time') {
704
- datatype = RDFaProcessor.deriveDateTimeType(content);
705
- }
706
- if (!datatype) {
707
- 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;
708
693
  }
709
- }
710
- }
711
- values = this.tokenize(propertyAtt.value);
712
- for (var _i13 = 0; _i13 < values.length; _i13++) {
713
- var _predicate2 = this.parsePredicate(values[_i13], vocabulary, context.terms, prefixes, base);
714
- if (_predicate2) {
715
- if (inlistAtt) {
716
- var _list3 = listMapping[_predicate2];
717
- if (!_list3) {
718
- _list3 = [];
719
- listMapping[_predicate2] = _list3;
720
- }
721
- _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, {
722
705
  type: datatype,
723
706
  value: current.childNodes
724
- } : {
707
+ });
708
+ } else {
709
+ this.addTriple(current, newSubject, predicate, {
725
710
  type: datatype || RDFaProcessor.PlainLiteralURI,
726
711
  value: content,
727
712
  language: language
728
713
  });
729
- } else {
730
- if (datatype === RDFaProcessor.XMLLiteralURI || datatype === RDFaProcessor.HTMLLiteralURI) {
731
- this.addTriple(current, newSubject, _predicate2, {
732
- type: datatype,
733
- value: current.childNodes
734
- });
735
- } else {
736
- this.addTriple(current, newSubject, _predicate2, {
737
- type: datatype || RDFaProcessor.PlainLiteralURI,
738
- value: content,
739
- language: language
740
- });
741
- // console.log(newSubject+" "+predicate+"="+content)
742
- }
714
+ // console.log(newSubject+" "+predicate+"="+content)
743
715
  }
744
716
  }
745
717
  }
746
718
  }
747
- // Sequence Step 12: complete incomplete triples with new subject
748
- if (newSubject && !skip) {
749
- for (var _i14 = 0; _i14 < context.incomplete.length; _i14++) {
750
- if (context.incomplete[_i14].list) {
751
- // console.log("Adding subject "+newSubject+" to list for "+context.incomplete[i].predicate)
752
- // TODO: it is unclear what to do here
753
- context.incomplete[_i14].list.push({
754
- type: RDFaProcessor.objectURI,
755
- value: newSubject
756
- });
757
- } else if (context.incomplete[_i14].forward) {
758
- // console.log(current.tagName+": completing forward triple "+context.incomplete[i].predicate+" with object="+newSubject)
759
- this.addTriple(current, context.subject, context.incomplete[_i14].predicate, {
760
- type: RDFaProcessor.objectURI,
761
- value: newSubject
762
- });
763
- } else {
764
- // console.log(current.tagName+": completing reverse triple with object="+context.subject)
765
- this.addTriple(current, newSubject, context.incomplete[_i14].predicate, {
766
- type: RDFaProcessor.objectURI,
767
- value: context.subject
768
- });
769
- }
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
+ });
770
742
  }
771
743
  }
772
- var childContext = null;
773
- var listSubject = newSubject;
774
- if (skip) {
775
- // TODO: should subject be null?
776
- childContext = this.push(context, context.subject);
777
- // TODO: should the entObject be passed along? If not, then intermediary children will keep properties from being associated with incomplete triples.
778
- // TODO: Verify: if the current baseURI has changed and the parentObject is the parent's base URI, then the baseURI should change
779
- childContext.parentObject = removeHash(current.parentNode.baseURI) === context.parentObject ? removeHash(current.baseURI) : context.parentObject;
780
- childContext.incomplete = context.incomplete;
781
- childContext.language = language;
782
- childContext.prefixes = prefixes;
783
- childContext.vocabulary = vocabulary;
784
- } else {
785
- childContext = this.push(context, newSubject);
786
- childContext.parentObject = currentObjectResource || newSubject || context.subject;
787
- childContext.prefixes = prefixes;
788
- childContext.incomplete = incomplete;
789
- if (currentObjectResource) {
790
- // console.log("Generating new list mapping for "+currentObjectResource)
791
- listSubject = currentObjectResource;
792
- listMapping = {};
793
- listMappingDifferent = true;
794
- }
795
- childContext.listMapping = listMapping;
796
- childContext.language = language;
797
- 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;
798
767
  }
799
- if (listMappingDifferent) {
800
- // 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
801
785
  queue.unshift({
802
- parent: current,
803
- context: context,
804
- subject: listSubject,
805
- listMapping: listMapping
786
+ current: child,
787
+ context: childContext
806
788
  });
807
789
  }
808
- for (var child = current.lastChild; child; child = child.previousSibling) {
809
- if (child.nodeType === Node.ELEMENT_NODE) {
810
- // console.log("Pushing child "+child.localName)
811
- // child.baseURI = current.baseURI
812
- queue.unshift({
813
- current: child,
814
- context: childContext
815
- });
816
- }
817
- }
818
- }
819
- if (this.inHTMLMode) {
820
- this.copyProperties();
821
- }
822
- for (var _i15 = 0; _i15 < this.finishedHandlers.length; _i15++) {
823
- this.finishedHandlers[_i15](node);
824
790
  }
825
791
  }
826
- }, {
827
- key: "push",
828
- value: function push(parent, subject) {
829
- return {
830
- parent: parent,
831
- subject: subject || (parent ? parent.subject : null),
832
- parentObject: null,
833
- incomplete: [],
834
- listMapping: parent ? parent.listMapping : {},
835
- language: parent ? parent.language : this.language,
836
- prefixes: parent ? parent.prefixes : this.target.graph.prefixes,
837
- terms: parent ? parent.terms : this.target.graph.terms,
838
- vocabulary: parent ? parent.vocabulary : this.vocabulary
839
- };
792
+ if (this.inHTMLMode) {
793
+ this.copyProperties();
840
794
  }
841
- }, {
842
- key: "resolveAndNormalize",
843
- value: function resolveAndNormalize(base, uri) {
844
- // console.log("Joining " + uri + " to " + base + " making " + Uri.join(uri, base))
845
- return Uri.join(uri, base); // @@ normalize?
795
+ for (let i = 0; i < this.finishedHandlers.length; i++) {
796
+ this.finishedHandlers[i](node);
846
797
  }
847
- }, {
848
- key: "setContext",
849
- value: function setContext(node) {
850
- // We only recognized XHTML+RDFa 1.1 if the version is set propertyly
851
- if (node.localName === 'html' && node.getAttribute('version') === 'XHTML+RDFa 1.1') {
852
- this.setXHTMLContext();
853
- } else if (node.localName === 'html' || node.namespaceURI === 'http://www.w3.org/1999/xhtml') {
854
- if (typeof document !== 'undefined' && document.doctype) {
855
- if (document.doctype.publicId === '-//W3C//DTD XHTML+RDFa 1.0//EN' && document.doctype.systemId === 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd') {
856
- console.log('WARNING: RDF 1.0 is not supported. Defaulting to HTML5 mode.');
857
- this.setHTMLContext();
858
- } 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') {
859
- this.setXHTMLContext();
860
- } else {
861
- this.setHTMLContext();
862
- }
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();
863
827
  } else {
864
828
  this.setHTMLContext();
865
829
  }
866
830
  } else {
867
- this.setXMLContext();
831
+ this.setHTMLContext();
868
832
  }
833
+ } else {
834
+ this.setXMLContext();
869
835
  }
870
- }, {
871
- key: "setHTMLContext",
872
- value: function setHTMLContext() {
873
- this.setInitialContext();
874
- this.langAttributes = [{
875
- namespaceURI: 'http://www.w3.org/XML/1998/namespace',
876
- localName: 'lang'
877
- }, {
878
- namespaceURI: null,
879
- localName: 'lang'
880
- }];
881
- this.inXHTMLMode = false;
882
- this.inHTMLMode = true;
883
- }
884
- }, {
885
- key: "setInitialContext",
886
- value: function setInitialContext() {
887
- this.vocabulary = null;
888
- // By default, the prefixes are terms are loaded to the RDFa 1.1. standard within the graph constructor
889
- this.langAttributes = [{
890
- namespaceURI: 'http://www.w3.org/XML/1998/namespace',
891
- localName: 'lang'
892
- }];
893
- }
894
- }, {
895
- key: "setXHTMLContext",
896
- value: function setXHTMLContext() {
897
- this.setInitialContext();
898
- this.inXHTMLMode = true;
899
- this.inHTMLMode = false;
900
- this.langAttributes = [{
901
- namespaceURI: 'http://www.w3.org/XML/1998/namespace',
902
- localName: 'lang'
903
- }, {
904
- namespaceURI: null,
905
- localName: 'lang'
906
- }];
907
- // From http://www.w3.org/2011/rdfa-context/xhtml-rdfa-1.1
908
- this.target.graph.terms['alternate'] = 'http://www.w3.org/1999/xhtml/vocab#alternate';
909
- this.target.graph.terms['appendix'] = 'http://www.w3.org/1999/xhtml/vocab#appendix';
910
- this.target.graph.terms['bookmark'] = 'http://www.w3.org/1999/xhtml/vocab#bookmark';
911
- this.target.graph.terms['cite'] = 'http://www.w3.org/1999/xhtml/vocab#cite';
912
- this.target.graph.terms['chapter'] = 'http://www.w3.org/1999/xhtml/vocab#chapter';
913
- this.target.graph.terms['contents'] = 'http://www.w3.org/1999/xhtml/vocab#contents';
914
- this.target.graph.terms['copyright'] = 'http://www.w3.org/1999/xhtml/vocab#copyright';
915
- this.target.graph.terms['first'] = 'http://www.w3.org/1999/xhtml/vocab#first';
916
- this.target.graph.terms['glossary'] = 'http://www.w3.org/1999/xhtml/vocab#glossary';
917
- this.target.graph.terms['help'] = 'http://www.w3.org/1999/xhtml/vocab#help';
918
- this.target.graph.terms['icon'] = 'http://www.w3.org/1999/xhtml/vocab#icon';
919
- this.target.graph.terms['index'] = 'http://www.w3.org/1999/xhtml/vocab#index';
920
- this.target.graph.terms['last'] = 'http://www.w3.org/1999/xhtml/vocab#last';
921
- this.target.graph.terms['license'] = 'http://www.w3.org/1999/xhtml/vocab#license';
922
- this.target.graph.terms['meta'] = 'http://www.w3.org/1999/xhtml/vocab#meta';
923
- this.target.graph.terms['next'] = 'http://www.w3.org/1999/xhtml/vocab#next';
924
- this.target.graph.terms['prev'] = 'http://www.w3.org/1999/xhtml/vocab#prev';
925
- this.target.graph.terms['previous'] = 'http://www.w3.org/1999/xhtml/vocab#previous';
926
- this.target.graph.terms['section'] = 'http://www.w3.org/1999/xhtml/vocab#section';
927
- this.target.graph.terms['stylesheet'] = 'http://www.w3.org/1999/xhtml/vocab#stylesheet';
928
- this.target.graph.terms['subsection'] = 'http://www.w3.org/1999/xhtml/vocab#subsection';
929
- this.target.graph.terms['start'] = 'http://www.w3.org/1999/xhtml/vocab#start';
930
- this.target.graph.terms['top'] = 'http://www.w3.org/1999/xhtml/vocab#top';
931
- this.target.graph.terms['up'] = 'http://www.w3.org/1999/xhtml/vocab#up';
932
- this.target.graph.terms['p3pv1'] = 'http://www.w3.org/1999/xhtml/vocab#p3pv1';
933
- // other
934
- this.target.graph.terms['related'] = 'http://www.w3.org/1999/xhtml/vocab#related';
935
- this.target.graph.terms['role'] = 'http://www.w3.org/1999/xhtml/vocab#role';
936
- this.target.graph.terms['transformation'] = 'http://www.w3.org/1999/xhtml/vocab#transformation';
937
- }
938
- }, {
939
- key: "setXMLContext",
940
- value: function setXMLContext() {
941
- this.setInitialContext();
942
- this.inXHTMLMode = false;
943
- this.inHTMLMode = false;
944
- }
945
- }, {
946
- key: "tokenize",
947
- value: function tokenize(str) {
948
- return this.trim(str).split(/\s+/);
949
- }
950
- }, {
951
- key: "toRDFNodeObject",
952
- value: function toRDFNodeObject(x) {
953
- var _this = this;
954
- if (typeof x === 'undefined') return undefined;
955
- if (typeof x === 'string') {
956
- if (x.substring(0, 2) === '_:') {
957
- if (typeof this.blankNodes[x.substring(2)] === 'undefined') {
958
- this.blankNodes[x.substring(2)] = new BlankNode(x.substring(2));
959
- }
960
- return this.blankNodes[x.substring(2)];
961
- }
962
- return rdf.namedNode(x);
963
- }
964
- switch (x.type) {
965
- case RDFaProcessor.objectURI:
966
- if (x.value.substring(0, 2) === '_:') {
967
- if (typeof this.blankNodes[x.value.substring(2)] === 'undefined') {
968
- this.blankNodes[x.value.substring(2)] = new BlankNode(x.value.substring(2));
969
- }
970
- return this.blankNodes[x.value.substring(2)];
971
- }
972
- return rdf.namedNode(x.value);
973
- case RDFaProcessor.PlainLiteralURI:
974
- return new Literal(x.value, x.language || '');
975
- case RDFaProcessor.XMLLiteralURI:
976
- case RDFaProcessor.HTMLLiteralURI:
977
- var string = '';
978
- Object.keys(x.value).forEach(function (i) {
979
- string += Util.domToString(x.value[i], _this.htmlOptions);
980
- });
981
- return new Literal(string, '', new NamedNode(x.type));
982
- default:
983
- return new Literal(x.value, '', new NamedNode(x.type));
984
- }
985
- }
986
- }, {
987
- key: "trim",
988
- value: function trim(str) {
989
- return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
990
- }
991
- }], [{
992
- key: "parseRDFaDOM",
993
- value: function parseRDFaDOM(dom, kb, base) {
994
- var p = new RDFaProcessor(kb, {
995
- 'base': base
996
- });
997
- // Cannot assign to read only property 'baseURI' of object '#<XMLDocument>':
998
- if (!dom.baseURI) {
999
- // Note this became a read-only attribute some time before 2018
1000
- 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)];
1001
918
  }
1002
-
1003
- p.process(dom, {
1004
- baseURI: base
1005
- });
1006
- }
1007
- }, {
1008
- key: "tokenize",
1009
- value: function tokenize(str) {
1010
- return this.trim(str).split(/\s+/);
919
+ return rdf.namedNode(x);
1011
920
  }
1012
- }, {
1013
- key: "trim",
1014
- value: function trim(str) {
1015
- 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));
1016
941
  }
1017
- }]);
1018
- return RDFaProcessor;
1019
- }();
1020
- 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
+ }
1021
950
  RDFaProcessor.XMLLiteralURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral';
1022
951
  RDFaProcessor.HTMLLiteralURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML';
1023
952
  RDFaProcessor.PlainLiteralURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral';
1024
953
  RDFaProcessor.objectURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#object';
1025
954
  RDFaProcessor.typeURI = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
1026
- 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]";
1027
- 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_]';
1028
957
  RDFaProcessor.NCNAME = new RegExp('^' + RDFaProcessor.nameStartChar + RDFaProcessor.nameChar + '*$');
1029
958
 
1030
959
  /*
@@ -1055,5 +984,5 @@ RDFaProcessor.dateTimeTypes = [{
1055
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]/,
1056
985
  type: 'http://www.w3.org/2001/XMLSchema#gYear'
1057
986
  }];
1058
- var parseRDFaDOM = RDFaProcessor.parseRDFaDOM;
987
+ const parseRDFaDOM = RDFaProcessor.parseRDFaDOM;
1059
988
  export { parseRDFaDOM };