rdflib 2.2.21 → 2.2.22-b51259b5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +9 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +61 -114
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -128
- package/esm/convert.js +1 -2
- package/esm/default-graph.js +14 -48
- package/esm/empty.js +8 -39
- package/esm/factories/canonical-data-factory.js +33 -65
- package/esm/factories/extended-term-factory.js +18 -25
- package/esm/factories/factory-types.js +3 -2
- package/esm/factories/rdflib-data-factory.js +9 -19
- package/esm/fetcher.js +1341 -1854
- package/esm/formula.js +639 -846
- package/esm/index.js +40 -76
- package/esm/jsonldparser.js +24 -49
- package/esm/jsonparser.js +1 -8
- package/esm/lists.js +47 -110
- package/esm/literal.js +120 -189
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1015 -1412
- package/esm/named-node.js +70 -119
- package/esm/namespace.js +2 -5
- package/esm/node-internal.js +73 -110
- package/esm/node.js +2 -7
- package/esm/parse.js +12 -19
- package/esm/patch-parser.js +10 -30
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +63 -147
- package/esm/rdfaparser.js +794 -997
- package/esm/rdfxmlparser.js +347 -461
- package/esm/serialize.js +9 -27
- package/esm/serializer.js +820 -1049
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +54 -85
- package/esm/store.js +830 -1103
- package/esm/types.js +22 -21
- package/esm/update-manager.js +869 -1106
- package/esm/updates-via.js +104 -161
- package/esm/uri.js +9 -53
- package/esm/utils/default-graph-uri.js +3 -2
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +19 -21
- package/esm/utils-js.js +20 -61
- package/esm/utils.js +10 -21
- package/esm/variable.js +32 -78
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +60 -113
- package/lib/class-order.js +1 -2
- package/lib/collection.js +69 -131
- package/lib/convert.js +3 -9
- package/lib/default-graph.js +13 -52
- package/lib/empty.js +8 -43
- package/lib/factories/canonical-data-factory.js +35 -79
- package/lib/factories/extended-term-factory.js +18 -32
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +1 -4
- package/lib/factories/rdflib-data-factory.js +9 -23
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +1370 -1843
- package/lib/formula.js +640 -855
- package/lib/index.js +66 -152
- package/lib/jsonldparser.js +23 -53
- package/lib/jsonparser.js +1 -10
- package/lib/lists.js +55 -112
- package/lib/literal.js +120 -195
- package/lib/log.d.ts +0 -6
- package/lib/log.js +7 -8
- package/lib/n3parser.js +1030 -1436
- package/lib/named-node.js +69 -126
- package/lib/namespace.js +2 -7
- package/lib/node-internal.js +74 -107
- package/lib/node.js +2 -12
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +12 -32
- package/lib/patch-parser.js +11 -34
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +62 -167
- package/lib/rdfaparser.js +796 -1009
- package/lib/rdfxmlparser.js +349 -466
- package/lib/serialize.js +11 -37
- package/lib/serializer.js +823 -1064
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +55 -91
- package/lib/store.d.ts +1 -1
- package/lib/store.js +850 -1112
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +23 -23
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +865 -1103
- package/lib/updates-via.js +105 -164
- package/lib/uri.js +8 -61
- package/lib/utils/default-graph-uri.js +3 -5
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +19 -40
- package/lib/utils-js.js +23 -88
- package/lib/utils.js +10 -27
- package/lib/variable.js +34 -85
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +2 -6
- package/package.json +35 -35
- package/src/fetcher.ts +2 -2
- package/src/update-manager.ts +12 -7
- package/changes.txt +0 -59
package/lib/named-node.js
CHANGED
|
@@ -1,169 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
9
|
var _classOrder = _interopRequireDefault(require("./class-order"));
|
|
25
|
-
|
|
26
10
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
27
|
-
|
|
28
11
|
var _types = require("./types");
|
|
29
|
-
|
|
30
12
|
var _termValue = require("./utils/termValue");
|
|
31
|
-
|
|
32
13
|
var _terms = require("./utils/terms");
|
|
33
|
-
|
|
34
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
35
|
-
|
|
36
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
37
|
-
|
|
38
14
|
/**
|
|
39
15
|
* A named (IRI) RDF node
|
|
40
16
|
*/
|
|
41
|
-
|
|
42
|
-
(0, _inherits2.default)(NamedNode, _Node);
|
|
43
|
-
|
|
44
|
-
var _super = _createSuper(NamedNode);
|
|
45
|
-
|
|
17
|
+
class NamedNode extends _nodeInternal.default {
|
|
46
18
|
/**
|
|
47
19
|
* Create a named (IRI) RDF Node
|
|
48
20
|
* @constructor
|
|
49
21
|
* @param iri - The IRI for this node
|
|
50
22
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(0,
|
|
55
|
-
|
|
56
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "termType", _types.NamedNodeTermType);
|
|
57
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "classOrder", _classOrder.default.NamedNode);
|
|
58
|
-
|
|
59
|
-
if (!_this.value) {
|
|
23
|
+
constructor(iri) {
|
|
24
|
+
super((0, _termValue.termValue)(iri));
|
|
25
|
+
(0, _defineProperty2.default)(this, "termType", _types.NamedNodeTermType);
|
|
26
|
+
(0, _defineProperty2.default)(this, "classOrder", _classOrder.default.NamedNode);
|
|
27
|
+
if (!this.value) {
|
|
60
28
|
throw new Error('Missing IRI for NamedNode');
|
|
61
29
|
}
|
|
62
|
-
|
|
63
|
-
if (!_this.value.includes(':')) {
|
|
30
|
+
if (!this.value.includes(':')) {
|
|
64
31
|
throw new Error('NamedNode IRI "' + iri + '" must be absolute.');
|
|
65
32
|
}
|
|
66
|
-
|
|
67
|
-
if (_this.value.includes(' ')) {
|
|
33
|
+
if (this.value.includes(' ')) {
|
|
68
34
|
var message = 'Error: NamedNode IRI "' + iri + '" must not contain unencoded spaces.';
|
|
69
35
|
throw new Error(message);
|
|
70
36
|
}
|
|
71
|
-
|
|
72
|
-
return _this;
|
|
73
37
|
}
|
|
38
|
+
|
|
74
39
|
/**
|
|
75
40
|
* Returns an $rdf node for the containing directory, ending in slash.
|
|
76
41
|
*/
|
|
42
|
+
dir() {
|
|
43
|
+
var str = this.value.split('#')[0];
|
|
44
|
+
var p = str.slice(0, -1).lastIndexOf('/');
|
|
45
|
+
var q = str.indexOf('//');
|
|
46
|
+
if (q >= 0 && p < q + 2 || p < 0) return null;
|
|
47
|
+
return new NamedNode(str.slice(0, p + 1));
|
|
48
|
+
}
|
|
77
49
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Returns an NN for the whole web site, ending in slash.
|
|
52
|
+
* Contrast with the "origin" which does NOT have a trailing slash
|
|
53
|
+
*/
|
|
54
|
+
site() {
|
|
55
|
+
var str = this.value.split('#')[0];
|
|
56
|
+
var p = str.indexOf('//');
|
|
57
|
+
if (p < 0) throw new Error('This URI does not have a web site part (origin)');
|
|
58
|
+
var q = str.indexOf('/', p + 2);
|
|
59
|
+
if (q < 0) {
|
|
60
|
+
return new NamedNode(str.slice(0) + '/'); // Add slash to a bare origin
|
|
61
|
+
} else {
|
|
62
|
+
return new NamedNode(str.slice(0, q + 1));
|
|
87
63
|
}
|
|
88
|
-
|
|
89
|
-
* Returns an NN for the whole web site, ending in slash.
|
|
90
|
-
* Contrast with the "origin" which does NOT have a trailing slash
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
}, {
|
|
94
|
-
key: "site",
|
|
95
|
-
value: function site() {
|
|
96
|
-
var str = this.value.split('#')[0];
|
|
97
|
-
var p = str.indexOf('//');
|
|
98
|
-
if (p < 0) throw new Error('This URI does not have a web site part (origin)');
|
|
99
|
-
var q = str.indexOf('/', p + 2);
|
|
64
|
+
}
|
|
100
65
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Creates the fetchable named node for the document.
|
|
68
|
+
* Removes everything from the # anchor tag.
|
|
69
|
+
*/
|
|
70
|
+
doc() {
|
|
71
|
+
if (this.value.indexOf('#') < 0) {
|
|
72
|
+
return this;
|
|
73
|
+
} else {
|
|
74
|
+
return new NamedNode(this.value.split('#')[0]);
|
|
106
75
|
}
|
|
107
|
-
|
|
108
|
-
* Creates the fetchable named node for the document.
|
|
109
|
-
* Removes everything from the # anchor tag.
|
|
110
|
-
*/
|
|
76
|
+
}
|
|
111
77
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return new NamedNode(this.value.split('#')[0]);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns the URI including <brackets>
|
|
123
|
-
*/
|
|
78
|
+
/**
|
|
79
|
+
* Returns the URI including <brackets>
|
|
80
|
+
*/
|
|
81
|
+
toString() {
|
|
82
|
+
return '<' + this.value + '>';
|
|
83
|
+
}
|
|
124
84
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
value
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
/** The local identifier with the document */
|
|
85
|
+
/** The local identifier with the document */
|
|
86
|
+
id() {
|
|
87
|
+
return this.value.split('#')[1];
|
|
88
|
+
}
|
|
131
89
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
value
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
90
|
+
/** Alias for value, favored by Tim */
|
|
91
|
+
get uri() {
|
|
92
|
+
return this.value;
|
|
93
|
+
}
|
|
94
|
+
set uri(uri) {
|
|
95
|
+
this.value = uri;
|
|
96
|
+
}
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Creates a named node from the specified input value
|
|
100
|
+
* @param value - An input value
|
|
101
|
+
*/
|
|
102
|
+
static fromValue(value) {
|
|
103
|
+
if (typeof value === 'undefined' || value === null) {
|
|
104
|
+
return value;
|
|
146
105
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
* @param value - An input value
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
}], [{
|
|
153
|
-
key: "fromValue",
|
|
154
|
-
value: function fromValue(value) {
|
|
155
|
-
if (typeof value === 'undefined' || value === null) {
|
|
156
|
-
return value;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if ((0, _terms.isTerm)(value)) {
|
|
160
|
-
return value;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return new NamedNode(value);
|
|
106
|
+
if ((0, _terms.isTerm)(value)) {
|
|
107
|
+
return value;
|
|
164
108
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
109
|
+
return new NamedNode(value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
169
112
|
exports.default = NamedNode;
|
package/lib/namespace.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = Namespace;
|
|
9
|
-
|
|
10
8
|
var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Gets a namespace for the specified namespace's URI
|
|
14
11
|
* @param nsuri - The URI for the namespace
|
|
15
12
|
* @param [factory] - The factory for creating named nodes with
|
|
16
13
|
*/
|
|
17
14
|
function Namespace(nsuri, factory) {
|
|
18
|
-
|
|
19
|
-
namedNode:
|
|
20
|
-
return new _namedNode.default(value);
|
|
21
|
-
}
|
|
15
|
+
const dataFactory = factory || {
|
|
16
|
+
namedNode: value => new _namedNode.default(value)
|
|
22
17
|
};
|
|
23
18
|
return function (ln) {
|
|
24
19
|
return dataFactory.namedNode(nsuri + (ln || ''));
|
package/lib/node-internal.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
9
|
/**
|
|
17
10
|
* The superclass of all RDF Statement objects, that is
|
|
18
11
|
* NamedNode, Literal, BlankNode, etc.
|
|
@@ -21,8 +14,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
21
14
|
* @link https://rdf.js.org/data-model-spec/#term-interface
|
|
22
15
|
* @class Node
|
|
23
16
|
*/
|
|
24
|
-
|
|
17
|
+
class Node {
|
|
25
18
|
// Specified in './node.ts' to prevent circular dependency
|
|
19
|
+
|
|
26
20
|
// Specified in './node.ts' to prevent circular dependency
|
|
27
21
|
|
|
28
22
|
/** The type of node */
|
|
@@ -30,126 +24,99 @@ var Node = /*#__PURE__*/function () {
|
|
|
30
24
|
/** The class order for this node */
|
|
31
25
|
|
|
32
26
|
/** The node's value */
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
|
|
28
|
+
constructor(value) {
|
|
35
29
|
(0, _defineProperty2.default)(this, "termType", void 0);
|
|
36
30
|
(0, _defineProperty2.default)(this, "classOrder", void 0);
|
|
37
31
|
(0, _defineProperty2.default)(this, "value", void 0);
|
|
38
32
|
this.value = value;
|
|
39
33
|
}
|
|
34
|
+
|
|
40
35
|
/**
|
|
41
36
|
* Creates the substituted node for this one, according to the specified bindings
|
|
42
37
|
* @param bindings - Bindings of identifiers to nodes
|
|
43
38
|
*/
|
|
39
|
+
substitute(bindings) {
|
|
40
|
+
console.log('@@@ node substitute' + this);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Compares this node with another
|
|
46
|
+
* @see {equals} to check if two nodes are equal
|
|
47
|
+
* @param other - The other node
|
|
48
|
+
*/
|
|
49
|
+
compareTerm(other) {
|
|
50
|
+
if (this.classOrder < other.classOrder) {
|
|
51
|
+
return -1;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* @see {equals} to check if two nodes are equal
|
|
55
|
-
* @param other - The other node
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
}, {
|
|
59
|
-
key: "compareTerm",
|
|
60
|
-
value: function compareTerm(other) {
|
|
61
|
-
if (this.classOrder < other.classOrder) {
|
|
62
|
-
return -1;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (this.classOrder > other.classOrder) {
|
|
66
|
-
return +1;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (this.value < other.value) {
|
|
70
|
-
return -1;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (this.value > other.value) {
|
|
74
|
-
return +1;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return 0;
|
|
53
|
+
if (this.classOrder > other.classOrder) {
|
|
54
|
+
return +1;
|
|
78
55
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* @param other The other node
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
}, {
|
|
85
|
-
key: "equals",
|
|
86
|
-
value: function equals(other) {
|
|
87
|
-
if (!other) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return this.termType === other.termType && this.value === other.value;
|
|
56
|
+
if (this.value < other.value) {
|
|
57
|
+
return -1;
|
|
92
58
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
* @deprecated use {rdfFactory.id} instead if possible
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
}, {
|
|
99
|
-
key: "hashString",
|
|
100
|
-
value: function hashString() {
|
|
101
|
-
return this.toCanonical();
|
|
59
|
+
if (this.value > other.value) {
|
|
60
|
+
return +1;
|
|
102
61
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
* @param other - Another node
|
|
106
|
-
*/
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
107
64
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Compares whether the two nodes are equal
|
|
67
|
+
* @param other The other node
|
|
68
|
+
*/
|
|
69
|
+
equals(other) {
|
|
70
|
+
if (!other) {
|
|
71
|
+
return false;
|
|
112
72
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
*/
|
|
73
|
+
return this.termType === other.termType && this.value === other.value;
|
|
74
|
+
}
|
|
116
75
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
*/
|
|
76
|
+
/**
|
|
77
|
+
* Creates a hash for this node
|
|
78
|
+
* @deprecated use {rdfFactory.id} instead if possible
|
|
79
|
+
*/
|
|
80
|
+
hashString() {
|
|
81
|
+
return this.toCanonical();
|
|
82
|
+
}
|
|
125
83
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
*/
|
|
84
|
+
/**
|
|
85
|
+
* Compares whether this node is the same as the other one
|
|
86
|
+
* @param other - Another node
|
|
87
|
+
*/
|
|
88
|
+
sameTerm(other) {
|
|
89
|
+
return this.equals(other);
|
|
90
|
+
}
|
|
134
91
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
* Creates a string representation of this node
|
|
142
|
-
*/
|
|
92
|
+
/**
|
|
93
|
+
* Creates a canonical string representation of this node
|
|
94
|
+
*/
|
|
95
|
+
toCanonical() {
|
|
96
|
+
return this.toNT();
|
|
97
|
+
}
|
|
143
98
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
return Node;
|
|
151
|
-
}();
|
|
99
|
+
/**
|
|
100
|
+
* Creates a n-triples string representation of this node
|
|
101
|
+
*/
|
|
102
|
+
toNT() {
|
|
103
|
+
return this.toString();
|
|
104
|
+
}
|
|
152
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Creates a n-quads string representation of this node
|
|
108
|
+
*/
|
|
109
|
+
toNQ() {
|
|
110
|
+
return this.toNT();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Creates a string representation of this node
|
|
115
|
+
*/
|
|
116
|
+
toString() {
|
|
117
|
+
throw new Error('Node.toString() is abstract - see the subclasses instead');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
153
120
|
exports.default = Node;
|
|
154
121
|
(0, _defineProperty2.default)(Node, "fromValue", void 0);
|
|
155
122
|
(0, _defineProperty2.default)(Node, "toJS", void 0);
|
package/lib/node.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _collection = require("./collection");
|
|
11
|
-
|
|
12
9
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
13
|
-
|
|
14
10
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
15
|
-
|
|
16
11
|
var _terms = require("./utils/terms");
|
|
17
|
-
|
|
18
12
|
// This file attaches all functionality to Node
|
|
19
13
|
// that would otherwise require circular dependencies.
|
|
20
14
|
|
|
@@ -29,32 +23,28 @@ var _terms = require("./utils/terms");
|
|
|
29
23
|
_nodeInternal.default.fromValue = _collection.fromValue;
|
|
30
24
|
var _default = _nodeInternal.default;
|
|
31
25
|
exports.default = _default;
|
|
32
|
-
|
|
26
|
+
const ns = {
|
|
33
27
|
xsd: (0, _namespace.default)('http://www.w3.org/2001/XMLSchema#')
|
|
34
28
|
};
|
|
29
|
+
|
|
35
30
|
/**
|
|
36
31
|
* Gets the javascript object equivalent to a node
|
|
37
32
|
* @param term The RDF node
|
|
38
33
|
*/
|
|
39
|
-
|
|
40
34
|
_nodeInternal.default.toJS = function (term) {
|
|
41
35
|
if ((0, _terms.isCollection)(term)) {
|
|
42
36
|
return term.elements.map(_nodeInternal.default.toJS); // Array node (not standard RDFJS)
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
if (!(0, _terms.isLiteral)(term)) return term;
|
|
46
|
-
|
|
47
40
|
if (term.datatype.equals(ns.xsd('boolean'))) {
|
|
48
41
|
return term.value === '1' || term.value === 'true';
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
if (term.datatype.equals(ns.xsd('dateTime')) || term.datatype.equals(ns.xsd('date'))) {
|
|
52
44
|
return new Date(term.value);
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
if (term.datatype.equals(ns.xsd('integer')) || term.datatype.equals(ns.xsd('float')) || term.datatype.equals(ns.xsd('decimal'))) {
|
|
56
47
|
return Number(term.value);
|
|
57
48
|
}
|
|
58
|
-
|
|
59
49
|
return term.value;
|
|
60
50
|
};
|
package/lib/parse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Formula from './formula';
|
|
2
2
|
import { ContentType } from './types';
|
|
3
|
-
|
|
3
|
+
type CallbackFunc = (error: any, kb: Formula | null) => void;
|
|
4
4
|
/**
|
|
5
5
|
* Parse a string and put the result into the graph kb.
|
|
6
6
|
* Normal method is sync.
|
package/lib/parse.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
4
|
Object.defineProperty(exports, "__esModule", {
|
|
8
5
|
value: true
|
|
9
6
|
});
|
|
10
7
|
exports.default = parse;
|
|
11
|
-
|
|
12
8
|
var _extendedTermFactory = _interopRequireDefault(require("./factories/extended-term-factory"));
|
|
13
|
-
|
|
14
9
|
var _jsonldparser = _interopRequireDefault(require("./jsonldparser"));
|
|
15
|
-
|
|
16
10
|
var _n = require("n3");
|
|
17
|
-
|
|
18
11
|
var _n3parser = _interopRequireDefault(require("./n3parser"));
|
|
19
|
-
|
|
20
12
|
var _rdfaparser = require("./rdfaparser");
|
|
21
|
-
|
|
22
13
|
var _rdfxmlparser = _interopRequireDefault(require("./rdfxmlparser"));
|
|
23
|
-
|
|
24
14
|
var _patchParser = _interopRequireDefault(require("./patch-parser"));
|
|
25
|
-
|
|
26
15
|
var Util = _interopRequireWildcard(require("./utils-js"));
|
|
27
|
-
|
|
28
16
|
var _types = require("./types");
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
-
|
|
17
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
19
|
// @ts-ignore is this injected?
|
|
35
20
|
// @@ Goal: remove this dependency
|
|
36
21
|
|
|
@@ -46,11 +31,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
46
31
|
* @param [callback] - The callback to call when the data has been loaded
|
|
47
32
|
*/
|
|
48
33
|
function parse(str, kb, base) {
|
|
49
|
-
|
|
50
|
-
|
|
34
|
+
let contentType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'text/turtle';
|
|
35
|
+
let callback = arguments.length > 4 ? arguments[4] : undefined;
|
|
51
36
|
contentType = contentType || _types.TurtleContentType;
|
|
52
37
|
contentType = contentType.split(';')[0];
|
|
53
|
-
|
|
54
38
|
try {
|
|
55
39
|
if (contentType === _types.N3ContentType || contentType === _types.TurtleContentType) {
|
|
56
40
|
var p = (0, _n3parser.default)(kb, kb, base, base, null, null, '', null);
|
|
@@ -90,7 +74,6 @@ function parse(str, kb, base) {
|
|
|
90
74
|
// @ts-ignore
|
|
91
75
|
executeErrorCallback(e);
|
|
92
76
|
}
|
|
93
|
-
|
|
94
77
|
parse.handled = {
|
|
95
78
|
'text/n3': true,
|
|
96
79
|
'text/turtle': true,
|
|
@@ -103,7 +86,6 @@ function parse(str, kb, base) {
|
|
|
103
86
|
'application/nquads': true,
|
|
104
87
|
'application/n-quads': true
|
|
105
88
|
};
|
|
106
|
-
|
|
107
89
|
function executeCallback() {
|
|
108
90
|
if (callback) {
|
|
109
91
|
callback(null, kb);
|
|
@@ -111,17 +93,19 @@ function parse(str, kb, base) {
|
|
|
111
93
|
return;
|
|
112
94
|
}
|
|
113
95
|
}
|
|
114
|
-
|
|
115
96
|
function executeErrorCallback(e) {
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
contentType !== _types.
|
|
97
|
+
if (
|
|
98
|
+
// TODO: Always true, what is the right behavior
|
|
99
|
+
contentType !== _types.JSONLDContentType ||
|
|
100
|
+
// @ts-ignore always true?
|
|
101
|
+
contentType !== _types.NQuadsContentType ||
|
|
102
|
+
// @ts-ignore always true?
|
|
119
103
|
contentType !== _types.NQuadsAltContentType) {
|
|
120
104
|
if (callback) {
|
|
121
105
|
callback(e, kb);
|
|
122
106
|
} else {
|
|
123
|
-
|
|
124
|
-
|
|
107
|
+
let e2 = new Error('' + e + ' while trying to parse <' + base + '> as ' + contentType);
|
|
108
|
+
//@ts-ignore .cause is not a default error property
|
|
125
109
|
e2.cause = e;
|
|
126
110
|
throw e2;
|
|
127
111
|
}
|
|
@@ -138,20 +122,16 @@ function parse(str, kb, base) {
|
|
|
138
122
|
doc['@context']['@base'] = base
|
|
139
123
|
}
|
|
140
124
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
125
|
function nquadCallback(err, nquads) {
|
|
144
126
|
if (err) {
|
|
145
127
|
callback(err, kb);
|
|
146
128
|
}
|
|
147
|
-
|
|
148
129
|
try {
|
|
149
130
|
n3Parser.parse(nquads, tripleCallback);
|
|
150
131
|
} catch (err) {
|
|
151
132
|
callback(err, kb);
|
|
152
133
|
}
|
|
153
134
|
}
|
|
154
|
-
|
|
155
135
|
function tripleCallback(err, triple) {
|
|
156
136
|
if (triple) {
|
|
157
137
|
kb.add(triple.subject, triple.predicate, triple.object, triple.graph);
|