rdflib 2.2.21 → 2.2.22-b51259b5

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