rdflib 2.2.21 → 2.2.22-0de51c50
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 +13 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +3 -27
- package/esm/collection.js +7 -29
- package/esm/default-graph.js +1 -15
- package/esm/empty.js +0 -13
- package/esm/factories/canonical-data-factory.js +5 -40
- package/esm/factories/extended-term-factory.js +0 -11
- package/esm/factories/factory-types.js +2 -1
- package/esm/factories/rdflib-data-factory.js +0 -8
- package/esm/fetcher.js +257 -481
- package/esm/formula.js +43 -142
- package/esm/index.js +19 -36
- package/esm/jsonldparser.js +20 -29
- package/esm/jsonparser.js +0 -7
- package/esm/lists.js +18 -33
- package/esm/literal.js +10 -42
- package/esm/n3parser.js +38 -351
- package/esm/named-node.js +8 -27
- package/esm/namespace.js +0 -1
- package/esm/node-internal.js +11 -24
- package/esm/node.js +1 -6
- package/esm/parse.js +10 -17
- package/esm/patch-parser.js +9 -29
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +50 -133
- package/esm/rdfaparser.js +72 -210
- package/esm/rdfxmlparser.js +31 -128
- package/esm/serialize.js +8 -33
- package/esm/serializer.js +122 -286
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +8 -19
- package/esm/store.js +109 -280
- package/esm/types.js +3 -2
- package/esm/update-manager.js +110 -246
- package/esm/updates-via.js +0 -27
- package/esm/uri.js +6 -50
- package/esm/utils/default-graph-uri.js +1 -0
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +15 -16
- package/esm/utils-js.js +16 -57
- package/esm/utils.js +4 -15
- package/esm/variable.js +0 -20
- package/lib/blank-node.js +3 -28
- package/lib/class-order.js +0 -1
- package/lib/collection.js +7 -34
- package/lib/default-graph.js +0 -20
- package/lib/empty.js +0 -18
- package/lib/factories/canonical-data-factory.js +4 -51
- package/lib/factories/extended-term-factory.js +0 -18
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +0 -3
- package/lib/factories/rdflib-data-factory.js +0 -12
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +258 -470
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +43 -151
- package/lib/index.d.ts +1 -2
- package/lib/index.js +14 -82
- package/lib/jsonldparser.js +19 -33
- package/lib/jsonparser.js +0 -9
- package/lib/lists.js +14 -39
- package/lib/literal.js +10 -49
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -1
- package/lib/n3parser.d.ts +1 -0
- package/lib/n3parser.js +39 -359
- package/lib/named-node.js +7 -35
- package/lib/namespace.js +0 -3
- package/lib/node-internal.js +11 -21
- package/lib/node.js +1 -11
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +8 -27
- package/lib/patch-parser.js +10 -33
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +46 -152
- package/lib/rdfaparser.js +72 -220
- package/lib/rdfxmlparser.js +31 -132
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +8 -43
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +121 -297
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +8 -24
- package/lib/store.d.ts +2 -2
- package/lib/store.js +102 -282
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +3 -3
- package/lib/update-manager.d.ts +2 -2
- package/lib/update-manager.js +110 -254
- package/lib/updates-via.js +0 -30
- package/lib/uri.js +5 -58
- package/lib/utils/default-graph-uri.js +1 -3
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +15 -34
- package/lib/utils-js.js +16 -80
- package/lib/utils.js +4 -21
- package/lib/variable.js +0 -25
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +0 -4
- package/package.json +40 -39
- package/src/fetcher.ts +2 -2
- package/src/index.ts +0 -2
- package/src/jsonldparser.js +13 -4
- package/src/n3parser.js +12 -4
- package/src/serialize.ts +4 -11
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +18 -7
- package/changes.txt +0 -59
- package/esm/convert.js +0 -61
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -77
- package/src/convert.js +0 -70
package/lib/named-node.js
CHANGED
|
@@ -1,48 +1,30 @@
|
|
|
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
10
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
11
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
12
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
13
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
15
|
var _classOrder = _interopRequireDefault(require("./class-order"));
|
|
25
|
-
|
|
26
16
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
27
|
-
|
|
28
17
|
var _types = require("./types");
|
|
29
|
-
|
|
30
18
|
var _termValue = require("./utils/termValue");
|
|
31
|
-
|
|
32
19
|
var _terms = require("./utils/terms");
|
|
33
|
-
|
|
34
20
|
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
21
|
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
22
|
/**
|
|
39
23
|
* A named (IRI) RDF node
|
|
40
24
|
*/
|
|
41
25
|
var NamedNode = /*#__PURE__*/function (_Node) {
|
|
42
26
|
(0, _inherits2.default)(NamedNode, _Node);
|
|
43
|
-
|
|
44
27
|
var _super = _createSuper(NamedNode);
|
|
45
|
-
|
|
46
28
|
/**
|
|
47
29
|
* Create a named (IRI) RDF Node
|
|
48
30
|
* @constructor
|
|
@@ -50,32 +32,26 @@ var NamedNode = /*#__PURE__*/function (_Node) {
|
|
|
50
32
|
*/
|
|
51
33
|
function NamedNode(iri) {
|
|
52
34
|
var _this;
|
|
53
|
-
|
|
54
35
|
(0, _classCallCheck2.default)(this, NamedNode);
|
|
55
36
|
_this = _super.call(this, (0, _termValue.termValue)(iri));
|
|
56
37
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "termType", _types.NamedNodeTermType);
|
|
57
38
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "classOrder", _classOrder.default.NamedNode);
|
|
58
|
-
|
|
59
39
|
if (!_this.value) {
|
|
60
40
|
throw new Error('Missing IRI for NamedNode');
|
|
61
41
|
}
|
|
62
|
-
|
|
63
42
|
if (!_this.value.includes(':')) {
|
|
64
43
|
throw new Error('NamedNode IRI "' + iri + '" must be absolute.');
|
|
65
44
|
}
|
|
66
|
-
|
|
67
45
|
if (_this.value.includes(' ')) {
|
|
68
46
|
var message = 'Error: NamedNode IRI "' + iri + '" must not contain unencoded spaces.';
|
|
69
47
|
throw new Error(message);
|
|
70
48
|
}
|
|
71
|
-
|
|
72
49
|
return _this;
|
|
73
50
|
}
|
|
51
|
+
|
|
74
52
|
/**
|
|
75
53
|
* Returns an $rdf node for the containing directory, ending in slash.
|
|
76
54
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
55
|
(0, _createClass2.default)(NamedNode, [{
|
|
80
56
|
key: "dir",
|
|
81
57
|
value: function dir() {
|
|
@@ -85,11 +61,11 @@ var NamedNode = /*#__PURE__*/function (_Node) {
|
|
|
85
61
|
if (q >= 0 && p < q + 2 || p < 0) return null;
|
|
86
62
|
return new NamedNode(str.slice(0, p + 1));
|
|
87
63
|
}
|
|
64
|
+
|
|
88
65
|
/**
|
|
89
66
|
* Returns an NN for the whole web site, ending in slash.
|
|
90
67
|
* Contrast with the "origin" which does NOT have a trailing slash
|
|
91
68
|
*/
|
|
92
|
-
|
|
93
69
|
}, {
|
|
94
70
|
key: "site",
|
|
95
71
|
value: function site() {
|
|
@@ -97,18 +73,17 @@ var NamedNode = /*#__PURE__*/function (_Node) {
|
|
|
97
73
|
var p = str.indexOf('//');
|
|
98
74
|
if (p < 0) throw new Error('This URI does not have a web site part (origin)');
|
|
99
75
|
var q = str.indexOf('/', p + 2);
|
|
100
|
-
|
|
101
76
|
if (q < 0) {
|
|
102
77
|
return new NamedNode(str.slice(0) + '/'); // Add slash to a bare origin
|
|
103
78
|
} else {
|
|
104
79
|
return new NamedNode(str.slice(0, q + 1));
|
|
105
80
|
}
|
|
106
81
|
}
|
|
82
|
+
|
|
107
83
|
/**
|
|
108
84
|
* Creates the fetchable named node for the document.
|
|
109
85
|
* Removes everything from the # anchor tag.
|
|
110
86
|
*/
|
|
111
|
-
|
|
112
87
|
}, {
|
|
113
88
|
key: "doc",
|
|
114
89
|
value: function doc() {
|
|
@@ -118,24 +93,24 @@ var NamedNode = /*#__PURE__*/function (_Node) {
|
|
|
118
93
|
return new NamedNode(this.value.split('#')[0]);
|
|
119
94
|
}
|
|
120
95
|
}
|
|
96
|
+
|
|
121
97
|
/**
|
|
122
98
|
* Returns the URI including <brackets>
|
|
123
99
|
*/
|
|
124
|
-
|
|
125
100
|
}, {
|
|
126
101
|
key: "toString",
|
|
127
102
|
value: function toString() {
|
|
128
103
|
return '<' + this.value + '>';
|
|
129
104
|
}
|
|
130
|
-
/** The local identifier with the document */
|
|
131
105
|
|
|
106
|
+
/** The local identifier with the document */
|
|
132
107
|
}, {
|
|
133
108
|
key: "id",
|
|
134
109
|
value: function id() {
|
|
135
110
|
return this.value.split('#')[1];
|
|
136
111
|
}
|
|
137
|
-
/** Alias for value, favored by Tim */
|
|
138
112
|
|
|
113
|
+
/** Alias for value, favored by Tim */
|
|
139
114
|
}, {
|
|
140
115
|
key: "uri",
|
|
141
116
|
get: function get() {
|
|
@@ -144,26 +119,23 @@ var NamedNode = /*#__PURE__*/function (_Node) {
|
|
|
144
119
|
set: function set(uri) {
|
|
145
120
|
this.value = uri;
|
|
146
121
|
}
|
|
122
|
+
|
|
147
123
|
/**
|
|
148
124
|
* Creates a named node from the specified input value
|
|
149
125
|
* @param value - An input value
|
|
150
126
|
*/
|
|
151
|
-
|
|
152
127
|
}], [{
|
|
153
128
|
key: "fromValue",
|
|
154
129
|
value: function fromValue(value) {
|
|
155
130
|
if (typeof value === 'undefined' || value === null) {
|
|
156
131
|
return value;
|
|
157
132
|
}
|
|
158
|
-
|
|
159
133
|
if ((0, _terms.isTerm)(value)) {
|
|
160
134
|
return value;
|
|
161
135
|
}
|
|
162
|
-
|
|
163
136
|
return new NamedNode(value);
|
|
164
137
|
}
|
|
165
138
|
}]);
|
|
166
139
|
return NamedNode;
|
|
167
140
|
}(_nodeInternal.default);
|
|
168
|
-
|
|
169
141
|
exports.default = NamedNode;
|
package/lib/namespace.js
CHANGED
|
@@ -1,14 +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 = 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
|
package/lib/node-internal.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* The superclass of all RDF Statement objects, that is
|
|
18
13
|
* NamedNode, Literal, BlankNode, etc.
|
|
@@ -23,6 +18,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
23
18
|
*/
|
|
24
19
|
var Node = /*#__PURE__*/function () {
|
|
25
20
|
// Specified in './node.ts' to prevent circular dependency
|
|
21
|
+
|
|
26
22
|
// Specified in './node.ts' to prevent circular dependency
|
|
27
23
|
|
|
28
24
|
/** The type of node */
|
|
@@ -30,6 +26,7 @@ var Node = /*#__PURE__*/function () {
|
|
|
30
26
|
/** The class order for this node */
|
|
31
27
|
|
|
32
28
|
/** The node's value */
|
|
29
|
+
|
|
33
30
|
function Node(value) {
|
|
34
31
|
(0, _classCallCheck2.default)(this, Node);
|
|
35
32
|
(0, _defineProperty2.default)(this, "termType", void 0);
|
|
@@ -37,110 +34,104 @@ var Node = /*#__PURE__*/function () {
|
|
|
37
34
|
(0, _defineProperty2.default)(this, "value", void 0);
|
|
38
35
|
this.value = value;
|
|
39
36
|
}
|
|
37
|
+
|
|
40
38
|
/**
|
|
41
39
|
* Creates the substituted node for this one, according to the specified bindings
|
|
42
40
|
* @param bindings - Bindings of identifiers to nodes
|
|
43
41
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
42
|
(0, _createClass2.default)(Node, [{
|
|
47
43
|
key: "substitute",
|
|
48
44
|
value: function substitute(bindings) {
|
|
49
45
|
console.log('@@@ node substitute' + this);
|
|
50
46
|
return this;
|
|
51
47
|
}
|
|
48
|
+
|
|
52
49
|
/**
|
|
53
50
|
* Compares this node with another
|
|
54
51
|
* @see {equals} to check if two nodes are equal
|
|
55
52
|
* @param other - The other node
|
|
56
53
|
*/
|
|
57
|
-
|
|
58
54
|
}, {
|
|
59
55
|
key: "compareTerm",
|
|
60
56
|
value: function compareTerm(other) {
|
|
61
57
|
if (this.classOrder < other.classOrder) {
|
|
62
58
|
return -1;
|
|
63
59
|
}
|
|
64
|
-
|
|
65
60
|
if (this.classOrder > other.classOrder) {
|
|
66
61
|
return +1;
|
|
67
62
|
}
|
|
68
|
-
|
|
69
63
|
if (this.value < other.value) {
|
|
70
64
|
return -1;
|
|
71
65
|
}
|
|
72
|
-
|
|
73
66
|
if (this.value > other.value) {
|
|
74
67
|
return +1;
|
|
75
68
|
}
|
|
76
|
-
|
|
77
69
|
return 0;
|
|
78
70
|
}
|
|
71
|
+
|
|
79
72
|
/**
|
|
80
73
|
* Compares whether the two nodes are equal
|
|
81
74
|
* @param other The other node
|
|
82
75
|
*/
|
|
83
|
-
|
|
84
76
|
}, {
|
|
85
77
|
key: "equals",
|
|
86
78
|
value: function equals(other) {
|
|
87
79
|
if (!other) {
|
|
88
80
|
return false;
|
|
89
81
|
}
|
|
90
|
-
|
|
91
82
|
return this.termType === other.termType && this.value === other.value;
|
|
92
83
|
}
|
|
84
|
+
|
|
93
85
|
/**
|
|
94
86
|
* Creates a hash for this node
|
|
95
87
|
* @deprecated use {rdfFactory.id} instead if possible
|
|
96
88
|
*/
|
|
97
|
-
|
|
98
89
|
}, {
|
|
99
90
|
key: "hashString",
|
|
100
91
|
value: function hashString() {
|
|
101
92
|
return this.toCanonical();
|
|
102
93
|
}
|
|
94
|
+
|
|
103
95
|
/**
|
|
104
96
|
* Compares whether this node is the same as the other one
|
|
105
97
|
* @param other - Another node
|
|
106
98
|
*/
|
|
107
|
-
|
|
108
99
|
}, {
|
|
109
100
|
key: "sameTerm",
|
|
110
101
|
value: function sameTerm(other) {
|
|
111
102
|
return this.equals(other);
|
|
112
103
|
}
|
|
104
|
+
|
|
113
105
|
/**
|
|
114
106
|
* Creates a canonical string representation of this node
|
|
115
107
|
*/
|
|
116
|
-
|
|
117
108
|
}, {
|
|
118
109
|
key: "toCanonical",
|
|
119
110
|
value: function toCanonical() {
|
|
120
111
|
return this.toNT();
|
|
121
112
|
}
|
|
113
|
+
|
|
122
114
|
/**
|
|
123
115
|
* Creates a n-triples string representation of this node
|
|
124
116
|
*/
|
|
125
|
-
|
|
126
117
|
}, {
|
|
127
118
|
key: "toNT",
|
|
128
119
|
value: function toNT() {
|
|
129
120
|
return this.toString();
|
|
130
121
|
}
|
|
122
|
+
|
|
131
123
|
/**
|
|
132
124
|
* Creates a n-quads string representation of this node
|
|
133
125
|
*/
|
|
134
|
-
|
|
135
126
|
}, {
|
|
136
127
|
key: "toNQ",
|
|
137
128
|
value: function toNQ() {
|
|
138
129
|
return this.toNT();
|
|
139
130
|
}
|
|
131
|
+
|
|
140
132
|
/**
|
|
141
133
|
* Creates a string representation of this node
|
|
142
134
|
*/
|
|
143
|
-
|
|
144
135
|
}, {
|
|
145
136
|
key: "toString",
|
|
146
137
|
value: function toString() {
|
|
@@ -149,7 +140,6 @@ var Node = /*#__PURE__*/function () {
|
|
|
149
140
|
}]);
|
|
150
141
|
return Node;
|
|
151
142
|
}();
|
|
152
|
-
|
|
153
143
|
exports.default = Node;
|
|
154
144
|
(0, _defineProperty2.default)(Node, "fromValue", void 0);
|
|
155
145
|
(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
|
|
|
@@ -32,29 +26,25 @@ exports.default = _default;
|
|
|
32
26
|
var 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,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = parse;
|
|
11
|
-
|
|
12
9
|
var _extendedTermFactory = _interopRequireDefault(require("./factories/extended-term-factory"));
|
|
13
|
-
|
|
14
10
|
var _jsonldparser = _interopRequireDefault(require("./jsonldparser"));
|
|
15
|
-
|
|
16
11
|
var _n = require("n3");
|
|
17
|
-
|
|
18
12
|
var _n3parser = _interopRequireDefault(require("./n3parser"));
|
|
19
|
-
|
|
20
13
|
var _rdfaparser = require("./rdfaparser");
|
|
21
|
-
|
|
22
14
|
var _rdfxmlparser = _interopRequireDefault(require("./rdfxmlparser"));
|
|
23
|
-
|
|
24
15
|
var _patchParser = _interopRequireDefault(require("./patch-parser"));
|
|
25
|
-
|
|
26
16
|
var Util = _interopRequireWildcard(require("./utils-js"));
|
|
27
|
-
|
|
28
17
|
var _types = require("./types");
|
|
29
|
-
|
|
30
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
-
|
|
32
19
|
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
|
-
|
|
34
20
|
// @ts-ignore is this injected?
|
|
35
21
|
// @@ Goal: remove this dependency
|
|
36
22
|
|
|
@@ -50,7 +36,6 @@ function parse(str, kb, base) {
|
|
|
50
36
|
var callback = arguments.length > 4 ? arguments[4] : undefined;
|
|
51
37
|
contentType = contentType || _types.TurtleContentType;
|
|
52
38
|
contentType = contentType.split(';')[0];
|
|
53
|
-
|
|
54
39
|
try {
|
|
55
40
|
if (contentType === _types.N3ContentType || contentType === _types.TurtleContentType) {
|
|
56
41
|
var p = (0, _n3parser.default)(kb, kb, base, base, null, null, '', null);
|
|
@@ -90,7 +75,6 @@ function parse(str, kb, base) {
|
|
|
90
75
|
// @ts-ignore
|
|
91
76
|
executeErrorCallback(e);
|
|
92
77
|
}
|
|
93
|
-
|
|
94
78
|
parse.handled = {
|
|
95
79
|
'text/n3': true,
|
|
96
80
|
'text/turtle': true,
|
|
@@ -103,7 +87,6 @@ function parse(str, kb, base) {
|
|
|
103
87
|
'application/nquads': true,
|
|
104
88
|
'application/n-quads': true
|
|
105
89
|
};
|
|
106
|
-
|
|
107
90
|
function executeCallback() {
|
|
108
91
|
if (callback) {
|
|
109
92
|
callback(null, kb);
|
|
@@ -111,17 +94,19 @@ function parse(str, kb, base) {
|
|
|
111
94
|
return;
|
|
112
95
|
}
|
|
113
96
|
}
|
|
114
|
-
|
|
115
97
|
function executeErrorCallback(e) {
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
contentType !== _types.
|
|
98
|
+
if (
|
|
99
|
+
// TODO: Always true, what is the right behavior
|
|
100
|
+
contentType !== _types.JSONLDContentType ||
|
|
101
|
+
// @ts-ignore always true?
|
|
102
|
+
contentType !== _types.NQuadsContentType ||
|
|
103
|
+
// @ts-ignore always true?
|
|
119
104
|
contentType !== _types.NQuadsAltContentType) {
|
|
120
105
|
if (callback) {
|
|
121
106
|
callback(e, kb);
|
|
122
107
|
} else {
|
|
123
|
-
var e2 = new Error('' + e + ' while trying to parse <' + base + '> as ' + contentType);
|
|
124
|
-
|
|
108
|
+
var e2 = new Error('' + e + ' while trying to parse <' + base + '> as ' + contentType);
|
|
109
|
+
//@ts-ignore .cause is not a default error property
|
|
125
110
|
e2.cause = e;
|
|
126
111
|
throw e2;
|
|
127
112
|
}
|
|
@@ -138,20 +123,16 @@ function parse(str, kb, base) {
|
|
|
138
123
|
doc['@context']['@base'] = base
|
|
139
124
|
}
|
|
140
125
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
126
|
function nquadCallback(err, nquads) {
|
|
144
127
|
if (err) {
|
|
145
128
|
callback(err, kb);
|
|
146
129
|
}
|
|
147
|
-
|
|
148
130
|
try {
|
|
149
131
|
n3Parser.parse(nquads, tripleCallback);
|
|
150
132
|
} catch (err) {
|
|
151
133
|
callback(err, kb);
|
|
152
134
|
}
|
|
153
135
|
}
|
|
154
|
-
|
|
155
136
|
function tripleCallback(err, triple) {
|
|
156
137
|
if (triple) {
|
|
157
138
|
kb.add(triple.subject, triple.predicate, triple.object, triple.graph);
|
package/lib/patch-parser.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
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 = sparqlUpdateParser;
|
|
9
|
-
|
|
10
8
|
var _n3parser = _interopRequireDefault(require("./n3parser"));
|
|
11
|
-
|
|
12
9
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
13
|
-
|
|
14
10
|
// Parse a simple SPARL-Update subset syntax for patches.
|
|
15
11
|
//
|
|
16
12
|
// This parses
|
|
@@ -18,104 +14,85 @@ var _namespace = _interopRequireDefault(require("./namespace"));
|
|
|
18
14
|
// (not necessarily in that order)
|
|
19
15
|
// as though it were the n3
|
|
20
16
|
// <#query> patch:where {xxx}; patch:delete {yyy}; patch:insert {zzz}.
|
|
17
|
+
|
|
21
18
|
function sparqlUpdateParser(str, kb, base) {
|
|
22
19
|
var i, j, k;
|
|
23
20
|
var keywords = ['INSERT', 'DELETE', 'WHERE'];
|
|
24
21
|
var SQNS = (0, _namespace.default)('http://www.w3.org/ns/pim/patch#');
|
|
25
22
|
var p = (0, _n3parser.default)(kb, kb, base, base, null, null, '', null);
|
|
26
23
|
var clauses = {};
|
|
27
|
-
|
|
28
24
|
var badSyntax = function badSyntax(uri, lines, str, i, why) {
|
|
29
25
|
return 'Line ' + (lines + 1) + ' of <' + uri + '>: Bad syntax:\n ' + why + '\n at: "' + str.slice(i, i + 30) + '"';
|
|
30
|
-
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// var check = function (next, last, message) {
|
|
31
29
|
// if (next < 0) {
|
|
32
30
|
// throw badSyntax(p._thisDoc, p.lines, str, j, last, message)
|
|
33
31
|
// }
|
|
34
32
|
// return next
|
|
35
33
|
// }
|
|
36
|
-
|
|
37
|
-
|
|
38
34
|
i = 0;
|
|
39
35
|
var query = kb.sym(base + '#query'); // Invent a URI for the query
|
|
40
|
-
|
|
41
36
|
clauses['query'] = query; // A way of accessing it in its N3 model.
|
|
42
37
|
|
|
43
38
|
while (true) {
|
|
44
39
|
// console.log("A Now at i = " + i)
|
|
45
40
|
j = p.skipSpace(str, i);
|
|
46
|
-
|
|
47
41
|
if (j < 0) {
|
|
48
42
|
return clauses;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
}
|
|
44
|
+
// console.log("B After space at j= " + j)
|
|
52
45
|
if (str[j] === ';') {
|
|
53
46
|
i = p.skipSpace(str, j + 1);
|
|
54
|
-
|
|
55
47
|
if (i < 0) {
|
|
56
48
|
return clauses; // Allow end in a
|
|
57
49
|
}
|
|
58
50
|
|
|
59
51
|
j = i;
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
var found = false;
|
|
63
|
-
|
|
64
54
|
for (k = 0; k < keywords.length; k++) {
|
|
65
55
|
var key = keywords[k];
|
|
66
|
-
|
|
67
56
|
if (str.slice(j, j + key.length) === key) {
|
|
68
57
|
i = p.skipSpace(str, j + key.length);
|
|
69
|
-
|
|
70
58
|
if (i < 0) {
|
|
71
59
|
throw badSyntax(p._thisDoc, p.lines, str, j + key.length, 'found EOF, needed {...} after ' + key);
|
|
72
60
|
}
|
|
73
|
-
|
|
74
61
|
if ((key === 'INSERT' || key === 'DELETE') && str.slice(i, i + 4) === 'DATA') {
|
|
75
62
|
// Some wanted 'DATA'. Whatever
|
|
76
63
|
j = p.skipSpace(str, i + 4);
|
|
77
|
-
|
|
78
64
|
if (j < 0) {
|
|
79
65
|
throw badSyntax(p._thisDoc, p.lines, str, i + 4, 'needed {...} after INSERT DATA ' + key);
|
|
80
66
|
}
|
|
81
|
-
|
|
82
67
|
i = j;
|
|
83
68
|
}
|
|
84
|
-
|
|
85
69
|
var res2 = [];
|
|
86
70
|
j = p.node(str, i, res2); // Parse all the complexity of the clause
|
|
87
71
|
|
|
88
72
|
if (j < 0) {
|
|
89
73
|
throw badSyntax(p._thisDoc, p.lines, str, i, 'bad syntax or EOF in {...} after ' + key);
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
clauses[key.toLowerCase()] = res2[0];
|
|
93
76
|
kb.add(query, SQNS(key.toLowerCase()), res2[0]); // , kb.sym(base)
|
|
94
77
|
// key is the keyword and res2 has the contents
|
|
95
|
-
|
|
96
78
|
found = true;
|
|
97
79
|
i = j;
|
|
98
80
|
}
|
|
99
81
|
}
|
|
100
|
-
|
|
101
82
|
if (!found && str.slice(j, j + 7) === '@prefix') {
|
|
102
83
|
i = p.directive(str, j);
|
|
103
|
-
|
|
104
84
|
if (i < 0) {
|
|
105
85
|
throw badSyntax(p._thisDoc, p.lines, str, i, 'bad syntax or EOF after @prefix ');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
86
|
+
}
|
|
87
|
+
// console.log("P before dot i= " + i)
|
|
88
|
+
i = p.checkDot(str, i);
|
|
89
|
+
// console.log("Q after dot i= " + i)
|
|
111
90
|
found = true;
|
|
112
91
|
}
|
|
113
|
-
|
|
114
92
|
if (!found) {
|
|
115
93
|
// console.log("Bad syntax " + j)
|
|
116
94
|
throw badSyntax(p._thisDoc, p.lines, str, j, "Unknown syntax at start of statememt: '" + str.slice(j).slice(0, 20) + "'");
|
|
117
95
|
}
|
|
118
96
|
} // while
|
|
119
97
|
// return clauses
|
|
120
|
-
|
|
121
98
|
}
|