rdflib 2.2.10 → 2.2.12-5f141ca2
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/.babelrc +0 -0
- package/README.md +1 -0
- package/changes.txt +0 -0
- package/dist/rdflib.min.js +62 -0
- package/dist/rdflib.min.js.map +1 -0
- package/esm/blank-node.js +137 -0
- package/esm/class-order.js +12 -0
- package/esm/collection.js +173 -0
- package/esm/convert.js +61 -0
- package/esm/default-graph.js +57 -0
- package/esm/empty.js +46 -0
- package/esm/factories/canonical-data-factory.js +204 -0
- package/esm/factories/extended-term-factory.js +55 -0
- package/esm/factories/factory-types.js +18 -0
- package/esm/factories/rdflib-data-factory.js +55 -0
- package/esm/fetcher.js +2180 -0
- package/esm/formula.js +987 -0
- package/esm/index.js +64 -0
- package/esm/jsonldparser.js +122 -0
- package/esm/jsonparser.js +60 -0
- package/esm/literal.js +236 -0
- package/esm/log.js +13 -0
- package/esm/n3parser.js +1854 -0
- package/esm/named-node.js +154 -0
- package/esm/namespace.js +17 -0
- package/esm/node-internal.js +151 -0
- package/esm/node.js +46 -0
- package/esm/parse.js +138 -0
- package/esm/patch-parser.js +110 -0
- package/esm/query-to-sparql.js +83 -0
- package/esm/query.js +620 -0
- package/esm/rdfaparser.js +1197 -0
- package/esm/rdfxmlparser.js +588 -0
- package/esm/serialize.js +95 -0
- package/esm/serializer.js +1162 -0
- package/esm/sparql-to-query.js +566 -0
- package/esm/statement.js +128 -0
- package/esm/store.js +1306 -0
- package/esm/tf-types.js +1 -0
- package/esm/types.js +25 -0
- package/esm/update-manager.js +1252 -0
- package/esm/updates-via.js +197 -0
- package/esm/uri.js +245 -0
- package/esm/utils/default-graph-uri.js +4 -0
- package/esm/utils/termValue.js +8 -0
- package/esm/utils/terms.js +72 -0
- package/esm/utils-js.js +348 -0
- package/esm/utils.js +103 -0
- package/esm/variable.js +101 -0
- package/esm/xsd-internal.js +10 -0
- package/esm/xsd.js +15 -0
- package/lib/blank-node.d.ts +44 -0
- package/lib/blank-node.js +0 -0
- package/lib/class-order.d.ts +7 -0
- package/lib/class-order.js +0 -0
- package/lib/collection.d.ts +65 -0
- package/lib/collection.js +0 -0
- package/lib/convert.d.ts +2 -0
- package/lib/convert.js +0 -0
- package/lib/default-graph.d.ts +13 -0
- package/lib/default-graph.js +0 -0
- package/lib/empty.d.ts +11 -0
- package/lib/empty.js +0 -0
- package/lib/factories/canonical-data-factory.d.ts +6 -0
- package/lib/factories/canonical-data-factory.js +0 -0
- package/lib/factories/extended-term-factory.d.ts +13 -0
- package/lib/factories/extended-term-factory.js +0 -0
- package/lib/factories/factory-types.d.ts +67 -0
- package/lib/factories/factory-types.js +0 -0
- package/lib/factories/rdflib-data-factory.d.ts +4 -0
- package/lib/factories/rdflib-data-factory.js +0 -0
- package/lib/fetcher.d.ts +443 -0
- package/lib/fetcher.js +3 -2
- package/lib/formula.d.ts +327 -0
- package/lib/formula.js +0 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +0 -0
- package/lib/jsonldparser.d.ts +13 -0
- package/lib/jsonldparser.js +0 -0
- package/lib/jsonparser.d.ts +4 -0
- package/lib/jsonparser.js +0 -0
- package/lib/literal.d.ts +67 -0
- package/lib/literal.js +0 -0
- package/lib/log.d.ts +15 -0
- package/lib/log.js +0 -0
- package/lib/n3parser.d.ts +62 -0
- package/lib/n3parser.js +1334 -1289
- package/lib/named-node.d.ts +44 -0
- package/lib/named-node.js +0 -0
- package/lib/namespace.d.ts +7 -0
- package/lib/namespace.js +0 -0
- package/lib/node-internal.d.ts +63 -0
- package/lib/node-internal.js +0 -0
- package/lib/node.d.ts +2 -0
- package/lib/node.js +0 -0
- package/lib/parse.d.ts +16 -0
- package/lib/parse.js +0 -0
- package/lib/patch-parser.d.ts +3 -0
- package/lib/patch-parser.js +0 -0
- package/lib/query-to-sparql.d.ts +1 -0
- package/lib/query-to-sparql.js +0 -0
- package/lib/query.d.ts +27 -0
- package/lib/query.js +0 -0
- package/lib/rdfaparser.d.ts +78 -0
- package/lib/rdfaparser.js +0 -0
- package/lib/rdfxmlparser.d.ts +60 -0
- package/lib/rdfxmlparser.js +430 -413
- package/lib/serialize.d.ts +23 -0
- package/lib/serialize.js +1 -1
- package/lib/serializer.d.ts +54 -0
- package/lib/serializer.js +851 -824
- package/lib/sparql-to-query.d.ts +6 -0
- package/lib/sparql-to-query.js +0 -0
- package/lib/statement.d.ts +55 -0
- package/lib/statement.js +0 -0
- package/lib/store.d.ts +302 -0
- package/lib/store.js +0 -0
- package/lib/tf-types.d.ts +151 -0
- package/lib/tf-types.js +0 -0
- package/lib/types.d.ts +68 -0
- package/lib/types.js +0 -0
- package/lib/update-manager.d.ts +198 -0
- package/lib/update-manager.js +0 -0
- package/lib/updates-via.d.ts +26 -0
- package/lib/updates-via.js +0 -0
- package/lib/uri.d.ts +33 -0
- package/lib/uri.js +0 -0
- package/lib/utils/default-graph-uri.d.ts +3 -0
- package/lib/utils/default-graph-uri.js +0 -0
- package/lib/utils/termValue.d.ts +3 -0
- package/lib/utils/termValue.js +0 -0
- package/lib/utils/terms.d.ts +33 -0
- package/lib/utils/terms.js +0 -0
- package/lib/utils-js.d.ts +50 -0
- package/lib/utils-js.js +0 -0
- package/lib/utils.d.ts +20 -0
- package/lib/utils.js +0 -0
- package/lib/variable.d.ts +29 -0
- package/lib/variable.js +0 -0
- package/lib/xsd-internal.d.ts +11 -0
- package/lib/xsd-internal.js +0 -0
- package/lib/xsd.d.ts +19 -0
- package/lib/xsd.js +8 -14
- package/package.json +3 -3
- package/src/blank-node.ts +0 -0
- package/src/class-order.ts +0 -0
- package/src/collection.ts +0 -0
- package/src/convert.js +0 -0
- package/src/default-graph.ts +0 -0
- package/src/empty.ts +0 -0
- package/src/factories/canonical-data-factory.ts +0 -0
- package/src/factories/extended-term-factory.ts +0 -0
- package/src/factories/factory-types.ts +0 -0
- package/src/factories/rdflib-data-factory.ts +0 -0
- package/src/fetcher.ts +6 -3
- package/src/formula.ts +0 -0
- package/src/index.ts +0 -0
- package/src/jsonldparser.js +0 -0
- package/src/jsonparser.js +0 -0
- package/src/literal.ts +0 -0
- package/src/log.js +0 -0
- package/src/n3parser.js +1114 -1110
- package/src/named-node.ts +0 -0
- package/src/namespace.ts +0 -0
- package/src/node-internal.ts +0 -0
- package/src/node.ts +0 -0
- package/src/parse.ts +0 -0
- package/src/patch-parser.js +0 -0
- package/src/query-to-sparql.js +0 -0
- package/src/query.js +0 -0
- package/src/rdfaparser.js +0 -0
- package/src/rdfxmlparser.js +22 -21
- package/src/serialize.ts +3 -3
- package/src/serializer.js +74 -62
- package/src/sparql-to-query.js +0 -0
- package/src/statement.ts +0 -0
- package/src/store.ts +0 -0
- package/src/tf-types.ts +0 -0
- package/src/types.ts +0 -0
- package/src/update-manager.ts +0 -0
- package/src/updates-via.js +0 -0
- package/src/uri.ts +0 -0
- package/src/utils/default-graph-uri.ts +0 -0
- package/src/utils/termValue.ts +0 -0
- package/src/utils/terms.ts +0 -0
- package/src/utils-js.js +0 -0
- package/src/utils.ts +0 -0
- package/src/variable.ts +0 -0
- package/src/xsd-internal.js +0 -0
- package/src/xsd.js +16 -14
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
|
|
11
|
+
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; } }
|
|
12
|
+
|
|
13
|
+
import ClassOrder from './class-order';
|
|
14
|
+
import Node from './node-internal';
|
|
15
|
+
import { BlankNodeTermType } from './types';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An RDF blank node is a Node without a URI
|
|
19
|
+
* @link https://rdf.js.org/data-model-spec/#blanknode-interface
|
|
20
|
+
*/
|
|
21
|
+
var BlankNode = /*#__PURE__*/function (_Node) {
|
|
22
|
+
_inherits(BlankNode, _Node);
|
|
23
|
+
|
|
24
|
+
var _super = _createSuper(BlankNode);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Initializes this node
|
|
28
|
+
* @param [id] The identifier for the blank node
|
|
29
|
+
*/
|
|
30
|
+
function BlankNode(id) {
|
|
31
|
+
var _this;
|
|
32
|
+
|
|
33
|
+
_classCallCheck(this, BlankNode);
|
|
34
|
+
|
|
35
|
+
_this = _super.call(this, BlankNode.getId(id));
|
|
36
|
+
|
|
37
|
+
_defineProperty(_assertThisInitialized(_this), "termType", BlankNodeTermType);
|
|
38
|
+
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.BlankNode);
|
|
40
|
+
|
|
41
|
+
_defineProperty(_assertThisInitialized(_this), "isBlank", 1);
|
|
42
|
+
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "isVar", 1);
|
|
44
|
+
|
|
45
|
+
return _this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The identifier for the blank node
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
_createClass(BlankNode, [{
|
|
53
|
+
key: "id",
|
|
54
|
+
get: function get() {
|
|
55
|
+
return this.value;
|
|
56
|
+
},
|
|
57
|
+
set: function set(value) {
|
|
58
|
+
this.value = value;
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "compareTerm",
|
|
62
|
+
value: function compareTerm(other) {
|
|
63
|
+
if (this.classOrder < other.classOrder) {
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (this.classOrder > other.classOrder) {
|
|
68
|
+
return +1;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.id < other.id) {
|
|
72
|
+
return -1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.id > other.id) {
|
|
76
|
+
return +1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets a copy of this blank node in the specified formula
|
|
83
|
+
* @param formula The formula
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
}, {
|
|
87
|
+
key: "copy",
|
|
88
|
+
value: function copy(formula) {
|
|
89
|
+
// depends on the formula
|
|
90
|
+
var bnodeNew = new BlankNode();
|
|
91
|
+
formula.copyTo(this, bnodeNew);
|
|
92
|
+
return bnodeNew;
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "toCanonical",
|
|
96
|
+
value: function toCanonical() {
|
|
97
|
+
return BlankNode.NTAnonymousNodePrefix + this.value;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "toString",
|
|
101
|
+
value: function toString() {
|
|
102
|
+
return BlankNode.NTAnonymousNodePrefix + this.id;
|
|
103
|
+
}
|
|
104
|
+
}], [{
|
|
105
|
+
key: "getId",
|
|
106
|
+
value:
|
|
107
|
+
/**
|
|
108
|
+
* The next unique identifier for blank nodes
|
|
109
|
+
*/
|
|
110
|
+
function getId(id) {
|
|
111
|
+
if (id) {
|
|
112
|
+
if (typeof id !== 'string') {
|
|
113
|
+
console.log('Bad blank id:', id);
|
|
114
|
+
throw new Error('Bad id argument to new blank node: ' + id);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (id.includes('#')) {
|
|
118
|
+
// Is a URI with hash fragment
|
|
119
|
+
var fragments = id.split('#');
|
|
120
|
+
return fragments[fragments.length - 1];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return id;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return 'n' + BlankNode.nextId++;
|
|
127
|
+
}
|
|
128
|
+
}]);
|
|
129
|
+
|
|
130
|
+
return BlankNode;
|
|
131
|
+
}(Node);
|
|
132
|
+
|
|
133
|
+
_defineProperty(BlankNode, "nextId", 0);
|
|
134
|
+
|
|
135
|
+
_defineProperty(BlankNode, "NTAnonymousNodePrefix", '_:');
|
|
136
|
+
|
|
137
|
+
export { BlankNode as default };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
|
|
11
|
+
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; } }
|
|
12
|
+
|
|
13
|
+
import RdflibBlankNode from './blank-node';
|
|
14
|
+
import ClassOrder from './class-order';
|
|
15
|
+
import Literal from './literal';
|
|
16
|
+
import Node from './node-internal';
|
|
17
|
+
import { CollectionTermType } from './types';
|
|
18
|
+
import { isTerm } from './utils/terms';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an RDF Node from a native javascript value.
|
|
22
|
+
* RDF Nodes are returned unchanged, undefined returned as itself.
|
|
23
|
+
* Arrays return Collections.
|
|
24
|
+
* Strings, numbers and booleans return Literals.
|
|
25
|
+
* @param value {Node|Date|String|Number|Boolean|Undefined}
|
|
26
|
+
* @return {Node|Collection}
|
|
27
|
+
*/
|
|
28
|
+
export function fromValue(value) {
|
|
29
|
+
if (typeof value === 'undefined' || value === null) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isTerm(value)) {
|
|
34
|
+
// a Node subclass or a Collection
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
return new Collection(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return Literal.fromValue(value);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A collection of other RDF nodes
|
|
46
|
+
*
|
|
47
|
+
* Use generic T to control the contents of the array.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
var Collection = /*#__PURE__*/function (_Node) {
|
|
51
|
+
_inherits(Collection, _Node);
|
|
52
|
+
|
|
53
|
+
var _super = _createSuper(Collection);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The nodes in this collection
|
|
57
|
+
*/
|
|
58
|
+
function Collection(initial) {
|
|
59
|
+
var _this;
|
|
60
|
+
|
|
61
|
+
_classCallCheck(this, Collection);
|
|
62
|
+
|
|
63
|
+
_this = _super.call(this, (RdflibBlankNode.nextId++).toString());
|
|
64
|
+
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "termType", CollectionTermType);
|
|
66
|
+
|
|
67
|
+
_defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.Collection);
|
|
68
|
+
|
|
69
|
+
_defineProperty(_assertThisInitialized(_this), "closed", false);
|
|
70
|
+
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "compareTerm", RdflibBlankNode.prototype.compareTerm);
|
|
72
|
+
|
|
73
|
+
_defineProperty(_assertThisInitialized(_this), "elements", []);
|
|
74
|
+
|
|
75
|
+
_defineProperty(_assertThisInitialized(_this), "isVar", 0);
|
|
76
|
+
|
|
77
|
+
if (initial && initial.length > 0) {
|
|
78
|
+
initial.forEach(function (element) {
|
|
79
|
+
_this.elements.push(fromValue(element));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return _this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
_createClass(Collection, [{
|
|
87
|
+
key: "id",
|
|
88
|
+
get: function get() {
|
|
89
|
+
return this.value;
|
|
90
|
+
},
|
|
91
|
+
set: function set(value) {
|
|
92
|
+
this.value = value;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Appends an element to this collection
|
|
96
|
+
* @param element - The new element
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
}, {
|
|
100
|
+
key: "append",
|
|
101
|
+
value: function append(element) {
|
|
102
|
+
return this.elements.push(element);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Closes this collection
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
}, {
|
|
109
|
+
key: "close",
|
|
110
|
+
value: function close() {
|
|
111
|
+
this.closed = true;
|
|
112
|
+
return this.closed;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Removes the first element from the collection (and return it)
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
}, {
|
|
119
|
+
key: "shift",
|
|
120
|
+
value: function shift() {
|
|
121
|
+
return this.elements.shift();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Creates a new Collection with the substituting bindings applied
|
|
125
|
+
* @param bindings - The bindings to substitute
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
}, {
|
|
129
|
+
key: "substitute",
|
|
130
|
+
value: function substitute(bindings) {
|
|
131
|
+
var elementsCopy = this.elements.map(function (ea) {
|
|
132
|
+
return ea.substitute(bindings);
|
|
133
|
+
});
|
|
134
|
+
return new Collection(elementsCopy);
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "toNT",
|
|
138
|
+
value: function toNT() {
|
|
139
|
+
return Collection.toNT(this);
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "toString",
|
|
143
|
+
value:
|
|
144
|
+
/**
|
|
145
|
+
* Serializes the collection to a string.
|
|
146
|
+
* Surrounded by (parentheses) and separated by spaces.
|
|
147
|
+
*/
|
|
148
|
+
function toString() {
|
|
149
|
+
return '(' + this.elements.join(' ') + ')';
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Prepends the specified element to the collection's front
|
|
153
|
+
* @param element - The element to prepend
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
}, {
|
|
157
|
+
key: "unshift",
|
|
158
|
+
value: function unshift(element) {
|
|
159
|
+
return this.elements.unshift(element);
|
|
160
|
+
}
|
|
161
|
+
}], [{
|
|
162
|
+
key: "toNT",
|
|
163
|
+
value: function toNT(collection) {
|
|
164
|
+
return RdflibBlankNode.NTAnonymousNodePrefix + collection.id;
|
|
165
|
+
}
|
|
166
|
+
}]);
|
|
167
|
+
|
|
168
|
+
return Collection;
|
|
169
|
+
}(Node);
|
|
170
|
+
|
|
171
|
+
_defineProperty(Collection, "termType", CollectionTermType);
|
|
172
|
+
|
|
173
|
+
export { Collection as default };
|
package/esm/convert.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import asyncLib from 'async'; // @@ Goal: remove this dependency
|
|
2
|
+
|
|
3
|
+
import jsonld from 'jsonld';
|
|
4
|
+
import { Parser, Writer } from 'n3'; // @@ Goal: remove this dependency
|
|
5
|
+
|
|
6
|
+
export function convertToJson(n3String, jsonCallback) {
|
|
7
|
+
var jsonString;
|
|
8
|
+
var n3Parser = new Parser();
|
|
9
|
+
var n3Writer = new Writer({
|
|
10
|
+
format: 'N-Quads'
|
|
11
|
+
});
|
|
12
|
+
asyncLib.waterfall([function (callback) {
|
|
13
|
+
n3Parser.parse(n3String, function (error, quad, prefixes) {
|
|
14
|
+
if (error) {
|
|
15
|
+
callback(error);
|
|
16
|
+
} else if (quad !== null) {
|
|
17
|
+
n3Writer.addQuad(quad);
|
|
18
|
+
} else {
|
|
19
|
+
n3Writer.end(callback);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}, function (result, callback) {
|
|
23
|
+
try {
|
|
24
|
+
jsonld.fromRDF(result, {
|
|
25
|
+
format: 'application/nquads'
|
|
26
|
+
}).then(function (result) {
|
|
27
|
+
callback(null, result);
|
|
28
|
+
});
|
|
29
|
+
} catch (err) {
|
|
30
|
+
callback(err);
|
|
31
|
+
}
|
|
32
|
+
}, function (json, callback) {
|
|
33
|
+
jsonString = JSON.stringify(json);
|
|
34
|
+
jsonCallback(null, jsonString);
|
|
35
|
+
}], function (err, result) {
|
|
36
|
+
jsonCallback(err, jsonString);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export function convertToNQuads(n3String, nquadCallback) {
|
|
40
|
+
var nquadString;
|
|
41
|
+
var n3Parser = new Parser();
|
|
42
|
+
var n3Writer = new Writer({
|
|
43
|
+
format: 'N-Quads'
|
|
44
|
+
});
|
|
45
|
+
asyncLib.waterfall([function (callback) {
|
|
46
|
+
n3Parser.parse(n3String, function (error, triple, prefixes) {
|
|
47
|
+
if (error) {
|
|
48
|
+
callback(error);
|
|
49
|
+
} else if (quad !== null) {
|
|
50
|
+
n3Writer.addQuad(quad);
|
|
51
|
+
} else {
|
|
52
|
+
n3Writer.end(callback);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}, function (result, callback) {
|
|
56
|
+
nquadString = result;
|
|
57
|
+
nquadCallback(null, nquadString);
|
|
58
|
+
}], function (err, result) {
|
|
59
|
+
nquadCallback(err, nquadString);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
|
|
11
|
+
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; } }
|
|
12
|
+
|
|
13
|
+
import Node from './node-internal';
|
|
14
|
+
import { DefaultGraphTermType } from './types';
|
|
15
|
+
import { defaultGraphURI } from './utils/default-graph-uri';
|
|
16
|
+
/** The RDF default graph */
|
|
17
|
+
|
|
18
|
+
var DefaultGraph = /*#__PURE__*/function (_Node) {
|
|
19
|
+
_inherits(DefaultGraph, _Node);
|
|
20
|
+
|
|
21
|
+
var _super = _createSuper(DefaultGraph);
|
|
22
|
+
|
|
23
|
+
function DefaultGraph() {
|
|
24
|
+
var _this;
|
|
25
|
+
|
|
26
|
+
_classCallCheck(this, DefaultGraph);
|
|
27
|
+
|
|
28
|
+
_this = _super.call(this, '');
|
|
29
|
+
|
|
30
|
+
_defineProperty(_assertThisInitialized(_this), "value", '');
|
|
31
|
+
|
|
32
|
+
_defineProperty(_assertThisInitialized(_this), "termType", DefaultGraphTermType);
|
|
33
|
+
|
|
34
|
+
_defineProperty(_assertThisInitialized(_this), "uri", defaultGraphURI);
|
|
35
|
+
|
|
36
|
+
return _this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
_createClass(DefaultGraph, [{
|
|
40
|
+
key: "toCanonical",
|
|
41
|
+
value: function toCanonical() {
|
|
42
|
+
return this.value;
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "toString",
|
|
46
|
+
value: function toString() {
|
|
47
|
+
return 'DefaultGraph';
|
|
48
|
+
}
|
|
49
|
+
}]);
|
|
50
|
+
|
|
51
|
+
return DefaultGraph;
|
|
52
|
+
}(Node);
|
|
53
|
+
|
|
54
|
+
export { DefaultGraph as default };
|
|
55
|
+
export function isDefaultGraph(object) {
|
|
56
|
+
return !!object && object.termType === DefaultGraphTermType;
|
|
57
|
+
}
|
package/esm/empty.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
|
|
9
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
10
|
+
|
|
11
|
+
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; } }
|
|
12
|
+
|
|
13
|
+
import Node from './node-internal';
|
|
14
|
+
import { EmptyTermType } from './types';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* An empty node
|
|
18
|
+
*/
|
|
19
|
+
var Empty = /*#__PURE__*/function (_Node) {
|
|
20
|
+
_inherits(Empty, _Node);
|
|
21
|
+
|
|
22
|
+
var _super = _createSuper(Empty);
|
|
23
|
+
|
|
24
|
+
function Empty() {
|
|
25
|
+
var _this;
|
|
26
|
+
|
|
27
|
+
_classCallCheck(this, Empty);
|
|
28
|
+
|
|
29
|
+
_this = _super.call(this, '');
|
|
30
|
+
|
|
31
|
+
_defineProperty(_assertThisInitialized(_this), "termType", EmptyTermType);
|
|
32
|
+
|
|
33
|
+
return _this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_createClass(Empty, [{
|
|
37
|
+
key: "toString",
|
|
38
|
+
value: function toString() {
|
|
39
|
+
return '()';
|
|
40
|
+
}
|
|
41
|
+
}]);
|
|
42
|
+
|
|
43
|
+
return Empty;
|
|
44
|
+
}(Node);
|
|
45
|
+
|
|
46
|
+
export { Empty as default };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
var _supports;
|
|
4
|
+
|
|
5
|
+
import BlankNode from '../blank-node';
|
|
6
|
+
import Literal from '../literal';
|
|
7
|
+
import NamedNode from '../named-node';
|
|
8
|
+
import Statement from '../statement';
|
|
9
|
+
import Variable from '../variable';
|
|
10
|
+
import { EmptyTermType, DefaultGraphTermType, VariableTermType, BlankNodeTermType, LiteralTermType, NamedNodeTermType, CollectionTermType, GraphTermType } from '../types';
|
|
11
|
+
import DefaultGraph from '../default-graph';
|
|
12
|
+
import { Feature } from './factory-types';
|
|
13
|
+
import { isQuad, isTerm } from '../utils/terms';
|
|
14
|
+
export { defaultGraphURI } from '../utils/default-graph-uri';
|
|
15
|
+
/**
|
|
16
|
+
* Gets the default graph
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
var _defaultGraph = new DefaultGraph();
|
|
20
|
+
/** A basic internal RDFlib datafactory, which does not support Collections */
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var CanonicalDataFactory = {
|
|
24
|
+
supports: (_supports = {}, _defineProperty(_supports, Feature.collections, false), _defineProperty(_supports, Feature.defaultGraphType, false), _defineProperty(_supports, Feature.equalsMethod, true), _defineProperty(_supports, Feature.identity, false), _defineProperty(_supports, Feature.id, true), _defineProperty(_supports, Feature.reversibleId, false), _defineProperty(_supports, Feature.variableType, true), _supports),
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new blank node
|
|
28
|
+
* @param value - The blank node's identifier
|
|
29
|
+
*/
|
|
30
|
+
blankNode: function blankNode(value) {
|
|
31
|
+
return new BlankNode(value);
|
|
32
|
+
},
|
|
33
|
+
defaultGraph: function defaultGraph() {
|
|
34
|
+
return _defaultGraph;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Compares to (rdf) objects for equality.
|
|
39
|
+
*/
|
|
40
|
+
equals: function equals(a, b) {
|
|
41
|
+
if (a === b || !a || !b) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isQuad(a) || isQuad(b)) {
|
|
46
|
+
if (isQuad(a) && isQuad(b)) {
|
|
47
|
+
return this.equals(a.subject, b.subject) && this.equals(a.predicate, b.predicate) && this.equals(a.object, b.object) && this.equals(a.graph, b.graph);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isTerm(a) && isTerm(b)) {
|
|
54
|
+
return this.id(a) === this.id(b);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Generates a uniquely identifiably *idempotent* string for the given {term}.
|
|
62
|
+
*
|
|
63
|
+
* Equivalent to [[Term.hashString]]
|
|
64
|
+
*
|
|
65
|
+
* @example Use this to associate data with a term in an object
|
|
66
|
+
* { obj[id(term)] = "myData" }
|
|
67
|
+
*/
|
|
68
|
+
id: function id(term) {
|
|
69
|
+
if (!term) {
|
|
70
|
+
return 'undefined';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (isQuad(term)) {
|
|
74
|
+
return this.quadToNQ(term);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
switch (term.termType) {
|
|
78
|
+
case DefaultGraphTermType:
|
|
79
|
+
return 'defaultGraph';
|
|
80
|
+
|
|
81
|
+
case VariableTermType:
|
|
82
|
+
return Variable.toString(term);
|
|
83
|
+
|
|
84
|
+
default:
|
|
85
|
+
var nq = this.termToNQ(term);
|
|
86
|
+
|
|
87
|
+
if (nq) {
|
|
88
|
+
return nq;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
throw new Error("Can't id term with type '".concat(term.termType, "'"));
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
isQuad: function isQuad(obj) {
|
|
95
|
+
return obj instanceof Statement;
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new literal node. Does some JS literal parsing for ease of use.
|
|
100
|
+
* @param value - The lexical value
|
|
101
|
+
* @param languageOrDatatype - Either the language or the datatype
|
|
102
|
+
*/
|
|
103
|
+
literal: function literal(value, languageOrDatatype) {
|
|
104
|
+
if (typeof value !== "string" && !languageOrDatatype) {
|
|
105
|
+
return Literal.fromValue(value);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var strValue = typeof value === 'string' ? value : '' + value;
|
|
109
|
+
|
|
110
|
+
if (typeof languageOrDatatype === 'string') {
|
|
111
|
+
if (languageOrDatatype.indexOf(':') === -1) {
|
|
112
|
+
return new Literal(strValue, languageOrDatatype);
|
|
113
|
+
} else {
|
|
114
|
+
return new Literal(strValue, null, this.namedNode(languageOrDatatype));
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
return new Literal(strValue, null, languageOrDatatype);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new named node
|
|
123
|
+
* @param value - The new named node
|
|
124
|
+
*/
|
|
125
|
+
namedNode: function namedNode(value) {
|
|
126
|
+
return new NamedNode(value);
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new statement
|
|
131
|
+
* @param subject - The subject
|
|
132
|
+
* @param predicate - The predicate
|
|
133
|
+
* @param object - The object
|
|
134
|
+
* @param graph - The containing graph
|
|
135
|
+
*/
|
|
136
|
+
quad: function quad(subject, predicate, object, graph) {
|
|
137
|
+
return new Statement(subject, predicate, object, graph || _defaultGraph);
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Creates a new statement
|
|
142
|
+
* @param subject - The subject
|
|
143
|
+
* @param predicate - The predicate
|
|
144
|
+
* @param object - The object
|
|
145
|
+
* @param graph - The containing graph
|
|
146
|
+
*/
|
|
147
|
+
triple: function triple(subject, predicate, object, graph) {
|
|
148
|
+
return this.quad(subject, predicate, object, graph);
|
|
149
|
+
},
|
|
150
|
+
quadToNQ: function quadToNQ(q) {
|
|
151
|
+
return "".concat(this.termToNQ(q.subject), " ").concat(this.termToNQ(q.predicate), " ").concat(this.termToNQ(q.object), " ").concat(this.termToNQ(q.graph), " .");
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
/** Stringify a {term} to n-quads serialization. */
|
|
155
|
+
termToNQ: function termToNQ(term) {
|
|
156
|
+
var _this = this;
|
|
157
|
+
|
|
158
|
+
switch (term.termType) {
|
|
159
|
+
case BlankNodeTermType:
|
|
160
|
+
return '_:' + term.value;
|
|
161
|
+
|
|
162
|
+
case DefaultGraphTermType:
|
|
163
|
+
return '';
|
|
164
|
+
|
|
165
|
+
case EmptyTermType:
|
|
166
|
+
return '<http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>';
|
|
167
|
+
|
|
168
|
+
case LiteralTermType:
|
|
169
|
+
return Literal.toNT(term);
|
|
170
|
+
|
|
171
|
+
case GraphTermType:
|
|
172
|
+
case NamedNodeTermType:
|
|
173
|
+
return '<' + term.value + '>';
|
|
174
|
+
|
|
175
|
+
case CollectionTermType:
|
|
176
|
+
return '(' + term.elements.map(function (t) {
|
|
177
|
+
return _this.termToNQ(t);
|
|
178
|
+
}).join(' ') + ')';
|
|
179
|
+
|
|
180
|
+
default:
|
|
181
|
+
throw new Error("Can't serialize nonstandard term type (was '".concat(term.termType, "')"));
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
/** Convert an rdf object (term or quad) to n-quads serialization. */
|
|
186
|
+
toNQ: function toNQ(term) {
|
|
187
|
+
if (this.isQuad(term)) {
|
|
188
|
+
return this.quadToNQ(term);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return this.termToNQ(term);
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new variable
|
|
196
|
+
* @param name - The name for the variable
|
|
197
|
+
*/
|
|
198
|
+
variable: function variable(name) {
|
|
199
|
+
return new Variable(name);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/** Contains the factory methods as defined in the spec, plus id */
|
|
203
|
+
|
|
204
|
+
export default CanonicalDataFactory;
|