@lblod/graph-rdfa-processor 2.1.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/bug.html +2617 -0
- package/bug2.html +3247 -0
- package/dist/rdfa-graph.js +1 -1
- package/package.json +1 -1
- package/src/rdfa-graph.js +9 -9
- package/src/rdfa-processor.js +23 -22
- package/test/test.js +5 -5
package/dist/rdfa-graph.js
CHANGED
package/package.json
CHANGED
package/src/rdfa-graph.js
CHANGED
@@ -4,10 +4,10 @@ export class RDFaGraph {
|
|
4
4
|
constructor() {
|
5
5
|
var dataContext = this;
|
6
6
|
this.curieParser = {
|
7
|
-
trim: function(str) {
|
7
|
+
trim: function (str) {
|
8
8
|
return str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
|
9
9
|
},
|
10
|
-
parse: function(value, resolve) {
|
10
|
+
parse: function (value, resolve) {
|
11
11
|
value = this.trim(value);
|
12
12
|
if (value.charAt(0) == "[" && value.charAt(value.length - 1) == "]") {
|
13
13
|
value = value.substring(1, value.length - 1);
|
@@ -34,19 +34,19 @@ export class RDFaGraph {
|
|
34
34
|
},
|
35
35
|
};
|
36
36
|
this.base = null;
|
37
|
-
this.toString = function(requestOptions) {
|
37
|
+
this.toString = function (requestOptions) {
|
38
38
|
var options =
|
39
39
|
requestOptions && requestOptions.shorten
|
40
40
|
? { graph: this, shorten: true, prefixesUsed: {} }
|
41
41
|
: null;
|
42
42
|
if (requestOptions && requestOptions.blankNodePrefix) {
|
43
|
-
options.filterBlankNode = function(id) {
|
43
|
+
options.filterBlankNode = function (id) {
|
44
44
|
return "_:" + requestOptions.blankNodePrefix + id.substring(2);
|
45
45
|
};
|
46
46
|
}
|
47
47
|
if (requestOptions && requestOptions.numericalBlankNodePrefix) {
|
48
48
|
var onlyNumbers = /^[0-9]+$/;
|
49
|
-
options.filterBlankNode = function(id) {
|
49
|
+
options.filterBlankNode = function (id) {
|
50
50
|
var label = id.substring(2);
|
51
51
|
return onlyNumbers.test(label)
|
52
52
|
? "_:" + requestOptions.numericalBlankNodePrefix + label
|
@@ -72,7 +72,7 @@ export class RDFaGraph {
|
|
72
72
|
return prolog.length == 0 ? s : prolog + "\n" + s;
|
73
73
|
};
|
74
74
|
this.blankNodeCounter = 0;
|
75
|
-
this.clear = function() {
|
75
|
+
this.clear = function () {
|
76
76
|
this.subjects = {};
|
77
77
|
this.prefixes = {};
|
78
78
|
this.terms = {};
|
@@ -130,7 +130,7 @@ export class RDFaGraph {
|
|
130
130
|
Object.defineProperty(this, "tripleCount", {
|
131
131
|
enumerable: true,
|
132
132
|
configurable: false,
|
133
|
-
get: function() {
|
133
|
+
get: function () {
|
134
134
|
var count = 0;
|
135
135
|
for (var s in this.subjects) {
|
136
136
|
var snode = this.subjects[s];
|
@@ -307,7 +307,7 @@ export class RDFaSubject {
|
|
307
307
|
s += " " + this.predicates[predicate].toString(options);
|
308
308
|
}
|
309
309
|
s += " .";
|
310
|
-
return s;
|
310
|
+
return s.replaceAll("\\", "\\\\");
|
311
311
|
}
|
312
312
|
|
313
313
|
toObject() {
|
@@ -498,7 +498,7 @@ export class RDFaPredicate {
|
|
498
498
|
}
|
499
499
|
}
|
500
500
|
|
501
|
-
RDFaPredicate.getPrefixMap = function(e) {
|
501
|
+
RDFaPredicate.getPrefixMap = function (e) {
|
502
502
|
var prefixMap = {};
|
503
503
|
while (e.attributes) {
|
504
504
|
for (var i = 0; i < e.attributes.length; i++) {
|
package/src/rdfa-processor.js
CHANGED
@@ -208,9 +208,9 @@ export default class RDFaProcessor extends URIResolver {
|
|
208
208
|
if (node.ownerDocument.doctype) {
|
209
209
|
if (
|
210
210
|
node.ownerDocument.doctype.publicId ==
|
211
|
-
|
211
|
+
"-//W3C//DTD XHTML+RDFa 1.0//EN" &&
|
212
212
|
node.ownerDocument.doctype.systemId ==
|
213
|
-
|
213
|
+
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"
|
214
214
|
) {
|
215
215
|
console.log(
|
216
216
|
"WARNING: RDF 1.0 is not supported. Defaulting to HTML5 mode.",
|
@@ -218,9 +218,9 @@ export default class RDFaProcessor extends URIResolver {
|
|
218
218
|
this.setHTMLContext();
|
219
219
|
} else if (
|
220
220
|
node.ownerDocument.doctype.publicId ==
|
221
|
-
|
221
|
+
"-//W3C//DTD XHTML+RDFa 1.1//EN" &&
|
222
222
|
node.ownerDocument.doctype.systemId ==
|
223
|
-
|
223
|
+
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd"
|
224
224
|
) {
|
225
225
|
this.setXHTMLContext();
|
226
226
|
} else {
|
@@ -329,11 +329,11 @@ export default class RDFaProcessor extends URIResolver {
|
|
329
329
|
"http://www.w3.org/1999/xhtml/vocab#transformation";
|
330
330
|
}
|
331
331
|
|
332
|
-
init() {
|
332
|
+
init() {}
|
333
333
|
|
334
|
-
newSubjectOrigin(origin, subject) {
|
334
|
+
newSubjectOrigin(origin, subject) {}
|
335
335
|
|
336
|
-
addTriple(origin, subject, predicate, object) {
|
336
|
+
addTriple(origin, subject, predicate, object) {}
|
337
337
|
|
338
338
|
process(node, options) {
|
339
339
|
if (node.nodeType == Node.DOCUMENT_NODE) {
|
@@ -344,7 +344,7 @@ export default class RDFaProcessor extends URIResolver {
|
|
344
344
|
}
|
345
345
|
var queue = [];
|
346
346
|
// Fix for Firefox that includes the hash in the base URI
|
347
|
-
var removeHash = function(baseURI) {
|
347
|
+
var removeHash = function (baseURI) {
|
348
348
|
var hash = baseURI.indexOf("#");
|
349
349
|
if (hash >= 0) {
|
350
350
|
baseURI = baseURI.substring(0, hash);
|
@@ -864,18 +864,18 @@ export default class RDFaProcessor extends URIResolver {
|
|
864
864
|
datatypeAtt.value == ""
|
865
865
|
? RDFaProcessor.PlainLiteralURI
|
866
866
|
: this.parseTermOrCURIEOrAbsURI(
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
867
|
+
datatypeAtt.value,
|
868
|
+
vocabulary,
|
869
|
+
context.terms,
|
870
|
+
prefixes,
|
871
|
+
base,
|
872
|
+
);
|
873
873
|
if (datetimeAtt && !contentAtt) {
|
874
874
|
content = datetimeAtt.value;
|
875
875
|
} else {
|
876
876
|
content =
|
877
877
|
datatype == RDFaProcessor.XMLLiteralURI ||
|
878
|
-
|
878
|
+
datatype == RDFaProcessor.HTMLLiteralURI
|
879
879
|
? null
|
880
880
|
: contentAtt
|
881
881
|
? contentAtt.value
|
@@ -913,6 +913,7 @@ export default class RDFaProcessor extends URIResolver {
|
|
913
913
|
content = typedResource;
|
914
914
|
} else {
|
915
915
|
content = current.textContent;
|
916
|
+
|
916
917
|
if (this.inHTMLMode && current.localName == "time") {
|
917
918
|
datatype = RDFaProcessor.deriveDateTimeType(content);
|
918
919
|
}
|
@@ -942,10 +943,10 @@ export default class RDFaProcessor extends URIResolver {
|
|
942
943
|
datatype == RDFaProcessor.HTMLLiteralURI
|
943
944
|
? { type: datatype, value: current.childNodes }
|
944
945
|
: {
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
946
|
+
type: datatype ? datatype : RDFaProcessor.PlainLiteralURI,
|
947
|
+
value: content,
|
948
|
+
language: language,
|
949
|
+
},
|
949
950
|
);
|
950
951
|
} else {
|
951
952
|
if (
|
@@ -1072,7 +1073,7 @@ export default class RDFaProcessor extends URIResolver {
|
|
1072
1073
|
}
|
1073
1074
|
}
|
1074
1075
|
|
1075
|
-
copyProperties() {
|
1076
|
+
copyProperties() {}
|
1076
1077
|
|
1077
1078
|
push(parent, subject) {
|
1078
1079
|
return {
|
@@ -1107,7 +1108,7 @@ RDFaProcessor.NCNAME = new RegExp(
|
|
1107
1108
|
"^" + RDFaProcessor.nameStartChar + RDFaProcessor.nameChar + "*$",
|
1108
1109
|
);
|
1109
1110
|
|
1110
|
-
RDFaProcessor.trim = function(str) {
|
1111
|
+
RDFaProcessor.trim = function (str) {
|
1111
1112
|
return str.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
|
1112
1113
|
};
|
1113
1114
|
|
@@ -1143,7 +1144,7 @@ RDFaProcessor.dateTimeTypes = [
|
|
1143
1144
|
},
|
1144
1145
|
];
|
1145
1146
|
|
1146
|
-
RDFaProcessor.deriveDateTimeType = function(value) {
|
1147
|
+
RDFaProcessor.deriveDateTimeType = function (value) {
|
1147
1148
|
for (var i = 0; i < RDFaProcessor.dateTimeTypes.length; i++) {
|
1148
1149
|
//console.log("Checking "+value+" against "+RDFaProcessor.dateTimeTypes[i].type);
|
1149
1150
|
var matched = RDFaProcessor.dateTimeTypes[i].pattern.exec(value);
|
package/test/test.js
CHANGED
@@ -2,7 +2,7 @@ import { jsdom } from "jsdom";
|
|
2
2
|
import assert from "assert";
|
3
3
|
import getRDFaGraph from "../src";
|
4
4
|
import { readFileSync, writeFileSync } from "fs";
|
5
|
-
describe("getRDFaGraph", function() {
|
5
|
+
describe("getRDFaGraph", function () {
|
6
6
|
let html = `<div typeof="rdfs:Class" resource="http://schema.org/CreativeWork">
|
7
7
|
<span class="h" property="rdfs:label">CreativeWork</span>
|
8
8
|
<span property="rdfs:comment">The most generic kind of creative work, including books, movies, photographs, software programs, etc.</span>
|
@@ -17,14 +17,14 @@ describe("getRDFaGraph", function() {
|
|
17
17
|
<http://purl.org/dc/terms/source> <http://www.w3.org/wiki/WebSchemas/SchemaDotOrgSources#source_rNews> .
|
18
18
|
`;
|
19
19
|
|
20
|
-
it("should getRDFaGraph from a document", function() {
|
20
|
+
it("should getRDFaGraph from a document", function () {
|
21
21
|
let { document } = jsdom(html).defaultView.window;
|
22
22
|
let graph = getRDFaGraph(document, { baseURI: "http://localhost" });
|
23
23
|
assert.equal(graph.toString(), expected);
|
24
24
|
});
|
25
25
|
|
26
26
|
it.only("whatever", () => {
|
27
|
-
let ht = readFileSync("./
|
27
|
+
let ht = readFileSync("./bug2.html");
|
28
28
|
let { document } = jsdom(ht).defaultView.window;
|
29
29
|
|
30
30
|
let graph = getRDFaGraph(document, {
|
@@ -37,10 +37,10 @@ describe("getRDFaGraph", function() {
|
|
37
37
|
},
|
38
38
|
],
|
39
39
|
});
|
40
|
-
writeFileSync("/tmp/x.
|
40
|
+
writeFileSync("/tmp/x.ttl", graph.toString(), "utf8");
|
41
41
|
});
|
42
42
|
|
43
|
-
it("should getRDFaGraph from a node", function() {
|
43
|
+
it("should getRDFaGraph from a node", function () {
|
44
44
|
let { document } = jsdom(html).defaultView.window;
|
45
45
|
let graph = getRDFaGraph(document.getElementsByTagName("div")[0], {
|
46
46
|
baseURI: "http://localhost",
|