rdflib 2.2.21 → 2.2.22-04669b23

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.
Files changed (118) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +11 -1
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +61 -114
  5. package/esm/class-order.js +1 -1
  6. package/esm/collection.js +70 -128
  7. package/esm/default-graph.js +14 -48
  8. package/esm/empty.js +8 -39
  9. package/esm/factories/canonical-data-factory.js +33 -65
  10. package/esm/factories/extended-term-factory.js +18 -25
  11. package/esm/factories/factory-types.js +3 -2
  12. package/esm/factories/rdflib-data-factory.js +9 -19
  13. package/esm/fetcher.js +1341 -1854
  14. package/esm/formula.js +639 -846
  15. package/esm/index.js +40 -77
  16. package/esm/jsonldparser.js +34 -50
  17. package/esm/jsonparser.js +1 -8
  18. package/esm/lists.js +47 -110
  19. package/esm/literal.js +120 -189
  20. package/esm/log.js +7 -7
  21. package/esm/n3parser.js +1022 -1412
  22. package/esm/named-node.js +70 -119
  23. package/esm/namespace.js +2 -5
  24. package/esm/node-internal.js +73 -110
  25. package/esm/node.js +2 -7
  26. package/esm/parse.js +12 -19
  27. package/esm/patch-parser.js +10 -30
  28. package/esm/query-to-sparql.js +0 -18
  29. package/esm/query.js +63 -147
  30. package/esm/rdfaparser.js +794 -997
  31. package/esm/rdfxmlparser.js +347 -461
  32. package/esm/serialize.js +9 -34
  33. package/esm/serializer.js +842 -1048
  34. package/esm/sparql-to-query.js +44 -134
  35. package/esm/statement.js +54 -85
  36. package/esm/store.js +830 -1103
  37. package/esm/types.js +22 -21
  38. package/esm/update-manager.js +869 -1106
  39. package/esm/updates-via.js +104 -161
  40. package/esm/uri.js +9 -53
  41. package/esm/utils/default-graph-uri.js +3 -2
  42. package/esm/utils/termValue.js +0 -1
  43. package/esm/utils/terms.js +19 -21
  44. package/esm/utils-js.js +20 -61
  45. package/esm/utils.js +10 -21
  46. package/esm/variable.js +32 -78
  47. package/esm/xsd.js +2 -2
  48. package/lib/blank-node.js +60 -113
  49. package/lib/class-order.js +1 -2
  50. package/lib/collection.js +69 -131
  51. package/lib/default-graph.js +13 -52
  52. package/lib/empty.js +8 -43
  53. package/lib/factories/canonical-data-factory.js +35 -79
  54. package/lib/factories/extended-term-factory.js +18 -32
  55. package/lib/factories/factory-types.d.ts +6 -6
  56. package/lib/factories/factory-types.js +1 -4
  57. package/lib/factories/rdflib-data-factory.js +9 -23
  58. package/lib/fetcher.d.ts +6 -6
  59. package/lib/fetcher.js +1370 -1843
  60. package/lib/formula.d.ts +1 -1
  61. package/lib/formula.js +640 -855
  62. package/lib/index.d.ts +1 -2
  63. package/lib/index.js +67 -156
  64. package/lib/jsonldparser.js +33 -54
  65. package/lib/jsonparser.js +1 -10
  66. package/lib/lists.js +55 -112
  67. package/lib/literal.js +120 -195
  68. package/lib/log.d.ts +0 -6
  69. package/lib/log.js +7 -8
  70. package/lib/n3parser.d.ts +1 -0
  71. package/lib/n3parser.js +1023 -1422
  72. package/lib/named-node.js +69 -126
  73. package/lib/namespace.js +2 -7
  74. package/lib/node-internal.js +74 -107
  75. package/lib/node.js +2 -12
  76. package/lib/parse.d.ts +1 -1
  77. package/lib/parse.js +12 -32
  78. package/lib/patch-parser.js +11 -34
  79. package/lib/query-to-sparql.js +0 -23
  80. package/lib/query.js +62 -167
  81. package/lib/rdfaparser.js +796 -1009
  82. package/lib/rdfxmlparser.js +349 -466
  83. package/lib/serialize.d.ts +1 -1
  84. package/lib/serialize.js +9 -44
  85. package/lib/serializer.d.ts +1 -0
  86. package/lib/serializer.js +846 -1063
  87. package/lib/sparql-to-query.js +42 -167
  88. package/lib/statement.js +55 -91
  89. package/lib/store.d.ts +2 -2
  90. package/lib/store.js +850 -1112
  91. package/lib/tf-types.d.ts +4 -4
  92. package/lib/types.d.ts +8 -8
  93. package/lib/types.js +23 -23
  94. package/lib/update-manager.d.ts +1 -1
  95. package/lib/update-manager.js +865 -1103
  96. package/lib/updates-via.js +105 -164
  97. package/lib/uri.js +8 -61
  98. package/lib/utils/default-graph-uri.js +3 -5
  99. package/lib/utils/termValue.js +0 -2
  100. package/lib/utils/terms.js +19 -40
  101. package/lib/utils-js.js +23 -88
  102. package/lib/utils.js +10 -27
  103. package/lib/variable.js +34 -85
  104. package/lib/xsd-internal.js +0 -3
  105. package/lib/xsd.js +2 -6
  106. package/package.json +40 -39
  107. package/src/fetcher.ts +2 -2
  108. package/src/index.ts +0 -2
  109. package/src/jsonldparser.js +13 -4
  110. package/src/n3parser.js +12 -4
  111. package/src/serialize.ts +4 -11
  112. package/src/serializer.js +24 -0
  113. package/src/update-manager.ts +12 -7
  114. package/changes.txt +0 -59
  115. package/esm/convert.js +0 -61
  116. package/lib/convert.d.ts +0 -2
  117. package/lib/convert.js +0 -77
  118. package/src/convert.js +0 -70
package/esm/index.js CHANGED
@@ -1,18 +1,6 @@
1
- import _createClass from "@babel/runtime/helpers/createClass";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
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
1
  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
2
  import BlankNode from './blank-node';
14
3
  import Collection from './collection';
15
- import * as convert from './convert';
16
4
  import Empty from './empty';
17
5
  import Fetcher from './fetcher';
18
6
  import Formula from './formula';
@@ -40,77 +28,52 @@ import { UpdatesVia } from './updates-via';
40
28
  import * as uri from './uri';
41
29
  import * as Util from './utils-js';
42
30
  import Variable from './variable';
43
- import DataFactory from './factories/rdflib-data-factory'; // Prepare bound versions of data factory methods for export
31
+ import DataFactory from './factories/rdflib-data-factory';
44
32
 
45
- var boundDataFactory = {};
46
-
47
- for (var name in DataFactory) {
33
+ // Prepare bound versions of data factory methods for export
34
+ const boundDataFactory = {};
35
+ for (const name in DataFactory) {
48
36
  if (typeof DataFactory[name] === 'function') boundDataFactory[name] = DataFactory[name].bind(DataFactory);
49
37
  }
50
-
51
- var fetcher = boundDataFactory.fetcher,
52
- graph = boundDataFactory.graph,
53
- lit = boundDataFactory.lit,
54
- st = boundDataFactory.st,
55
- namedNode = boundDataFactory.namedNode,
56
- variable = boundDataFactory.variable,
57
- blankNode = boundDataFactory.blankNode,
58
- defaultGraph = boundDataFactory.defaultGraph,
59
- literal = boundDataFactory.literal,
60
- quad = boundDataFactory.quad,
61
- triple = boundDataFactory.triple;
62
- var formula = new Formula();
63
-
64
- var fromNT = function fromNT(str) {
65
- return formula.fromNT(str);
66
- };
67
-
68
- var term = Node.fromValue; // TODO: this export is broken;
38
+ const {
39
+ fetcher,
40
+ graph,
41
+ lit,
42
+ st,
43
+ namedNode,
44
+ variable,
45
+ blankNode,
46
+ defaultGraph,
47
+ literal,
48
+ quad,
49
+ triple
50
+ } = boundDataFactory;
51
+ const formula = new Formula();
52
+ const fromNT = str => formula.fromNT(str);
53
+ const term = Node.fromValue;
54
+
55
+ // TODO: this export is broken;
69
56
  // it exports the _current_ value of nextId, which is always 0
70
-
71
- var NextId = BlankNode.nextId;
57
+ const NextId = BlankNode.nextId;
72
58
  export * from './utils/terms';
73
- 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
74
- NextId, fromNT, fetcher, graph, lit, st, namedNode as sym, // RDFJS DataFactory interface
59
+ export { BlankNode, Collection, 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,
60
+ // Alias
61
+
62
+ NextId, fromNT, fetcher, graph, lit, st, namedNode as sym,
63
+ // RDFJS DataFactory interface
75
64
  blankNode, defaultGraph, literal, namedNode, quad, triple, variable };
76
65
  export { termValue } from './utils/termValue';
77
- export var ConnectedStore = /*#__PURE__*/function (_Store) {
78
- _inherits(ConnectedStore, _Store);
79
-
80
- var _super = _createSuper(ConnectedStore);
81
-
82
- function ConnectedStore(features) {
83
- var _this;
84
-
85
- _classCallCheck(this, ConnectedStore);
86
-
87
- _this = _super.call(this, features);
88
-
89
- _defineProperty(_assertThisInitialized(_this), "fetcher", void 0);
90
-
91
- _this.fetcher = new Fetcher(_assertThisInitialized(_this), {});
92
- return _this;
66
+ export class ConnectedStore extends Store {
67
+ constructor(features) {
68
+ super(features);
69
+ _defineProperty(this, "fetcher", void 0);
70
+ this.fetcher = new Fetcher(this, {});
93
71
  }
94
-
95
- return _createClass(ConnectedStore);
96
- }(Store);
97
- export var LiveStore = /*#__PURE__*/function (_ConnectedStore) {
98
- _inherits(LiveStore, _ConnectedStore);
99
-
100
- var _super2 = _createSuper(LiveStore);
101
-
102
- function LiveStore(features) {
103
- var _this2;
104
-
105
- _classCallCheck(this, LiveStore);
106
-
107
- _this2 = _super2.call(this, features);
108
-
109
- _defineProperty(_assertThisInitialized(_this2), "updater", void 0);
110
-
111
- _this2.updater = new UpdateManager(_assertThisInitialized(_this2));
112
- return _this2;
72
+ }
73
+ export class LiveStore extends ConnectedStore {
74
+ constructor(features) {
75
+ super(features);
76
+ _defineProperty(this, "updater", void 0);
77
+ this.updater = new UpdateManager(this);
113
78
  }
114
-
115
- return _createClass(LiveStore);
116
- }(ConnectedStore);
79
+ }
@@ -1,118 +1,106 @@
1
1
  import jsonld from 'jsonld';
2
2
  import { arrayToStatements } from './utils';
3
+
3
4
  /**
4
5
  * Parses json-ld formatted JS objects to a rdf Term.
5
6
  * @param kb - The DataFactory to use.
6
7
  * @param obj - The json-ld object to process.
7
8
  * @return {Literal|NamedNode|BlankNode|Collection}
8
9
  */
9
-
10
10
  export function jsonldObjectToTerm(kb, obj) {
11
11
  if (typeof obj === 'string') {
12
12
  return kb.rdfFactory.literal(obj);
13
13
  }
14
-
15
14
  if (Object.prototype.hasOwnProperty.call(obj, '@list')) {
16
15
  if (kb.rdfFactory.supports["COLLECTIONS"] === true) {
17
16
  return listToCollection(kb, obj['@list']);
18
17
  }
19
-
20
18
  return listToStatements(kb, obj);
21
19
  }
22
-
23
20
  if (Object.prototype.hasOwnProperty.call(obj, '@id')) {
24
- return kb.rdfFactory.namedNode(obj['@id']);
21
+ return nodeType(kb, obj);
25
22
  }
26
-
27
23
  if (Object.prototype.hasOwnProperty.call(obj, '@language')) {
28
24
  return kb.rdfFactory.literal(obj['@value'], obj['@language']);
29
25
  }
30
-
31
26
  if (Object.prototype.hasOwnProperty.call(obj, '@type')) {
32
27
  return kb.rdfFactory.literal(obj['@value'], kb.rdfFactory.namedNode(obj['@type']));
33
28
  }
34
-
35
29
  if (Object.prototype.hasOwnProperty.call(obj, '@value')) {
36
30
  return kb.rdfFactory.literal(obj['@value']);
37
31
  }
38
-
39
32
  return kb.rdfFactory.literal(obj);
40
33
  }
34
+
41
35
  /**
42
36
  * Adds the statements in a json-ld list object to {kb}.
43
37
  */
44
-
45
38
  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);
39
+ const listId = obj['@id'] ? nodeType(kb, obj) : kb.rdfFactory.blankNode();
40
+ const items = obj['@list'].map(listItem => jsonldObjectToTerm(kb, listItem));
41
+ const statements = arrayToStatements(kb.rdfFactory, listId, items);
51
42
  kb.addAll(statements);
52
43
  return listId;
53
44
  }
54
-
55
45
  function listToCollection(kb, obj) {
56
46
  if (!Array.isArray(obj)) {
57
47
  throw new TypeError("Object must be an array");
58
48
  }
59
-
60
- return kb.rdfFactory.collection(obj.map(function (o) {
61
- return jsonldObjectToTerm(kb, o);
62
- }));
49
+ return kb.rdfFactory.collection(obj.map(o => jsonldObjectToTerm(kb, o)));
63
50
  }
51
+
64
52
  /**
65
53
  * Takes a json-ld formatted string {str} and adds its statements to {kb}.
66
54
  *
67
55
  * Ensure that {kb.rdfFactory} is a DataFactory.
68
56
  */
69
-
70
-
71
57
  export default function jsonldParser(str, kb, base, callback) {
72
- var baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
58
+ const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
73
59
  return jsonld.flatten(JSON.parse(str), null, {
74
60
  base: baseString
75
- }).then(function (flattened) {
76
- return flattened.reduce(function (store, flatResource) {
77
- kb = processResource(kb, base, flatResource);
78
- return kb;
79
- }, kb);
80
- }).then(callback).catch(callback);
61
+ }).then(flattened => flattened.reduce((store, flatResource) => {
62
+ kb = processResource(kb, base, flatResource);
63
+ return kb;
64
+ }, kb)).then(callback).catch(callback);
65
+ }
66
+ function nodeType(kb, obj) {
67
+ if (obj['@id'].startsWith('_:')) {
68
+ // This object is a Blank Node. Pass the id without the `_:` prefix
69
+ return kb.rdfFactory.blankNode(obj['@id'].substring(2));
70
+ } else {
71
+ // This object is a Named Node
72
+ return kb.rdfFactory.namedNode(obj['@id']);
73
+ }
81
74
  }
82
-
83
75
  function processResource(kb, base, flatResource) {
84
- var id = flatResource['@id'] ? kb.rdfFactory.namedNode(flatResource['@id']) : kb.rdfFactory.blankNode();
85
-
86
- for (var _i = 0, _Object$keys = Object.keys(flatResource); _i < _Object$keys.length; _i++) {
87
- var property = _Object$keys[_i];
88
-
76
+ const id = flatResource['@id'] ? nodeType(kb, flatResource) : kb.rdfFactory.blankNode();
77
+ for (const property of Object.keys(flatResource)) {
89
78
  if (property === '@id') {
90
79
  continue;
91
80
  } else if (property == '@graph') {
92
81
  // the JSON-LD flattened structure may contain nested graphs
93
82
  // the id value for this object is the new base (named graph id) for all nested flat resources
94
- var graphId = id; // this is an array of resources
95
-
96
- var nestedFlatResources = flatResource[property]; // recursively process all flat resources in the array, but with the graphId as base.
83
+ const graphId = id;
84
+ // this is an array of resources
85
+ const nestedFlatResources = flatResource[property];
97
86
 
98
- for (var i = 0; i < nestedFlatResources.length; i++) {
87
+ // recursively process all flat resources in the array, but with the graphId as base.
88
+ for (let i = 0; i < nestedFlatResources.length; i++) {
99
89
  kb = processResource(kb, graphId, nestedFlatResources[i]);
100
90
  }
101
91
  }
102
-
103
- var value = flatResource[property];
104
-
92
+ const value = flatResource[property];
105
93
  if (Array.isArray(value)) {
106
- for (var _i2 = 0; _i2 < value.length; _i2++) {
107
- kb.addStatement(createStatement(kb, id, property, value[_i2], base));
94
+ for (let i = 0; i < value.length; i++) {
95
+ kb.addStatement(createStatement(kb, id, property, value[i], base));
108
96
  }
109
97
  } else {
110
98
  kb.addStatement(createStatement(kb, id, property, value, base));
111
99
  }
112
100
  }
113
-
114
101
  return kb;
115
102
  }
103
+
116
104
  /**
117
105
  * Create statement quad depending on @type being a type node
118
106
  * @param kb
@@ -121,11 +109,8 @@ function processResource(kb, base, flatResource) {
121
109
  * @param value
122
110
  * @return quad statement
123
111
  */
124
-
125
-
126
112
  function createStatement(kb, id, property, value, base) {
127
- var predicate, object;
128
-
113
+ let predicate, object;
129
114
  if (property === "@type") {
130
115
  predicate = kb.rdfFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
131
116
  object = kb.rdfFactory.namedNode(value);
@@ -133,6 +118,5 @@ function createStatement(kb, id, property, value, base) {
133
118
  predicate = kb.rdfFactory.namedNode(property);
134
119
  object = jsonldObjectToTerm(kb, value);
135
120
  }
136
-
137
121
  return kb.rdfFactory.quad(id, predicate, object, kb.rdfFactory.namedNode(base));
138
122
  }
package/esm/jsonparser.js CHANGED
@@ -1,10 +1,9 @@
1
1
  export default (function () {
2
2
  return {
3
- parseJSON: function parseJSON(data, source, store) {
3
+ parseJSON: function (data, source, store) {
4
4
  var subject, predicate, object;
5
5
  var bnodes = {};
6
6
  var why = store.sym(source);
7
-
8
7
  for (var x in data) {
9
8
  if (x.indexOf('_:') === 0) {
10
9
  if (bnodes[x]) {
@@ -16,16 +15,12 @@ export default (function () {
16
15
  } else {
17
16
  subject = store.sym(x);
18
17
  }
19
-
20
18
  var preds = data[x];
21
-
22
19
  for (var y in preds) {
23
20
  var objects = preds[y];
24
21
  predicate = store.sym(y);
25
-
26
22
  for (var z in objects) {
27
23
  var obj = objects[z];
28
-
29
24
  if (obj.type === 'uri') {
30
25
  object = store.sym(obj.value);
31
26
  store.add(subject, predicate, object, why);
@@ -36,7 +31,6 @@ export default (function () {
36
31
  object = store.bnode(obj.value);
37
32
  bnodes[obj.value] = object;
38
33
  }
39
-
40
34
  store.add(subject, predicate, object, why);
41
35
  } else if (obj.type === 'Literal') {
42
36
  // var datatype
@@ -47,7 +41,6 @@ export default (function () {
47
41
  } else {
48
42
  object = store.literal(obj.value);
49
43
  }
50
-
51
44
  store.add(subject, predicate, object, why);
52
45
  } else {
53
46
  throw new Error('error: unexpected termtype: ' + z.type);
package/esm/lists.js CHANGED
@@ -1,11 +1,6 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
-
3
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
-
5
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
-
7
1
  /* Lists form conversion
8
2
  */
3
+
9
4
  // import DataFactory from './factories/extended-term-factory'
10
5
  // import jsonldParser from './jsonldparser'
11
6
  // @ts-ignore is this injected?
@@ -15,109 +10,54 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
15
10
  // import RDFParser from './rdfxmlparser'
16
11
  // import sparqlUpdateParser from './patch-parser'
17
12
  // import * as Util from './utils-js'
13
+
18
14
  // import BlankNode from './blank-node'
19
15
  // import NamedNode from './named-node'
20
16
  import Collection from './collection';
21
- import Statement from './statement'; // import Formula from './formula'
17
+ import Statement from './statement';
18
+ // import Formula from './formula'
22
19
 
23
20
  import Namespace from './namespace';
24
- var RDF = Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
21
+ const RDF = Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
22
+
25
23
  /* Replace a given node with another node throughout a given document
26
24
  *
27
25
  * we do the predicate as well for complenesss though we don't expect Collections to use it
28
26
  */
29
-
30
27
  export function substituteInDoc(store, x, y, doc) {
31
28
  // console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
32
- var _iterator = _createForOfIteratorHelper(store.statementsMatching(y, null, null, doc)),
33
- _step;
34
-
35
- try {
36
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
37
- var quad = _step.value;
38
- var newStatement = new Statement(x, quad.predicate, quad.object, doc);
39
- store.remove(quad);
40
- store.add(newStatement);
41
- }
42
- } catch (err) {
43
- _iterator.e(err);
44
- } finally {
45
- _iterator.f();
29
+ for (const quad of store.statementsMatching(y, null, null, doc)) {
30
+ const newStatement = new Statement(x, quad.predicate, quad.object, doc);
31
+ store.remove(quad);
32
+ store.add(newStatement);
46
33
  }
47
-
48
- var _iterator2 = _createForOfIteratorHelper(store.statementsMatching(null, y, null, doc)),
49
- _step2;
50
-
51
- try {
52
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
53
- var _quad = _step2.value;
54
- store.remove(_quad); // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
55
-
56
- store.add(new Statement(_quad.subject, x, _quad.object, doc));
57
- }
58
- } catch (err) {
59
- _iterator2.e(err);
60
- } finally {
61
- _iterator2.f();
34
+ for (const quad of store.statementsMatching(null, y, null, doc)) {
35
+ store.remove(quad);
36
+ // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
37
+ store.add(new Statement(quad.subject, x, quad.object, doc));
62
38
  }
63
-
64
- var _iterator3 = _createForOfIteratorHelper(store.statementsMatching(null, null, y, doc)),
65
- _step3;
66
-
67
- try {
68
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
69
- var _quad2 = _step3.value;
70
- store.remove(_quad2);
71
- store.add(new Statement(_quad2.subject, _quad2.predicate, x, doc));
72
- }
73
- } catch (err) {
74
- _iterator3.e(err);
75
- } finally {
76
- _iterator3.f();
39
+ for (const quad of store.statementsMatching(null, null, y, doc)) {
40
+ store.remove(quad);
41
+ store.add(new Statement(quad.subject, quad.predicate, x, doc));
77
42
  }
78
43
  }
44
+
79
45
  /* Change all lone rdf:nil nodes into empty Collections
80
46
  */
81
-
82
47
  export function substituteNillsInDoc(store, doc) {
83
- var x = RDF('nil');
84
-
85
- var _iterator4 = _createForOfIteratorHelper(store.statementsMatching(x, null, null, doc)),
86
- _step4;
87
-
88
- try {
89
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
90
- var quad = _step4.value;
91
- store.remove(quad);
92
- var y = new Collection();
93
- store.add(new Statement(y, quad.predicate, quad.object, doc));
94
- }
95
- } catch (err) {
96
- _iterator4.e(err);
97
- } finally {
98
- _iterator4.f();
48
+ const x = RDF('nil');
49
+ for (const quad of store.statementsMatching(x, null, null, doc)) {
50
+ store.remove(quad);
51
+ const y = new Collection();
52
+ store.add(new Statement(y, quad.predicate, quad.object, doc));
99
53
  }
100
-
101
- var _iterator5 = _createForOfIteratorHelper(store.statementsMatching(null, null, x, doc)),
102
- _step5;
103
-
104
- try {
105
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
106
- var _quad3 = _step5.value;
107
-
108
- if (!_quad3.predicate.sameTerm(RDF('rest'))) {
109
- // If not a tail
110
- store.remove(_quad3);
111
-
112
- var _y = new Collection();
113
-
114
- store.add(new Statement(_quad3.subject, _quad3.predicate, _y, doc));
115
- }
54
+ for (const quad of store.statementsMatching(null, null, x, doc)) {
55
+ if (!quad.predicate.sameTerm(RDF('rest'))) {
56
+ // If not a tail
57
+ store.remove(quad);
58
+ const y = new Collection();
59
+ store.add(new Statement(quad.subject, quad.predicate, y, doc));
116
60
  }
117
- } catch (err) {
118
- _iterator5.e(err);
119
- } finally {
120
- _iterator5.f();
121
61
  }
122
62
  }
123
63
  /**
@@ -132,37 +72,34 @@ export function substituteNillsInDoc(store, doc) {
132
72
  export function convertFirstRestNil(store, doc // Do whole store?
133
73
  ) {
134
74
  function preceding(ele, listSoFar, trash) {
135
- var rests = store.statementsMatching(ele, RDF('rest'), null, doc);
136
- if (rests.length !== 1) throw new Error("Bad list structure: no rest at ".concat(ele));
137
- var firsts = store.statementsMatching(ele, RDF('first'), null, doc);
138
- if (firsts.length !== 1) throw new Error("Bad list structure: rest but ".concat(firsts.length, " firsts at ").concat(ele));
139
- var value = firsts[0].object;
140
- var total = [value].concat(listSoFar); // console.log(' List now is: ', total)
141
-
142
- var totalTrash = trash.concat(rests).concat(firsts);
143
- var pres = store.statementsMatching(null, RDF('rest'), ele, doc);
144
-
75
+ const rests = store.statementsMatching(ele, RDF('rest'), null, doc);
76
+ if (rests.length !== 1) throw new Error(`Bad list structure: no rest at ${ele}`);
77
+ const firsts = store.statementsMatching(ele, RDF('first'), null, doc);
78
+ if (firsts.length !== 1) throw new Error(`Bad list structure: rest but ${firsts.length} firsts at ${ele}`);
79
+ const value = firsts[0].object;
80
+ const total = [value].concat(listSoFar);
81
+ // console.log(' List now is: ', total)
82
+ const totalTrash = trash.concat(rests).concat(firsts);
83
+ const pres = store.statementsMatching(null, RDF('rest'), ele, doc);
145
84
  if (pres.length === 0) {
146
85
  // Head of the list
147
- var newList = new Collection(total);
148
- store.remove(totalTrash); // Replace old list with new list:
149
-
86
+ const newList = new Collection(total);
87
+ store.remove(totalTrash);
88
+ // Replace old list with new list:
150
89
  substituteInDoc(store, newList, ele, doc);
151
90
  return;
152
91
  }
153
-
154
- if (pres.length !== 1) throw new Error("Bad list structure: ".concat(pres.length, " pres at ").concat(ele));
155
- var pre = pres[0].subject;
156
- if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
92
+ if (pres.length !== 1) throw new Error(`Bad list structure: ${pres.length} pres at ${ele}`);
93
+ const pre = pres[0].subject;
94
+ if (pre.termType !== 'BlankNode') throw new Error(`Bad list element node ${pre} type: ${pre.termType} `);
157
95
  preceding(pre, total, totalTrash);
158
96
  return;
159
97
  }
160
-
161
98
  substituteNillsInDoc(store, doc); // lone ones only
162
99
 
163
- var tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
164
- tails.forEach(function (tail) {
165
- if (tail.subject.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(tail.subject, " type: ").concat(tail.subject.termType, " "));
100
+ const tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
101
+ tails.forEach(tail => {
102
+ if (tail.subject.termType !== 'BlankNode') throw new Error(`Bad list element node ${tail.subject} type: ${tail.subject.termType} `);
166
103
  preceding(tail.subject, [], []);
167
104
  });
168
105
  }