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
package/esm/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import BlankNode from './blank-node';
|
|
2
|
+
import Collection from './collection';
|
|
3
|
+
import * as convert from './convert';
|
|
4
|
+
import Empty from './empty';
|
|
5
|
+
import Fetcher from './fetcher';
|
|
6
|
+
import Formula from './formula';
|
|
7
|
+
import Store from './store';
|
|
8
|
+
import jsonParser from './jsonparser';
|
|
9
|
+
import Literal from './literal';
|
|
10
|
+
import log from './log';
|
|
11
|
+
import N3Parser from './n3parser';
|
|
12
|
+
import NamedNode from './named-node';
|
|
13
|
+
import Namespace from './namespace';
|
|
14
|
+
import Node from './node';
|
|
15
|
+
import parse from './parse';
|
|
16
|
+
import { Query } from './query';
|
|
17
|
+
import queryToSPARQL from './query-to-sparql';
|
|
18
|
+
import RDFaProcessor from './rdfaparser';
|
|
19
|
+
import RDFParser from './rdfxmlparser';
|
|
20
|
+
import serialize from './serialize';
|
|
21
|
+
import Serializer from './serializer';
|
|
22
|
+
import SPARQLToQuery from './sparql-to-query';
|
|
23
|
+
import sparqlUpdateParser from './patch-parser';
|
|
24
|
+
import Statement from './statement';
|
|
25
|
+
import UpdateManager from './update-manager';
|
|
26
|
+
import { UpdatesSocket } from './updates-via';
|
|
27
|
+
import { UpdatesVia } from './updates-via';
|
|
28
|
+
import * as uri from './uri';
|
|
29
|
+
import * as Util from './utils-js';
|
|
30
|
+
import Variable from './variable';
|
|
31
|
+
import DataFactory from './factories/rdflib-data-factory'; // Prepare bound versions of data factory methods for export
|
|
32
|
+
|
|
33
|
+
var boundDataFactory = {};
|
|
34
|
+
|
|
35
|
+
for (var name in DataFactory) {
|
|
36
|
+
if (typeof DataFactory[name] === 'function') boundDataFactory[name] = DataFactory[name].bind(DataFactory);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var fetcher = boundDataFactory.fetcher,
|
|
40
|
+
graph = boundDataFactory.graph,
|
|
41
|
+
lit = boundDataFactory.lit,
|
|
42
|
+
st = boundDataFactory.st,
|
|
43
|
+
namedNode = boundDataFactory.namedNode,
|
|
44
|
+
variable = boundDataFactory.variable,
|
|
45
|
+
blankNode = boundDataFactory.blankNode,
|
|
46
|
+
defaultGraph = boundDataFactory.defaultGraph,
|
|
47
|
+
literal = boundDataFactory.literal,
|
|
48
|
+
quad = boundDataFactory.quad,
|
|
49
|
+
triple = boundDataFactory.triple;
|
|
50
|
+
var formula = new Formula();
|
|
51
|
+
|
|
52
|
+
var fromNT = function fromNT(str) {
|
|
53
|
+
return formula.fromNT(str);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
var term = Node.fromValue; // TODO: this export is broken;
|
|
57
|
+
// it exports the _current_ value of nextId, which is always 0
|
|
58
|
+
|
|
59
|
+
var NextId = BlankNode.nextId;
|
|
60
|
+
export * from './utils/terms';
|
|
61
|
+
export { BlankNode, Collection, convert, DataFactory, Empty, Fetcher, Formula, Store, jsonParser, Literal, log, N3Parser, NamedNode, Namespace, Node, parse, Query, queryToSPARQL, RDFaProcessor, RDFParser, serialize, Serializer, SPARQLToQuery, sparqlUpdateParser, Statement, term, UpdateManager, UpdatesSocket, UpdatesVia, uri, Util, Variable, Store as IndexedFormula, // Alias
|
|
62
|
+
NextId, fromNT, fetcher, graph, lit, st, namedNode as sym, // RDFJS DataFactory interface
|
|
63
|
+
blankNode, defaultGraph, literal, namedNode, quad, triple, variable };
|
|
64
|
+
export { termValue } from './utils/termValue';
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import jsonld from 'jsonld';
|
|
2
|
+
import { arrayToStatements } from './utils';
|
|
3
|
+
/**
|
|
4
|
+
* Parses json-ld formatted JS objects to a rdf Term.
|
|
5
|
+
* @param kb - The DataFactory to use.
|
|
6
|
+
* @param obj - The json-ld object to process.
|
|
7
|
+
* @return {Literal|NamedNode|BlankNode|Collection}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function jsonldObjectToTerm(kb, obj) {
|
|
11
|
+
if (typeof obj === 'string') {
|
|
12
|
+
return kb.rdfFactory.literal(obj);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(obj, '@list')) {
|
|
16
|
+
if (kb.rdfFactory.supports["COLLECTIONS"] === true) {
|
|
17
|
+
return listToCollection(kb, obj['@list']);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return listToStatements(kb, obj);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(obj, '@id')) {
|
|
24
|
+
return kb.rdfFactory.namedNode(obj['@id']);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(obj, '@language')) {
|
|
28
|
+
return kb.rdfFactory.literal(obj['@value'], obj['@language']);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(obj, '@type')) {
|
|
32
|
+
return kb.rdfFactory.literal(obj['@value'], kb.rdfFactory.namedNode(obj['@type']));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(obj, '@value')) {
|
|
36
|
+
return kb.rdfFactory.literal(obj['@value']);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return kb.rdfFactory.literal(obj);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Adds the statements in a json-ld list object to {kb}.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
function listToStatements(kb, obj) {
|
|
46
|
+
var listId = obj['@id'] ? kb.rdfFactory.namedNode(obj['@id']) : kb.rdfFactory.blankNode();
|
|
47
|
+
var items = obj['@list'].map(function (listItem) {
|
|
48
|
+
return jsonldObjectToTerm(kb, listItem);
|
|
49
|
+
});
|
|
50
|
+
var statements = arrayToStatements(kb.rdfFactory, listId, items);
|
|
51
|
+
kb.addAll(statements);
|
|
52
|
+
return listId;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function listToCollection(kb, obj) {
|
|
56
|
+
if (!Array.isArray(obj)) {
|
|
57
|
+
throw new TypeError("Object must be an array");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return kb.rdfFactory.collection(obj.map(function (o) {
|
|
61
|
+
return jsonldObjectToTerm(kb, o);
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Takes a json-ld formatted string {str} and adds its statements to {kb}.
|
|
66
|
+
*
|
|
67
|
+
* Ensure that {kb.rdfFactory} is a DataFactory.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
export default function jsonldParser(str, kb, base, callback) {
|
|
72
|
+
var baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
|
|
73
|
+
return jsonld.flatten(JSON.parse(str), null, {
|
|
74
|
+
base: baseString
|
|
75
|
+
}).then(function (flattened) {
|
|
76
|
+
return flattened.reduce(function (store, flatResource) {
|
|
77
|
+
var id = flatResource['@id'] ? kb.rdfFactory.namedNode(flatResource['@id']) : kb.rdfFactory.blankNode();
|
|
78
|
+
|
|
79
|
+
for (var _i = 0, _Object$keys = Object.keys(flatResource); _i < _Object$keys.length; _i++) {
|
|
80
|
+
var property = _Object$keys[_i];
|
|
81
|
+
|
|
82
|
+
if (property === '@id') {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var value = flatResource[property];
|
|
87
|
+
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
for (var i = 0; i < value.length; i++) {
|
|
90
|
+
kb.addStatement(createStatement(kb, id, property, value[i], base));
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
kb.addStatement(createStatement(kb, id, property, value, base));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return kb;
|
|
98
|
+
}, kb);
|
|
99
|
+
}).then(callback).catch(callback);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create statement quad depending on @type being a type node
|
|
103
|
+
* @param kb
|
|
104
|
+
* @param subject id
|
|
105
|
+
* @param property
|
|
106
|
+
* @param value
|
|
107
|
+
* @return quad statement
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
function createStatement(kb, id, property, value, base) {
|
|
111
|
+
var predicate, object;
|
|
112
|
+
|
|
113
|
+
if (property === "@type") {
|
|
114
|
+
predicate = kb.rdfFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
|
|
115
|
+
object = kb.rdfFactory.namedNode(value);
|
|
116
|
+
} else {
|
|
117
|
+
predicate = kb.rdfFactory.namedNode(property);
|
|
118
|
+
object = jsonldObjectToTerm(kb, value);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return kb.rdfFactory.quad(id, predicate, object, kb.rdfFactory.namedNode(base));
|
|
122
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export default (function () {
|
|
2
|
+
return {
|
|
3
|
+
parseJSON: function parseJSON(data, source, store) {
|
|
4
|
+
var subject, predicate, object;
|
|
5
|
+
var bnodes = {};
|
|
6
|
+
var why = store.sym(source);
|
|
7
|
+
|
|
8
|
+
for (var x in data) {
|
|
9
|
+
if (x.indexOf('_:') === 0) {
|
|
10
|
+
if (bnodes[x]) {
|
|
11
|
+
subject = bnodes[x];
|
|
12
|
+
} else {
|
|
13
|
+
subject = store.bnode(x);
|
|
14
|
+
bnodes[x] = subject;
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
subject = store.sym(x);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var preds = data[x];
|
|
21
|
+
|
|
22
|
+
for (var y in preds) {
|
|
23
|
+
var objects = preds[y];
|
|
24
|
+
predicate = store.sym(y);
|
|
25
|
+
|
|
26
|
+
for (var z in objects) {
|
|
27
|
+
var obj = objects[z];
|
|
28
|
+
|
|
29
|
+
if (obj.type === 'uri') {
|
|
30
|
+
object = store.sym(obj.value);
|
|
31
|
+
store.add(subject, predicate, object, why);
|
|
32
|
+
} else if (obj.type === 'BlankNode') {
|
|
33
|
+
if (bnodes[obj.value]) {
|
|
34
|
+
object = bnodes[obj.value];
|
|
35
|
+
} else {
|
|
36
|
+
object = store.bnode(obj.value);
|
|
37
|
+
bnodes[obj.value] = object;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
store.add(subject, predicate, object, why);
|
|
41
|
+
} else if (obj.type === 'Literal') {
|
|
42
|
+
// var datatype
|
|
43
|
+
if (obj.datatype) {
|
|
44
|
+
object = store.literal(obj.value, undefined, store.sym(obj.datatype));
|
|
45
|
+
} else if (obj.lang) {
|
|
46
|
+
object = store.literal(obj.value, obj.lang);
|
|
47
|
+
} else {
|
|
48
|
+
object = store.literal(obj.value);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
store.add(subject, predicate, object, why);
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error('error: unexpected termtype: ' + z.type);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
})();
|
package/esm/literal.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
|
+
|
|
10
|
+
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); }; }
|
|
11
|
+
|
|
12
|
+
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; } }
|
|
13
|
+
|
|
14
|
+
import ClassOrder from './class-order';
|
|
15
|
+
import RDFlibNamedNode from './named-node';
|
|
16
|
+
import Node from './node-internal';
|
|
17
|
+
import { LiteralTermType } from './types';
|
|
18
|
+
import { isLiteral } from './utils/terms';
|
|
19
|
+
import XSD from './xsd-internal';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An RDF literal, containing some value which isn't expressed as an IRI.
|
|
23
|
+
* @link https://rdf.js.org/data-model-spec/#literal-interface
|
|
24
|
+
*/
|
|
25
|
+
var Literal = /*#__PURE__*/function (_Node) {
|
|
26
|
+
_inherits(Literal, _Node);
|
|
27
|
+
|
|
28
|
+
var _super = _createSuper(Literal);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The literal's datatype as a named node
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The language for the literal
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Initializes a literal
|
|
40
|
+
* @param value - The literal's lexical value
|
|
41
|
+
* @param language - The language for the literal. Defaults to ''.
|
|
42
|
+
* @param datatype - The literal's datatype as a named node. Defaults to xsd:string.
|
|
43
|
+
*/
|
|
44
|
+
function Literal(value, language, datatype) {
|
|
45
|
+
var _this;
|
|
46
|
+
|
|
47
|
+
_classCallCheck(this, Literal);
|
|
48
|
+
|
|
49
|
+
_this = _super.call(this, value);
|
|
50
|
+
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "termType", LiteralTermType);
|
|
52
|
+
|
|
53
|
+
_defineProperty(_assertThisInitialized(_this), "classOrder", ClassOrder.Literal);
|
|
54
|
+
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "datatype", XSD.string);
|
|
56
|
+
|
|
57
|
+
_defineProperty(_assertThisInitialized(_this), "isVar", 0);
|
|
58
|
+
|
|
59
|
+
_defineProperty(_assertThisInitialized(_this), "language", '');
|
|
60
|
+
|
|
61
|
+
if (language) {
|
|
62
|
+
_this.language = language;
|
|
63
|
+
_this.datatype = XSD.langString;
|
|
64
|
+
} else if (datatype) {
|
|
65
|
+
_this.datatype = RDFlibNamedNode.fromValue(datatype);
|
|
66
|
+
} else {
|
|
67
|
+
_this.datatype = XSD.string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return _this;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets a copy of this literal
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
_createClass(Literal, [{
|
|
78
|
+
key: "copy",
|
|
79
|
+
value: function copy() {
|
|
80
|
+
return new Literal(this.value, this.lang, this.datatype);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets whether two literals are the same
|
|
84
|
+
* @param other The other statement
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
}, {
|
|
88
|
+
key: "equals",
|
|
89
|
+
value: function equals(other) {
|
|
90
|
+
if (!other) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return this.termType === other.termType && this.value === other.value && this.language === other.language && (!this.datatype && !other.datatype || this.datatype && this.datatype.equals(other.datatype));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The language for the literal
|
|
98
|
+
* @deprecated use {language} instead
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
}, {
|
|
102
|
+
key: "lang",
|
|
103
|
+
get: function get() {
|
|
104
|
+
return this.language;
|
|
105
|
+
},
|
|
106
|
+
set: function set(language) {
|
|
107
|
+
this.language = language || '';
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "toNT",
|
|
111
|
+
value: function toNT() {
|
|
112
|
+
return Literal.toNT(this);
|
|
113
|
+
}
|
|
114
|
+
/** Serializes a literal to an N-Triples string */
|
|
115
|
+
|
|
116
|
+
}, {
|
|
117
|
+
key: "toString",
|
|
118
|
+
value: function toString() {
|
|
119
|
+
return '' + this.value;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Builds a literal node from a boolean value
|
|
123
|
+
* @param value - The value
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
}], [{
|
|
127
|
+
key: "toNT",
|
|
128
|
+
value: function toNT(literal) {
|
|
129
|
+
if (typeof literal.value === 'number') {
|
|
130
|
+
return '' + literal.value;
|
|
131
|
+
} else if (typeof literal.value !== 'string') {
|
|
132
|
+
throw new Error('Value of RDF literal is not string or number: ' + literal.value);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var str = literal.value; // #x22 ("), #x5C (\), #x0A (\n) and #xD (\r) are disallowed and need to be replaced
|
|
136
|
+
// see https://www.w3.org/TR/n-triples/#grammar-production-STRING_LITERAL_QUOTE
|
|
137
|
+
|
|
138
|
+
str = str.replace(/\\/g, '\\\\');
|
|
139
|
+
str = str.replace(/\"/g, '\\"');
|
|
140
|
+
str = str.replace(/\n/g, '\\n');
|
|
141
|
+
str = str.replace(/\r/g, '\\r');
|
|
142
|
+
str = '"' + str + '"';
|
|
143
|
+
|
|
144
|
+
if (literal.language) {
|
|
145
|
+
str += '@' + literal.language;
|
|
146
|
+
} else if (!literal.datatype.equals(XSD.string)) {
|
|
147
|
+
// Only add datatype if it's not a string
|
|
148
|
+
str += '^^' + literal.datatype.toCanonical();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return str;
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
key: "fromBoolean",
|
|
155
|
+
value: function fromBoolean(value) {
|
|
156
|
+
var strValue = value ? '1' : '0';
|
|
157
|
+
return new Literal(strValue, null, XSD.boolean);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Builds a literal node from a date value
|
|
161
|
+
* @param value The value
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
}, {
|
|
165
|
+
key: "fromDate",
|
|
166
|
+
value: function fromDate(value) {
|
|
167
|
+
if (!(value instanceof Date)) {
|
|
168
|
+
throw new TypeError('Invalid argument to Literal.fromDate()');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var d2 = function d2(x) {
|
|
172
|
+
return ('' + (100 + x)).slice(1, 3);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
var date = '' + value.getUTCFullYear() + '-' + d2(value.getUTCMonth() + 1) + '-' + d2(value.getUTCDate()) + 'T' + d2(value.getUTCHours()) + ':' + d2(value.getUTCMinutes()) + ':' + d2(value.getUTCSeconds()) + 'Z';
|
|
176
|
+
return new Literal(date, null, XSD.dateTime);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Builds a literal node from a number value
|
|
180
|
+
* @param value - The value
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
}, {
|
|
184
|
+
key: "fromNumber",
|
|
185
|
+
value: function fromNumber(value) {
|
|
186
|
+
if (typeof value !== 'number') {
|
|
187
|
+
throw new TypeError('Invalid argument to Literal.fromNumber()');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var datatype;
|
|
191
|
+
var strValue = value.toString();
|
|
192
|
+
|
|
193
|
+
if (strValue.indexOf('e') < 0 && Math.abs(value) <= Number.MAX_SAFE_INTEGER) {
|
|
194
|
+
datatype = Number.isInteger(value) ? XSD.integer : XSD.decimal;
|
|
195
|
+
} else {
|
|
196
|
+
datatype = XSD.double;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return new Literal(strValue, null, datatype);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Builds a literal node from an input value
|
|
203
|
+
* @param value - The input value
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
}, {
|
|
207
|
+
key: "fromValue",
|
|
208
|
+
value: function fromValue(value) {
|
|
209
|
+
if (isLiteral(value)) {
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
switch (_typeof(value)) {
|
|
214
|
+
case 'object':
|
|
215
|
+
if (value instanceof Date) {
|
|
216
|
+
return Literal.fromDate(value);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
case 'boolean':
|
|
220
|
+
return Literal.fromBoolean(value);
|
|
221
|
+
|
|
222
|
+
case 'number':
|
|
223
|
+
return Literal.fromNumber(value);
|
|
224
|
+
|
|
225
|
+
case 'string':
|
|
226
|
+
return new Literal(value);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
throw new Error("Can't make literal from " + value + ' of type ' + _typeof(value));
|
|
230
|
+
}
|
|
231
|
+
}]);
|
|
232
|
+
|
|
233
|
+
return Literal;
|
|
234
|
+
}(Node);
|
|
235
|
+
|
|
236
|
+
export { Literal as default };
|
package/esm/log.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Dummy log
|
|
3
|
+
* @module log
|
|
4
|
+
*/
|
|
5
|
+
var log = {
|
|
6
|
+
debug: function debug(x) {},
|
|
7
|
+
warn: function warn(x) {},
|
|
8
|
+
info: function info(x) {},
|
|
9
|
+
error: function error(x) {},
|
|
10
|
+
success: function success(x) {},
|
|
11
|
+
msg: function msg(x) {}
|
|
12
|
+
};
|
|
13
|
+
export default log;
|