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