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.
Files changed (115) hide show
  1. package/dist/rdflib.min.js +1 -1
  2. package/dist/rdflib.min.js.LICENSE.txt +13 -1
  3. package/dist/rdflib.min.js.map +1 -1
  4. package/esm/blank-node.js +3 -27
  5. package/esm/collection.js +7 -29
  6. package/esm/default-graph.js +1 -15
  7. package/esm/empty.js +0 -13
  8. package/esm/factories/canonical-data-factory.js +5 -40
  9. package/esm/factories/extended-term-factory.js +0 -11
  10. package/esm/factories/factory-types.js +2 -1
  11. package/esm/factories/rdflib-data-factory.js +0 -8
  12. package/esm/fetcher.js +257 -481
  13. package/esm/formula.js +43 -142
  14. package/esm/index.js +19 -36
  15. package/esm/jsonldparser.js +20 -29
  16. package/esm/jsonparser.js +0 -7
  17. package/esm/lists.js +18 -33
  18. package/esm/literal.js +10 -42
  19. package/esm/n3parser.js +38 -351
  20. package/esm/named-node.js +8 -27
  21. package/esm/namespace.js +0 -1
  22. package/esm/node-internal.js +11 -24
  23. package/esm/node.js +1 -6
  24. package/esm/parse.js +10 -17
  25. package/esm/patch-parser.js +9 -29
  26. package/esm/query-to-sparql.js +0 -18
  27. package/esm/query.js +50 -133
  28. package/esm/rdfaparser.js +72 -210
  29. package/esm/rdfxmlparser.js +31 -128
  30. package/esm/serialize.js +8 -33
  31. package/esm/serializer.js +122 -286
  32. package/esm/sparql-to-query.js +44 -134
  33. package/esm/statement.js +8 -19
  34. package/esm/store.js +109 -280
  35. package/esm/types.js +3 -2
  36. package/esm/update-manager.js +110 -246
  37. package/esm/updates-via.js +0 -27
  38. package/esm/uri.js +6 -50
  39. package/esm/utils/default-graph-uri.js +1 -0
  40. package/esm/utils/termValue.js +0 -1
  41. package/esm/utils/terms.js +15 -16
  42. package/esm/utils-js.js +16 -57
  43. package/esm/utils.js +4 -15
  44. package/esm/variable.js +0 -20
  45. package/lib/blank-node.js +3 -28
  46. package/lib/class-order.js +0 -1
  47. package/lib/collection.js +7 -34
  48. package/lib/default-graph.js +0 -20
  49. package/lib/empty.js +0 -18
  50. package/lib/factories/canonical-data-factory.js +4 -51
  51. package/lib/factories/extended-term-factory.js +0 -18
  52. package/lib/factories/factory-types.d.ts +6 -6
  53. package/lib/factories/factory-types.js +0 -3
  54. package/lib/factories/rdflib-data-factory.js +0 -12
  55. package/lib/fetcher.d.ts +6 -6
  56. package/lib/fetcher.js +258 -470
  57. package/lib/formula.d.ts +1 -1
  58. package/lib/formula.js +43 -151
  59. package/lib/index.d.ts +1 -2
  60. package/lib/index.js +14 -82
  61. package/lib/jsonldparser.js +19 -33
  62. package/lib/jsonparser.js +0 -9
  63. package/lib/lists.js +14 -39
  64. package/lib/literal.js +10 -49
  65. package/lib/log.d.ts +0 -6
  66. package/lib/log.js +0 -1
  67. package/lib/n3parser.d.ts +1 -0
  68. package/lib/n3parser.js +39 -359
  69. package/lib/named-node.js +7 -35
  70. package/lib/namespace.js +0 -3
  71. package/lib/node-internal.js +11 -21
  72. package/lib/node.js +1 -11
  73. package/lib/parse.d.ts +1 -1
  74. package/lib/parse.js +8 -27
  75. package/lib/patch-parser.js +10 -33
  76. package/lib/query-to-sparql.js +0 -23
  77. package/lib/query.js +46 -152
  78. package/lib/rdfaparser.js +72 -220
  79. package/lib/rdfxmlparser.js +31 -132
  80. package/lib/serialize.d.ts +1 -1
  81. package/lib/serialize.js +8 -43
  82. package/lib/serializer.d.ts +1 -0
  83. package/lib/serializer.js +121 -297
  84. package/lib/sparql-to-query.js +42 -167
  85. package/lib/statement.js +8 -24
  86. package/lib/store.d.ts +2 -2
  87. package/lib/store.js +102 -282
  88. package/lib/tf-types.d.ts +4 -4
  89. package/lib/types.d.ts +8 -8
  90. package/lib/types.js +3 -3
  91. package/lib/update-manager.d.ts +2 -2
  92. package/lib/update-manager.js +110 -254
  93. package/lib/updates-via.js +0 -30
  94. package/lib/uri.js +5 -58
  95. package/lib/utils/default-graph-uri.js +1 -3
  96. package/lib/utils/termValue.js +0 -2
  97. package/lib/utils/terms.js +15 -34
  98. package/lib/utils-js.js +16 -80
  99. package/lib/utils.js +4 -21
  100. package/lib/variable.js +0 -25
  101. package/lib/xsd-internal.js +0 -3
  102. package/lib/xsd.js +0 -4
  103. package/package.json +40 -39
  104. package/src/fetcher.ts +2 -2
  105. package/src/index.ts +0 -2
  106. package/src/jsonldparser.js +13 -4
  107. package/src/n3parser.js +12 -4
  108. package/src/serialize.ts +4 -11
  109. package/src/serializer.js +24 -0
  110. package/src/update-manager.ts +18 -7
  111. package/changes.txt +0 -59
  112. package/esm/convert.js +0 -61
  113. package/lib/convert.d.ts +0 -2
  114. package/lib/convert.js +0 -77
  115. package/src/convert.js +0 -70
package/lib/query.js CHANGED
@@ -1,25 +1,17 @@
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.Query = void 0;
9
8
  exports.indexedFormulaQuery = indexedFormulaQuery;
10
-
11
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
-
13
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
14
-
15
11
  var _store = _interopRequireDefault(require("./store"));
16
-
17
12
  var _defaultGraphUri = require("./utils/default-graph-uri");
18
-
19
13
  var _log = _interopRequireDefault(require("./log"));
20
-
21
14
  var _uri = require("./uri");
22
-
23
15
  // Matching a formula against another formula
24
16
  // Assync as well as Synchronously
25
17
  //
@@ -36,20 +28,16 @@ var _uri = require("./uri");
36
28
  // Compare with BlankNode. They are similar, but a variable
37
29
  // stands for something whose value is to be returned.
38
30
  // Also, users name variables and want the same name back when stuff is printed
39
-
40
31
  /* jsl:option explicit */
41
32
  // Turn on JavaScriptLint variable declaration checking
42
-
43
33
  /**
44
34
  * Query class, for tracking queries the user has in the UI.
45
35
  */
46
36
  var Query = /*#__PURE__*/(0, _createClass2.default)(function Query(name, id) {
47
37
  (0, _classCallCheck2.default)(this, Query);
48
38
  this.pat = new _store.default(); // The pattern to search for
49
-
50
39
  this.vars = []; // Used by UI code but not in query.js
51
40
  // this.orderBy = [] // Not used yet
52
-
53
41
  this.name = name;
54
42
  this.id = id;
55
43
  });
@@ -68,34 +56,27 @@ var Query = /*#__PURE__*/(0, _createClass2.default)(function Query(name, id) {
68
56
  * which has been created for the quadstore being queried.
69
57
  * @param onDone - callback when query finished
70
58
  */
71
-
72
59
  exports.Query = Query;
73
-
74
60
  function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
75
61
  /** Debug strings
76
62
  */
77
63
  function bindingDebug(b) {
78
64
  var str = '';
79
65
  var v;
80
-
81
66
  for (v in b) {
82
67
  if (b.hasOwnProperty(v)) {
83
68
  str += ' ' + v + ' -> ' + b[v];
84
69
  }
85
70
  }
86
-
87
71
  return str;
88
72
  }
89
-
90
73
  function bindingsDebug(nbs) {
91
74
  var str = 'Bindings: ';
92
75
  var i;
93
76
  var n = nbs.length;
94
-
95
77
  for (i = 0; i < n; i++) {
96
78
  str += bindingDebug(nbs[i][0]) + ';\n\t';
97
79
  }
98
-
99
80
  return str;
100
81
  } // bindingsDebug
101
82
 
@@ -106,11 +87,8 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
106
87
  * @returns {Arrray}- a list of bindings, where a binding is an associative array
107
88
  * mapping variuable to value.
108
89
  */
109
-
110
-
111
90
  function unifyTerm(self, other, bindings, formula) {
112
91
  var actual = bindings[self];
113
-
114
92
  if (actual === undefined) {
115
93
  // Not mapped
116
94
  if (self.isVar) {
@@ -121,40 +99,32 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
121
99
 
122
100
  actual = self;
123
101
  }
124
-
125
102
  if (!actual.complexType) {
126
103
  if (formula.redirections[actual]) {
127
104
  actual = formula.redirections[actual];
128
105
  }
129
-
130
106
  if (formula.redirections[other]) {
131
107
  other = formula.redirections[other];
132
108
  }
133
-
134
109
  if (actual.equals(other) || actual.uri && actual.uri === _defaultGraphUri.defaultGraphURI) {
135
110
  // Used to mean 'any graph' in a query
136
111
  return [[[], null]];
137
112
  }
138
-
139
113
  return [];
140
114
  }
141
-
142
115
  if (self instanceof Array) {
143
116
  if (!(other instanceof Array)) {
144
117
  return [];
145
118
  }
146
-
147
119
  return unifyContents(self, other, bindings);
148
120
  }
149
-
150
- throw new Error('query.js: oops - code not written yet'); // return undefined; // for lint - no jslint objects to unreachables
121
+ throw new Error('query.js: oops - code not written yet');
122
+ // return undefined; // for lint - no jslint objects to unreachables
151
123
  // return actual.unifyContents(other, bindings)
152
124
  } // unifyTerm
153
125
 
154
-
155
126
  function unifyContents(self, other, bindings, formula) {
156
127
  var nbs2;
157
-
158
128
  if (self.length !== other.length) {
159
129
  return []; // no way
160
130
  }
@@ -164,11 +134,9 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
164
134
  }
165
135
 
166
136
  var nbs = unifyTerm(self[0], other[0], bindings, formula);
167
-
168
137
  if (nbs.length === 0) {
169
138
  return nbs;
170
139
  }
171
-
172
140
  var res = [];
173
141
  var i;
174
142
  var n = nbs.length;
@@ -178,13 +146,10 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
178
146
  var v;
179
147
  var nb2;
180
148
  var bindings2;
181
-
182
149
  for (i = 0; i < n; i++) {
183
150
  // for each possibility from the first term
184
151
  nb = nbs[i][0]; // new bindings
185
-
186
152
  bindings2 = [];
187
-
188
153
  for (v in nb) {
189
154
  if (nb.hasOwnProperty(v)) {
190
155
  bindings2[v] = nb[v]; // copy
@@ -199,132 +164,111 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
199
164
 
200
165
  nbs2 = unifyContents(self.slice(1), other.slice(1), bindings2, formula);
201
166
  m = nbs2.length;
202
-
203
167
  for (j = 0; j < m; j++) {
204
168
  nb2 = nbs2[j][0]; // @@@@ no idea whether this is used or right
205
-
206
169
  for (v in nb) {
207
170
  if (nb.hasOwnProperty(v)) {
208
171
  nb2[v] = nb[v];
209
172
  }
210
173
  }
211
-
212
174
  res.push([nb2, null]);
213
175
  }
214
176
  }
215
-
216
177
  return res;
217
178
  } // unifyContents
179
+
218
180
  // Matching
219
181
  //
220
182
  // Matching finds all bindings such that when the binding is applied
221
183
  // to one term it is equal to the other term. We only match formulae.
222
184
 
223
185
  /** if x is not in the bindings array, return the var; otherwise, return the bindings **/
224
-
225
-
226
186
  function bind(x, binding) {
227
187
  var y = binding[x];
228
-
229
188
  if (y === undefined) {
230
189
  return x;
231
190
  }
232
-
233
191
  return y;
234
- } // When there are OPTIONAL clauses, we must return bindings without them if none of them
192
+ }
193
+
194
+ // When there are OPTIONAL clauses, we must return bindings without them if none of them
235
195
  // succeed. However, if any of them do succeed, we should not. (This is what branchCount()
236
196
  // tracked. The problem currently is (2011/7) that when several optionals exist, and they
237
197
  // all match, multiple sets of bindings are returned, each with one optional filled in.)
238
198
 
239
-
240
199
  function union(a, b) {
241
200
  var c = {};
242
201
  var x;
243
-
244
202
  for (x in a) {
245
203
  if (a.hasOwnProperty(x)) {
246
204
  c[x] = a[x];
247
205
  }
248
206
  }
249
-
250
207
  for (x in b) {
251
208
  if (b.hasOwnProperty(x)) {
252
209
  c[x] = b[x];
253
210
  }
254
211
  }
255
-
256
212
  return c;
257
213
  }
258
-
259
214
  function OptionalBranchJunction(originalCallback, trunkBindings) {
260
215
  this.trunkBindings = trunkBindings;
261
216
  this.originalCallback = originalCallback;
262
- this.branches = []; // this.results = []; // result[i] is an array of bindings for branch i
217
+ this.branches = [];
218
+ // this.results = []; // result[i] is an array of bindings for branch i
263
219
  // this.done = {}; // done[i] means all/any results are in for branch i
264
220
  // this.count = {}
265
-
266
221
  return this;
267
222
  }
268
-
269
223
  OptionalBranchJunction.prototype.checkAllDone = function () {
270
224
  var i;
271
-
272
225
  for (i = 0; i < this.branches.length; i++) {
273
226
  if (!this.branches[i].done) {
274
227
  return;
275
228
  }
276
229
  }
277
-
278
230
  _log.default.debug('OPTIONAL BIDNINGS ALL DONE:');
279
-
280
231
  this.doCallBacks(this.branches.length - 1, this.trunkBindings);
281
- }; // Recrursively generate the cross product of the bindings
282
-
283
-
232
+ };
233
+ // Recrursively generate the cross product of the bindings
284
234
  OptionalBranchJunction.prototype.doCallBacks = function (b, bindings) {
285
235
  var j;
286
-
287
236
  if (b < 0) {
288
237
  return this.originalCallback(bindings);
289
238
  }
290
-
291
239
  for (j = 0; j < this.branches[b].results.length; j++) {
292
240
  this.doCallBacks(b - 1, union(bindings, this.branches[b].results[j]));
293
241
  }
294
- }; // A mandatory branch is the normal one, where callbacks
242
+ };
243
+
244
+ // A mandatory branch is the normal one, where callbacks
295
245
  // are made immediately and no junction is needed.
296
246
  // Might be useful for onFinsihed callback for query API.
297
-
298
-
299
247
  function MandatoryBranch(callback, onDone) {
300
248
  this.count = 0;
301
249
  this.success = false;
302
- this.done = false; // this.results = []
303
-
250
+ this.done = false;
251
+ // this.results = []
304
252
  this.callback = callback;
305
- this.onDone = onDone; // this.junction = junction
253
+ this.onDone = onDone;
254
+ // this.junction = junction
306
255
  // junction.branches.push(this)
307
-
308
256
  return this;
309
257
  }
310
-
311
258
  MandatoryBranch.prototype.reportMatch = function (bindings) {
312
259
  // log.error("@@@@ query.js 1"); // @@
313
260
  this.callback(bindings);
314
261
  this.success = true;
315
262
  };
316
-
317
263
  MandatoryBranch.prototype.reportDone = function () {
318
264
  this.done = true;
319
-
320
265
  _log.default.info('Mandatory query branch finished.***');
321
-
322
266
  if (this.onDone !== undefined) {
323
267
  this.onDone();
324
268
  }
325
- }; // An optional branch hoards its results.
326
-
269
+ };
327
270
 
271
+ // An optional branch hoards its results.
328
272
  var OptionalBranch = function OptionalBranch(junction) {
329
273
  this.count = 0;
330
274
  this.done = false;
@@ -333,45 +277,39 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
333
277
  junction.branches.push(this);
334
278
  return this;
335
279
  };
336
-
337
280
  OptionalBranch.prototype.reportMatch = function (bindings) {
338
281
  this.results.push(bindings);
339
282
  };
340
-
341
283
  OptionalBranch.prototype.reportDone = function () {
342
284
  _log.default.debug('Optional branch finished - results.length = ' + this.results.length);
343
-
344
285
  if (this.results.length === 0) {
345
286
  // This is what optional means: if no hits,
346
287
  this.results.push({}); // mimic success, but with no bindings
347
-
348
288
  _log.default.debug("Optional branch FAILED - that's OK.");
349
289
  }
350
-
351
290
  this.done = true;
352
291
  this.junction.checkAllDone();
353
292
  };
293
+
354
294
  /** prepare -- sets the index of the item to the possible matches
355
295
  * @param f - formula
356
296
  * @param item - an Statement, possibly w/ vars in it
357
297
  * @param bindings - Bindings so far
358
298
  * @returns false if the query fails -- there are no items that match
359
299
  */
360
-
361
-
362
300
  function prepare(f, item, bindings) {
363
301
  var terms, termIndex, i, ind;
364
302
  item.nvars = 0;
365
- item.index = null; // if (!f.statements) log.warn("@@@ prepare: f is "+f)
303
+ item.index = null;
304
+ // if (!f.statements) log.warn("@@@ prepare: f is "+f)
366
305
  // log.debug("Prepare: f has "+ f.statements.length)
367
306
  // log.debug("Prepare: Kb size "+f.statements.length+" Preparing "+item)
368
307
 
369
308
  terms = [item.subject, item.predicate, item.object, item.why];
370
309
  ind = [f.subjectIndex, f.predicateIndex, f.objectIndex, f.whyIndex];
371
-
372
310
  for (i = 0; i < 4; i++) {
373
- var t = terms[i]; // console.log(" Prepare (" + t + ") "+(t in bindings))
374
-
311
+ var t = terms[i];
312
+ // console.log(" Prepare (" + t + ") "+(t in bindings))
375
313
  if (t.uri && t.uri === _defaultGraphUri.defaultGraphURI) {// chrome:session
376
314
  // console.log(' query: Ignoring slot ' + i)
377
315
  } else if (t.isVar && !(bindings[t] !== undefined)) {
@@ -379,13 +317,11 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
379
317
  } else {
380
318
  t = bind(terms[i], bindings); // returns the RDF binding if bound, otherwise itself
381
319
  // if (terms[i]!=bind(terms[i],bindings) alert("Term: "+terms[i]+"Binding: "+bind(terms[i], bindings))
382
-
383
320
  if (f.redirections[f.id(t)]) {
384
321
  t = f.redirections[f.id(t)]; // redirect
385
322
  }
386
323
 
387
324
  termIndex = ind[i][f.id(t)];
388
-
389
325
  if (!termIndex) {
390
326
  item.index = [];
391
327
  return false; // Query line cannot match
@@ -397,30 +333,23 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
397
333
  }
398
334
  }
399
335
  }
400
-
401
336
  if (item.index === null) {
402
337
  // All 4 are variables?
403
338
  item.index = f.statements;
404
339
  }
405
-
406
340
  return true;
407
341
  } // prepare
408
342
 
409
343
  /** sorting function -- negative if self is easier **/
410
344
  // We always prefer to start with a URI to be able to browse a graph
411
345
  // this is why we put off items with more variables till later.
412
-
413
-
414
346
  function easiestQuery(self, other) {
415
347
  if (self.nvars !== other.nvars) {
416
348
  return self.nvars - other.nvars;
417
349
  }
418
-
419
350
  return self.index.length - other.index.length;
420
351
  }
421
-
422
352
  var matchIndex = 0; // index
423
-
424
353
  /** matches a pattern formula against the knowledge base, e.g. to find matches for table-view
425
354
  *
426
355
  * @param f - knowledge base formula
@@ -433,71 +362,58 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
433
362
  *
434
363
  * Will fetch linked data from the web iff the knowledge base an associated source fetcher (f.fetcher)
435
364
  ***/
436
-
437
365
  var match = function match(f, g, bindingsSoFar, level, fetcher, localCallback, branch) {
438
- _log.default.debug('Match begins, Branch count now: ' + branch.count + ' for ' + branch.pattern_debug); // log.debug("match: f has "+f.statements.length+", g has "+g.statements.length)
439
-
366
+ _log.default.debug('Match begins, Branch count now: ' + branch.count + ' for ' + branch.pattern_debug);
440
367
 
368
+ // log.debug("match: f has "+f.statements.length+", g has "+g.statements.length)
441
369
  var pattern = g.statements;
442
-
443
370
  if (pattern.length === 0) {
444
371
  // when it's satisfied all the pattern triples
445
372
  _log.default.debug('FOUND MATCH WITH BINDINGS:' + bindingDebug(bindingsSoFar));
446
-
447
373
  if (g.optional.length === 0) {
448
374
  branch.reportMatch(bindingsSoFar);
449
375
  } else {
450
376
  _log.default.debug('OPTIONAL: ' + g.optional);
451
-
452
377
  var junction = new OptionalBranchJunction(callback, bindingsSoFar); // @@ won't work with nested optionals? nest callbacks
453
-
454
378
  var br = [];
455
379
  var b;
456
-
457
380
  for (b = 0; b < g.optional.length; b++) {
458
381
  br[b] = new OptionalBranch(junction); // Allocate branches to prevent premature ending
459
-
460
382
  br[b].pattern_debug = g.optional[b]; // for diagnotics only
461
383
  }
462
384
 
463
385
  for (b = 0; b < g.optional.length; b++) {
464
386
  br[b].count = br[b].count + 1; // Count how many matches we have yet to complete
465
-
466
387
  match(f, g.optional[b], bindingsSoFar, '', fetcher, callback, br[b]);
467
388
  }
468
389
  }
469
-
470
390
  branch.count--;
471
-
472
391
  _log.default.debug('Match ends -- success , Branch count now: ' + branch.count + ' for ' + branch.pattern_debug);
473
-
474
392
  return; // Success
475
393
  }
476
394
 
477
395
  var item;
478
396
  var i;
479
- var n = pattern.length; // log.debug(level + "Match "+n+" left, bs so far:"+bindingDebug(bindingsSoFar))
480
- // Follow links from variables in query
397
+ var n = pattern.length;
398
+ // log.debug(level + "Match "+n+" left, bs so far:"+bindingDebug(bindingsSoFar))
481
399
 
400
+ // Follow links from variables in query
482
401
  if (fetcher) {
483
402
  // Fetcher is used to fetch URIs, function first term is a URI term, second is the requester
484
403
  var id = 'match' + matchIndex++;
485
-
486
404
  var fetchResource = function fetchResource(requestedTerm, id) {
487
405
  var docuri = requestedTerm.uri.split('#')[0];
488
406
  fetcher.nowOrWhenFetched(docuri, undefined, function (ok, body, xhr) {
489
407
  if (!ok) {
490
408
  console.log('Error following link to <' + requestedTerm.uri + '> in query: ' + body);
491
409
  }
492
-
493
- match(f, g, bindingsSoFar, level, fetcher, // match not match2 to look up any others necessary.
410
+ match(f, g, bindingsSoFar, level, fetcher,
411
+ // match not match2 to look up any others necessary.
494
412
  localCallback, branch);
495
413
  });
496
414
  };
497
-
498
415
  for (i = 0; i < n; i++) {
499
416
  item = pattern[i]; // for each of the triples in the query
500
-
501
417
  if (bindingsSoFar[item.subject] !== undefined && bindingsSoFar[item.subject].uri && fetcher && fetcher.getState((0, _uri.docpart)(bindingsSoFar[item.subject].uri)) === 'unrequested') {
502
418
  // fetch the subject info and return to id
503
419
  fetchResource(bindingsSoFar[item.subject], id);
@@ -510,34 +426,27 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
510
426
  }
511
427
  }
512
428
  } // if fetcher
513
-
514
-
515
429
  match2(f, g, bindingsSoFar, level, fetcher, localCallback, branch);
516
430
  }; // match
517
431
 
518
-
519
432
  var constraintsSatisfied = function constraintsSatisfied(bindings, constraints) {
520
433
  var res = true;
521
434
  var x;
522
435
  var test;
523
-
524
436
  for (x in bindings) {
525
437
  if (bindings.hasOwnProperty(x)) {
526
438
  if (constraints[x]) {
527
439
  test = constraints[x].test;
528
-
529
440
  if (test && !test(bindings[x])) {
530
441
  res = false;
531
442
  }
532
443
  }
533
444
  }
534
445
  }
535
-
536
446
  return res;
537
447
  };
538
- /** match2 -- stuff after the fetch **/
539
-
540
448
 
449
+ /** match2 -- stuff after the fetch **/
541
450
  var match2 = function match2(f, g, bindingsSoFar, level, fetcher, callback, branch) {
542
451
  // post fetch
543
452
  var pattern = g.statements;
@@ -549,47 +458,41 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
549
458
  var bindings2;
550
459
  var newBindings1;
551
460
  var item;
552
-
553
461
  for (i = 0; i < n; i++) {
554
462
  // For each statement left in the query, run prepare
555
- item = pattern[i]; // log.info('match2: item=' + item + ', bindingsSoFar=' + bindingDebug(bindingsSoFar))
556
-
557
- prepare(f, item, bindingsSoFar); // if (item.index) console.log(' item.index.length ' + item.index.length)
463
+ item = pattern[i];
464
+ // log.info('match2: item=' + item + ', bindingsSoFar=' + bindingDebug(bindingsSoFar))
465
+ prepare(f, item, bindingsSoFar);
466
+ // if (item.index) console.log(' item.index.length ' + item.index.length)
558
467
  }
559
468
 
560
469
  pattern.sort(easiestQuery);
561
- item = pattern[0]; // log.debug("Sorted pattern:\n"+pattern)
562
-
470
+ item = pattern[0];
471
+ // log.debug("Sorted pattern:\n"+pattern)
563
472
  var rest = f.formula();
564
473
  rest.optional = g.optional;
565
474
  rest.constraints = g.constraints;
566
475
  rest.statements = pattern.slice(1); // No indexes: we will not query g.
567
-
568
- _log.default.debug(level + 'match2 searching ' + item.index.length + ' for ' + item + '; bindings so far=' + bindingDebug(bindingsSoFar)); // var results = []
569
-
570
-
476
+ _log.default.debug(level + 'match2 searching ' + item.index.length + ' for ' + item + '; bindings so far=' + bindingDebug(bindingsSoFar));
477
+ // var results = []
571
478
  var c;
572
479
  var nc = item.index.length;
573
480
  var nbs1;
574
481
  var st;
575
- var onward = 0; // var x
576
-
482
+ var onward = 0;
483
+ // var x
577
484
  for (c = 0; c < nc; c++) {
578
485
  // For each candidate statement
579
486
  st = item.index[c]; // for each statement in the item's index, spawn a new match with that binding
580
-
581
487
  nbs1 = unifyContents([item.subject, item.predicate, item.object, item.why], [st.subject, st.predicate, st.object, st.why], bindingsSoFar, f);
582
-
583
488
  _log.default.info(level + ' From first: ' + nbs1.length + ': ' + bindingsDebug(nbs1));
584
-
585
- nk = nbs1.length; // branch.count += nk
489
+ nk = nbs1.length;
490
+ // branch.count += nk
586
491
  // log.debug("Branch count bumped "+nk+" to: "+branch.count)
587
-
588
492
  for (k = 0; k < nk; k++) {
589
493
  // For each way that statement binds
590
494
  bindings2 = [];
591
495
  newBindings1 = nbs1[k][0];
592
-
593
496
  if (!constraintsSatisfied(newBindings1, g.constraints)) {
594
497
  // branch.count--
595
498
  _log.default.debug('Branch count CS: ' + branch.count);
@@ -607,7 +510,6 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
607
510
  }
608
511
 
609
512
  branch.count++; // Count how many matches we have yet to complete
610
-
611
513
  onward++;
612
514
  match(f, rest, bindings2, level + ' ', fetcher, callback, branch); // call match
613
515
  }
@@ -615,29 +517,20 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
615
517
  }
616
518
 
617
519
  branch.count--;
618
-
619
520
  if (onward === 0) {
620
521
  _log.default.debug('Match2 fails completely on ' + item);
621
522
  }
622
-
623
523
  _log.default.debug('Match2 ends, Branch count: ' + branch.count + ' for ' + branch.pattern_debug);
624
-
625
524
  if (branch.count === 0) {
626
525
  _log.default.debug('Branch finished.');
627
-
628
526
  branch.reportDone();
629
527
  }
630
528
  }; // match2
631
529
  // ////////////////////////// Body of query() ///////////////////////
632
-
633
-
634
530
  var f = this;
635
-
636
531
  _log.default.debug('Query on ' + this.statements.length);
637
-
638
532
  var trunck = new MandatoryBranch(callback, onDone);
639
533
  trunck.count++; // count one branch to complete at the moment
640
-
641
534
  if (myQuery.sync) {
642
535
  match(f, myQuery.pat, myQuery.pat.initBindings, '', fetcher, callback, trunck);
643
536
  } else {
@@ -645,6 +538,7 @@ function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
645
538
  setTimeout(function () {
646
539
  match(f, myQuery.pat, myQuery.pat.initBindings, '', fetcher, callback, trunck);
647
540
  }, 0);
648
- } // returns nothing; callback does the work
541
+ }
649
542
 
543
+ // returns nothing; callback does the work
650
544
  } // query