@lblod/graph-rdfa-processor 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.woodpecker/release.yml +16 -0
- package/LICENSE +201 -0
- package/README.md +34 -0
- package/dist/graph-rdfa-processor.js +256 -0
- package/dist/index.js +32 -0
- package/dist/node.js +23 -0
- package/dist/rdfa-graph.js +603 -0
- package/dist/rdfa-processor.js +1106 -0
- package/dist/uri-resolver.js +274 -0
- package/package.json +47 -0
- package/release.sh +15 -0
- package/src/graph-rdfa-processor.js +177 -0
- package/src/index.js +21 -0
- package/src/node.js +16 -0
- package/src/rdfa-graph.js +518 -0
- package/src/rdfa-processor.js +1156 -0
- package/src/uri-resolver.js +203 -0
- package/test/test.js +50 -0
- package/test-page.html +405 -0
- package/test-prov-value.html +87 -0
@@ -0,0 +1,274 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
9
|
+
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
11
|
+
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
13
|
+
|
14
|
+
var URIResolver =
|
15
|
+
/*#__PURE__*/
|
16
|
+
function () {
|
17
|
+
function URIResolver() {
|
18
|
+
_classCallCheck(this, URIResolver);
|
19
|
+
}
|
20
|
+
|
21
|
+
_createClass(URIResolver, [{
|
22
|
+
key: "parseURI",
|
23
|
+
value: function parseURI(uri) {
|
24
|
+
var match = URIResolver.SCHEME.exec(uri);
|
25
|
+
|
26
|
+
if (!match) {
|
27
|
+
throw new Error("Bad URI value, no scheme: " + uri);
|
28
|
+
}
|
29
|
+
|
30
|
+
var parsed = {
|
31
|
+
spec: uri
|
32
|
+
};
|
33
|
+
parsed.scheme = match[0].substring(0, match[0].length - 1);
|
34
|
+
parsed.schemeSpecificPart = parsed.spec.substring(match[0].length);
|
35
|
+
|
36
|
+
if (parsed.schemeSpecificPart.charAt(0) == '/' && parsed.schemeSpecificPart.charAt(1) == '/') {
|
37
|
+
this.parseGeneric(parsed);
|
38
|
+
} else {
|
39
|
+
parsed.isGeneric = false;
|
40
|
+
}
|
41
|
+
|
42
|
+
parsed.normalize = function () {
|
43
|
+
if (!this.isGeneric) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
if (this.segments.length == 0) {
|
48
|
+
return;
|
49
|
+
} // edge case of ending in "/."
|
50
|
+
|
51
|
+
|
52
|
+
if (this.path.length > 1 && this.path.substring(this.path.length - 2) == "/.") {
|
53
|
+
this.path = this.path.substring(0, this.path.length - 1);
|
54
|
+
this.segments.splice(this.segments.length - 1, 1);
|
55
|
+
this.schemeSpecificPart = "//" + this.authority + this.path;
|
56
|
+
|
57
|
+
if (typeof this.query != "undefined") {
|
58
|
+
this.schemeSpecificPart += "?" + this.query;
|
59
|
+
}
|
60
|
+
|
61
|
+
if (typeof this.fragment != "undefined") {
|
62
|
+
this.schemeSpecificPart += "#" + this.fragment;
|
63
|
+
}
|
64
|
+
|
65
|
+
this.spec = this.scheme + ":" + this.schemeSpecificPart;
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
var end = this.path.charAt(this.path.length - 1);
|
70
|
+
|
71
|
+
if (end != "/") {
|
72
|
+
end = "";
|
73
|
+
}
|
74
|
+
|
75
|
+
for (var i = 0; i < this.segments.length; i++) {
|
76
|
+
if (i > 0 && this.segments[i] == "..") {
|
77
|
+
this.segments.splice(i - 1, 2);
|
78
|
+
i -= 2;
|
79
|
+
}
|
80
|
+
|
81
|
+
if (this.segments[i] == ".") {
|
82
|
+
this.segments.splice(i, 1);
|
83
|
+
i--;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
this.path = this.segments.length == 0 ? "/" : "/" + this.segments.join("/") + end;
|
88
|
+
this.schemeSpecificPart = "//" + this.authority + this.path;
|
89
|
+
|
90
|
+
if (typeof this.query != "undefined") {
|
91
|
+
this.schemeSpecificPart += "?" + this.query;
|
92
|
+
}
|
93
|
+
|
94
|
+
if (typeof this.fragment != "undefined") {
|
95
|
+
this.schemeSpecificPart += "#" + this.fragment;
|
96
|
+
}
|
97
|
+
|
98
|
+
this.spec = this.scheme + ":" + this.schemeSpecificPart;
|
99
|
+
};
|
100
|
+
|
101
|
+
parsed.resolve = function (href) {
|
102
|
+
if (!href) {
|
103
|
+
return this.spec;
|
104
|
+
}
|
105
|
+
|
106
|
+
if (href.charAt(0) == '#') {
|
107
|
+
var lastHash = this.spec.lastIndexOf('#');
|
108
|
+
return lastHash < 0 ? this.spec + href : this.spec.substring(0, lastHash) + href;
|
109
|
+
}
|
110
|
+
|
111
|
+
if (!this.isGeneric) {
|
112
|
+
throw new Error("Cannot resolve uri against non-generic URI: " + this.spec);
|
113
|
+
}
|
114
|
+
|
115
|
+
var colon = href.indexOf(':');
|
116
|
+
|
117
|
+
if (href.charAt(0) == '/') {
|
118
|
+
return this.scheme + "://" + this.authority + href;
|
119
|
+
} else if (href.charAt(0) == '.' && href.charAt(1) == '/') {
|
120
|
+
if (this.path.charAt(this.path.length - 1) == '/') {
|
121
|
+
return this.scheme + "://" + this.authority + this.path + href.substring(2);
|
122
|
+
} else {
|
123
|
+
var last = this.path.lastIndexOf('/');
|
124
|
+
return this.scheme + "://" + this.authority + this.path.substring(0, last) + href.substring(1);
|
125
|
+
}
|
126
|
+
} else if (URIResolver.SCHEME.test(href)) {
|
127
|
+
return href;
|
128
|
+
} else if (href.charAt(0) == "?") {
|
129
|
+
return this.scheme + "://" + this.authority + this.path + href;
|
130
|
+
} else {
|
131
|
+
if (this.path.charAt(this.path.length - 1) == '/') {
|
132
|
+
return this.scheme + "://" + this.authority + this.path + href;
|
133
|
+
} else {
|
134
|
+
var last = this.path.lastIndexOf('/');
|
135
|
+
return this.scheme + "://" + this.authority + this.path.substring(0, last + 1) + href;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
parsed.relativeTo = function (otherURI) {
|
141
|
+
if (otherURI.scheme != this.scheme) {
|
142
|
+
return this.spec;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (!this.isGeneric) {
|
146
|
+
throw new Error("A non generic URI cannot be made relative: " + this.spec);
|
147
|
+
}
|
148
|
+
|
149
|
+
if (!otherURI.isGeneric) {
|
150
|
+
throw new Error("Cannot make a relative URI against a non-generic URI: " + otherURI.spec);
|
151
|
+
}
|
152
|
+
|
153
|
+
if (otherURI.authority != this.authority) {
|
154
|
+
return this.spec;
|
155
|
+
}
|
156
|
+
|
157
|
+
var i = 0;
|
158
|
+
|
159
|
+
for (; i < this.segments.length && i < otherURI.segments.length; i++) {
|
160
|
+
if (this.segments[i] != otherURI.segments[i]) {
|
161
|
+
//alert(this.path+" different from "+otherURI.path+" at '"+this.segments[i]+"' vs '"+otherURI.segments[i]+"'");
|
162
|
+
var offset = otherURI.path.charAt(otherURI.path.length - 1) == '/' ? 0 : -1;
|
163
|
+
var relative = "";
|
164
|
+
|
165
|
+
for (var j = i; j < otherURI.segments.length + offset; j++) {
|
166
|
+
relative += "../";
|
167
|
+
}
|
168
|
+
|
169
|
+
for (var j = i; j < this.segments.length; j++) {
|
170
|
+
relative += this.segments[j];
|
171
|
+
|
172
|
+
if (j + 1 < this.segments.length) {
|
173
|
+
relative += "/";
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
if (this.path.charAt(this.path.length - 1) == '/') {
|
178
|
+
relative += "/";
|
179
|
+
}
|
180
|
+
|
181
|
+
return relative;
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
if (this.segments.length == otherURI.segments.length) {
|
186
|
+
return this.hash ? this.hash : this.query ? this.query : "";
|
187
|
+
} else if (i < this.segments.length) {
|
188
|
+
var relative = "";
|
189
|
+
|
190
|
+
for (var j = i; j < this.segments.length; j++) {
|
191
|
+
relative += this.segments[j];
|
192
|
+
|
193
|
+
if (j + 1 < this.segments.length) {
|
194
|
+
relative += "/";
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
if (this.path.charAt(this.path.length - 1) == '/') {
|
199
|
+
relative += "/";
|
200
|
+
}
|
201
|
+
|
202
|
+
return relative;
|
203
|
+
} else {
|
204
|
+
throw new Error("Cannot calculate a relative URI for " + this.spec + " against " + otherURI.spec);
|
205
|
+
}
|
206
|
+
};
|
207
|
+
|
208
|
+
return parsed;
|
209
|
+
}
|
210
|
+
}, {
|
211
|
+
key: "parseGeneric",
|
212
|
+
value: function parseGeneric(parsed) {
|
213
|
+
if (parsed.schemeSpecificPart.charAt(0) != '/' || parsed.schemeSpecificPart.charAt(1) != '/') {
|
214
|
+
throw new Error("Generic URI values should start with '//':" + parsed.spec);
|
215
|
+
}
|
216
|
+
|
217
|
+
var work = parsed.schemeSpecificPart.substring(2);
|
218
|
+
var pathStart = work.indexOf("/");
|
219
|
+
parsed.authority = pathStart < 0 ? work : work.substring(0, pathStart);
|
220
|
+
parsed.path = pathStart < 0 ? "" : work.substring(pathStart);
|
221
|
+
var hash = parsed.path.indexOf('#');
|
222
|
+
|
223
|
+
if (hash >= 0) {
|
224
|
+
parsed.fragment = parsed.path.substring(hash + 1);
|
225
|
+
parsed.path = parsed.path.substring(0, hash);
|
226
|
+
}
|
227
|
+
|
228
|
+
var questionMark = parsed.path.indexOf('?');
|
229
|
+
|
230
|
+
if (questionMark >= 0) {
|
231
|
+
parsed.query = parsed.path.substring(questionMark + 1);
|
232
|
+
parsed.path = parsed.path.substring(0, questionMark);
|
233
|
+
}
|
234
|
+
|
235
|
+
if (parsed.path == "/" || parsed.path == "") {
|
236
|
+
parsed.segments = [];
|
237
|
+
} else {
|
238
|
+
parsed.segments = parsed.path.split(/\//);
|
239
|
+
|
240
|
+
if (parsed.segments.length > 0 && parsed.segments[0] == '' && parsed.path.length > 1 && parsed.path.charAt(1) != '/') {
|
241
|
+
// empty segment at the start, remove it
|
242
|
+
parsed.segments.shift();
|
243
|
+
}
|
244
|
+
|
245
|
+
if (parsed.segments.length > 0 && parsed.path.length > 0 && parsed.path.charAt(parsed.path.length - 1) == '/' && parsed.segments[parsed.segments.length - 1] == '') {
|
246
|
+
// we may have an empty the end
|
247
|
+
// check to see if it is legimate
|
248
|
+
if (parsed.path.length > 1 && parsed.path.charAt(parsed.path.length - 2) != '/') {
|
249
|
+
parsed.segments.pop();
|
250
|
+
}
|
251
|
+
} // check for non-escaped characters
|
252
|
+
|
253
|
+
|
254
|
+
for (var i = 0; i < parsed.segments.length; i++) {
|
255
|
+
var check = parsed.segments[i].split(/%[A-Za-z0-9][A-Za-z0-9]|[\ud800-\udfff][\ud800-\udfff]|[A-Za-z0-9\-\._~!$&'()*+,;=@:\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+/);
|
256
|
+
|
257
|
+
for (var j = 0; j < check.length; j++) {
|
258
|
+
if (check[j].length > 0) {
|
259
|
+
throw new Error("Unecaped character " + check[j].charAt(0) + " (" + check[j].charCodeAt(0) + ") in URI " + parsed.spec);
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
parsed.isGeneric = true;
|
266
|
+
}
|
267
|
+
}]);
|
268
|
+
|
269
|
+
return URIResolver;
|
270
|
+
}();
|
271
|
+
|
272
|
+
exports.default = URIResolver;
|
273
|
+
URIResolver.SCHEME = /^[A-Za-z][A-Za-z0-9\+\-\.]*\:/;
|
274
|
+
module.exports = exports.default;
|
package/package.json
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
{
|
2
|
+
"name": "@lblod/graph-rdfa-processor",
|
3
|
+
"version": "2.1.0",
|
4
|
+
"description": "Green turtle GraphRdfaProcessor extracted and available as a commonJS module",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"module": "src/index.js",
|
7
|
+
"scripts": {
|
8
|
+
"test": "mocha --require @babel/register --exit",
|
9
|
+
"prepare": "rm -rf dist && babel src --out-dir dist",
|
10
|
+
"postversion": "git push && git push --tags"
|
11
|
+
},
|
12
|
+
"babel": {
|
13
|
+
"presets": [
|
14
|
+
[
|
15
|
+
"@babel/preset-env",
|
16
|
+
{
|
17
|
+
"targets": "> 0.25%, not dead"
|
18
|
+
}
|
19
|
+
]
|
20
|
+
],
|
21
|
+
"plugins": [
|
22
|
+
"add-module-exports"
|
23
|
+
]
|
24
|
+
},
|
25
|
+
"repository": {
|
26
|
+
"type": "git",
|
27
|
+
"url": "git+https://github.com/science-periodicals/graph-rdfa-processor.git"
|
28
|
+
},
|
29
|
+
"keywords": [
|
30
|
+
"RDFa"
|
31
|
+
],
|
32
|
+
"author": "Sebastien Ballesteros",
|
33
|
+
"license": "Apache-2.0",
|
34
|
+
"bugs": {
|
35
|
+
"url": "https://github.com/science-periodicals/graph-rdfa-processor/issues"
|
36
|
+
},
|
37
|
+
"homepage": "https://github.com/science-periodicals/graph-rdfa-processor#readme",
|
38
|
+
"devDependencies": {
|
39
|
+
"@babel/cli": "^7.5.5",
|
40
|
+
"@babel/core": "^7.5.5",
|
41
|
+
"@babel/preset-env": "^7.5.5",
|
42
|
+
"@babel/register": "^7.5.5",
|
43
|
+
"babel-plugin-add-module-exports": "^1.0.2",
|
44
|
+
"jsdom": "^9.11.0",
|
45
|
+
"mocha": "^6.2.0"
|
46
|
+
}
|
47
|
+
}
|
package/release.sh
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
import RDFaProcessor from './rdfa-processor';
|
2
|
+
import { RDFaSubject, RDFaPredicate } from './rdfa-graph';
|
3
|
+
|
4
|
+
export default class GraphRDFaProcessor extends RDFaProcessor {
|
5
|
+
constructor(target) {
|
6
|
+
super(target);
|
7
|
+
}
|
8
|
+
|
9
|
+
getObjectSize(obj) {
|
10
|
+
var size = 0;
|
11
|
+
for (var key in obj) {
|
12
|
+
if (obj.hasOwnProperty(key)) {
|
13
|
+
size++;
|
14
|
+
}
|
15
|
+
}
|
16
|
+
return size;
|
17
|
+
}
|
18
|
+
|
19
|
+
init() {
|
20
|
+
var thisObj = this;
|
21
|
+
this.finishedHandlers.push(function(node) {
|
22
|
+
for (var subject in thisObj.target.graph.subjects) {
|
23
|
+
var snode = thisObj.target.graph.subjects[subject];
|
24
|
+
if (thisObj.getObjectSize(snode.predicates)==0) {
|
25
|
+
delete thisObj.target.graph.subjects[subject];
|
26
|
+
}
|
27
|
+
}
|
28
|
+
});
|
29
|
+
}
|
30
|
+
|
31
|
+
newBlankNode() {
|
32
|
+
return this.target.graph.newBlankNode();
|
33
|
+
}
|
34
|
+
|
35
|
+
newSubjectOrigin(origin,subject) {
|
36
|
+
var snode = this.newSubject(null,subject);
|
37
|
+
for (var i=0; i < snode.origins.length; i++) {
|
38
|
+
if (snode.origins[i]===origin) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
snode.origins.push(origin);
|
43
|
+
if (!origin.data) {
|
44
|
+
Object.defineProperty(origin,"data", {
|
45
|
+
value: snode,
|
46
|
+
writable: false,
|
47
|
+
configurable: true,
|
48
|
+
enumerable: true
|
49
|
+
});
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
newSubject(origin,subject) {
|
54
|
+
var snode = this.target.graph.subjects[subject];
|
55
|
+
if (!snode) {
|
56
|
+
snode = new RDFaSubject(this.target.graph,subject);
|
57
|
+
this.target.graph.subjects[subject] = snode;
|
58
|
+
}
|
59
|
+
return snode;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
addTriple(origin,subject,predicate,object) {
|
64
|
+
var snode = this.newSubject(origin,subject);
|
65
|
+
var pnode = snode.predicates[predicate];
|
66
|
+
if (!pnode) {
|
67
|
+
pnode = new RDFaPredicate(predicate);
|
68
|
+
snode.predicates[predicate] = pnode;
|
69
|
+
}
|
70
|
+
|
71
|
+
for (var i=0; i < pnode.objects.length; i++) {
|
72
|
+
if (pnode.objects[i].type==object.type && pnode.objects[i].value==object.value) {
|
73
|
+
if (pnode.objects[i].origin!==origin) {
|
74
|
+
if (!Array.isArray(pnode.objects[i].origin)) {
|
75
|
+
var origins = [];
|
76
|
+
origins.push(pnode.objects[i].origin);
|
77
|
+
pnode.objects[i].origin = origins;
|
78
|
+
}
|
79
|
+
pnode.objects[i].origin.push(origin);
|
80
|
+
}
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
pnode.objects.push(object);
|
85
|
+
object.origin = origin;
|
86
|
+
if (predicate==RDFaProcessor.typeURI) {
|
87
|
+
snode.types.push(object.value);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
copyProperties() {
|
93
|
+
var copySubjects = [];
|
94
|
+
var patternSubjects = {};
|
95
|
+
for (var subject in this.target.graph.subjects) {
|
96
|
+
var snode = this.target.graph.subjects[subject];
|
97
|
+
var pnode = snode.predicates[GraphRDFaProcessor.rdfaCopyPredicate];
|
98
|
+
if (!pnode) {
|
99
|
+
continue;
|
100
|
+
}
|
101
|
+
copySubjects.push(subject);
|
102
|
+
for (var i=0; i < pnode.objects.length; i++) {
|
103
|
+
if (pnode.objects[i].type!=RDFaProcessor.objectURI) {
|
104
|
+
continue;
|
105
|
+
}
|
106
|
+
var target = pnode.objects[i].value;
|
107
|
+
var patternSubjectNode = this.target.graph.subjects[target];
|
108
|
+
if (!patternSubjectNode) {
|
109
|
+
continue;
|
110
|
+
}
|
111
|
+
var patternTypes = patternSubjectNode.predicates[RDFaProcessor.typeURI];
|
112
|
+
if (!patternTypes) {
|
113
|
+
continue;
|
114
|
+
}
|
115
|
+
var isPattern = false;
|
116
|
+
for (var j=0; j < patternTypes.objects.length && !isPattern; j++) {
|
117
|
+
if (patternTypes.objects[j].value==GraphRDFaProcessor.rdfaPatternType &&
|
118
|
+
patternTypes.objects[j].type==RDFaProcessor.objectURI) {
|
119
|
+
isPattern = true;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
if (!isPattern) {
|
123
|
+
continue;
|
124
|
+
}
|
125
|
+
patternSubjects[target] = true;
|
126
|
+
for (var predicate in patternSubjectNode.predicates) {
|
127
|
+
var targetPNode = patternSubjectNode.predicates[predicate];
|
128
|
+
if (predicate==RDFaProcessor.typeURI) {
|
129
|
+
if (targetPNode.objects.length==1) {
|
130
|
+
continue;
|
131
|
+
}
|
132
|
+
for (var j=0; j < targetPNode.objects.length; j++) {
|
133
|
+
if (targetPNode.objects[j].value!=GraphRDFaProcessor.rdfaPatternType) {
|
134
|
+
var subjectPNode = snode.predicates[predicate];
|
135
|
+
if (!subjectPNode) {
|
136
|
+
subjectPNode = new RDFaPredicate(predicate);
|
137
|
+
snode.predicates[predicate] = subjectPNode;
|
138
|
+
}
|
139
|
+
subjectPNode.objects.push(
|
140
|
+
{ type: targetPNode.objects[j].type,
|
141
|
+
value: targetPNode.objects[j].value,
|
142
|
+
language: targetPNode.objects[j].language,
|
143
|
+
origin: targetPNode.objects[j].origin}
|
144
|
+
);
|
145
|
+
snode.types.push(targetPNode.objects[j].value);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
} else {
|
149
|
+
var subjectPNode = snode.predicates[predicate];
|
150
|
+
if (!subjectPNode) {
|
151
|
+
subjectPNode = new RDFaPredicate(predicate);
|
152
|
+
snode.predicates[predicate] = subjectPNode;
|
153
|
+
}
|
154
|
+
for (var j=0; j < targetPNode.objects.length; j++) {
|
155
|
+
subjectPNode.objects.push(
|
156
|
+
{ type: targetPNode.objects[j].type,
|
157
|
+
value: targetPNode.objects[j].value,
|
158
|
+
language: targetPNode.objects[j].language,
|
159
|
+
origin: targetPNode.objects[j].origin}
|
160
|
+
);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
for (var i=0; i < copySubjects.length; i++) {
|
167
|
+
var snode = this.target.graph.subjects[copySubjects[i]];
|
168
|
+
delete snode.predicates[GraphRDFaProcessor.rdfaCopyPredicate];
|
169
|
+
}
|
170
|
+
for (var subject in patternSubjects) {
|
171
|
+
delete this.target.graph.subjects[subject];
|
172
|
+
}
|
173
|
+
}
|
174
|
+
};
|
175
|
+
|
176
|
+
GraphRDFaProcessor.rdfaCopyPredicate = "http://www.w3.org/ns/rdfa#copy";
|
177
|
+
GraphRDFaProcessor.rdfaPatternType = "http://www.w3.org/ns/rdfa#Pattern";
|
package/src/index.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
import URIResolver from "./uri-resolver";
|
2
|
+
import GraphRDFaProcessor from "./graph-rdfa-processor";
|
3
|
+
import { RDFaGraph } from "./rdfa-graph";
|
4
|
+
|
5
|
+
export default function(document, options = {}) {
|
6
|
+
let node = document.documentElement || document;
|
7
|
+
let baseURI = options.baseURI ? options.baseURI : node.baseURI;
|
8
|
+
let specialHtmlPredicates = options.specialHtmlPredicates || [];
|
9
|
+
|
10
|
+
let graph = new RDFaGraph();
|
11
|
+
|
12
|
+
let target = {
|
13
|
+
graph,
|
14
|
+
baseURI: new URIResolver().parseURI(baseURI),
|
15
|
+
specialHtmlPredicates,
|
16
|
+
};
|
17
|
+
|
18
|
+
var processor = new GraphRDFaProcessor(target);
|
19
|
+
processor.process(node, options);
|
20
|
+
return target.graph;
|
21
|
+
}
|
package/src/node.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
const Node = {
|
2
|
+
ELEMENT_NODE: 1,
|
3
|
+
ATTRIBUTE_NODE: 2,
|
4
|
+
TEXT_NODE: 3,
|
5
|
+
CDATA_SECTION_NODE: 4,
|
6
|
+
ENTITY_REFERENCE_NODE: 5,
|
7
|
+
ENTITY_NODE: 6,
|
8
|
+
PROCESSING_INSTRUCTION_NODE: 7,
|
9
|
+
COMMENT_NODE: 8,
|
10
|
+
DOCUMENT_NODE: 9,
|
11
|
+
DOCUMENT_TYPE_NODE: 10,
|
12
|
+
DOCUMENT_FRAGMENT_NODE: 11,
|
13
|
+
NOTATION_NODE:12
|
14
|
+
};
|
15
|
+
|
16
|
+
export default Node;
|