forked from mhausenblas/turtled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdf_store_min.js
601 lines (601 loc) · 300 KB
/
rdf_store_min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
(function(){typeof console=="undefined"&&(console={log:function(){}});var v={"extends":function(a,b){b.prototype=new a},stackCounterLimit:1E3,stackCounter:0};v.recur=function(a){v.stackCounter===v.stackCounterLimit?(v.stackCounter=0,setTimeout(a,0)):(v.stackCounter++,a())};v.clone=function(a){return JSON.parse(JSON.stringify(a))};v.shuffle=function(a){for(var b,e,c=a.length;c;b=parseInt(Math.random()*c),e=a[--c],a[c]=a[b],a[b]=e);return a};v.include=function(a,b,e){for(var c=a.length-1;c>=0;c--){var i=
!1,i=e==null?a[c]===b:e(a[c],b)===0;if(i===!0)return!0}return!1};v.remove=function(a,b){for(var e=[],c=0;c<a.length;c++)a[c]!==b&&e.push(a[c]);return e};v.repeat=function(a,b,e,c,i){arguments.length===4&&(i={});a<b?(i._i=a,e(function(e,i){v.recur(function(){v.repeat(a+1,b,e,c,i)})},i)):c(i)};v.meanwhile=function(a,b,e,c){arguments.length===3&&(c={});c._stack_counter==null&&(c._stack_counter=0);a===!0?b(function(a,b,c){c._stack_counter%40==39?(c._stack_counter+=1,setTimeout(function(){v.neanwhile(a,
b,e,c)},0)):(c._stack_counter+=1,v.meanwhile(a,b,e,c))},c):e(c)};v.seq=function(){var a=arguments;return function(b){v.repeat(0,a.length,function(e,b){var i=arguments.callee;a[b._i](function(){e(i,b)})},function(){b()})}};v.partition=function(a,b){for(var e=a.length%b,c=[],i=0;i<e;i++)c.push(null);e=[];for(i=0;i<a.length;i++)c.push(a[i]),c.length%b==0&&(e.push(c),c=[]);return e};v.keys=function(a){var b=[],e;for(e in a)b.push(e);return b};v.iso8601=function(a){function b(a){return a<10?"0"+a:a}return a.getUTCFullYear()+
"-"+b(a.getUTCMonth()+1)+"-"+b(a.getUTCDate())+"T"+b(a.getUTCHours())+":"+b(a.getUTCMinutes())+":"+b(a.getUTCSeconds())+"Z"};v.parseStrictISO8601=function(a){var b=a.match(RegExp("([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?")),a=0,e=new Date(b[1],0,1);if(b[3])e.setMonth(b[3]-1);else throw"missing ISO8061 component";if(b[5])e.setDate(b[5]);else throw"missing ISO8061 component";if(b[7])e.setHours(b[7]);else throw"missing ISO8061 component";
if(b[8])e.setMinutes(b[8]);else throw"missing ISO8061 component";if(b[10])e.setSeconds(b[10]);else throw"missing ISO8061 component";b[12]&&e.setMilliseconds(Number("0."+b[12])*1E3);b[14]&&(a=Number(b[16])*60+Number(b[17]),a*=b[15]=="-"?1:-1);a-=e.getTimezoneOffset();b=new Date;b.setTime(Number(Number(e)+a*6E4));return b};v.parseISO8601=function(a){var b=a.match(RegExp("([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?")),a=
0,e=new Date(b[1],0,1);b[3]&&e.setMonth(b[3]-1);b[5]&&e.setDate(b[5]);b[7]&&e.setHours(b[7]);b[8]&&e.setMinutes(b[8]);b[10]&&e.setSeconds(b[10]);b[12]&&e.setMilliseconds(Number("0."+b[12])*1E3);b[14]&&(a=Number(b[16])*60+Number(b[17]),a*=b[15]=="-"?1:-1);a-=e.getTimezoneOffset();b=new Date;b.setTime(Number(Number(e)+a*6E4));return b};v.parseISO8601Components=function(a){var a=a.match(RegExp("([0-9]{4})(-([0-9]{2}))(-([0-9]{2}))(T([0-9]{2}):([0-9]{2})(:([0-9]{2}))?(.([0-9]+))?)?(Z|([-+])([0-9]{2})(:([0-9]{2}))?)?")),
b,e,c,i,h,f,g,o;b=Number(a[1]);e=a[3]-1;c=Number(a[5]);i=Number(a[7]);h=Number(a[8]);f=Number(a[10]);a[12]&&(g=Number("0."+a[12])*1E3);a[13]==="Z"?o=0:a[14]?(o=0,a[17]&&(o=Number(a[17])),o+=Number(a[15])*60,o*=a[14]=="-"?-1:1):a[14]==null&&a[11]&&(o=Number(a[12])*60);return{year:isNaN(b)?null:b,month:isNaN(e)?null:e,date:isNaN(c)?null:c,hours:isNaN(i)?null:i,minutes:isNaN(h)?null:h,seconds:isNaN(f)?null:f,millisecs:isNaN(g)?null:g,timezone:isNaN(o)?null:o}};v.compareDateComponents=function(a,b){var e=
v.parseISO8601Components(a),c=v.parseISO8601Components(b);if(e.timezone==null&&c.timezone==null||e.timezone!=null&&c.timezone!=null)return e=v.parseISO8601(a),c=v.parseISO8601(b),e.getTime()==c.getTime()?0:e.getTime()<c.getTime()?-1:1;else if(e.timezone!=null&&c.timezone==null){var e=v.parseISO8601(a),c=v.parseISO8601(b),e=e.getTime(),c=c.getTime(),i=50400;return e<c&&e<c+i?-1:e>c&&e>c-i?1:null}else return e=v.parseISO8601(a),c=v.parseISO8601(b),e=e.getTime(),c=c.getTime(),i=50400,e<c&&e+i<c?-1:e>
c&&e+i>c?1:null};v.lexicalFormLiteral=function(a,b){var e=a.value,c=a.lang,i=a.type,h=null;if(e!=null&&i!=null&&typeof i!="string"){e=i.value;if(e==null)e=i.suffix,i=b.namespaces[i.prefix],a.type=i+e,e=i+e;h=e.indexOf("hexBinary")!=-1?'"'+a.value.toLowerCase()+'"^^<'+e+">":'"'+a.value+'"^^<'+e+">"}else h=c==null&&i==null?'"'+e+'"':i==null?'"'+e+'"@'+c:i.indexOf("hexBinary")!=-1?'"'+a.value.toLowerCase()+'"^^<'+i+">":'"'+a.value+'"^^<'+i+">";return h};v.lexicalFormBaseUri=function(a,b){var e=null,
b=b||{};if(a.value==null)var e=a.prefix,c=a.suffix,i=b.namespaces[e],e=i!=null?i+c:e+":"+c;else e=a.value;if(e===null)return null;else e.indexOf(":")==-1&&(e=(b.base||"")+e);return e};v.lexicalFormTerm=function(a,b){if(a.token==="uri")return{uri:v.lexicalFormBaseUri(a,b)};else if(a.token==="literal")return{literal:v.lexicalFormLiteral(a,b)};else if(a.token==="blank")return{blank:"_:"+a.value};else throw"Error, cannot get lexical form of unknown token: "+a.token;};v.normalizeUnicodeLiterals=function(a){for(var b=
a.match(/\\u[0-9abcdefABCDEF]{4,4}/g)||[],e={},c=0;c<b.length;c++)e[b[c]]==null&&(e[b[c]]=!0,a=a.replace(RegExp("\\"+b[c],"g"),eval("'"+b[c]+"'")));return a};v.hashTerm=function(a){try{if(a==null)return"";if(a.token==="uri")return"u"+a.value;else if(a.token==="blank")return"b"+a.value;else if(a.token==="literal"){var b="l"+a.value;b+=a.type||"";b+=a.lang||"";return b}}catch(e){if(typeof a==="object"){b="";for(p in a)b=b+p+a[p];return b}return a}};var I={Tree:function(a){if(arguments.length!=0)this.order=
a,this.root=this._allocateNode(),this.root.isLeaf=!0,this.root.level=0,this._diskWrite(this.root),this._updateRootNode(this.root),this.comparator=function(a,e){return a<e?-1:a>e?1:0},this.merger=null}};I.Tree.prototype._allocateNode=function(){return new I.Node};I.Tree.prototype._diskWrite=function(){};I.Tree.prototype._diskRead=function(a){return a};I.Tree.prototype._diskDelete=function(){};I.Tree.prototype._updateRootNode=function(a){return a};I.Tree.prototype.clear=function(){this.root=this._allocateNode();
this.root.isLeaf=!0;this.root.level=0;this._updateRootNode(this.root)};I.Tree.prototype.search=function(a,b){for(var e=!0,c=this.root;e;){for(var i=0;i<c.numberActives&&this.comparator(a,c.keys[i].key)===1;)i++;if(i<c.numberActives&&this.comparator(c.keys[i].key,a)===0)return b!=null&&b==!0?!0:c.keys[i].data;else c.isLeaf===!0?e=!1:c=this._diskRead(c.children[i])}return null};I.Tree.prototype.walk=function(a){this._walk(a,this.root)};I.Tree.prototype._walk=function(a,b){if(b.isLeaf)for(var e=0;e<
b.numberActives;e++)a(b.keys[e]);else{for(e=0;e<b.numberActives;e++)this._walk(a,this._diskRead(b.children[e])),a(b.keys[e]);this._walk(a,this._diskRead(b.children[b.numberActives]))}};I.Tree.prototype.walkNodes=function(a){this._walkNodes(a,this.root)};I.Tree.prototype._walkNodes=function(a,b){if(b.isLeaf)a(b);else{a(b);for(var e=0;e<b.numberActives;e++)this._walkNodes(a,this._diskRead(b.children[e]));this._walkNodes(a,this._diskRead(b.children[b.numberActives]))}};I.Tree.prototype._splitChild=function(a,
b,e){var c=this._allocateNode();c.isLeaf=e.isLeaf;c.level=e.level;c.numberActives=this.order-1;var i=e.keys[this.order-1];e.keys[this.order-1]=null;for(var h=0;h<this.order-1;h++)c.keys[h]=e.keys[h+this.order],e.keys[h+this.order]=null,e.isLeaf||(c.children[h]=e.children[h+this.order],e.children[h+this.order]=null);e.isLeaf||(c.children[h]=e.children[h+this.order],e.children[h+this.order]=null);e.numberActives=this.order-1;for(h=a.numberActives+1;h>b+1;h--)a.children[h]=a.children[h-1];a.children[b+
1]=c;for(h=a.numberActives;h>b;h--)a.keys[h]=a.keys[h-1];a.keys[b]=i;a.numberActives++;this._diskWrite(c);this._diskWrite(a);this._diskWrite(e)};I.Tree.prototype.insert=function(a,b){if(this.root.numberActives===2*this.order-1){var e=this._allocateNode();e.isLeaf=!1;e.level=this.root.level+1;e.numberActives=0;e.children[0]=this.root;this._splitChild(e,0,this.root);this.root=e;this._updateRootNode(this.root);this._insertNonFull(e,a,b)}else this._insertNonFull(this.root,a,b)};I.Tree.prototype._insertNonFull=
function(a,b,e){for(var c=a.numberActives-1;!a.isLeaf;){for(;c>=0&&this.comparator(b,a.keys[c].key)===-1;)c--;c++;var i=this._diskRead(a.children[c]);i.numberActives===2*this.order-1&&(this._splitChild(a,c,i),this.comparator(b,a.keys[c].key)===1&&c++);a=this._diskRead(a.children[c]);c=a.numberActives-1}for(;c>=0&&this.comparator(b,a.keys[c].key)===-1;)a.keys[c+1]=a.keys[c],c--;a.keys[c+1]={key:b,data:e};a.numberActives++;this._diskWrite(a)};I.Tree.prototype["delete"]=function(a){for(var b=this.root,
e=null,c=!0,i=null,h=null,f=null,g=!0;g===!0;){for(g=!1;c===!0;){o=0;if(b.numberActives===0)return!1;for(;o<b.numberActives&&this.comparator(a,b.keys[o].key)===1;)o++;i=o;o<b.numberActives&&this.comparator(a,b.keys[o].key)===0&&(c=!1);if(c===!0){if(b.isLeaf===!0)return!1;e=b;b=this._diskRead(b.children[o]);if(b===null)return!1;i===e.numberActives?(h=this._diskRead(e.children[i-1]),f=null):i===0?(h=null,f=this._diskRead(e.children[1])):(h=this._diskRead(e.children[i-1]),f=this._diskRead(e.children[i+
1]));b.numberActives===this.order-1&&e!=null&&(f!=null&&f.numberActives>this.order-1?this._moveKey(e,o,-1):h!=null&&h.numberActives>this.order-1?this._moveKey(e,o,1):h!=null&&h.numberActives===this.order-1?b=this._mergeSiblings(e,o,-1):f!=null&&f.numberActives===this.order-1&&(b=this._mergeSiblings(e,o,1)))}}if(b.isLeaf&&b.numberActives>this.order-1)return this._deleteKeyFromNode(b,i),!0;if(b.isLeaf&&b===this.root)return this._deleteKeyFromNode(b,i),!0;if(b.isLeaf===!1)if(e=o=null,(o=this._diskRead(b.children[i])).numberActives>
this.order-1)a=this._getMaxKeyPos(o),a=a.node.keys[a.index],b.keys[i]=a,this._diskWrite(b),b=o,a=a.key,c=g=!0;else if((o=this._diskRead(b.children[i+1])).numberActives>this.order-1)a=this._getMinKeyPos(o),a=a.node.keys[a.index],b.keys[i]=a,this._diskWrite(b),b=o,a=a.key,c=g=!0;else if((o=this._diskRead(b.children[i])).numberActives===this.order-1&&(e=this._diskRead(b.children[i+1])).numberActives===this.order-1){c=this._mergeNodes(o,b.keys[i],e);b.children[i]=c;i++;for(var o=i;o<b.numberActives;o++)b.children[o]=
b.children[o+1],b.keys[o-1]=b.keys[o];b.children[o]=null;b.keys[o-1]=null;b.numberActives--;if(b.numberActives===0&&this.root===b)this.root=c;this._diskWrite(b);b=c;c=g=!0}b.isLeaf&&b.numberActives>this.order-1&&c===!1&&this._deleteKeyFromNode(b,i);if(g===!1)return!0}};I.Tree.prototype._moveKey=function(a,b,e){e===1&&b--;var c=this._diskRead(a.children[b]),i=this._diskRead(a.children[b+1]);if(e==-1){c.keys[c.numberActives]=a.keys[b];c.children[c.numberActives+1]=i.children[0];i.children[0]=null;c.numberActives++;
a.keys[b]=i.keys[0];for(e=1;e<i.numberActives;e++)i.keys[e-1]=i.keys[e],i.children[e-1]=i.children[e];i.children[i.numberActives-1]=i.children[i.numberActives];i.numberActives--}else{i.children[i.numberActives+1]=i.children[i.numberActives];for(e=i.numberActives;e>0;e--)i.children[e]=i.children[e-1],i.keys[e]=i.keys[e-1];i.keys[0]=null;i.children[0]=null;i.children[0]=c.children[c.numberActives];i.keys[0]=a.keys[b];i.numberActives++;c.children[c.numberActives]=null;a.keys[b]=c.keys[c.numberActives-
1];c.keys[c.numberActives-1]=null;c.numberActives--}this._diskWrite(c);this._diskWrite(i);this._diskWrite(a)};I.Tree.prototype._mergeSiblings=function(a,b){var e,c,i;b===a.numberActives?(b--,c=this._diskRead(a.children[a.numberActives-1]),i=this._diskRead(a.children[a.numberActives])):(c=this._diskRead(a.children[b]),i=this._diskRead(a.children[b+1]));var h=this._allocateNode();h.isLeaf=c.isLeaf;h.level=c.level;for(e=0;e<this.order-1;e++)h.keys[e]=c.keys[e],h.children[e]=c.children[e];h.keys[this.order-
1]=a.keys[b];h.children[this.order-1]=c.children[this.order-1];for(e=0;e<this.order-1;e++)h.keys[e+this.order]=i.keys[e],h.children[e+this.order]=i.children[e];h.children[2*this.order-1]=i.children[this.order-1];a.children[b]=h;for(e=b;e<a.numberActives;e++)a.keys[e]=a.keys[e+1],a.children[e+1]=a.children[e+2];h.numberActives=c.numberActives+i.numberActives+1;a.numberActives--;for(e=a.numberActives;e<2*this.order-1;e++)a.keys[e]=null;if(a.numberActives===0&&this.root===a)this.root=h,h.isLeaf=h.level?
!1:!0;this._diskWrite(h);this.root===h&&this._updateRootNode(this.root);this._diskWrite(a);this._diskDelete(c);this._diskDelete(i);return h};I.Tree.prototype._deleteKeyFromNode=function(a,b){var e=2*this.order-1;if(a.numberActives<e)e=a.numberActives;var c;if(a.isLeaf===!1)return!1;for(c=b;c<e-1;c++)a.keys[c]=a.keys[c+1];a.keys.pop();a.numberActives--;this._diskWrite(a);return!0};I.Tree.prototype._mergeNodes=function(a,b,e){var c,i;c=this._allocateNode();c.isLeaf=!0;for(i=0;i<a.numberActives;i++)c.keys[i]=
a.keys[i],c.children[i]=a.children[i];c.children[a.numberActives]=a.children[a.numberActives];c.keys[a.numberActives]=b;for(i=0;i<e.numberActives;i++)c.keys[i+a.numberActives+1]=e.keys[i],c.children[i+a.numberActives+1]=e.children[i];c.children[2*this.order-1]=e.children[e.numberActives];c.numberActives=a.numberActives+e.numberActives+1;c.isLeaf=a.isLeaf;c.level=a.level;this._diskWrite(c);return c};I.Tree.prototype.audit=function(a){var b=[],e=[],c=this,i=function(i){for(var h=0;h<e.length;h++)if(c.comparator(e[h],
i)===0){var g=" !!! duplicated key "+i;a===!0&&console.log(g);b.push(g)}},h=null,c=this;this.walkNodes(function(f){a===!0&&(console.log("--- Node at "+f.level+" level"),console.log(" - leaf? "+f.isLeaf),console.log(" - num actives? "+f.numberActives),console.log(" - keys: "));for(var g=f.numberActives;g<f.keys.length;g++)f.keys[g]!=null&&a===!0&&(console.log(" * warning : redundant key data"),b.push(" * warning : redundant key data"));for(g=f.numberActives+1;g<f.children.length;g++)f.children[g]!=
null&&a===!0&&(console.log(" * warning : redundant children data"),b.push(" * warning : redundant key data"));if(f.isLeaf===!1)for(g=0;g<f.numberActives;g++){var o=c._diskRead(f.children[g]).keys[c._diskRead(f.children[g]).numberActives-1].key,t=c._diskRead(f.children[g+1]).keys[0].key;a===!0&&console.log(" "+f.keys[g].key+"("+o+","+t+")");if(c.comparator(f.keys[g].key,o)===-1){var q=" !!! value max left "+o+" > key "+f.keys[g].key;a===!0&&console.log(q);b.push(q)}c.comparator(f.keys[g].key,t)===
1&&(q=" !!! value min right "+t+" < key "+f.keys[g].key,a===!0&&console.log(q),b.push(q));i(f.keys[g].key);e.push(f.keys[g].key)}else{h===null?h=f.level:h!=f.level&&(q=" !!! Leaf node with wrong level value",a===!0&&console.log(q),b.push(q));for(g=0;g<f.numberActives;g++)a===!0&&console.log(" "+f.keys[g].key),i(f.keys[g].key),e.push(f.keys[g].key)}f!=c.root&&(f.numberActives>2*c.order-1&&(a===!0&&(q=" !!!! MAX num keys restriction violated "),console.log(q),b.push(q)),f.numberActives<c.order-1&&(a===
!0&&(q=" !!!! MIN num keys restriction violated "),console.log(q),b.push(q)))});return b};I.Tree.prototype._getMaxKeyPos=function(a){for(var b={};;){if(a===null)break;if(a.isLeaf===!0){b.node=a;b.index=a.numberActives-1;break}else b.node=a,b.index=a.numberActives-1,a=this._diskRead(a.children[a.numberActives])}return b};I.Tree.prototype._getMinKeyPos=function(a){for(var b={};;){if(a===null)break;if(a.isLeaf===!0){b.node=a;b.index=0;break}else b.node=a,b.index=0,a=this._diskRead(a.children[0])}return b};
I.Node=function(){this.numberActives=0;this.isLeaf=null;this.keys=[];this.children=[];this.level=0};var R={NodeKey:function(a,b){this.subject=a.subject;this.predicate=a.predicate;this.object=a.object;this.graph=a.graph;this.order=b}};R.NodeKey.prototype.comparator=function(a){for(var b=0;b<this.order.length;b++){var e=this.order[b];if(a[e]==null)break;else if(this[e]<a[e])return-1;else if(this[e]>a[e])return 1}return 0};R.Pattern=function(a){this.subject=a.subject;this.predicate=a.predicate;this.object=
a.object;this.graph=a.graph;this.indexKey=[];this.keyComponents={};for(var b=[],e=[],a=["subject","predicate","object","graph"],c=0;c<a.length;c++)typeof this[a[c]]==="string"?(e.push(a[c]),this.keyComponents[a[c]]=null):(b.push(a[c]),this.keyComponents[a[c]]=this[a[c]],this.indexKey.push(a[c]));this.order=b.concat(e);this.key=new R.NodeKey(this.keyComponents,this.order)};var Z={Tree:function(a,b){if(arguments!=0)this.componentOrder=a.componentOrder,I.Tree.call(this,a.order,a.name,a.persistent,a.cacheMaxSize),
this.comparator=function(a,b){for(var i=0;i<this.componentOrder.length;i++){var h=this.componentOrder[i],f=a[h],h=b[h];if(f<h)return-1;else if(f>h)return 1}return 0},this.rangeComparator=function(a,b){for(var i=0;i<this.componentOrder.length;i++){var h=this.componentOrder[i];if(b[h]==null||a[h]==null)break;else if(a[h]<b[h])return-1;else if(a[h]>b[h])return 1}return 0},b!=null&&b(this)}};v["extends"](I.Tree,Z.Tree);Z.Tree.prototype.insert=function(a,b){I.Tree.prototype.insert.call(this,a,null);b&&
b(!0);return!0};Z.Tree.prototype.search=function(a,b){var e=I.Tree.prototype.search.call(this,a,!0);b&&b(e);return e};Z.Tree.prototype.range=function(a,b){var e=null,e=typeof this.root==="string"?this._rangeTraverse(this,this._diskRead(this.root),a):this._rangeTraverse(this,this.root,a);b&&b(e);return e};Z.Tree.prototype._rangeTraverse=function(a,b,e){for(var e=e.key,c=[],i=[b],h;i.length>0;){b=i.shift();for(h=0;h<b.numberActives&&a.rangeComparator(b.keys[h].key,e)===-1;)h++;if(b.isLeaf===!0)for(;h<
b.numberActives&&a.rangeComparator(b.keys[h].key,e)===0;)c.push(b.keys[h].key),h++;else{var f=a._diskRead(b.children[h]);for(i.push(f);;)if(h<b.numberActives&&a.rangeComparator(b.keys[h].key,e)===0)c.push(b.keys[h].key),h++,f=a._diskRead(b.children[h]),i.push(f);else break}}return c};var W={QuadBackend:function(a,b){if(arguments!=0){this.indexMap={};this.treeOrder=a.treeOrder;this.indices=["SPOG","GP","OGS","POG","GSP","OS"];this.componentOrders={SPOG:["subject","predicate","object","graph"],GP:["graph",
"predicate","subject","object"],OGS:["object","graph","subject","predicate"],POG:["predicate","object","graph","subject"],GSP:["graph","subject","predicate","object"],OS:["object","subject","predicate","graph"]};for(var e=0;e<this.indices.length;e++){var c=this.indices[e];this.indexMap[c]=new Z.Tree({order:this.treeOrder,componentOrder:this.componentOrders[c],persistent:a.persistent,name:(a.name||"")+c,cacheMaxSize:a.cacheMaxSize})}b&&b(this)}}};W.QuadBackend.prototype.clear=function(){for(var a=
0;a<this.indices.length;a++)this.indexMap[this.indices[a]].clear()};W.QuadBackend.prototype._indexForPattern=function(a){for(var a=a.indexKey,b=this.indices,e=0;e<b.length;e++)for(var c=b[e],i=this.componentOrders[c],h=0;h<i.length;h++){if(v.include(a,i[h])===!1)break;if(h==a.length-1)return c}return"SPOG"};W.QuadBackend.prototype.index=function(a,b){for(var e=0;e<this.indices.length;e++)this.indexMap[this.indices[e]].insert(a);b&&b(!0);return!0};W.QuadBackend.prototype.range=function(a,b){var e=
this.indexMap[this._indexForPattern(a)].range(a);b&&b(e);return e};W.QuadBackend.prototype.search=function(a,b){var e=this.indexMap[this.indices[0]].search(a);b&&b(e!=null);return e!=null};W.QuadBackend.prototype["delete"]=function(a,b){for(var e,c=0;c<this.indices.length;c++)e=this.indices[c],e=this.indexMap[e],e["delete"](a);b&&b(!0);return!0};var L={Lexicon:function(a){this.uriToOID={};this.OIDToUri={};this.literalToOID={};this.OIDToLiteral={};this.blankToOID={};this.OIDToBlank={};this.defaultGraphOid=
0;this.defaultGraphUri="https://github.com/antoniogarrote/rdfstore-js#default_graph";this.defaultGraphUriTerm={token:"uri",prefix:null,suffix:null,value:this.defaultGraphUri,oid:this.defaultGraphOid};this.oidCounter=1;this.knownGraphs={};a!=null&&a(this)}};L.Lexicon.prototype.registerGraph=function(a){a!=this.defaultGraphOid&&(this.knownGraphs[a]=!0);return!0};L.Lexicon.prototype.registeredGraphs=function(a){var b=[],e;for(e in this.knownGraphs)a===!0?b.push(this.OIDToUri["u"+e]):b.push(e);return b};
L.Lexicon.prototype.registerUri=function(a){if(a===this.defaultGraphUri)return this.defaultGraphOid;else{if(this.uriToOID[a]==null){var b=this.oidCounter;this.oidCounter++;this.uriToOID[a]=[b,0];this.OIDToUri["u"+b]=a}else{var e=this.uriToOID[a],b=e[0];this.uriToOID[a]=[b,e[1]+1]}return b}};L.Lexicon.prototype.resolveUri=function(a){return a===this.defaultGraphUri?this.defaultGraphOid:(a=this.uriToOID[a],a!=null?a[0]:-1)};L.Lexicon.prototype.resolveUriCost=function(a){return a===this.defaultGraphUri?
this.defaultGraphOid:(a=this.uriToOID[a],a!=null?a[1]:-1)};L.Lexicon.prototype.registerBlank=function(){var a=this.oidCounter;this.oidCounter++;a=""+a;this.OIDToBlank[a]=!0;return a};L.Lexicon.prototype.resolveBlank=function(){var a=this.oidCounter;this.oidCounter++;return""+a};L.Lexicon.prototype.resolveBlankCost=function(){return 0};L.Lexicon.prototype.registerLiteral=function(a){if(this.literalToOID[a]==null){var b=this.oidCounter;this.oidCounter++;this.literalToOID[a]=[b,0];this.OIDToLiteral["l"+
b]=a}else{var e=this.literalToOID[a],b=e[0];this.literalToOID[a]=[b,e[1]+1]}return b};L.Lexicon.prototype.resolveLiteral=function(a){a=this.literalToOID[a];return a!=null?a[0]:-1};L.Lexicon.prototype.resolveLiteralCost=function(a){a=this.literalToOID[a];return a!=null?a[1]:0};L.Lexicon.prototype.parseLiteral=function(a){var b=a.lastIndexOf("@");if(b!=-1&&a[b-1]==='"'&&a.substring(b,a.length).match(/^@[a-zA-Z\-]+$/g)!=null){var e=a.substring(1,b-1),a=a.substring(b+1,a.length);return{token:"literal",
value:e,lang:a}}b=a.lastIndexOf("^^");if(b!=-1&&a[b-1]==='"'&&a[b+2]==="<"&&a[a.length-1]===">")return e=a.substring(1,b-1),a=a.substring(b+3,a.length-1),{token:"literal",value:e,type:a};e=a.substring(1,a.length-1);return{token:"literal",value:e}};L.Lexicon.prototype.parseUri=function(a){return{token:"uri",value:a}};L.Lexicon.prototype.retrieve=function(a){try{if(a===this.defaultGraphOid)return{token:"uri",value:this.defaultGraphUri,prefix:null,suffix:null,defaultGraph:!0};else{var b=this.OIDToUri["u"+
a];if(b!=null)return this.parseUri(b);else{var e=this.OIDToLiteral["l"+a];if(e!=null)return this.parseLiteral(e);else if(this.OIDToBlank[""+a]!=null)return{token:"blank",value:"_:"+a};else throw"Null value for OID";}}}catch(c){throw console.log("error in lexicon retrieving OID:"),console.log(a),c.message||c.stack?(c.message&&console.log(c.message),c.stack&&console.log(c.stack)):console.log(c),Error("Unknown retrieving OID in lexicon:"+a);}};L.Lexicon.prototype.clear=function(){this.uriToOID={};this.OIDToUri=
{};this.literalToOID={};this.OIDToLiteral={};this.blankToOID={};this.OIDToBlank={}};L.Lexicon.prototype.unregister=function(a,b){try{return this.unregisterTerm(a.subject.token,b.subject),this.unregisterTerm(a.predicate.token,b.predicate),this.unregisterTerm(a.object.token,b.object),a.graph!=null&&this.unregisterTerm(a.graph.token,b.graph),!0}catch(e){return console.log("Error unregistering quad"),console.log(e.message),!1}};L.Lexicon.prototype.unregisterTerm=function(a,b){if(a==="uri"){if(b!=this.defaultGraphOid){var e=
"u"+b,c=this.OIDToUri[e],i=this.uriToOID[c],h=i[1];if(""+i[0]===""+b)h===0?(delete this.OIDToUri[e],delete this.uriToOID[c],delete this.knownGraphs[b]):this.uriToOID[c]=[b,h-1];else throw"Not matching OID : "+b+" vs "+i[0];}}else if(a==="literal")if(this.oidCounter++,e="l"+b,c=this.OIDToLiteral[e],i=this.literalToOID[c],h=i[1],""+i[0]===""+b)h===0?(delete this.OIDToLiteral[e],delete this.literalToOID[c]):this.literalToOID[c]=[b,h-1];else throw"Not matching OID : "+b+" vs "+i[0];else a==="blank"&&
delete this.OIDToBlank[""+b]};var O={};O.load=function(a,b,e){jQuery.ajax({url:a,headers:{Accept:b},success:function(a,b,h){if((""+h.status)[0]=="2"){for(var b=h.getAllResponseHeaders().split("\n"),h={},f=0;f<b.length;f++){var g=b[f].split(":");h[g[0]]=g[1]}e(!0,{headers:h,data:a})}},error:function(a){(""+a.status)[0]=="3"?redirection==0?e(!1,500):(a=a.getAllResponseHeaders().Location||a.getAllResponseHeaders().location,a!=null?O.load(a,b,e,redirection-1):e(!1,500)):e(!1,a.statusCode())}})};var qa=
null;(function(){var a=function(a,e){a.stack="";for(var b in e)a[b]=e[b]};if(typeof window!=="undefined"){var b=window.jsonld=window.jsonld||{};Exception=function(e){a(this,e)};if(!Object.keys)Object.keys=function(a){if(a!==Object(a))throw new TypeError("Object.keys called on non-object");var e=[],b;for(b in a)Object.prototype.hasOwnProperty.call(a,b)&&e.push(b);return e};if(!Array.prototype.filter)Array.prototype.filter=function(a,e){if(this==null)throw new TypeError;var b=Object(this),i=b.length>>>
0;if(typeof a!="function")throw new TypeError;for(var c=[],f=0;f<i;f++)if(f in b){var h=b[f];a.call(e,h,f,b)&&c.push(h)}return c}}else typeof module!=="undefined"&&module.exports&&(b={},Exception=function(e){a(this,e);this.stack=Error().stack});qa=b;var e={rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",owl:"http://www.w3.org/2002/07/owl#",xsd:"http://www.w3.org/2001/XMLSchema#",dcterms:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cal:"http://www.w3.org/2002/12/cal/ical#",
vcard:"http://www.w3.org/2006/vcard/ns# ",geo:"http://www.w3.org/2003/01/geo/wgs84_pos#",cc:"http://creativecommons.org/ns#",sioc:"http://rdfs.org/sioc/ns#",doap:"http://usefulinc.com/ns/doap#",com:"http://purl.org/commerce#",ps:"http://purl.org/payswarm#",gr:"http://purl.org/goodrelations/v1#",sig:"http://purl.org/signature#",ccard:"http://purl.org/commerce/creditcard#"},c={xsd:"http://www.w3.org/2001/XMLSchema#"},i={"boolean":c.xsd+"boolean","double":c.xsd+"double",integer:c.xsd+"integer"},h=function(a,
e,b){e in a?a[e].constructor===Array?a[e].push(b):a[e]=[a[e],b]:a[e]=b},f=function(a){var e;if(a.constructor===Object){e={};var b=Object.keys(a).sort(),i;for(i in b){var c=b[i];e[c]=f(a[c])}}else if(a.constructor===Array)for(i in e=[],a)e[i]=f(a[i]);else e=a;return e},g=function(a){var e={"@id":"@id","@language":"@language","@literal":"@literal","@type":"@type"};if(a){var b={},i;for(i in a)a[i].constructor===String&&a[i]in e&&(b[a[i]]=i);for(i in b)e[i]=b[i]}return e},o=function(a,e){var b=null;e in
a&&(a[e].constructor===String?b=a[e]:a[e].constructor===Object&&"@id"in a[e]&&(b=a[e]["@id"]));return b},t=function(a,e,b){var i=null,c;for(c in a)if(c.length>0&&c[0]!=="@"&&e===o(a,c)){i=c;b!==null&&(b[c]=f(a[c]));break}i===null&&e==="@type"&&(i=g(a)["@type"]);if(i===null)for(c in a)if(c.length>0&&c[0]!=="@"){var h=o(a,c);if(h!==null&&e.indexOf(h)===0&&e.length>h.length){i=c+":"+e.substr(h.length);b!==null&&(b[c]=f(a[c]));break}}i===null&&(i=e);return i},q=function(a,e,b){var i=e,c=g(a),h=e.indexOf(":");
if(h!==-1)c=e.substr(0,h),c in a&&(i=o(a,c)+e.substr(h+1),b!==null&&(b[c]=f(a[c])));else if(e in a)i=o(a,e),b!==null&&(b[e]=f(a[e]));else for(var m in c)if(e===c[m]){i=m;break}return i},u=function(a){var e=!1;a!==null&&a.constructor===Object&&!("@literal"in a)&&(e=Object.keys(a).length>1||!("@id"in a));return e};b.normalize=function(a){return(new F).normalize(a)};b.expand=function(a){return(new F).expand({},null,a)};b.compact=function(a,e){var i=null;if(e!==null){var e=b.expand(e),c;e.constructor===
Array?(i=[],c=e):c=[e];a.constructor===Array&&(a=b.mergeContexts({},a));for(var h in c){var g={},n=(new F).compact(f(a),null,c[h],g);if(Object.keys(g).length>0){var m=g,g={},r=Object.keys(m).sort(),s=void 0;for(s in r){var o=r[s];g[o]=m[o]}m=Object.keys(n);m.sort();m.unshift("@context");n["@context"]=g;var g={},q;for(q in m)r=m[q],g[r]=n[r];n=g}i===null?i=n:i.push(n)}}return i};b.mergeContexts=function(a,e){a.constructor===Array&&(a=b.mergeContexts({},a));var i=f(a);if(e.constructor===Array)for(var c in e)i=
b.mergeContexts(i,e[c]);else{for(var h in e)if(h.indexOf("@")!==0)for(var g in i)if(i[g]===e[h]){delete i[g];break}for(h in e)i[h]=f(e[h])}return i};b.expandTerm=q;b.compactIri=function(a,e){return t(a,e,null)};b.frame=function(a,e,b){return(new F).frame(a,e,b)};b.toTriples=function(a,e,i){var c=null,a=b.normalize(a),i=i||null;i===null&&(c=[],i=function(a,b,i){c.push({subject:v.lexicalFormTerm(a),predicate:v.lexicalFormTerm(b),object:v.lexicalFormTerm(i),graph:e})});var f=!1,h;for(h in a){var g=a[h],
n=g["@id"],n=n[0]=="_"?{token:"blank",value:n.split(":")[1]}:{token:"uri",value:n},m;for(m in g)if(m!=="@id"){var r=g[m];r.constructor!==Array&&(r=[r]);for(var s in r)if(f=r[s],m==="@type"||m==="http://www.w3.org/1999/02/22-rdf-syntax-ns#type"?(m="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",f={token:"uri",value:f}):typeof f==="string"?f={token:"literal",value:f}:f["@id"]!=null?f=f["@id"][0]=="_"?{token:"blank",value:f["@id"].split(":")[1]}:{token:"uri",value:f["@id"]}:f["@type"]!=null?f={token:"literal",
value:f["@literal"],type:f["@type"]}:f["@language"]!=null&&(f={token:"literal",value:f["@literal"],lang:f["@language"]}),f=i(n,{token:"uri",value:m},f)===!1)break;if(f)break}if(f)break}return c};b.resolve=function(a,e,b){var i={},c=function(a,e){if(a.constructor===Array)for(var b in a)c(a[b]);else if(a.constructor===Object)for(var f in a)if(f==="@context")if(a[f].constructor===Array){var h=a[f];for(b in h)h[b].constructor===String&&(e?h[b]=i[h[b]]:i[h[b]]={})}else a[f].constructor===String&&(e?a[f]=
i[a[f]]:i[a[f]]={})};c(a,!1);var f=Object.keys(i).length,h=null;if(f===0)b(a,h);else for(var g in i)e(g,function(e,n){--f;if(e===null)h=h||[],h.push({url:g,error:n});else try{i[g]=e.constructor===String?JSON.parse(e)["@context"]:e["@context"]}catch(m){h=h||[],h.push({url:g,error:m})}f===0&&(h===null&&c(a,!0),b(a,h))})};var F=function(){};F.prototype.compact=function(a,e,b,c){var h,m=g(a);if(b===null)h=null,this.getCoerceType(a,e,c);else if(b.constructor===Array){h=[];for(var r in b)h.push(this.compact(a,
e,b[r],c))}else if(b.constructor===Object&&"@id"in b&&b["@id"].constructor===Array)h={},h[m["@id"]]=this.compact(a,e,b["@id"],c);else if(u(b)){h={};for(var s in b)if(b[s]!=="@context"&&(m=t(a,s,c),m!==s||!(m in h)))h[m]=this.compact(a,s,b[s],c)}else{e=this.getCoerceType(a,e,c);r=null;b.constructor===Object?"@language"in b||(r="@type"in b?b["@type"]:"@id"in b?"@id":e):b.constructor===String&&(r=e);if(e===null&&(r===i["boolean"]||r===i.integer||r===i["double"]))e=r;if(e!==null)if(r===null)throw{message:"Cannot coerce type when a language is specified. The language information would be lost."};
else if(r!==e)throw new Exception({message:"Cannot coerce type because the type does not match.",type:r,expected:e});else b.constructor===Object?"@id"in b?h=b["@id"]:"@literal"in b&&(h=b["@literal"]):h=b,e===i["boolean"]?h=h==="true"||h!=0:e===i["double"]?h=parseFloat(h):e===i.integer&&(h=parseInt(h));else if(b.constructor===Object)for(s in h={},b)h[m[s]]=b[s];else h=f(b);r==="@id"&&(h.constructor===Object?h[m["@id"]]=t(a,h[m["@id"]],c):h=t(a,h,c))}return h};F.prototype.expand=function(a,e,c){var m;
if(c===null)m=null;else if(e===null&&c.constructor===String)m=q(a,c,null);else if(c.constructor===Array){m=[];for(var r in c)m.push(this.expand(a,e,c[r]))}else if(c.constructor===Object){"@context"in c&&(a=b.mergeContexts(a,c["@context"]));m={};for(var s in c)s==="@embed"||s==="@explicit"||s==="@default"||s==="@omitDefault"?h(m,s,f(c[s])):s!=="@context"&&h(m,q(a,s,null),this.expand(a,s,c[s]))}else{r=this.getCoerceType(a,e,null);m=g(a);if(r===null&&(c.constructor===Number||c.constructor===Boolean))r=
c.constructor===Boolean?i["boolean"]:(""+c).indexOf(".")==-1?i.integer:i["double"];e===m["@id"]||e===m["@type"]?m=q(a,c,null):r!==null?(m={},r==="@id"?m["@id"]=q(a,c,null):(m["@type"]=r,r===i["double"]&&(c=c.toExponential(6).replace(/(e(?:\+|-))([0-9])$/,"$10$2")),m["@literal"]=""+c)):m=""+c}return m};F.prototype.normalize=function(a){var b=[];if(a!==null){this.ng={tmp:null,c14n:null};var i=this.expand(e,null,a);this.nameBlankNodes(i);a={};y(null,null,i,a);for(var c in a){var i=a[c],f={},h=Object.keys(i).sort(),
g;for(g in h){var n=h[g];f[n]=i[n]}b.push(f)}this.canonicalizeBlankNodes(b);b.sort(function(a,e){return m(a["@id"],e["@id"])})}return b};F.prototype.getCoerceType=function(a,e,b){var i=null,e=q(a,e,null);e==="@id"||e==="@type"?i="@id":(e=t(a,e,null),e in a&&a[e].constructor===Object&&"@type"in a[e]&&(i=q(a,a[e]["@type"],b),b!==null&&(b[e]=f(a[e]))));return i};var x=function(a){return a.indexOf("_:")===0},Ta=function(a){return a.constructor===Object&&"@id"in a&&x(a["@id"])},m=function(a,e){var b=0;
if(a.constructor===Array&&e.constructor===Array)for(var i=0;i<a.length&&b===0;++i)b=m(a[i],e[i]);else b=a<e?-1:a>e?1:0;return b},r=function(a,e,b){var i=0;b in a?i=b in e?m(a[b],e[b]):-1:b in e&&(i=1);return i},z=function(a,e){var b=0;a.constructor===String?b=e.constructor!==String?-1:m(a,e):e.constructor===String?b=1:(b=r(a,e,"@literal"),b===0&&("@literal"in a?(b=r(a,e,"@type"),b===0&&(b=r(a,e,"@language"))):b=m(a["@id"],e["@id"])));return b},s=function(a,e){var b=0,i;for(i in a)if(i!=="@id"){b=
m(a[i].constructor===Array?a[i].length:1,e[i].constructor===Array?e[i].length:1);if(b===0){var c=a[i],f=e[i];c.constructor!==Array&&(c=[c],f=[f]);c=c.filter(function(a){return!Ta(a)});f=f.filter(function(a){return!Ta(a)});b=m(c.length,f.length)}if(b===0){c.sort(z);f.sort(z);for(var h=0;h<c.length&&b===0;++h)b=z(c[h],f[h])}if(b!==0)break}return b},G=function(a){var e=-1,b={next:function(){++e;return b.current()},current:function(){return"_:"+a+e},inNamespace:function(e){return e.indexOf("_:"+a)===
0}};return b},U=function(a,e,b){if(a!==null)if(a.constructor===Array)for(var i in a)U(a[i],e,b);else if(a.constructor===Object){"@id"in a?a["@id"].constructor==Array?U(a["@id"],e,b):u(a)&&(e[a["@id"]]=a):u(a)&&(!("@id"in a)||Ta(a))&&b.push(a);for(var c in a)U(a[c],e,b)}},y=function(a,e,b,i){var c=null;if(b!==null)if(b.constructor===Array)for(var h in b)y(a,e,b[h],i);else if(b.constructor===Object)if("@literal"in b||e==="@type")c=f(b);else if(b["@id"].constructor===Array){if(a!==null)throw{message:"Embedded graph literals cannot be flattened."};
for(var g in b["@id"])y(a,e,b["@id"][g],i)}else{b["@id"]in i?h=i[b["@id"]]:(h={"@id":b["@id"]},i[b["@id"]]=h);var c={"@id":h["@id"]},m;for(m in b)g=b[m],g!==null&&m!=="@id"&&(m in h?h[m].constructor!==Array&&(h[m]=[h[m]]):h[m]=[],y(h[m],m,g,i),h[m].length===1&&(h[m]=h[m][0]))}else c=b;c!==null&&a!==null&&(a.constructor===Array?(e=!1,c.constructor===Object&&"@id"in c&&(e=a.filter(function(a){return a.constructor===Object&&"@id"in a&&a["@id"]===c["@id"]}).length>0),e||a.push(c)):a[e]=c)};F.prototype.nameBlankNodes=
function(a){var e=this.ng.tmp=G("tmp"),b={},i=[];U(a,b,i);for(var c in i)if(a=i[c],!("@id"in a)){for(;e.next()in b;);a["@id"]=e.current();b[e.current()]=a}};F.prototype.renameBlankNode=function(a,e){var b=a["@id"];a["@id"]=e;var i=this.subjects;i[e]=i[b];delete i[b];this.edges.refs[e]=this.edges.refs[b];this.edges.props[e]=this.edges.props[b];delete this.edges.refs[b];delete this.edges.props[b];var c=this.edges.refs[e].all,f;for(f in c){var h=c[f].s;h===b&&(h=e);var g=i[h],m=this.edges.props[h].all,
n;for(n in m)if(m[n].s===b){m[n].s=e;var h=m[n].p,h=g[h].constructor===Object?[g[h]]:g[h].constructor===Array?g[h]:[],r;for(r in h)h[r].constructor===Object&&"@id"in h[r]&&h[r]["@id"]===b&&(h[r]["@id"]=e)}}m=this.edges.props[e].all;for(f in m){var h=m[f].s,c=this.edges.refs[h].all,s;for(s in c)if(c[s].s===b)c[s].s=e}};F.prototype.canonicalizeBlankNodes=function(a){this.renamed={};this.mappings={};this.serializations={};var e=this.edges={refs:{},props:{}},b=this.subjects={},i=[],c;for(c in a){var f=
a[c]["@id"];b[f]=a[c];e.refs[f]={all:[],bnodes:[]};e.props[f]={all:[],bnodes:[]};x(f)&&i.push(a[c])}this.collectEdges();var a=this.ng.c14n=G("c14n"),h=this.ng.tmp;for(c in i){var g=i[c],f=g["@id"];if(a.inNamespace(f)){for(;h.next()in b;);this.renameBlankNode(g,h.current());f=g["@id"]}this.serializations[f]={props:null,refs:null}}for(var h=!0,n=this;i.length>0;){h&&(h=!1,i.sort(function(a,e){return n.deepCompareBlankNodes(a,e)}));var g=i.shift(),f=g["@id"],g=["props","refs"],r;for(r in g){var s=g[r];
if(this.serializations[f][s]===null){var o={};o[f]="s1"}else o=this.serializations[f][s].m;var q=Object.keys(o);q.sort(function(a,e){return m(o[a],o[e])});var t=[];for(c in q){var u=q[c];!a.inNamespace(f)&&u in b&&(this.renameBlankNode(b[u],a.next()),t.push(u))}q=i;i=[];for(c in q){var u=q[c],v=u["@id"];if(!a.inNamespace(v)){for(var F in t)this.markSerializationDirty(v,t[F],s)&&(h=!0);i.push(u)}}}}for(var y in e.props)if(e.props[y].bnodes.length>0){var g=b[y],ea;for(ea in g)ea.indexOf("@")!==0&&g[ea].constructor===
Array&&g[ea].sort(z)}};MappingBuilder=function(){this.count=1;this.processed={};this.mapping={};this.adj={};this.keyStack=[{keys:["s1"],idx:0}];this.done={};this.s=""};MappingBuilder.prototype.copy=function(){var a=new MappingBuilder;a.count=this.count;a.processed=f(this.processed);a.mapping=f(this.mapping);a.adj=f(this.adj);a.keyStack=f(this.keyStack);a.done=f(this.done);a.s=this.s;return a};MappingBuilder.prototype.mapNode=function(a){a in this.mapping||(this.mapping[a]=a.indexOf("_:c14n")===0?
"c"+a.substr(6):"s"+this.count++);return this.mapping[a]};MappingBuilder.prototype.serialize=function(a,e){if(this.keyStack.length>0)for(var b=this.keyStack.pop();b.idx<b.keys.length;++b.idx){var i=b.keys[b.idx];if(!(i in this.adj)){this.keyStack.push(b);break}if(i in this.done)this.s+="_"+i;else{this.done[i]=!0;var c=i,i=this.adj[i],f=i.i;if(f in a){var h=a[f],g="",m=!0,n=void 0;for(n in h)if(n!=="@id"){m?m=!1:g+="|";g+="<"+n+">";var r=h[n].constructor===Array?h[n]:[h[n]],s;for(s in r){var o=r[s];
o.constructor===Object?"@id"in o?g+=x(o["@id"])?"_:":"<"+o["@id"]+">":(g+='"'+o["@literal"]+'"',"@type"in o?g+="^^<"+o["@type"]+">":"@language"in o&&(g+="@"+o["@language"])):g+='"'+o+'"'}}c+="["+g+"]";h=!0;c+="[";var f=e.refs[f].all,q;for(q in f)h?h=!1:c+="|",c+="<"+f[q].p+">",c+=x(f[q].s)?"_:":"<"+f[q].s+">";c+="]"}c+=i.k.join("");this.s+=c;this.keyStack.push({keys:i.k,idx:0});this.serialize(a,e)}}};F.prototype.markSerializationDirty=function(a,e,b){var i=!1,a=this.serializations[a];a[b]!==null&&
e in a[b].m&&(a[b]=null,i=!0);return i};var A=function(a,e){var b=0;return b=a.length==e.length?m(a,e):a.length>e.length?m(a.substr(0,e.length),e):m(a,e.substr(0,a.length))};F.prototype.serializeCombos=function(a,e,b,i,c,h,g){if(g.length>0){h=f(h);h[i.mapNode(g[0].s)]=g[0].s;for(var m=i.copy(),g=g.slice(1),n=Math.max(1,g.length),r=0;r<n;++r){var s=r===0?i:m.copy();this.serializeCombos(a,e,b,s,c,h,g);g.unshift.apply(g,g.splice(1,g.length))}}else if(g=Object.keys(h).sort(),i.adj[b]={i:e,k:g,m:h},i.serialize(this.subjects,
this.edges),a[c]===null||A(i.s,a[c].s)<=0){for(m in g)this.serializeBlankNode(a,h[g[m]],i,c);i.serialize(this.subjects,this.edges);if(a[c]===null||A(i.s,a[c].s)<=0&&i.s.length>=a[c].s.length)a[c]={s:i.s,m:i.mapping}}};F.prototype.serializeBlankNode=function(a,e,b,i){if(!(e in b.processed)){b.processed[e]=!0;var c=b.mapNode(e),f=b.copy(),h=this.edges[i][e].bnodes,g={},m=[],n;for(n in h)h[n].s in b.mapping?g[b.mapping[h[n].s]]=h[n].s:m.push(h[n]);h=Math.max(1,m.length);for(n=0;n<h;++n){var r=n===0?
b:f.copy();this.serializeCombos(a,e,c,r,i,g,m)}}};F.prototype.deepCompareBlankNodes=function(a,e){var b=0,i=a["@id"],c=e["@id"];if(i===c)b=0;else if(b=this.shallowCompareBlankNodes(a,e),b===0)for(var h=["props","refs"],g=0;b===0&&g<h.length;++g){var b=h[g],n=this.serializations[i],r=this.serializations[c];if(n[b]===null){var s=new MappingBuilder;if(b==="refs")s.mapping=f(n.props.m),s.count=Object.keys(s.mapping).length+1;this.serializeBlankNode(n,i,s,b)}if(r[b]===null){s=new MappingBuilder;if(b===
"refs")s.mapping=f(r.props.m),s.count=Object.keys(s.mapping).length+1;this.serializeBlankNode(r,c,s,b)}b=m(n[b].s,r[b].s)}return b};F.prototype.shallowCompareBlankNodes=function(a,e){var b=0,i=Object.keys(a),c=Object.keys(e),b=m(i.length,c.length);b===0&&(b=m(i.sort(),c.sort()));b===0&&(b=s(a,e));if(b===0)var f=this.edges.refs[a["@id"]].all,h=this.edges.refs[e["@id"]].all,b=m(f.length,h.length);if(b===0)for(i=0;i<f.length&&b===0;++i)b=this.compareEdges(f[i],h[i]);return b};F.prototype.compareEdges=
function(a,e){var b=0,i=x(a.s),c=x(e.s),f=this.ng.c14n;i!=c?b=i?1:-1:(i||(b=m(a.s,e.s)),b===0&&(b=m(a.p,e.p)),b===0&&f!==null&&(i=f.inNamespace(a.s),f=f.inNamespace(e.s),i!=f?b=i?1:-1:i&&(b=m(a.s,e.s))));return b};F.prototype.collectEdges=function(){var a=this.edges.refs,e=this.edges.props,b;for(b in this.subjects){var i=this.subjects[b],c;for(c in i)if(c!=="@id"){var f=i[c],f=f.constructor!==Array?[f]:f,h;for(h in f){var g=f[h];g.constructor===Object&&"@id"in g&&g["@id"]in this.subjects&&(g=g["@id"],
a[g].all.push({s:b,p:c}),e[b].all.push({s:g,p:c}))}}}var m=this;for(b in a)a[b].all.sort(function(a,e){return m.compareEdges(a,e)}),a[b].bnodes=a[b].all.filter(function(a){return x(a.s)});for(b in e)e[b].all.sort(function(a,e){return m.compareEdges(a,e)}),e[b].bnodes=e[b].all.filter(function(a){return x(a.s)})};var B=function(a,e){var b=!1;if(!("@type"in e)){var i=Object.keys(e).filter(function(a){return a.indexOf("@")!==0});if(i.length===0)b=!0;else if(a.constructor===Object&&"@id"in a){var b=!0,
c;for(c in i)if(!(i[c]in a)){b=!1;break}}}return b},C=function(a,e,b,i,c,f,h,g){var m=e["@id"],n=m in i?i[m]:null;if(("@embed"in b&&b["@embed"]||!("@embed"in b)&&g.defaults.embedOn)&&(n===null||n.autoembed&&!c)){if(n===null)n={},i[m]=n;else if(n.parent!==null){if(n.parent[n.key].constructor===Array){var r=n.parent[n.key],s;for(s in r)if(r[s].constructor===Object&&"@id"in r[s]&&r[s]["@id"]===m){r[s]={"@id":e["@id"]};break}}else n.parent[n.key]={"@id":e["@id"]};var o=function(a){var e=Object.keys(i),
b;for(b in e)b=e[b],b in i&&i[b].parent!==null&&i[b].parent["@id"]===a&&(delete i[b],o(b))};o(m)}n.autoembed=c;n.parent=f;n.key=h;if(b["@explicit"]===!0||g.defaults.explicitOn)for(q in e)q!=="@id"&&!(q in b)&&delete e[q];c=Object.keys(e);for(s in c){var q=c[s];if(q.indexOf("@")!==0){q in b?(f=b[q],h=!1):(f=e[q].constructor===Array?[]:{},h=!0);var m=e[q],m=m.constructor===Array?m:[m],t;for(t in m)m[t].constructor===Object&&"@id"in m[t]&&m[t]["@id"]in a&&(m[t]=a[m[t]["@id"]]);e[q]=D(a,m,f,i,h,e,q,g)}}for(q in b)if(q.indexOf("@")!==
0&&(!(q in e)||e[q]===null))f=b[q],f.constructor===Array?e[q]=[]:(f.constructor===Array&&(f=f.length>0?f[0]:{}),f["@omitDefault"]===!0||g.defaults.omitDefaultOn||(e[q]="@default"in f?f["@default"]:null))}else e={"@id":e["@id"]};return e},D=function(a,e,b,i,c,f,h,g){var m=null,n=-1,r;b.constructor===Array?(m=[],r=b,r.length===0&&r.push({})):(r=[b],n=1);for(var s=[],q=0;q<r.length&&n!==0;++q){b=r[q];if(b.constructor!==Object)throw{message:"Invalid JSON-LD frame. Frame must be an object or an array.",
frame:b};s[q]=[];for(var o=0;o<e.length&&n!==0;++o){var t=e[o],z=!1,G="@type";if("@type"in b&&t.constructor===Object&&G in t)for(var v=t[G].constructor===Array?t[G]:[t[G]],F=b[G].constructor===Array?b[G]:[b[G]],y=0;y<F.length&&!z;++y){var G=F[y],x;for(x in v)if(v[x]===G){z=!0;break}}if(z||B(t,b))s[q].push(t),--n}}for(var U in s)for(var A in s[U])b=r[U],e=s[U][A],u(e)&&(e=C(a,e,b,i,c,f,h,g)),m===null?m=e:(b=e!==null&&e.constructor===Object&&"@id"in e&&Object.keys(e).length===1&&e["@id"]in i,f===null&&
b||m.push(e));return m};F.prototype.frame=function(a,e,i){var a=b.normalize(a),c=null;if("@context"in e)c=f(e["@context"]),e=b.expand(e);else if(e.constructor===Array){e.length>0&&"@context"in e[0]&&(c=f(e[0]["@context"]));var i=[],h;for(h in e)i.push(b.expand(e[h]));e=i}var i={defaults:{embedOn:!0,explicitOn:!1,omitDefaultOn:!1}},g={};for(h in a)g[a[h]["@id"]]=a[h];a=D(g,a,e,{},!1,null,null,i);c!==null&&a!==null&&(a=b.compact(c,a));return a}})();var ja={parser:{}};ja.parser.parse=function(a,b){typeof a===
"string"&&(a=JSON.parse(a));return qa.toTriples(a,b)};var X={RDFLoader:function(a){this.precedences=["text/turtle","text/n3","application/ld+json","application/json"];this.parsers={"text/turtle":ka.parser,"text/n3":ka.parser,"application/ld+json":ja.parser,"application/json":ja.parser};if(a!=null)for(var b in a.parsers)this.parsers[b]=a.parsers[b];if(a&&a.precedences!=null)for(b in this.precedences=a.precedences,a.parsers)v.include(this.precedences,b)||this.precedences.push(b);this.acceptHeaderValue=
"";for(a=0;a<this.precedences.length;a++)a!=0?this.acceptHeaderValue=this.acceptHeaderValue+","+this.precedences[a]:this.acceptHeaderValue+=this.precedences[a]}};X.RDFLoader.prototype.registerParser=function(a,b){this.parsers[a]=b;this.precedences.push(a)};X.RDFLoader.prototype.unregisterParser=function(a){delete this.parsers[a];for(var b=[],e=0;e<this.precedences.length;e++)this.precedences[e]!=a&&b.push(this.precedences[e]);this.precedences=b};X.RDFLoader.prototype.setAcceptHeaderPrecedence=function(a){this.precedences=
a};X.RDFLoader.prototype.load=function(a,b,e){var c=this;O.load(a,this.acceptHeaderValue,function(i,h){if(i==!0){var f=h.headers["Content-Type"]||h.headers["content-type"],g=h.data;if(f!=null){var f=f.split(";")[0],o;for(o in c.parsers)if(o.indexOf("/")!=-1){var t=o.split("/");if(t[1]==="*"){if(f.indexOf(t[0])!=-1)return c.tryToParse(c.parsers[o],b,g,e)}else if(f.indexOf(o)!=-1)return c.tryToParse(c.parsers[o],b,g,e);else if(f.indexOf(t[1])!=-1)return c.tryToParse(c.parsers[o],b,g,e)}else if(f.indexOf(o)!=
-1)return c.tryToParse(c.parsers[o],a,b,e);e(!1,"Unknown media type : "+f)}else console.log("Unknown media type"),console.log(h.headers),e(!1,"Uknown media type")}else e(!1,"Network error: "+h)})};X.RDFLoader.prototype.loadFromFile=function(a,b,e,c){try{var i=this;require("fs").readFile(e.split("file:/")[1],function(e,h){if(e)throw e;h=h.toString("utf8");i.tryToParse(a,b,h,c)})}catch(h){c(!1,h)}};X.RDFLoader.prototype.tryToParse=function(a,b,e,c){try{typeof e==="string"&&(e=v.normalizeUnicodeLiterals(e));
var i=a.parse(e,b);i!=null?c(!0,i):c(!1,"parsing error")}catch(h){console.log(h.message),console.log(h.stack),c(!1,"parsing error with mime type : "+h)}};var K={AbstractQueryTree:function(){}};K.AbstractQueryTree.prototype.parseQueryString=function(a){return ra.parser.parse(a)};K.AbstractQueryTree.prototype.parseExecutableUnit=function(a){if(a.kind==="select")return this.parseSelect(a);else if(a.kind==="ask")return this.parseSelect(a);else if(a.kind==="modify")return this.parseSelect(a);else if(a.kind===
"construct")return this.parseSelect(a);else if(a.kind==="insertdata")return this.parseInsertData(a);else if(a.kind==="deletedata")return this.parseInsertData(a);else if(a.kind==="load")return a;else if(a.kind==="clear")return a;else if(a.kind==="drop")return a;else if(a.kind==="create")return a;else throw Error("unknown executable unit: "+a.kind);};K.AbstractQueryTree.prototype.parseSelect=function(a){return a==null?(console.log("error parsing query"),null):(a.pattern=this.build(a.pattern,{freshCounter:0}),
a)};K.AbstractQueryTree.prototype.parseInsertData=function(a){return a==null?(console.log("error parsing query"),null):a};K.AbstractQueryTree.prototype.build=function(a,b){if(a.token==="groupgraphpattern")return this._buildGroupGraphPattern(a,b);else if(a.token==="basicgraphpattern"){var e={kind:"BGP",value:a.triplesContext};return e=K.translatePathExpressionsInBGP(e,b)}else if(a.token==="graphunionpattern"){var e=this.build(a.value[0],b),c=this.build(a.value[1],b);return{kind:"UNION",value:[e,c]}}else if(a.token===
"graphgraphpattern")return{kind:"GRAPH",value:this.build(a.value,b),graph:a.graph};else throw Error("not supported token in query:"+a.token);};K.translatePathExpressionsInBGP=function(a,b){var e,c=[],i,h;for(h=0;h<a.value.length;h++)if(a.value[h].predicate&&a.value[h].predicate.token==="path"){e=a.value[h];i=a.value.slice(h+1);var f=K.translatePathExpression(e,b);e=null;if(f.kind==="BGP")c=c.concat(f.value);else if(f.kind==="ZERO_OR_MORE_PATH"||f.kind==="ONE_OR_MORE_PATH"){h=c.length>0?{kind:"JOIN",
lvalue:{kind:"BGP",value:c},rvalue:f}:f;if(f.kind==="ZERO_OR_MORE_PATH")if(f.y.token==="var"&&f.y.value.indexOf("fresh:")===0&&f.x.token==="var"&&f.x.value.indexOf("fresh:")===0)for(var g=0;g<a.value.length;g++){if(a.value[g].object&&a.value[g].object.token==="var"&&a.value[g].object.value===f.x.value)e=v.clone(a.value[g]),e.object=f.y}else if(f.y.token==="var"&&f.y.value.indexOf("fresh:")===0)for(g=0;g<a.value.length;g++)if(a.value[g].subject&&a.value[g].subject.token==="var"&&a.value[g].subject.value===
f.y.value)e=v.clone(a.value[g]),e.subject=f.x;return i.length>0?(f=K.translatePathExpressionsInBGP({kind:"BGP",value:i},b),e!=null?(c=c.concat([e]).concat(i),{kind:"UNION",value:[{kind:"JOIN",lvalue:h,rvalue:f},{kind:"BGP",value:c}]}):{kind:"JOIN",lvalue:h,rvalue:f}):h}else return f}else c.push(a.value[h]);a.value=c;return a};K.translatePathExpression=function(a,b){if(a.predicate.kind==="element")if(a.predicate.modifier==="+"){a.predicate.modifier=null;var e=K.translatePathExpression(a,b);return{kind:"ONE_OR_MORE_PATH",
path:e,x:a.subject,y:a.object}}else return a.predicate.modifier==="*"?(a.predicate.modifier=null,e=K.translatePathExpression(a,b),{kind:"ZERO_OR_MORE_PATH",path:e,x:a.subject,y:a.object}):(a.predicate=a.predicate.value,{kind:"BGP",value:[a]});else if(a.predicate.kind==="sequence"){for(var e=a.subject,c=a.object,i=a.graph,h,f,g=[],o=0;o<a.predicate.value.length;o++){o!=a.predicate.value.length-1?(h={token:"var",value:"fresh:"+b.freshCounter},b.freshCounter++):h=c;f={subject:e,predicate:a.predicate.value[o],
object:h};if(i!=null)f.graph=v.clone(i);g.push(f);o!=a.predicate.value.length-1&&(e=v.clone(h))}return K.translatePathExpressionsInBGP({kind:"BGP",value:g},b)}};K.AbstractQueryTree.prototype._buildGroupGraphPattern=function(a,b){for(var e=a.filters||[],c={kind:"EMPTY_PATTERN"},i=0;i<a.patterns.length;i++){var h=a.patterns[i];h.token==="optionalgraphpattern"?(h=this.build(h.value,b),c=h.kind==="FILTER"?{kind:"LEFT_JOIN",lvalue:c,rvalue:h.value,filter:h.filter}:{kind:"LEFT_JOIN",lvalue:c,rvalue:h,filter:!0}):
(h=this.build(h,b),c=c.kind=="EMPTY_PATTERN"?h:{kind:"JOIN",lvalue:c,rvalue:h})}if(e.length!=0)if(c.kind==="EMPTY_PATTERN")return{kind:"FILTER",filter:e,value:c};else if(c.kind==="LEFT_JOIN"&&c.filter===!0)return{kind:"FILTER",filter:e,value:c};else if(c.kind==="LEFT_JOIN")return{kind:"FILTER",filter:e,value:c};else if(c.kind==="JOIN")return{kind:"FILTER",filter:e,value:c};else if(c.kind==="UNION")return{kind:"FILTER",filter:e,value:c};else if(c.kind==="GRAPH")return{kind:"FILTER",filter:e,value:c};
else if(c.kind==="BGP")return{kind:"FILTER",filter:e,value:c};else throw Error("Unknow kind of algebra expression: "+c.kind);else return c};K.AbstractQueryTree.prototype.collectBasicTriples=function(a,b){b==null&&(b=[]);if(a.kind==="select")b=this.collectBasicTriples(a.pattern,b);else if(a.kind==="BGP")b=b.concat(a.value);else if(a.kind==="ZERO_OR_MORE_PATH")b=this.collectBasicTriples(a.path);else if(a.kind==="UNION")b=this.collectBasicTriples(a.value[0],b),b=this.collectBasicTriples(a.value[1],b);
else if(a.kind==="GRAPH")b=this.collectBasicTriples(a.value,b);else if(a.kind==="LEFT_JOIN"||a.kind==="JOIN")b=this.collectBasicTriples(a.lvalue,b),b=this.collectBasicTriples(a.rvalue,b);else if(a.kind==="FILTER")b=this.collectBasicTriples(a.value,b);else if(a.kind==="construct")b=this.collectBasicTriples(a.pattern,b);else if(a.kind!=="EMPTY_PATTERN")throw"Unknown pattern: "+a.kind;return b};K.AbstractQueryTree.prototype.bind=function(a,b){if(a.graph!=null&&a.graph.token&&a.graph.token==="var"&&b[a.graph.value]!=
null)a.graph=b[a.graph.value];if(a.filter!=null){for(var e=[],c=0;c<a.filter.length;c++)a.filter[c].value=this._bindFilter(a.filter[c].value,b),e.push(a.filter[c]);a.filter=e}if(a.kind==="select")a.pattern=this.bind(a.pattern,b);else if(a.kind==="BGP")a.value=this._bindTripleContext(a.value,b);else if(a.kind==="ZERO_OR_MORE_PATH"){a.path=this._bindTripleContext(a.path,b);if(a.x&&a.x.token==="var"&&b[a.x.value]!=null)a.x=b[a.x.value];if(a.y&&a.y.token==="var"&&b[a.y.value]!=null)a.y=b[a.y.value]}else if(a.kind===
"UNION")a.value[0]=this.bind(a.value[0],b),a.value[1]=this.bind(a.value[1],b);else if(a.kind==="GRAPH")a.value=this.bind(a.value,b);else if(a.kind==="LEFT_JOIN"||a.kind==="JOIN")a.lvalue=this.bind(a.lvalue,b),a.rvalue=this.bind(a.rvalue,b);else if(a.kind==="FILTER")a.filter=this._bindFilter(a.filter[c].value,b);else if(a.kind!=="EMPTY_PATTERN")throw"Unknown pattern: "+a.kind;return a};K.AbstractQueryTree.prototype._bindTripleContext=function(a,b){for(var e=0;e<a.length;e++){delete a[e].graph;delete a[e].variables;
for(var c in a[e]){var i=a[e][c];i.token==="var"&&b[i.value]!=null&&(a[e][c]=b[i.value])}}return a};K.AbstractQueryTree.prototype._bindFilter=function(a,b){if(a.expressionType!=null){var e=a.expressionType;if(e=="relationalexpression")a.op1=this._bindFilter(a.op1,b),a.op2=this._bindFilter(a.op2,b);else if(e=="conditionalor"||e=="conditionaland")for(e=0;e<a.operands.length;e++)a.operands[e]=this._bindFilter(a.operands[e],b);else if(e=="additiveexpression"){a.summand=this._bindFilter(a.summand,b);for(e=
0;e<a.summands.length;e++)a.summands[e].expression=this._bindFilter(a.summands[e].expression,b)}else if(e=="builtincall")for(e=0;e<a.args.length;e++)a.args[e]=this._bindFilter(a.args[e],b);else if(e=="multiplicativeexpression"){a.factor=this._bindFilter(a.factor,b);for(e=0;e<a.factors.length;e++)a.factors[e].expression=this._bindFilter(a.factors[e].expression,b)}else if(e=="unaryexpression")a.expression=this._bindFilter(a.expression,b);else if(e=="irireforfunction")for(e=0;e<a.factors.args;e++)a.args[e]=
this._bindFilter(a.args[e],b);else if(e=="atomic"&&a.primaryexpression=="var"&&b[a.value.value]!=null)e=b[a.value.value],a.primaryexpression=e.token==="uri"?"iri":"literal",a.value=e}return a};K.AbstractQueryTree.prototype.replace=function(a,b,e,c){if(a.graph!=null&&a.graph.token&&a.graph.token===b.token&&a.graph.value==b.value)a.graph=v.clone(e);if(a.filter!=null){for(var i=[],h=0;h<a.filter.length;h++)a.filter[h].value=this._replaceFilter(a.filter[h].value,b,e,c),i.push(a.filter[h]);a.filter=i}if(a.kind===
"select")a.pattern=this.replace(a.pattern,b,e,c);else if(a.kind==="BGP")a.value=this._replaceTripleContext(a.value,b,e,c);else if(a.kind==="ZERO_OR_MORE_PATH"){a.path=this._replaceTripleContext(a.path,b,e,c);if(a.x&&a.x.token===b.token&&a.value===b.value)a.x=v.clone(e);if(a.y&&a.y.token===b.token&&a.value===b.value)a.y=v.clone(e)}else if(a.kind==="UNION")a.value[0]=this.replace(a.value[0],b,e,c),a.value[1]=this.replace(a.value[1],b,e,c);else if(a.kind==="GRAPH")a.value=this.replace(a.value,b,e);else if(a.kind===
"LEFT_JOIN"||a.kind==="JOIN")a.lvalue=this.replace(a.lvalue,b,e,c),a.rvalue=this.replace(a.rvalue,b,e,c);else if(a.kind==="FILTER")a.value=this._replaceFilter(a.value,b,e,c);else if(a.kind!=="EMPTY_PATTERN")throw"Unknown pattern: "+a.kind;return a};K.AbstractQueryTree.prototype._replaceTripleContext=function(a,b,e,c){for(var i=0;i<a.length;i++)for(var h in a[i]){var f=a[i][h];if(f.token==="var"&&b.token==="var"&&f.value===b.value)a[i][h]=e;else if(f.token==="blank"&&b.token==="blank"&&f.value===b.value)a[i][h]=
e;else if((f.token==="literal"||f.token==="uri")&&(b.token==="literal"||b.token==="uri")&&f.token===b.token&&v.lexicalFormTerm(f,c)[f.token]===v.lexicalFormTerm(b,c)[f.token])a[i][h]=e}return a};K.AbstractQueryTree.prototype._replaceFilter=function(a,b,e,c){if(a.expressionType!=null){var i=a.expressionType;if(i=="relationalexpression")a.op1=this._replaceFilter(a.op1,b,e,c),a.op2=this._replaceFilter(a.op2,b,e,c);else if(i=="conditionalor"||i=="conditionaland")for(i=0;i<a.operands.length;i++)a.operands[i]=
this._replaceFilter(a.operands[i],b,e,c);else if(i=="additiveexpression"){a.summand=this._replaceFilter(a.summand,b,e,c);for(i=0;i<a.summands.length;i++)a.summands[i].expression=this._replaceFilter(a.summands[i].expression,b,e,c)}else if(i=="builtincall")for(i=0;i<a.args.length;i++)a.args[i]=this._replaceFilter(a.args[i],b,e,c);else if(i=="multiplicativeexpression"){a.factor=this._replaceFilter(a.factor,b,e,c);for(i=0;i<a.factors.length;i++)a.factors[i].expression=this._replaceFilter(a.factors[i].expression,
b,e,c)}else if(i=="unaryexpression")a.expression=this._replaceFilter(a.expression,b,e,c);else if(i=="irireforfunction")for(i=0;i<a.factors.args;i++)a.args[i]=this._replaceFilter(a.args[i],b,e,c);else if(i=="atomic"){c=null;if(a.primaryexpression==b.token&&a.value==b.value)c=e.value;else if(a.primaryexpression=="iri"&&b.token=="uri"&&a.value==b.value)c=e.value;if(c!=null)a.primaryexpression=e.token==="uri"?"iri":e.token,a.value=c}}return a};K.AbstractQueryTree.prototype.treeWithUnion=function(a){if(a==
null)return!1;if(a.kind==null)return!1;if(a.kind==="select")return this.treeWithUnion(a.pattern);else if(a.kind==="BGP")return this.treeWithUnion(a.value);else if(a.kind==="ZERO_OR_MORE_PATH")return!1;else if(a.kind==="UNION")if(console.log("UNION!!"),a.value[0].value!=null&&a.value[0].value.variables!=null&&a.value[1].value!=null&&a.value[1].value.variables!=null){if(console.log("COMPARING:"+a.value[0].variables.join("/")),console.log("VS "+a.values[1].variables.join("/")),a.value[0].variables.join("/")===
a.values[1].variables.join("/"))return this.treeWithUnion(a.value[0])?!0:this.treeWithUnion(a.value[1])}else return!0;else if(a.kind==="GRAPH")return!1;else if(a.kind==="LEFT_JOIN"||a.kind==="JOIN")if(this.treeWithUnion(a.lvalue))return!0;else this.treeWithUnion(a.rvalue);else return!1};var ra={};ra.parser=function(){function a(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,
escape)+'"'}var b={parse:function(e,b){function i(j){d<sa||(d>sa&&(sa=d,ab=[]),ab.push(j))}function h(){var j,a,e,b;k++;b=e=d;j=f();j!==null?(a=t(),a===null&&(a=v(),a===null&&(a=x(),a===null&&(a=A()))),a!==null?j=[j,a]:(j=null,d=b)):(j=null,d=b);j!==null&&(j={token:"query",kind:"query",prologue:j[0],units:[j[1]]});j===null&&(d=e);k--;k===0&&j===null&&i("[2] Query");return j}function f(){var j,a,e,b,c,f;k++;f=c=d;j=g();j=j!==null?j:"";if(j!==null){a=[];for(e=l();e!==null;)a.push(e),e=l();if(a!==null){e=
[];for(b=o();b!==null;)e.push(b),b=o();e!==null?j=[j,a,e]:(j=null,d=f)}else j=null,d=f}else j=null,d=f;j!==null&&(j={token:"prologue",base:j[0],prefixes:j[2]});j===null&&(d=c);k--;k===0&&j===null&&i("[3] Prologue");return j}function g(){var j,a,b,P,c,f;k++;f=c=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(e.substr(d,4)==="BASE"?(a="BASE",d+=4):(a=null,k===0&&i('"BASE"')),a===null&&(e.substr(d,4)==="base"?(a="base",d+=4):(a=null,k===0&&i('"base"'))),a!==null){b=[];for(P=l();P!==null;)b.push(P),
P=l();b!==null?(P=Ba(),P!==null?j=[j,a,b,P]:(j=null,d=f)):(j=null,d=f)}else j=null,d=f;else j=null,d=f;j!==null&&(j=function(j,a){var d={token:"base"};d.value=a;return d}(c,j[3]));j===null&&(d=c);k--;k===0&&j===null&&i("[4] BaseDecl");return j}function o(){var j,a,b,P,c,f,h,g;k++;g=h=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(e.substr(d,6)==="PREFIX"?(a="PREFIX",d+=6):(a=null,k===0&&i('"PREFIX"')),a===null&&(e.substr(d,6)==="prefix"?(a="prefix",d+=6):(a=null,k===0&&i('"prefix"'))),
a!==null){b=[];for(P=l();P!==null;)b.push(P),P=l();if(b!==null)if(P=Ca(),P!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=Ba(),f!==null?j=[j,a,b,P,c,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;else j=null,d=g;j!==null&&(j=function(j,a,d){j={token:"prefix"};j.prefix=a;j.local=d;return j}(h,j[3],j[5]));j===null&&(d=h);k--;k===0&&j===null&&i("[5] PrefixDecl");return j}function t(){var j,a,e,b,c,f,h,g,fa,r,n;k++;n=r=d;j=u();if(j!==null){a=[];for(e=l();e!==
null;)a.push(e),e=l();if(a!==null){e=[];for(b=m();b!==null;)e.push(b),b=m();if(e!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=s(),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=G(),h!==null){g=[];for(fa=l();fa!==null;)g.push(fa),fa=l();g!==null?(fa=L(),fa!==null?j=[j,a,e,b,c,f,h,g,fa]:(j=null,d=n)):(j=null,d=n)}else j=null,d=n;else j=null,d=n}else j=null,d=n;else j=null,d=n}else j=null,d=n}else j=null,d=n}else j=null,d=n;j!==null&&(j=function(j,a,d,e,b){for(var j=
{named:[],implicit:[]},i=0;i<d.length;i++){var T=d[i];T.kind==="default"?j.implicit.push(T.graph):j.named.push(T.graph)}j.named.length===0&&j.implicit.length===0&&j.implicit.push({token:"uri",prefix:null,suffix:null,value:"https://github.com/antoniogarrote/rdfstore-js#default_graph"});d={kind:"select",token:"executableunit"};d.dataset=j;d.projection=a.vars;d.modifier=a.modifier;d.pattern=e;if(b!=null&&b.limit!=null)d.limit=b.limit;if(b!=null&&b.offset!=null)d.offset=b.offset;if(b!=null&&b.order!=
null&&b.order!="")d.order=b.order;if(b!=null&&b.group!=null)d.group=b.group;return d}(r,j[0],j[2],j[4],j[6]));j===null&&(d=r);k--;k===0&&j===null&&i("[6] SelectQuery");return j}function q(){var j,a,e,b;k++;b=d;j=u();j!==null?(a=s(),a!==null?(e=G(),e!==null?j=[j,a,e]:(j=null,d=b)):(j=null,d=b)):(j=null,d=b);k--;k===0&&j===null&&i("[7] SubSelect");return j}function u(){var j,a,b,c,E,f,h,g,m,r,n,s,q,o,t,z,w,G,v,F,y;k++;F=v=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(e.substr(d,6)==="SELECT"?
(a="SELECT",d+=6):(a=null,k===0&&i('"SELECT"')),a===null&&(e.substr(d,6)==="select"?(a="select",d+=6):(a=null,k===0&&i('"select"'))),a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.substr(d,8)==="DISTINCT"?(c="DISTINCT",d+=8):(c=null,k===0&&i('"DISTINCT"')),c===null&&(e.substr(d,8)==="distinct"?(c="distinct",d+=8):(c=null,k===0&&i('"distinct"'))),c===null&&(e.substr(d,7)==="REDUCED"?(c="REDUCED",d+=7):(c=null,k===0&&i('"REDUCED"')),c===null&&(e.substr(d,7)==="reduced"?(c="reduced",
d+=7):(c=null,k===0&&i('"reduced"')))),c=c!==null?c:"",c!==null){E=[];for(f=l();f!==null;)E.push(f),f=l();if(E!==null){y=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(g=M(),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?h=[h,g,m]:(h=null,d=y)}else h=null,d=y;else h=null,d=y;if(h===null){y=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===40?(g="(",d++):(g=null,k===0&&i('"("')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();if(m!==null)if(r=H(),
r!==null){n=[];for(s=l();s!==null;)n.push(s),s=l();if(n!==null)if(e.substr(d,2)==="AS"?(s="AS",d+=2):(s=null,k===0&&i('"AS"')),s===null&&(e.substr(d,2)==="as"?(s="as",d+=2):(s=null,k===0&&i('"as"'))),s!==null){q=[];for(o=l();o!==null;)q.push(o),o=l();if(q!==null)if(o=M(),o!==null){t=[];for(z=l();z!==null;)t.push(z),z=l();if(t!==null)if(e.charCodeAt(d)===41?(z=")",d++):(z=null,k===0&&i('")"')),z!==null){w=[];for(G=l();G!==null;)w.push(G),G=l();w!==null?h=[h,g,m,r,n,s,q,o,t,z,w]:(h=null,d=y)}else h=
null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}if(h!==null)for(f=[];h!==null;){f.push(h);y=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(g=M(),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?h=[h,g,m]:(h=null,d=y)}else h=null,d=y;else h=null,d=y;if(h===null){y=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===40?(g="(",d++):(g=null,k===0&&i('"("')),
g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();if(m!==null)if(r=H(),r!==null){n=[];for(s=l();s!==null;)n.push(s),s=l();if(n!==null)if(e.substr(d,2)==="AS"?(s="AS",d+=2):(s=null,k===0&&i('"AS"')),s===null&&(e.substr(d,2)==="as"?(s="as",d+=2):(s=null,k===0&&i('"as"'))),s!==null){q=[];for(o=l();o!==null;)q.push(o),o=l();if(q!==null)if(o=M(),o!==null){t=[];for(z=l();z!==null;)t.push(z),z=l();if(t!==null)if(e.charCodeAt(d)===41?(z=")",d++):(z=null,k===0&&i('")"')),z!==null){w=[];for(G=l();G!==null;)w.push(G),
G=l();w!==null?h=[h,g,m,r,n,s,q,o,t,z,w]:(h=null,d=y)}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}else h=null,d=y;else h=null,d=y}}else f=null;if(f===null){y=d;f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.charCodeAt(d)===42?(h="*",d++):(h=null,k===0&&i('"*"')),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?f=[f,h,g]:(f=null,d=y)}else f=null,d=y;else f=null,d=y}f!==null?j=[j,a,b,c,E,f]:(j=
null,d=F)}else j=null,d=F}else j=null,d=F;else j=null,d=F}else j=null,d=F;else j=null,d=F;j!==null&&(j=function(j,a,d){j=[];if(d.length===3&&d[1]==="*")return{vars:[{token:"variable",kind:"*"}],modifier:nb(a)};for(var e=0;e<d.length;e++){var b=d[e];b.length===3?j.push({token:"variable",kind:"var",value:b[1]}):j.push({token:"variable",kind:"aliased",expression:b[3],alias:b[7]})}return{vars:j,modifier:nb(a)}}(v,j[3],j[5]));j===null&&(d=v);k--;k===0&&j===null&&i("[8] SelectClause");return j}function v(){var j,
a,b,c,E,f,h,g,r,n,q,o;k++;o=q=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(e.substr(d,9)==="CONSTRUCT"?(a="CONSTRUCT",d+=9):(a=null,k===0&&i('"CONSTRUCT"')),a===null&&(e.substr(d,9)==="construct"?(a="construct",d+=9):(a=null,k===0&&i('"construct"'))),a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=ob(),c!==null){E=[];for(f=l();f!==null;)E.push(f),f=l();if(E!==null){f=[];for(h=m();h!==null;)f.push(h),h=m();if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==
null)if(g=s(),g!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();r!==null?(n=G(),n!==null?j=[j,a,b,c,E,f,h,g,r,n]:(j=null,d=o)):(j=null,d=o)}else j=null,d=o;else j=null,d=o}else j=null,d=o}else j=null,d=o}else j=null,d=o;else j=null,d=o}else j=null,d=o;else j=null,d=o;j!==null&&(j=function(j,a,d,e,b){for(var j={named:[],implicit:[]},i=0;i<d.length;i++){var T=d[i];T.kind==="default"?j.implicit.push(T.graph):j.named.push(T.graph)}j.named.length===0&&j.implicit.length===0&&j.implicit.push({token:"uri",
prefix:null,suffix:null,value:"https://github.com/antoniogarrote/rdfstore-js#default_graph"});d={kind:"construct",token:"executableunit"};d.dataset=j;d.template=a;d.pattern=e;if(b!=null&&b.limit!=null)d.limit=b.limit;if(b!=null&&b.offset!=null)d.offset=b.offset;if(b!=null&&b.order!=null&&b.order!="")d.order=b.order;return d}(q,j[3],j[5],j[7],j[9]));j===null&&(d=q);k--;k===0&&j===null&&i("[9] ConstructQuery");return j}function x(){var j,a,b,c,E,f;k++;f=d;e.substr(d,8)==="DESCRIBE"?(j="DESCRIBE",d+=
8):(j=null,k===0&&i('"DESCRIBE"'));if(j!==null){b=ga();if(b!==null)for(a=[];b!==null;)a.push(b),b=ga();else a=null;a===null&&(e.charCodeAt(d)===42?(a="*",d++):(a=null,k===0&&i('"*"')));if(a!==null){b=[];for(c=m();c!==null;)b.push(c),c=m();b!==null?(c=s(),c=c!==null?c:"",c!==null?(E=G(),E!==null?j=[j,a,b,c,E]:(j=null,d=f)):(j=null,d=f)):(j=null,d=f)}else j=null,d=f}else j=null,d=f;k--;k===0&&j===null&&i("[10] DescribeQuery");return j}function A(){var j,a,b,c,E,f,h,g;k++;g=h=d;j=[];for(a=l();a!==null;)j.push(a),
a=l();if(j!==null)if(e.substr(d,3)==="ASK"?(a="ASK",d+=3):(a=null,k===0&&i('"ASK"')),a===null&&(e.substr(d,3)==="ask"?(a="ask",d+=3):(a=null,k===0&&i('"ask"'))),a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null){c=[];for(E=m();E!==null;)c.push(E),E=m();if(c!==null){E=[];for(f=l();f!==null;)E.push(f),f=l();E!==null?(f=s(),f!==null?j=[j,a,b,c,E,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g}else j=null,d=g}else j=null,d=g;else j=null,d=g;j!==null&&(j=function(j,a,d){for(var j={named:[],
implicit:[]},e=0;e<a.length;e++){var b=a[e];b.kind==="implicit"?j.implicit.push(b.graph):j.named.push(b.graph)}j.named.length===0&&j.implicit.length===0&&j.implicit.push({token:"uri",prefix:null,suffix:null,value:"https://github.com/antoniogarrote/rdfstore-js#default_graph"});a={kind:"ask",token:"executableunit"};a.dataset=j;a.pattern=d;return a}(h,j[3],j[5]));j===null&&(d=h);k--;k===0&&j===null&&i("[11] AskQuery");return j}function m(){var j,a,b,c,E,f,h;k++;h=f=d;e.substr(d,4)==="FROM"?(j="FROM",
d+=4):(j=null,k===0&&i('"FROM"'));j===null&&(e.substr(d,4)==="from"?(j="from",d+=4):(j=null,k===0&&i('"from"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=r(),b===null&&(b=z()),b!==null){c=[];for(E=l();E!==null;)c.push(E),E=l();c!==null?j=[j,a,b,c]:(j=null,d=h)}else j=null,d=h;else j=null,d=h}else j=null,d=h;j!==null&&(j=j[2]);j===null&&(d=f);k--;k===0&&j===null&&i("[12] DatasetClause");return j}function r(){var j,a,e,b;k++;b=e=d;j=[];for(a=l();a!==null;)j.push(a),a=l();
j!==null?(a=N(),a!==null?j=[j,a]:(j=null,d=b)):(j=null,d=b);j!==null&&(j={graph:j[1],kind:"default",token:"graphClause"});j===null&&(d=e);k--;k===0&&j===null&&i("[13] DefaultGraphClause");return j}function z(){var j,a,b,c,E;k++;E=c=d;e.substr(d,5)==="NAMED"?(j="NAMED",d+=5):(j=null,k===0&&i('"NAMED"'));j===null&&(e.substr(d,5)==="named"?(j="named",d+=5):(j=null,k===0&&i('"named"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();a!==null?(b=N(),b!==null?j=[j,a,b]:(j=null,d=E)):(j=null,d=E)}else j=
null,d=E;j!==null&&(j={graph:j[2],kind:"named",token:"graphCluase"});j===null&&(d=c);k--;k===0&&j===null&&i("[14] NamedGraphClause");return j}function s(){var j,a,b,c,E,f,h;k++;h=f=d;e.substr(d,5)==="WHERE"?(j="WHERE",d+=5):(j=null,k===0&&i('"WHERE"'));j===null&&(e.substr(d,5)==="where"?(j="where",d+=5):(j=null,k===0&&i('"where"')));j=j!==null?j:"";if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=S(),b!==null){c=[];for(E=l();E!==null;)c.push(E),E=l();c!==null?j=[j,a,b,c]:(j=
null,d=h)}else j=null,d=h;else j=null,d=h}else j=null,d=h;j!==null&&(j=j[2]);j===null&&(d=f);k--;k===0&&j===null&&i("[16] WhereClause");return j}function G(){var j,a,b,e,c,f;k++;f=c=d;j=U();j=j!==null?j:"";j!==null?(a=B(),a=a!==null?a:"",a!==null?(b=D(),b=b!==null?b:"",b!==null?(e=I(),e=e!==null?e:"",e!==null?j=[j,a,b,e]:(j=null,d=f)):(j=null,d=f)):(j=null,d=f)):(j=null,d=f);j!==null&&(j=function(j,a,d,b){j={};if(b!=null){if(b.limit!=null)j.limit=b.limit;if(b.offset!=null)j.offset=b.offset}if(a!=
null)j.group=a;j.order=d;return j}(c,j[0],j[2],j[3]));j===null&&(d=c);k--;k===0&&j===null&&i("[17] SolutionModifier");return j}function U(){var j,a,b,c,E,f,h,g;k++;g=h=d;e.substr(d,5)==="GROUP"?(j="GROUP",d+=5):(j=null,k===0&&i('"GROUP"'));j===null&&(e.substr(d,5)==="group"?(j="group",d+=5):(j=null,k===0&&i('"group"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,2)==="BY"?(b="BY",d+=2):(b=null,k===0&&i('"BY"')),b===null&&(e.substr(d,2)==="by"?(b="by",d+=2):(b=
null,k===0&&i('"by"'))),b!==null){c=[];for(E=l();E!==null;)c.push(E),E=l();if(c!==null){f=y();if(f!==null)for(E=[];f!==null;)E.push(f),f=y();else E=null;E!==null?j=[j,a,b,c,E]:(j=null,d=g)}else j=null,d=g}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j=j[4]);j===null&&(d=h);k--;k===0&&j===null&&i("[18] GroupClause");return j}function y(){var j,a,b,c,f,h,g,m,r,n,s,o;k++;o=s=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(a=Da(),a!==null){b=[];for(c=l();c!==null;)b.push(c),c=
l();b!==null?j=[j,a,b]:(j=null,d=o)}else j=null,d=o;else j=null,d=o;j!==null&&(j=j[1]);j===null&&(d=s);if(j===null){o=s=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(a=bb(),a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?j=[j,a,b]:(j=null,d=o)}else j=null,d=o;else j=null,d=o;j!==null&&(j=j[1]);j===null&&(d=s);if(j===null){o=s=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(e.charCodeAt(d)===40?(a="(",d++):(a=null,k===0&&i('"("')),a!==null){b=[];for(c=l();c!==null;)b.push(c),
c=l();if(b!==null)if(c=H(),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null){r=d;e.substr(d,2)==="AS"?(h="AS",d+=2):(h=null,k===0&&i('"AS"'));h===null&&(e.substr(d,2)==="as"?(h="as",d+=2):(h=null,k===0&&i('"as"')));if(h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=M(),m!==null?h=[h,g,m]:(h=null,d=r)):(h=null,d=r)}else h=null,d=r;h=h!==null?h:"";if(h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),
m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();r!==null?j=[j,a,b,c,f,h,g,m,r]:(j=null,d=o)}else j=null,d=o;else j=null,d=o}else j=null,d=o}else j=null,d=o}else j=null,d=o;else j=null,d=o}else j=null,d=o;else j=null,d=o;j!==null&&(j=j[5].length!=0?{token:"aliased_expression",expression:j[3],alias:j[5][2]}:j[3]);j===null&&(d=s);if(j===null){o=s=d;j=[];for(a=l();a!==null;)j.push(a),a=l();if(j!==null)if(a=M(),a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?j=[j,a,b]:(j=null,d=o)}else j=
null,d=o;else j=null,d=o;j!==null&&(j=j[1]);j===null&&(d=s)}}}k--;k===0&&j===null&&i("[19] GroupCondition");return j}function B(){var j,a,b,c;k++;c=d;e.substr(d,6)==="HAVING"?(j="HAVING",d+=6):(j=null,k===0&&i('"HAVING"'));if(j!==null){b=ta();if(b!==null)for(a=[];b!==null;)a.push(b),b=ta();else a=null;a!==null?j=[j,a]:(j=null,d=c)}else j=null,d=c;k--;k===0&&j===null&&i("[20] HavingClause");return j}function D(){var j,a,b,c,f,h,g,m,r;k++;r=m=d;e.substr(d,5)==="ORDER"?(j="ORDER",d+=5):(j=null,k===0&&
i('"ORDER"'));j===null&&(e.substr(d,5)==="order"?(j="order",d+=5):(j=null,k===0&&i('"order"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,2)==="BY"?(b="BY",d+=2):(b=null,k===0&&i('"BY"')),b===null&&(e.substr(d,2)==="by"?(b="by",d+=2):(b=null,k===0&&i('"by"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null){h=C();if(h!==null)for(f=[];h!==null;)f.push(h),h=C();else f=null;if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?j=[j,a,b,c,
f,h]:(j=null,d=r)}else j=null,d=r}else j=null,d=r}else j=null,d=r;else j=null,d=r}else j=null,d=r;j!==null&&(j=j[4]);j===null&&(d=m);k--;k===0&&j===null&&i("[22] OrderClause");return j}function C(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,3)==="ASC"?(j="ASC",d+=3):(j=null,k===0&&i('"ASC"'));j===null&&(e.substr(d,3)==="asc"?(j="asc",d+=3):(j=null,k===0&&i('"asc"')),j===null&&(e.substr(d,4)==="DESC"?(j="DESC",d+=4):(j=null,k===0&&i('"DESC"')),j===null&&(e.substr(d,4)==="desc"?(j="desc",d+=4):(j=null,
k===0&&i('"desc"')))));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ea(),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?j=[j,a,b,c]:(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j={direction:j[0].toUpperCase(),expression:j[2]});j===null&&(d=h);if(j===null){g=h=d;j=ta();j===null&&(j=M());if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();a!==null?j=[j,a]:(j=null,d=g)}else j=null,d=g;j!==null&&(j=function(j,a){a.token==="var"&&(a={token:"expression",
expressionType:"atomic",primaryexpression:"var",value:a});return{direction:"ASC",expression:a}}(h,j[0]));j===null&&(d=h)}k--;k===0&&j===null&&i("[23] OrderCondition");return j}function I(){var j,a,b,e;k++;e=b=d;j=J();j!==null?(a=K(),a=a!==null?a:"",a!==null?j=[j,a]:(j=null,d=e)):(j=null,d=e);j===null&&(e=d,j=K(),j!==null?(a=J(),a=a!==null?a:"",a!==null?j=[j,a]:(j=null,d=e)):(j=null,d=e));j!==null&&(j=function(j,a){for(var d={},b=0;b<a.length;b++){var e=a[b];if(e.limit!=null)d.limit=e.limit;else if(e.offset!=
null)d.offset=e.offset}return d}(b,j));j===null&&(d=b);k--;k===0&&j===null&&i("[24] LimitOffsetClauses");return j}function J(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,5)==="LIMIT"?(j="LIMIT",d+=5):(j=null,k===0&&i('"LIMIT"'));j===null&&(e.substr(d,5)==="limit"?(j="limit",d+=5):(j=null,k===0&&i('"limit"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=$(),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?j=[j,a,b,c]:(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=
null,d=g;j!==null&&(j={limit:parseInt(j[2].value)});j===null&&(d=h);k--;k===0&&j===null&&i("[25] LimitClause");return j}function K(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,6)==="OFFSET"?(j="OFFSET",d+=6):(j=null,k===0&&i('"OFFSET"'));j===null&&(e.substr(d,6)==="offset"?(j="offset",d+=6):(j=null,k===0&&i('"offset"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=$(),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?j=[j,a,b,c]:(j=null,d=g)}else j=null,d=g;else j=
null,d=g}else j=null,d=g;j!==null&&(j={offset:parseInt(j[2].value)});j===null&&(d=h);k--;k===0&&j===null&&i("[26] OffsetClause");return j}function L(){var j,a,b,c,f,h,g,l,m;k++;l=d;e.substr(d,8)==="BINDINGS"?(j="BINDINGS",d+=8):(j=null,k===0&&i('"BINDINGS"'));if(j!==null){a=[];for(b=M();b!==null;)a.push(b),b=M();if(a!==null)if(e.charCodeAt(d)===123?(b="{",d++):(b=null,k===0&&i('"{"')),b!==null){c=[];m=d;e.charCodeAt(d)===40?(f="(",d++):(f=null,k===0&&i('"("'));if(f!==null){g=O();if(g!==null)for(h=
[];g!==null;)h.push(g),g=O();else h=null;h!==null?(e.charCodeAt(d)===41?(g=")",d++):(g=null,k===0&&i('")"')),g!==null?f=[f,h,g]:(f=null,d=m)):(f=null,d=m)}else f=null,d=m;for(f===null&&(f=ha());f!==null;){c.push(f);m=d;e.charCodeAt(d)===40?(f="(",d++):(f=null,k===0&&i('"("'));if(f!==null){g=O();if(g!==null)for(h=[];g!==null;)h.push(g),g=O();else h=null;h!==null?(e.charCodeAt(d)===41?(g=")",d++):(g=null,k===0&&i('")"')),g!==null?f=[f,h,g]:(f=null,d=m)):(f=null,d=m)}else f=null,d=m;f===null&&(f=ha())}c!==
null?(e.charCodeAt(d)===125?(f="}",d++):(f=null,k===0&&i('"}"')),f!==null?j=[j,a,b,c,f]:(j=null,d=l)):(j=null,d=l)}else j=null,d=l;else j=null,d=l}else j=null,d=l;j=j!==null?j:"";k--;k===0&&j===null&&i("[27] BindingsClause");return j}function O(){var j;k++;j=N();j===null&&(j=Fa(),j===null&&(j=Ga(),j===null&&(j=Ha(),j===null&&(e.substr(d,5)==="UNDEF"?(j="UNDEF",d+=5):(j=null,k===0&&i('"UNDEF"'))))));k--;k===0&&j===null&&i("[28] BindingValue");return j}function R(){var j,a,b,c,h,g,m,r,n,s;k++;n=r=d;
j=f();if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=W(),b!==null){s=d;c=[];for(h=l();h!==null;)c.push(h),h=l();if(c!==null)if(e.charCodeAt(d)===59?(h=";",d++):(h=null,k===0&&i('";"')),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=R(),m=m!==null?m:"",m!==null?c=[c,h,g,m]:(c=null,d=s)):(c=null,d=s)}else c=null,d=s;else c=null,d=s;c=c!==null?c:"";c!==null?j=[j,a,b,c]:(j=null,d=n)}else j=null,d=n;else j=null,d=n}else j=null,d=n;j!==null&&(j=function(j,a,d,b){j=
{token:"query",kind:"update"};j.prologue=a;a=[d];b.length!=null&&b[3]!=null&&b[3].units!=null&&(a=a.concat(b[3].units));j.units=a;return j}(r,j[0],j[2],j[3]));j===null&&(d=r);k--;k===0&&j===null&&i("[30] Update");return j}function W(){var j;k++;j=X();j===null&&(j=Z(),j===null&&(j=da(),j===null&&(j=ja(),j===null&&(j=ka(),j===null&&(j=qa(),j===null&&(j=ra(),j===null&&(j=za())))))));k--;k===0&&j===null&&i("[31] Update1");return j}function X(){var j,a,b,c,f,h,g,m,r,n;k++;r=m=d;e.substr(d,4)==="LOAD"?
(j="LOAD",d+=4):(j=null,k===0&&i('"LOAD"'));j===null&&(e.substr(d,4)==="load"?(j="load",d+=4):(j=null,k===0&&i('"load"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=N(),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null){n=d;e.substr(d,4)==="INTO"?(f="INTO",d+=4):(f=null,k===0&&i('"INTO"'));f===null&&(e.substr(d,4)==="into"?(f="into",d+=4):(f=null,k===0&&i('"into"')));if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Aa(),g!==null?f=[f,h,g]:
(f=null,d=n)):(f=null,d=n)}else f=null,d=n;f=f!==null?f:"";f!==null?j=[j,a,b,c,f]:(j=null,d=r)}else j=null,d=r}else j=null,d=r;else j=null,d=r}else j=null,d=r;j!==null&&(j=function(j,a,d){j={kind:"load",token:"executableunit"};j.sourceGraph=a;j.destinyGraph=d[2];return j}(m,j[2],j[4]));j===null&&(d=m);k--;k===0&&j===null&&i("[32] Load");return j}function Z(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,5)==="CLEAR"?(j="CLEAR",d+=5):(j=null,k===0&&i('"CLEAR"'));j===null&&(e.substr(d,5)==="clear"?(j="clear",
d+=5):(j=null,k===0&&i('"clear"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,6)==="SILENT"?(b="SILENT",d+=6):(b=null,k===0&&i('"SILENT"')),b===null&&(e.substr(d,6)==="silent"?(b="silent",d+=6):(b=null,k===0&&i('"silent"'))),b=b!==null?b:"",b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=Ya(),f!==null?j=[j,a,b,c,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j=function(j,a){var d={kind:"clear",token:"executableunit"};
d.destinyGraph=a;return d}(h,j[4]));j===null&&(d=h);k--;k===0&&j===null&&i("[33] Clear");return j}function da(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,4)==="DROP"?(j="DROP",d+=4):(j=null,k===0&&i('"DROP"'));j===null&&(e.substr(d,4)==="drop"?(j="drop",d+=4):(j=null,k===0&&i('"drop"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,6)==="SILENT"?(b="SILENT",d+=6):(b=null,k===0&&i('"SILENT"')),b===null&&(e.substr(d,6)==="silent"?(b="silent",d+=6):(b=null,k===0&&i('"silent"'))),
b=b!==null?b:"",b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=Ya(),f!==null?j=[j,a,b,c,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j=function(j,a){var d={kind:"drop",token:"executableunit"};d.destinyGraph=a;return d}(h,j[4]));j===null&&(d=h);k--;k===0&&j===null&&i("[34] Drop");return j}function ja(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,6)==="CREATE"?(j="CREATE",d+=6):(j=null,k===0&&i('"CREATE"'));j===null&&(e.substr(d,6)==="create"?(j=
"create",d+=6):(j=null,k===0&&i('"create"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,6)==="SILENT"?(b="SILENT",d+=6):(b=null,k===0&&i('"SILENT"')),b===null&&(e.substr(d,6)==="silent"?(b="silent",d+=6):(b=null,k===0&&i('"silent"'))),b=b!==null?b:"",b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=Aa(),f!==null?j=[j,a,b,c,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j=function(j,a){var d={kind:"create",
token:"executableunit"};d.destinyGraph=a;return d}(h,j[4]));j===null&&(d=h);k--;k===0&&j===null&&i("[35] Create");return j}function ka(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,6)==="INSERT"?(j="INSERT",d+=6):(j=null,k===0&&i('"INSERT"'));j===null&&(e.substr(d,6)==="insert"?(j="insert",d+=6):(j=null,k===0&&i('"insert"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,4)==="DATA"?(b="DATA",d+=4):(b=null,k===0&&i('"DATA"')),b===null&&(e.substr(d,4)==="data"?(b="data",
d+=4):(b=null,k===0&&i('"data"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=Va(),f!==null?j=[j,a,b,c,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j=function(j,a){var d={kind:"insertdata",token:"executableunit"};d.quads=a;return d}(h,j[4]));j===null&&(d=h);k--;k===0&&j===null&&i("[36] InsertData");return j}function qa(){var j,a,b,c,f,h;k++;h=f=d;e.substr(d,6)==="DELETE"?(j="DELETE",d+=6):(j=null,k===0&&i('"DELETE"'));j===null&&(e.substr(d,
6)==="delete"?(j="delete",d+=6):(j=null,k===0&&i('"delete"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();a!==null?(e.substr(d,4)==="DATA"?(b="DATA",d+=4):(b=null,k===0&&i('"DATA"')),b===null&&(e.substr(d,4)==="data"?(b="data",d+=4):(b=null,k===0&&i('"data"'))),b!==null?(c=Va(),c!==null?j=[j,a,b,c]:(j=null,d=h)):(j=null,d=h)):(j=null,d=h)}else j=null,d=h;j!==null&&(j=function(j,a){var d={kind:"deletedata",token:"executableunit"};d.quads=a;return d}(f,j[3]));j===null&&(d=f);k--;k===0&&j===
null&&i("[37] DeleteData");return j}function ra(){var j,a,b,c,f,h,g;k++;g=h=d;e.substr(d,6)==="DELETE"?(j="DELETE",d+=6):(j=null,k===0&&i('"DELETE"'));j===null&&(e.substr(d,6)==="delete"?(j="delete",d+=6):(j=null,k===0&&i('"delete"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,5)==="WHERE"?(b="WHERE",d+=5):(b=null,k===0&&i('"WHERE"')),b===null&&(e.substr(d,5)==="where"?(b="where",d+=5):(b=null,k===0&&i('"where"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),
f=l();c!==null?(f=S(),f!==null?j=[j,a,b,c,f]:(j=null,d=g)):(j=null,d=g)}else j=null,d=g;else j=null,d=g}else j=null,d=g;j!==null&&(j=function(j,a){var d={kind:"modify"};d.pattern=a;d["with"]=null;d.using=null;for(var b=[],e=a.patterns[0],e=e.triplesContext==null&&e.patterns!=null?e.patterns[0].triplesContext:e.triplesContext,i=0;i<e.length;i++){var c={},T=e[i];c.subject=T.subject;c.predicate=T.predicate;c.object=T.object;c.graph=T.graph;b.push(c)}d["delete"]=b;return d}(h,j[4]));j===null&&(d=h);k--;
k===0&&j===null&&i("[38] DeleteWhere");return j}function za(){var j,a,b,c,f,h,g,m,r,n,s,o,q;k++;h=q=o=d;e.substr(d,4)==="WITH"?(j="WITH",d+=4):(j=null,k===0&&i('"WITH"'));j===null&&(e.substr(d,4)==="with"?(j="with",d+=4):(j=null,k===0&&i('"with"')));if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();a!==null?(b=N(),b!==null?j=[j,a,b]:(j=null,d=h)):(j=null,d=h)}else j=null,d=h;j=j!==null?j:"";if(j!==null){a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null){h=d;b=mb();if(b!==null){c=[];for(f=l();f!==
null;)c.push(f),f=l();c!==null?(f=Wa(),f=f!==null?f:"",f!==null?b=[b,c,f]:(b=null,d=h)):(b=null,d=h)}else b=null,d=h;b===null&&(b=Wa());if(b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null){f=[];for(h=Xa();h!==null;)f.push(h),h=Xa();if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.substr(d,5)==="WHERE"?(g="WHERE",d+=5):(g=null,k===0&&i('"WHERE"')),g===null&&(e.substr(d,5)==="where"?(g="where",d+=5):(g=null,k===0&&i('"where"'))),g!==null){m=[];for(r=l();r!==null;)m.push(r),
r=l();if(m!==null)if(r=S(),r!==null){n=[];for(s=l();s!==null;)n.push(s),s=l();n!==null?j=[j,a,b,c,f,h,g,m,r,n]:(j=null,d=q)}else j=null,d=q;else j=null,d=q}else j=null,d=q;else j=null,d=q}else j=null,d=q}else j=null,d=q}else j=null,d=q}else j=null,d=q}else j=null,d=q;j!==null&&(j=function(a,j,d,b,e){a={kind:"modify"};a["with"]=j!=""?j[2]:null;d.length===3&&d[2]===""?(a["delete"]=d[0],a.insert=null):d.length===3&&d[0].length!=null&&d[1].length!=null&&d[2].length!=null?(a["delete"]=d[0],a.insert=d[2]):
(a.insert=d,a["delete"]=null);b!=""&&(a.using=b);a.pattern=e;return a}(o,j[0],j[2],j[4],j[8]));j===null&&(d=o);k--;k===0&&j===null&&i("[39] Modify");return j}function mb(){var a,b,c,f;k++;f=c=d;e.substr(d,6)==="DELETE"?(a="DELETE",d+=6):(a=null,k===0&&i('"DELETE"'));a===null&&(e.substr(d,6)==="delete"?(a="delete",d+=6):(a=null,k===0&&i('"delete"')));a!==null?(b=Ua(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=a[1]);a===null&&(d=c);k--;k===0&&a===null&&i("[40] DeleteClause");return a}
function Wa(){var a,b,c,f;k++;f=c=d;e.substr(d,6)==="INSERT"?(a="INSERT",d+=6):(a=null,k===0&&i('"INSERT"'));a===null&&(e.substr(d,6)==="insert"?(a="insert",d+=6):(a=null,k===0&&i('"insert"')));a!==null?(b=Ua(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=a[1]);a===null&&(d=c);k--;k===0&&a===null&&i("[41] InsertClause");return a}function Xa(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,5)==="USING"?(b="USING",d+=5):(b=null,k===0&&
i('"USING"')),b===null&&(e.substr(d,5)==="using"?(b="using",d+=5):(b=null,k===0&&i('"using"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null){f=N();if(f===null)if(n=d,e.substr(d,5)==="NAMED"?(f="NAMED",d+=5):(f=null,k===0&&i('"NAMED"')),f===null&&(e.substr(d,5)==="named"?(f="named",d+=5):(f=null,k===0&&i('"named"'))),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=N(),g!==null?f=[f,h,g]:(f=null,d=n)):(f=null,d=n)}else f=null,d=n;f!==null?a=[a,b,c,f]:(a=null,d=r)}else a=
null,d=r}else a=null,d=r;else a=null,d=r;a!==null&&(a=a[3].length!=null?{kind:"named",uri:a[3][2]}:{kind:"default",uri:a[3]});a===null&&(d=m);k--;k===0&&a===null&&i("[42] UsingClause");return a}function Aa(){var a,b,c,f,h;k++;h=f=d;e.substr(d,5)==="GRAPH"?(a="GRAPH",d+=5):(a=null,k===0&&i('"GRAPH"'));a===null&&(e.substr(d,5)==="graph"?(a="graph",d+=5):(a=null,k===0&&i('"graph"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(c=N(),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=
null,d=h;a!==null&&(a=a[2]);a===null&&(d=f);k--;k===0&&a===null&&i("[43] GraphRef");return a}function Ya(){var a,b;k++;b=d;a=Aa();a===null&&(d=b);a===null&&(b=d,e.substr(d,7)==="DEFAULT"?(a="DEFAULT",d+=7):(a=null,k===0&&i('"DEFAULT"')),a===null&&(e.substr(d,7)==="default"?(a="default",d+=7):(a=null,k===0&&i('"default"'))),a!==null&&(a="default"),a===null&&(d=b),a===null&&(b=d,e.substr(d,5)==="NAMED"?(a="NAMED",d+=5):(a=null,k===0&&i('"NAMED"')),a===null&&(e.substr(d,5)==="named"?(a="named",d+=5):
(a=null,k===0&&i('"named"'))),a!==null&&(a="named"),a===null&&(d=b),a===null&&(b=d,e.substr(d,3)==="ALL"?(a="ALL",d+=3):(a=null,k===0&&i('"ALL"')),a===null&&(e.substr(d,3)==="all"?(a="all",d+=3):(a=null,k===0&&i('"all"'))),a!==null&&(a="all"),a===null&&(d=b))));k--;k===0&&a===null&&i("[44] GraphRefAll");return a}function Ua(){var a,b,c,f,h,g,m,r,n,s;k++;s=n=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.charCodeAt(d)===123?(b="{",d++):(b=null,k===0&&i('"{"')),b!==null){c=[];for(f=l();f!==
null;)c.push(f),f=l();if(c!==null)if(f=Za(),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===125?(g="}",d++):(g=null,k===0&&i('"}"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=s)}else a=null,d=s;else a=null,d=s}else a=null,d=s;else a=null,d=s}else a=null,d=s;else a=null,d=s;a!==null&&(a=a[3].quadsContext);a===null&&(d=n);k--;k===0&&a===null&&i("[45] QuadPattern");return a}function Va(){var a,b,c,f,h,g,m,r,n,s;k++;s=n=
d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.charCodeAt(d)===123?(b="{",d++):(b=null,k===0&&i('"{"')),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(f=Za(),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===125?(g="}",d++):(g=null,k===0&&i('"}"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=s)}else a=null,d=s;else a=null,d=s}else a=null,d=s;else a=null,d=s}else a=null,d=s;else a=null,d=s;
a!==null&&(a=a[3].quadsContext);a===null&&(d=n);k--;k===0&&a===null&&i("[46] QuadData");return a}function Za(){var a,b,c,f,h,g,l,m;k++;l=g=d;a=la();a=a!==null?a:"";if(a!==null){b=[];m=d;c=$a();c!==null?(e.charCodeAt(d)===46?(f=".",d++):(f=null,k===0&&i('"."')),f=f!==null?f:"",f!==null?(h=la(),h=h!==null?h:"",h!==null?c=[c,f,h]:(c=null,d=m)):(c=null,d=m)):(c=null,d=m);for(;c!==null;)b.push(c),m=d,c=$a(),c!==null?(e.charCodeAt(d)===46?(f=".",d++):(f=null,k===0&&i('"."')),f=f!==null?f:"",f!==null?(h=
la(),h=h!==null?h:"",h!==null?c=[c,f,h]:(c=null,d=m)):(c=null,d=m)):(c=null,d=m);b!==null?a=[a,b]:(a=null,d=l)}else a=null,d=l;a!==null&&(a=function(a,j,b){a=[];if(j.triplesContext!=null&&j.triplesContext!=null)for(var d=0;d<j.triplesContext.length;d++){var e=j.triplesContext[d];e.graph=null;a.push(e)}if(b&&b.length>0&&b[0].length>0&&(a=a.concat(b[0][0].quadsContext),b[0][2]!=null&&b[0][2].triplesContext!=null))for(d=0;d<b[0][2].triplesContext.length;d++)e=b[0][2].triplesContext[d],e.graph=null,a.push(e);
return{token:"quads",quadsContext:a}}(g,a[0],a[1]));a===null&&(d=g);k--;k===0&&a===null&&i("[47] Quads");return a}function $a(){var a,b,c,f,h,g,m,r,n,s,o,q,t,z;k++;z=t=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,5)==="GRAPH"?(b="GRAPH",d+=5):(b=null,k===0&&i('"GRAPH"')),b===null&&(e.substr(d,5)==="graph"?(b="graph",d+=5):(b=null,k===0&&i('"graph"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(f=ga(),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();
if(h!==null)if(e.charCodeAt(d)===123?(g="{",d++):(g=null,k===0&&i('"{"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();if(m!==null)if(r=la(),r=r!==null?r:"",r!==null){n=[];for(s=l();s!==null;)n.push(s),s=l();if(n!==null)if(e.charCodeAt(d)===125?(s="}",d++):(s=null,k===0&&i('"}"')),s!==null){o=[];for(q=l();q!==null;)o.push(q),q=l();o!==null?a=[a,b,c,f,h,g,m,r,n,s,o]:(a=null,d=z)}else a=null,d=z;else a=null,d=z}else a=null,d=z;else a=null,d=z}else a=null,d=z;else a=null,d=z}else a=null,d=z;else a=
null,d=z}else a=null,d=z;else a=null,d=z;a!==null&&(a=function(a,j,b){for(var a=[],d=0;d<b.triplesContext.length;d++){var e=b.triplesContext[d];e.graph=j;a.push(e)}return{token:"quadsnottriples",quadsContext:a}}(t,a[3],a[7]));a===null&&(d=t);k--;k===0&&a===null&&i("[48] QuadsNotTriples");return a}function la(){var a,b,c,f,h,g,m,r;k++;m=g=d;a=cb();if(a!==null){r=d;b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===46?(c=".",d++):(c=null,k===0&&i('"."')),c!==null){f=[];for(h=
l();h!==null;)f.push(h),h=l();f!==null?(h=la(),h=h!==null?h:"",h!==null?b=[b,c,f,h]:(b=null,d=r)):(b=null,d=r)}else b=null,d=r;else b=null,d=r;b=b!==null?b:"";b!==null?a=[a,b]:(a=null,d=m)}else a=null,d=m;a!==null&&(a=function(a,j,b){a=j.triplesContext;typeof b==="object"&&b.length!=null&&b[3].triplesContext!=null&&(a=a.concat(b[3].triplesContext));return{token:"triplestemplate",triplesContext:a}}(g,a[0],a[1]));a===null&&(d=g);k--;k===0&&a===null&&i("[49] TriplesTemplate");return a}function S(){var a,
b,c,f,h,g,m;k++;m=g=d;e.charCodeAt(d)===123?(a="{",d++):(a=null,k===0&&i('"{"'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=q(),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();f!==null?(e.charCodeAt(d)===125?(h="}",d++):(h=null,k===0&&i('"}"')),h!==null?a=[a,b,c,f,h]:(a=null,d=m)):(a=null,d=m)}else a=null,d=m;else a=null,d=m}else a=null,d=m;a!==null&&(a=a[2]);a===null&&(d=g);if(a===null){m=g=d;e.charCodeAt(d)===123?(a="{",d++):(a=null,k===0&&i('"{"'));if(a!==null){b=
[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=pb(),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();f!==null?(e.charCodeAt(d)===125?(h="}",d++):(h=null,k===0&&i('"}"')),h!==null?a=[a,b,c,f,h]:(a=null,d=m)):(a=null,d=m)}else a=null,d=m;else a=null,d=m}else a=null,d=m;a!==null&&(a=a[2]);a===null&&(d=g)}k--;k===0&&a===null&&i("[50] GroupGraphPattern");return a}function pb(){var a,b,c,f,h,g,m,r,n,s,o;k++;s=n=d;a=ua();a=a!==null?a:"";if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==
null){c=[];o=d;f=db();if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===46?(g=".",d++):(g=null,k===0&&i('"."')),g=g!==null?g:"",g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?(r=ua(),r=r!==null?r:"",r!==null?f=[f,h,g,m,r]:(f=null,d=o)):(f=null,d=o)}else f=null,d=o;else f=null,d=o}else f=null,d=o;for(;f!==null;)if(c.push(f),o=d,f=db(),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===46?(g=".",d++):(g=null,k===0&&i('"."')),
g=g!==null?g:"",g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?(r=ua(),r=r!==null?r:"",r!==null?f=[f,h,g,m,r]:(f=null,d=o)):(f=null,d=o)}else f=null,d=o;else f=null,d=o}else f=null,d=o;c!==null?a=[a,b,c]:(a=null,d=s)}else a=null,d=s}else a=null,d=s;a!==null&&(a=function(a,j,b){a=[];j!=null&&j!=[]&&a.push(j);for(j=0;j<b.length;j++)for(var d=0;d<b[j].length;d++)b[j][d].token!=null&&a.push(b[j][d]);for(var b=[],e=[],i=[],j=0;j<a.length;j++)if(a[j].token!="triplespattern"&&a[j].token!="filter"){if(e.length!=
0||i.length!=0){for(var c=[],d=0;d<e.length;d++)c=c.concat(e[d].triplesContext);c.length>0&&b.push({token:"basicgraphpattern",triplesContext:c});e=[]}b.push(a[j])}else a[j].token==="triplespattern"?e.push(a[j]):i.push(a[j]);if(e.length!=0||i.length!=0){c=[];for(d=0;d<e.length;d++)c=c.concat(e[d].triplesContext);c.length>0&&b.push({token:"basicgraphpattern",triplesContext:c})}return{token:"groupgraphpattern",patterns:b,filters:i}}(n,a[0],a[2]));a===null&&(d=n);k--;k===0&&a===null&&i("[51] GroupGraphPatternSub");
return a}function ua(){var a,b,c,f,h,g,m;k++;g=h=d;a=qb();if(a!==null){m=d;b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(e.charCodeAt(d)===46?(c=".",d++):(c=null,k===0&&i('"."')),c!==null?(f=ua(),f=f!==null?f:"",f!==null?b=[b,c,f]:(b=null,d=m)):(b=null,d=m)):(b=null,d=m);b=b!==null?b:"";b!==null?a=[a,b]:(a=null,d=g)}else a=null,d=g;a!==null&&(a=function(a,j,b){a=j.triplesContext;typeof b==="object"&&b.length!=null&&b[2].triplesContext!=null&&(a=a.concat(b[2].triplesContext));return{token:"triplespattern",
triplesContext:a}}(h,a[0],a[1]));a===null&&(d=h);k--;k===0&&a===null&&i("[54] TriplesBlock");return a}function db(){var a;k++;a=rb();a===null&&(a=sb(),a===null&&(a=tb(),a===null&&(a=ub(),a===null&&(a=vb(),a===null&&(a=wb())))));k--;k===0&&a===null&&i("[53] GraphPatternNotTriples");return a}function sb(){var a,b,c,f,h,g;k++;g=h=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,8)==="OPTIONAL"?(b="OPTIONAL",d+=8):(b=null,k===0&&i('"OPTIONAL"')),b===null&&(e.substr(d,8)==="optional"?
(b="optional",d+=8):(b=null,k===0&&i('"optional"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=S(),f!==null?a=[a,b,c,f]:(a=null,d=g)):(a=null,d=g)}else a=null,d=g;else a=null,d=g;a!==null&&(a={token:"optionalgraphpattern",value:a[3]});a===null&&(d=h);k--;k===0&&a===null&&i("[54] OptionalGraphPattern");return a}function ub(){var a,b,c,f,h,g,m,r;k++;r=m=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.substr(d,5)==="GRAPH"?(b="GRAPH",d+=5):(b=null,k===0&&i('"GRAPH"')),
b===null&&(e.substr(d,5)==="graph"?(b="graph",d+=5):(b=null,k===0&&i('"graph"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(f=ga(),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=S(),g!==null?a=[a,b,c,f,h,g]:(a=null,d=r)):(a=null,d=r)}else a=null,d=r;else a=null,d=r}else a=null,d=r;else a=null,d=r;a!==null&&(a=function(a,j,b){for(a=0;a<b.patterns.length;a++)for(var d=b.patterns[a],e=0;e<d.triplesContext.length;e++)d.triplesContext[e].graph=j;b.token="groupgraphpattern";
return b}(m,a[3],a[5]));a===null&&(d=m);k--;k===0&&a===null&&i("[55] GraphGraphPattern");return a}function vb(){var a,b,c,f,h;k++;h=f=d;e.substr(d,7)==="SERVICE"?(a="SERVICE",d+=7):(a=null,k===0&&i('"SERVICE"'));a!==null?(b=ga(),b!==null?(c=S(),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)):(a=null,d=h);a!==null&&(a={token:"servicegraphpattern",status:"todo",value:[a[1],a[2]]});a===null&&(d=f);k--;k===0&&a===null&&i("[56] ServiceGraphPattern");return a}function tb(){var a,b,c,f;k++;f=c=d;e.substr(d,
5)==="MINUS"?(a="MINUS",d+=5):(a=null,k===0&&i('"MINUS"'));a!==null?(b=S(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a={token:"minusgraphpattern",status:"todo",value:a[1]});a===null&&(d=c);k--;k===0&&a===null&&i("[57] MinusGraphPattern");return a}function rb(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;a=S();if(a!==null){b=[];n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,5)==="UNION"?(f="UNION",d+=5):(f=null,k===0&&i('"UNION"')),f===null&&(e.substr(d,5)==="union"?(f="union",
d+=5):(f=null,k===0&&i('"union"'))),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=S(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;for(;c!==null;){b.push(c);n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,5)==="UNION"?(f="UNION",d+=5):(f=null,k===0&&i('"UNION"')),f===null&&(e.substr(d,5)==="union"?(f="union",d+=5):(f=null,k===0&&i('"union"'))),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=S(),g!==null?c=[c,
f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}b!==null?a=[a,b]:(a=null,d=r)}else a=null,d=r;a!==null&&(a=function(a,j,b){if(b.length===0)return j;else{a={token:"graphunionpattern",value:[j]};for(j=0;j<b.length;j++)j==b.length-1?a.value.push(b[j][3]):(a.value.push(b[j][3]),a={token:"graphunionpattern",value:[a]});return a}}(m,a[0],a[1]));a===null&&(d=m);k--;k===0&&a===null&&i("[58] GroupOrUnionGraphPattern");return a}function wb(){var a,b,c,f,h,g;k++;g=h=d;a=[];for(b=l();b!==null;)a.push(b),
b=l();if(a!==null)if(e.substr(d,6)==="FILTER"?(b="FILTER",d+=6):(b=null,k===0&&i('"FILTER"')),b===null&&(e.substr(d,6)==="filter"?(b="filter",d+=6):(b=null,k===0&&i('"filter"'))),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();c!==null?(f=ta(),f!==null?a=[a,b,c,f]:(a=null,d=g)):(a=null,d=g)}else a=null,d=g;else a=null,d=g;a!==null&&(a={token:"filter",value:a[3]});a===null&&(d=h);k--;k===0&&a===null&&i("[59] Filter");return a}function ta(){var a;k++;a=Ea();a===null&&(a=Da(),a===null&&(a=bb()));
k--;k===0&&a===null&&i("[60] Constraint");return a}function bb(){var a,b,e,c;k++;c=e=d;a=N();a!==null?(b=eb(),b!==null?a=[a,b]:(a=null,d=c)):(a=null,d=c);a!==null&&(a=function(a,j,b){a={token:"expression",expressionType:"irireforfunction"};a.iriref=j;a.args=b.value;return a}(e,a[0],a[1]));a===null&&(d=e);k--;k===0&&a===null&&i("[61] FunctionCall");return a}function eb(){var a,b,c,f,h,g,l,m,r;k++;l=d;a=ha();a!==null&&(a={token:"args",value:[]});a===null&&(d=l);if(a===null){m=l=d;e.charCodeAt(d)===
40?(a="(",d++):(a=null,k===0&&i('"("'));if(a!==null)if(e.substr(d,8)==="DISTINCT"?(b="DISTINCT",d+=8):(b=null,k===0&&i('"DISTINCT"')),b===null&&(e.substr(d,8)==="distinct"?(b="distinct",d+=8):(b=null,k===0&&i('"distinct"'))),b=b!==null?b:"",b!==null)if(c=H(),c!==null){f=[];r=d;e.charCodeAt(d)===44?(h=",",d++):(h=null,k===0&&i('","'));h!==null?(g=H(),g!==null?h=[h,g]:(h=null,d=r)):(h=null,d=r);for(;h!==null;)f.push(h),r=d,e.charCodeAt(d)===44?(h=",",d++):(h=null,k===0&&i('","')),h!==null?(g=H(),g!==
null?h=[h,g]:(h=null,d=r)):(h=null,d=r);f!==null?(e.charCodeAt(d)===41?(h=")",d++):(h=null,k===0&&i('")"')),h!==null?a=[a,b,c,f,h]:(a=null,d=m)):(a=null,d=m)}else a=null,d=m;else a=null,d=m;else a=null,d=m;a!==null&&(a=function(a,j,b,d){for(var a=[],e=0;e<d.length;e++)a.push(d[e][1]);d={token:"args"};d.value=[b].concat(a);d.distinct=j!=null&&j.toUpperCase()==="DISTINCT"?!0:!1;return d}(l,a[1],a[2],a[3]));a===null&&(d=l)}k--;k===0&&a===null&&i("[62] ArgList");return a}function xb(){var a,b,c,f,h,g,
l,m;k++;g=d;a=ha();a!==null&&(a={token:"args",value:[]});a===null&&(d=g);if(a===null){l=g=d;e.charCodeAt(d)===40?(a="(",d++):(a=null,k===0&&i('"("'));if(a!==null)if(b=H(),b!==null){c=[];m=d;e.charCodeAt(d)===44?(f=",",d++):(f=null,k===0&&i('","'));f!==null?(h=H(),h!==null?f=[f,h]:(f=null,d=m)):(f=null,d=m);for(;f!==null;)c.push(f),m=d,e.charCodeAt(d)===44?(f=",",d++):(f=null,k===0&&i('","')),f!==null?(h=H(),h!==null?f=[f,h]:(f=null,d=m)):(f=null,d=m);c!==null?(e.charCodeAt(d)===41?(f=")",d++):(f=
null,k===0&&i('")"')),f!==null?a=[a,b,c,f]:(a=null,d=l)):(a=null,d=l)}else a=null,d=l;else a=null,d=l;a!==null&&(a=function(a,j,b){for(var a=[],d=0;d<b.length;d++)a.push(b[d][1]);b={token:"args"};b.value=[j].concat(a);return b}(g,a[1],a[2]));a===null&&(d=g)}k--;k===0&&a===null&&i("[63] ExpressionList");return a}function ob(){var a,b,c,f,h,g,m;k++;m=g=d;e.charCodeAt(d)===123?(a="{",d++):(a=null,k===0&&i('"{"'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=fb(),c=c!==null?
c:"",c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();f!==null?(e.charCodeAt(d)===125?(h="}",d++):(h=null,k===0&&i('"}"')),h!==null?a=[a,b,c,f,h]:(a=null,d=m)):(a=null,d=m)}else a=null,d=m;else a=null,d=m}else a=null,d=m;a!==null&&(a=a[2]);a===null&&(d=g);k--;k===0&&a===null&&i("[64] ConstructTemplate");return a}function fb(){var a,b,c,f,h,g,m,r;k++;m=g=d;a=cb();if(a!==null){r=d;b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===46?(c=".",d++):(c=null,k===0&&i('"."')),c!==
null){f=[];for(h=l();h!==null;)f.push(h),h=l();f!==null?(h=fb(),h=h!==null?h:"",h!==null?b=[b,c,f,h]:(b=null,d=r)):(b=null,d=r)}else b=null,d=r;else b=null,d=r;b=b!==null?b:"";b!==null?a=[a,b]:(a=null,d=m)}else a=null,d=m;a!==null&&(a=function(a,j,b){a=j.triplesContext;typeof b==="object"&&b.length!=null&&b[3].triplesContext!=null&&(a=a.concat(b[3].triplesContext));return{token:"triplestemplate",triplesContext:a}}(g,a[0],a[1]));a===null&&(d=g);k--;k===0&&a===null&&i("[65] ConstructTriples");return a}
function cb(){var a,b,e,c,f,h;k++;h=f=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ia(),b!==null){e=[];for(c=l();c!==null;)e.push(c),c=l();e!==null?(c=va(),c!==null?a=[a,b,e,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;else a=null,d=h;a!==null&&(a=function(a,b,j){a=j.triplesContext;if(j.pairs)for(var d=0;d<j.pairs.length;d++){var e=j.pairs[d],i=null;e[1].length!=null&&(e[1]=e[1][0]);b.token&&b.token==="triplesnodecollection"?(i={subject:b.chainSubject[0],predicate:e[0],object:e[1]},
a.push(i),a=a.concat(b.triplesContext)):(i={subject:b,predicate:e[0],object:e[1]},a.push(i))}j={token:"triplessamesubject"};j.triplesContext=a;j.chainSubject=b;return j}(f,a[1],a[3]));a===null&&(d=f);if(a===null){h=f=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ja(),b!==null){e=[];for(c=l();c!==null;)e.push(c),c=l();e!==null?(c=yb(),c!==null?a=[a,b,e,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;else a=null,d=h;a!==null&&(a=function(a,b,j){var a=b.triplesContext,d=b.chainSubject;if(j.pairs)for(var e=
0;e<j.pairs.length;e++){var i=j.pairs[e];i[1].length!=null&&(i[1]=i[1][0]);if(b.token==="triplesnodecollection")for(var c=0;c<d.length;c++){var f=d[c];if(f.triplesContext!=null){var h={subject:f.chainSubject,predicate:i[0],object:i[1]};a.concat(f.triplesContext)}else h={subject:d[c],predicate:i[0],object:i[1]},a.push(h)}else h={subject:d,predicate:i[0],object:i[1]},a.push(h)}b={token:"triplessamesubject"};b.triplesContext=a;b.chainSubject=d;return b}(f,a[1],a[3]));a===null&&(d=f)}k--;k===0&&a===null&&
i("[66] TriplesSameSubject");return a}function va(){var a,b,c,f,h,g,m,r,n,s,o,q,t,z;k++;q=o=d;a=Ka();if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=ia(),c!==null){f=[];t=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===59?(g=";",d++):(g=null,k===0&&i('";"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();if(m!==null){z=d;r=Ka();if(r!==null){n=[];for(s=l();s!==null;)n.push(s),s=l();n!==null?(s=ia(),s!==null?r=[r,n,s]:(r=null,d=z)):(r=null,d=z)}else r=
null,d=z;r=r!==null?r:"";r!==null?h=[h,g,m,r]:(h=null,d=t)}else h=null,d=t}else h=null,d=t;else h=null,d=t;for(;h!==null;){f.push(h);t=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===59?(g=";",d++):(g=null,k===0&&i('";"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();if(m!==null){z=d;r=Ka();if(r!==null){n=[];for(s=l();s!==null;)n.push(s),s=l();n!==null?(s=ia(),s!==null?r=[r,n,s]:(r=null,d=z)):(r=null,d=z)}else r=null,d=z;r=r!==null?r:"";r!==null?h=[h,g,m,r]:(h=null,
d=t)}else h=null,d=t}else h=null,d=t;else h=null,d=t}f!==null?a=[a,b,c,f]:(a=null,d=q)}else a=null,d=q;else a=null,d=q}else a=null,d=q;a!==null&&(a=function(a,b,j,d){for(var a={token:"propertylist"},e=[],i=[],c=0;c<j.length;c++)j[c].triplesContext!=null?(e=e.concat(j[c].triplesContext),j[c].token==="triplesnodecollection"&&j[c].chainSubject.length!=null?i.push([b,j[c].chainSubject[0]]):i.push([b,j[c].chainSubject])):i.push([b,j[c]]);for(c=0;c<d.length;c++)for(var j=d[c][3],b=j[0],j=j[2]||[],f=0;f<
j.length;f++)j[f].triplesContext!=null?(e=e.concat(j[f].triplesContext),i.push([b,j[f].chainSubject])):i.push([b,j[f]]);a.pairs=i;a.triplesContext=e;return a}(o,a[0],a[2],a[3]));a===null&&(d=o);k--;k===0&&a===null&&i("[67] PropertyListNotEmpty");return a}function yb(){var a;k++;a=va();a=a!==null?a:"";k--;k===0&&a===null&&i("[68] PropertyList");return a}function ia(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;a=ma();if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null){c=[];n=d;e.charCodeAt(d)===
44?(f=",",d++):(f=null,k===0&&i('","'));if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=ma(),g!==null?f=[f,h,g]:(f=null,d=n)):(f=null,d=n)}else f=null,d=n;for(;f!==null;)if(c.push(f),n=d,e.charCodeAt(d)===44?(f=",",d++):(f=null,k===0&&i('","')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=ma(),g!==null?f=[f,h,g]:(f=null,d=n)):(f=null,d=n)}else f=null,d=n;c!==null?a=[a,b,c]:(a=null,d=r)}else a=null,d=r}else a=null,d=r;a!==null&&(a=function(a,b,j){a=[];a.push(b);
for(b=0;b<j.length;b++)for(var d=0;d<j[b].length;d++)typeof j[b][d]=="object"&&j[b][d].token!=null&&a.push(j[b][d]);return a}(m,a[0],a[2]));a===null&&(d=m);k--;k===0&&a===null&&i("[69] ObjectList");return a}function Ka(){var a,b;k++;a=ga();a===null&&(b=d,e.charCodeAt(d)===97?(a="a",d++):(a=null,k===0&&i('"a"')),a!==null&&(a={token:"uri",prefix:null,suffix:null,value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}),a===null&&(d=b));k--;k===0&&a===null&&i("[71] Verb");return a}function qb(){var a,
b,e,c,f,h;k++;h=f=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ia(),b!==null){e=[];for(c=l();c!==null;)e.push(c),c=l();e!==null?(c=zb(),c!==null?a=[a,b,e,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;else a=null,d=h;a!==null&&(a=function(a,b,j){a=j.triplesContext;if(j.pairs)for(var d=0;d<j.pairs.length;d++){var e=j.pairs[d],i=null;e[1].length!=null&&(e[1]=e[1][0]);b.token&&b.token==="triplesnodecollection"?(i={subject:b.chainSubject[0],predicate:e[0],object:e[1]},a.push(i),a=a.concat(b.triplesContext)):
(i={subject:b,predicate:e[0],object:e[1]},a.push(i))}j={token:"triplessamesubject"};j.triplesContext=a;j.chainSubject=b;return j}(f,a[1],a[3]));a===null&&(d=f);if(a===null){h=f=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ja(),b!==null){e=[];for(c=l();c!==null;)e.push(c),c=l();e!==null?(c=Ab(),c!==null?a=[a,b,e,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;else a=null,d=h;a!==null&&(a=function(a,b,j){var a=b.triplesContext,d=b.chainSubject;if(j.pairs)for(var e=0;e<j.pairs.length;e++){var i=
j.pairs[e];i[1].length!=null&&(i[1]=i[1][0]);if(b.token==="triplesnodecollection")for(var c=0;c<d.length;c++){var f=d[c];if(f.triplesContext!=null){var h={subject:f.chainSubject,predicate:i[0],object:i[1]};a.concat(f.triplesContext)}else h={subject:d[c],predicate:i[0],object:i[1]},a.push(h)}else h={subject:d,predicate:i[0],object:i[1]},a.push(h)}b={token:"triplessamesubject"};b.triplesContext=a;b.chainSubject=d;return b}(f,a[1],a[3]));a===null&&(d=f)}k--;k===0&&a===null&&i("[72] TriplesSameSubjectPath");
return a}function zb(){var a,b,c,f,h,g,m,r,n,s,o,q,t;k++;o=s=d;a=La();a===null&&(a=M());if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=ia(),c!==null){f=[];q=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===59?(g=";",d++):(g=null,k===0&&i('";"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?(t=d,r=La(),r===null&&(r=M()),r!==null?(n=ia(),n!==null?r=[r,n]:(r=null,d=t)):(r=null,d=t),r=r!==null?r:"",r!==null?h=[h,g,m,r]:(h=null,d=q)):(h=
null,d=q)}else h=null,d=q;else h=null,d=q;for(;h!==null;){f.push(h);q=d;h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===59?(g=";",d++):(g=null,k===0&&i('";"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?(t=d,r=La(),r===null&&(r=M()),r!==null?(n=ia(),n!==null?r=[r,n]:(r=null,d=t)):(r=null,d=t),r=r!==null?r:"",r!==null?h=[h,g,m,r]:(h=null,d=q)):(h=null,d=q)}else h=null,d=q;else h=null,d=q}f!==null?a=[a,b,c,f]:(a=null,d=o)}else a=null,d=o;else a=null,d=o}else a=
null,d=o;a!==null&&(a=function(a,b,j,d){token={token:"propertylist"};for(var a=[],e=[],i=0;i<j.length;i++)j[i].triplesContext!=null?(a=a.concat(j[i].triplesContext),j[i].token==="triplesnodecollection"&&j[i].chainSubject.length!=null?e.push([b,j[i].chainSubject[0]]):e.push([b,j[i].chainSubject])):e.push([b,j[i]]);for(i=0;i<d.length;i++)for(var j=d[i][3],b=j[0],j=j[1]||[],c=0;c<j.length;c++)j[c].triplesContext!=null?(a=a.concat(j[c].triplesContext),e.push([b,j[c].chainSubject])):e.push([b,j[c]]);token.pairs=
e;token.triplesContext=a;return token}(s,a[0],a[2],a[3]));a===null&&(d=s);k--;k===0&&a===null&&i("[73] PropertyListNotEmptyPath");return a}function Ab(){var a;k++;a=va();a=a!==null?a:"";k--;k===0&&a===null&&i("[74] PropertyListPath");return a}function La(){var a,b;k++;b=d;a=gb();a===null&&(d=b);k--;k===0&&a===null&&i("[75]");return a}function gb(){var a,b,c,f,h,g,m;k++;g=h=d;a=Ma();if(a!==null){b=[];m=d;e.charCodeAt(d)===124?(c="|",d++):(c=null,k===0&&i('"|"'));c!==null?(f=Ma(),f!==null?c=[c,f]:(c=
null,d=m)):(c=null,d=m);for(;c!==null;)b.push(c),m=d,e.charCodeAt(d)===124?(c="|",d++):(c=null,k===0&&i('"|"')),c!==null?(f=Ma(),f!==null?c=[c,f]:(c=null,d=m)):(c=null,d=m);b!==null?a=[a,b]:(a=null,d=g)}else a=null,d=g;a!==null&&(a=function(a,b,j){if(j==null||j.length===0)return b;else{a=[];for(b=0;b<j.length;b++)a.push(j[1]);j={token:"path",kind:"alternative"};j.value=a;return j}}(h,a[0],a[1]));a===null&&(d=h);k--;k===0&&a===null&&i("[78] PathAlternative");return a}function Ma(){var a,b,c,f,h,g,
m;k++;g=h=d;a=Na();if(a!==null){b=[];m=d;e.charCodeAt(d)===47?(c="/",d++):(c=null,k===0&&i('"/"'));c!==null?(f=Na(),f!==null?c=[c,f]:(c=null,d=m)):(c=null,d=m);for(;c!==null;)b.push(c),m=d,e.charCodeAt(d)===47?(c="/",d++):(c=null,k===0&&i('"/"')),c!==null?(f=Na(),f!==null?c=[c,f]:(c=null,d=m)):(c=null,d=m);b!==null?a=[a,b]:(a=null,d=g)}else a=null,d=g;a!==null&&(a=function(a,b,j){if(j==null||j.length===0)return b;else{a=[b];for(b=0;b<j.length;b++)a.push(j[b][1]);j={token:"path",kind:"sequence"};j.value=
a;return j}}(h,a[0],a[1]));a===null&&(d=h);k--;k===0&&a===null&&i("[79] PathSequence");return a}function hb(){var a,b,e,c;k++;c=e=d;a=Bb();a!==null?(b=Cb(),b=b!==null?b:"",b!==null?a=[a,b]:(a=null,d=c)):(a=null,d=c);a!==null&&(a=function(a,b,j){if(b.token&&b.token!="path"&&j=="")return b;else if(b.token&&b.token!=d&&j!=""){var d={token:"path",kind:"element"};d.value=b;d.modifier=j;return d}else return b.modifier=j,b}(e,a[0],a[1]));a===null&&(d=e);k--;k===0&&a===null&&i("[88] PathElt");return a}function Na(){var a,
b,c,f;k++;a=hb();a===null&&(f=c=d,e.charCodeAt(d)===94?(a="^",d++):(a=null,k===0&&i('"^"')),a!==null?(b=hb(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f),a!==null&&(a=function(a,b){var j={token:"path",kind:"inversePath"};j.value=b;return j}(c,a[1])),a===null&&(d=c));k--;k===0&&a===null&&i("[81] PathEltOrInverse");return a}function Cb(){var a,b,c,f,h,g,m,r,l;k++;e.charCodeAt(d)===42?(a="*",d++):(a=null,k===0&&i('"*"'));a===null&&(e.charCodeAt(d)===63?(a="?",d++):(a=null,k===0&&i('"?"')),a===null&&(e.charCodeAt(d)===
43?(a="+",d++):(a=null,k===0&&i('"+"')),a===null&&(g=d,e.charCodeAt(d)===123?(a="{",d++):(a=null,k===0&&i('"{"')),a!==null?(m=d,b=$(),b!==null?(r=d,e.charCodeAt(d)===44?(c=",",d++):(c=null,k===0&&i('","')),c!==null?(e.charCodeAt(d)===125?(f="}",d++):(f=null,k===0&&i('"}"')),f===null&&(l=d,f=$(),f!==null?(e.charCodeAt(d)===125?(h="}",d++):(h=null,k===0&&i('"}"')),h!==null?f=[f,h]:(f=null,d=l)):(f=null,d=l)),f!==null?c=[c,f]:(c=null,d=r)):(c=null,d=r),c===null&&(e.charCodeAt(d)===125?(c="}",d++):(c=
null,k===0&&i('"}"'))),c!==null?b=[b,c]:(b=null,d=m)):(b=null,d=m),b===null&&(m=d,e.charCodeAt(d)===44?(b=",",d++):(b=null,k===0&&i('","')),b!==null?(c=$(),c!==null?(e.charCodeAt(d)===125?(f="}",d++):(f=null,k===0&&i('"}"')),f!==null?b=[b,c,f]:(b=null,d=m)):(b=null,d=m)):(b=null,d=m)),b!==null?a=[a,b]:(a=null,d=g)):(a=null,d=g))));k--;k===0&&a===null&&i("[82] PathMod");return a}function Bb(){var a,b,c,f,h;k++;a=N();a===null&&(f=d,e.charCodeAt(d)===97?(a="a",d++):(a=null,k===0&&i('"a"')),a!==null&&
(a={token:"uri",prefix:null,suffix:null,value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"}),a===null&&(d=f),a===null&&(f=d,e.charCodeAt(d)===33?(a="!",d++):(a=null,k===0&&i('"!"')),a!==null?(b=Db(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f),a===null&&(h=f=d,e.charCodeAt(d)===40?(a="(",d++):(a=null,k===0&&i('"("')),a!==null?(b=gb(),b!==null?(e.charCodeAt(d)===41?(c=")",d++):(c=null,k===0&&i('")"')),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)):(a=null,d=h),a!==null&&(a=a[1]),a===null&&(d=f))));
k--;k===0&&a===null&&i("[83] PathPrimary");return a}function Db(){var a,b,c,f,h,g,m,r;a=wa();if(a===null)if(g=d,e.charCodeAt(d)===40?(a="(",d++):(a=null,k===0&&i('"("')),a!==null){m=d;b=wa();if(b!==null){c=[];r=d;e.charCodeAt(d)===124?(f="|",d++):(f=null,k===0&&i('"|"'));f!==null?(h=wa(),h!==null?f=[f,h]:(f=null,d=r)):(f=null,d=r);for(;f!==null;)c.push(f),r=d,e.charCodeAt(d)===124?(f="|",d++):(f=null,k===0&&i('"|"')),f!==null?(h=wa(),h!==null?f=[f,h]:(f=null,d=r)):(f=null,d=r);c!==null?b=[b,c]:(b=
null,d=m)}else b=null,d=m;b=b!==null?b:"";b!==null?(e.charCodeAt(d)===41?(c=")",d++):(c=null,k===0&&i('")"')),c!==null?a=[a,b,c]:(a=null,d=g)):(a=null,d=g)}else a=null,d=g;return a}function wa(){var a,b,c;k++;a=N();a===null&&(e.charCodeAt(d)===97?(a="a",d++):(a=null,k===0&&i('"a"')),a===null&&(c=d,e.charCodeAt(d)===94?(a="^",d++):(a=null,k===0&&i('"^"')),a!==null?(b=N(),b===null&&(e.charCodeAt(d)===97?(b="a",d++):(b=null,k===0&&i('"a"'))),b!==null?a=[a,b]:(a=null,d=c)):(a=null,d=c)));k--;k===0&&a===
null&&i("[85] PathOneInPropertySet");return a}function Ja(){var a,b;k++;b=d;a=Eb();a!==null&&(a=function(a,b){for(var d=[],j=[],e=null,c=0;c<b.length;c++)aa++,e=null,b[c].chainSubject==null&&b[c].triplesContext==null?e=b[c]:(e=b[c].chainSubject,d=d.concat(nextSubject.triplesContext)),e={subject:{token:"blank",value:"_:"+aa},predicate:{token:"uri",prefix:null,suffix:null,value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#first"},object:e},c==0&&j.push(e.subject),d.push(e),e=c===b.length-1?{subject:{token:"blank",
value:"_:"+aa},predicate:{token:"uri",prefix:null,suffix:null,value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"},object:{token:"uri",prefix:null,suffix:null,value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"}}:{subject:{token:"blank",value:"_:"+aa},predicate:{token:"uri",prefix:null,suffix:null,value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"},object:{token:"blank",value:"_:"+(aa+1)}},d.push(e);return{token:"triplesnodecollection",triplesContext:d,chainSubject:j}}(b,a));a===null&&
(d=b);a===null&&(a=Fb());k--;k===0&&a===null&&i("[87] TriplesNode");return a}function Fb(){var a,b,c,f,h,g,m,r,n,s;k++;s=n=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.charCodeAt(d)===91?(b="[",d++):(b=null,k===0&&i('"["')),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(f=va(),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===93?(g="]",d++):(g=null,k===0&&i('"]"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?a=[a,
b,c,f,h,g,m]:(a=null,d=s)}else a=null,d=s;else a=null,d=s}else a=null,d=s;else a=null,d=s}else a=null,d=s;else a=null,d=s;a!==null&&(a=function(a,b){aa++;for(var d={token:"blank",value:"_:"+aa},j=[],e=0;e<b.pairs.length;e++){var c=b.pairs[e],i={};i.subject=d;i.predicate=c[0];c[1].length!=null&&(c[1]=c[1][0]);i.object=c[1];j.push(i)}return{token:"triplesnode",kind:"blanknodepropertylist",triplesContext:b.triplesContext.concat(j),chainSubject:d}}(n,a[3]));a===null&&(d=n);k--;k===0&&a===null&&i("[88] BlankNodePropertyList");
return a}function Eb(){var a,b,c,f,h,g,m,r,n,s;k++;s=n=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(e.charCodeAt(d)===40?(b="(",d++):(b=null,k===0&&i('"("')),b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null){h=ma();if(h!==null)for(f=[];h!==null;)f.push(h),h=ma();else f=null;if(f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();if(h!==null)if(e.charCodeAt(d)===41?(g=")",d++):(g=null,k===0&&i('")"')),g!==null){m=[];for(r=l();r!==null;)m.push(r),r=l();m!==null?a=[a,b,c,f,h,
g,m]:(a=null,d=s)}else a=null,d=s;else a=null,d=s}else a=null,d=s}else a=null,d=s}else a=null,d=s;else a=null,d=s;a!==null&&(a=a[3]);a===null&&(d=n);k--;k===0&&a===null&&i("[89] Collection");return a}function ma(){var a,b,e,c,f,h;k++;h=f=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ia(),b!==null){e=[];for(c=l();c!==null;)e.push(c),c=l();e!==null?a=[a,b,e]:(a=null,d=h)}else a=null,d=h;else a=null,d=h;if(a===null){h=d;a=[];for(b=l();b!==null;)a.push(b),b=l();if(a!==null)if(b=Ja(),b!==
null){e=[];for(c=l();c!==null;)e.push(c),c=l();e!==null?a=[a,b,e]:(a=null,d=h)}else a=null,d=h;else a=null,d=h}a!==null&&(a=a[1]);a===null&&(d=f);k--;k===0&&a===null&&i("[90] GraphNode");return a}function Ia(){var a;k++;a=M();a===null&&(a=Gb());k--;k===0&&a===null&&i("[91] VarOrTerm");return a}function ga(){var a;k++;a=M();a===null&&(a=N());k--;k===0&&a===null&&i("[92] VarOrIRIref");return a}function M(){var a,b;k++;b=d;a=Hb();a===null&&(a=Ib());a!==null&&(a=function(a,b){var d={token:"var"};d.value=
b;return d}(b,a));a===null&&(d=b);k--;k===0&&a===null&&i("[93] Var");return a}function Gb(){var a;k++;a=N();a===null&&(a=Fa(),a===null&&(a=Ga(),a===null&&(a=Ha(),a===null&&(a=Jb(),a===null&&(a=ha())))));k--;k===0&&a===null&&i("[94] GraphTerm");return a}function H(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;a=Oa();if(a!==null){b=[];n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="||"?(f="||",d+=2):(f=null,k===0&&i('"||"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?
(g=Oa(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;for(;c!==null;){b.push(c);n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="||"?(f="||",d+=2):(f=null,k===0&&i('"||"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Oa(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}b!==null?a=[a,b]:(a=null,d=r)}else a=null,d=r;a!==null&&(a=function(a,b,d){if(d.length===0)return b;for(var a={token:"expression",
expressionType:"conditionalor"},b=[b],j=0;j<d.length;j++)b.push(d[j][3]);a.operands=b;return a}(m,a[0],a[1]));a===null&&(d=m);k--;k===0&&a===null&&i("[96] ConditionalOrExpression");return a}function Oa(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;a=Pa();if(a!==null){b=[];n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="&&"?(f="&&",d+=2):(f=null,k===0&&i('"&&"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Pa(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=
null,d=n;else c=null,d=n;for(;c!==null;){b.push(c);n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="&&"?(f="&&",d+=2):(f=null,k===0&&i('"&&"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Pa(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}b!==null?a=[a,b]:(a=null,d=r)}else a=null,d=r;a!==null&&(a=function(a,b,d){if(d.length===0)return b;for(var a={token:"expression",expressionType:"conditionaland"},b=[b],j=0;j<d.length;j++)b.push(d[j][3]);
a.operands=b;return a}(m,a[0],a[1]));a===null&&(d=m);k--;k===0&&a===null&&i("[97] ConditionalAndExpression");return a}function Pa(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;a=Q();if(a!==null){b=[];n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===61?(f="=",d++):(f=null,k===0&&i('"="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),
f=l();if(c!==null)if(e.substr(d,2)==="!="?(f="!=",d+=2):(f=null,k===0&&i('"!="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===60?(f="<",d++):(f=null,k===0&&i('"<"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,
d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===62?(f=">",d++):(f=null,k===0&&i('">"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="<="?(f="<=",d+=2):(f=null,k===0&&i('"<="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,
g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)===">="?(f=">=",d+=2):(f=null,k===0&&i('">="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}}}}}for(;c!==null;){b.push(c);n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===61?(f="=",d++):(f=null,k===0&&i('"="')),f!==null){h=
[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="!="?(f="!=",d+=2):(f=null,k===0&&i('"!="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===
60?(f="<",d++):(f=null,k===0&&i('"<"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===62?(f=">",d++):(f=null,k===0&&i('">"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==
null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)==="<="?(f="<=",d+=2):(f=null,k===0&&i('"<="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.substr(d,2)===">="?(f=">=",d+=2):(f=null,k===0&&i('">="')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Q(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=
null,d=n;else c=null,d=n}}}}}}b!==null?a=[a,b]:(a=null,d=r)}else a=null,d=r;a!==null&&(a=function(a,b,d){return d.length===0?b:(a={expressionType:"relationalexpression"},a.operator=d[0][1],a.op1=b,a.op2=d[0][3],a.token="expression",a)}(m,a[0],a[1]));a===null&&(d=m);k--;k===0&&a===null&&i("[99] RelationalExpression");return a}function Q(){var a,b,c,f,h,g,m,r,n,s,o;k++;n=r=d;a=na();if(a!==null){b=[];s=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===43?(f="+",d++):(f=null,
k===0&&i('"+"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=na(),g!==null?c=[c,f,h,g]:(c=null,d=s)):(c=null,d=s)}else c=null,d=s;else c=null,d=s;if(c===null){s=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===45?(f="-",d++):(f=null,k===0&&i('"-"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=na(),g!==null?c=[c,f,h,g]:(c=null,d=s)):(c=null,d=s)}else c=null,d=s;else c=null,d=s;if(c===null)if(s=d,c=oa(),c===null&&(c=oa()),c!==null){o=
d;f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.charCodeAt(d)===42?(h="*",d++):(h=null,k===0&&i('"*"')),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=Y(),m!==null?f=[f,h,g,m]:(f=null,d=o)):(f=null,d=o)}else f=null,d=o;else f=null,d=o;if(f===null){o=d;f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.charCodeAt(d)===47?(h="/",d++):(h=null,k===0&&i('"/"')),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=Y(),m!==null?f=[f,h,g,m]:(f=null,d=o)):(f=null,
d=o)}else f=null,d=o;else f=null,d=o}f=f!==null?f:"";f!==null?c=[c,f]:(c=null,d=s)}else c=null,d=s}for(;c!==null;){b.push(c);s=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===43?(f="+",d++):(f=null,k===0&&i('"+"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=na(),g!==null?c=[c,f,h,g]:(c=null,d=s)):(c=null,d=s)}else c=null,d=s;else c=null,d=s;if(c===null){s=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===45?(f="-",d++):(f=null,
k===0&&i('"-"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=na(),g!==null?c=[c,f,h,g]:(c=null,d=s)):(c=null,d=s)}else c=null,d=s;else c=null,d=s;if(c===null)if(s=d,c=oa(),c===null&&(c=oa()),c!==null){o=d;f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.charCodeAt(d)===42?(h="*",d++):(h=null,k===0&&i('"*"')),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=Y(),m!==null?f=[f,h,g,m]:(f=null,d=o)):(f=null,d=o)}else f=null,d=o;else f=null,d=o;if(f===null){o=d;
f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.charCodeAt(d)===47?(h="/",d++):(h=null,k===0&&i('"/"')),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=Y(),m!==null?f=[f,h,g,m]:(f=null,d=o)):(f=null,d=o)}else f=null,d=o;else f=null,d=o}f=f!==null?f:"";f!==null?c=[c,f]:(c=null,d=s)}else c=null,d=s}}b!==null?a=[a,b]:(a=null,d=n)}else a=null,d=n;a!==null&&(a=function(a,b,d){if(d.length===0)return b;a={token:"expression",expressionType:"additiveexpression"};a.summand=b;a.summands=
[];for(b=0;b<d.length;b++){var j=d[b],e={};if(j.length==4&&typeof j[1]==="string")e.operator=j[1],e.expression=j[3];else{var j={},c=e[0],f=e[1][1],i=e[1][3],f=null;c.value<0?(e.operator="-",c.value=-c.value):e.operator="+";j.token="expression";j.expressionType="multiplicativeexpression";j.operator=c;j.factors=[{operator:f,expression:i}];e.expression=j}a.summands.push(e)}return a}(r,a[0],a[1]));a===null&&(d=r);k--;k===0&&a===null&&i("[101] AdditiveExpression");return a}function na(){var a,b,c,f,h,
g,m,r,n;k++;r=m=d;a=Y();if(a!==null){b=[];n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===42?(f="*",d++):(f=null,k===0&&i('"*"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Y(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===47?(f="/",d++):(f=null,k===0&&i('"/"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=
Y(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}for(;c!==null;){b.push(c);n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===42?(f="*",d++):(f=null,k===0&&i('"*"')),f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Y(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n;if(c===null){n=d;c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===47?(f="/",d++):(f=null,k===0&&i('"/"')),
f!==null){h=[];for(g=l();g!==null;)h.push(g),g=l();h!==null?(g=Y(),g!==null?c=[c,f,h,g]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}}b!==null?a=[a,b]:(a=null,d=r)}else a=null,d=r;a!==null&&(a=function(a,b,d){if(d.length===0)return b;a={token:"expression",expressionType:"multiplicativeexpression"};a.factor=b;a.factors=[];for(b=0;b<d.length;b++){var j=d[b],e={};e.operator=j[1];e.expression=j[3];a.factors.push(e)}return a}(m,a[0],a[1]));a===null&&(d=m);k--;k===0&&a===null&&i("[102] MultiplicativeExpression");
return a}function Y(){var a,b,c,f,h;k++;h=f=d;e.charCodeAt(d)===33?(a="!",d++):(a=null,k===0&&i('"!"'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(c=xa(),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"unaryexpression",unaryexpression:"!"};d.expression=b;return d}(f,a[2]));a===null&&(d=f);if(a===null){h=f=d;e.charCodeAt(d)===43?(a="+",d++):(a=null,k===0&&i('"+"'));if(a!==null){b=[];for(c=l();c!==
null;)b.push(c),c=l();b!==null?(c=xa(),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"unaryexpression",unaryexpression:"+"};d.expression=b;return d}(f,a[2]));a===null&&(d=f);if(a===null){h=f=d;e.charCodeAt(d)===45?(a="-",d++):(a=null,k===0&&i('"-"'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(c=xa(),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=function(a,b){var d=
{token:"expression",expressionType:"unaryexpression",unaryexpression:"-"};d.expression=b;return d}(f,a[2]));a===null&&(d=f);a===null&&(a=xa())}}k--;k===0&&a===null&&i("[103] UnaryExpression");return a}function xa(){var a,b;k++;a=Ea();a===null&&(a=Da(),a===null&&(a=Kb(),a===null&&(b=d,a=Fa(),a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"atomic",primaryexpression:"rdfliteral"};d.value=b;return d}(b,a)),a===null&&(d=b),a===null&&(b=d,a=Ga(),a!==null&&(a=function(a,b){var d={token:"expression",
expressionType:"atomic",primaryexpression:"numericliteral"};d.value=b;return d}(b,a)),a===null&&(d=b),a===null&&(b=d,a=Ha(),a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"atomic",primaryexpression:"booleanliteral"};d.value=b;return d}(b,a)),a===null&&(d=b),a===null&&(a=Lb(),a===null&&(b=d,a=M(),a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"atomic",primaryexpression:"var"};d.value=b;return d}(b,a)),a===null&&(d=b))))))));k--;k===0&&a===null&&i("[104] PrimaryExpression");
return a}function Ea(){var a,b,c,f,h,g,m;k++;m=g=d;e.charCodeAt(d)===40?(a="(",d++):(a=null,k===0&&i('"("'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(c=H(),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();f!==null?(e.charCodeAt(d)===41?(h=")",d++):(h=null,k===0&&i('")"')),h!==null?a=[a,b,c,f,h]:(a=null,d=m)):(a=null,d=m)}else a=null,d=m;else a=null,d=m}else a=null,d=m;a!==null&&(a=a[2]);a===null&&(d=g);k--;k===0&&a===null&&i("[105] BrackettedExpression");return a}function Da(){var a,
b,c,f,h,g,m,r,n,s,o,q,t,z,G,u,w;k++;w=u=d;e.substr(d,3)==="STR"?(a="STR",d+=3):(a=null,k===0&&i('"STR"'));a===null&&(e.substr(d,3)==="str"?(a="str",d+=3):(a=null,k===0&&i('"str"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==
null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"str"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,4)==="LANG"?(a="LANG",d+=4):(a=null,k===0&&i('"LANG"'));a===null&&(e.substr(d,4)==="lang"?(a="lang",d+=4):(a=null,k===0&&i('"lang"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==
null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"lang"};d.args=[b];
return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,11)==="LANGMATCHES"?(a="LANGMATCHES",d+=11):(a=null,k===0&&i('"LANGMATCHES"'));a===null&&(e.substr(d,11)==="langmatches"?(a="langmatches",d+=11):(a=null,k===0&&i('"langmatches"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==
null)if(e.charCodeAt(d)===44?(m=",",d++):(m=null,k===0&&i('","')),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(n=H(),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();s!==null?(e.charCodeAt(d)===41?(o=")",d++):(o=null,k===0&&i('")"')),o!==null?a=[a,b,c,f,h,g,m,r,n,s,o]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b,d){a={token:"expression",
expressionType:"builtincall",builtincall:"langmatches"};a.args=[b,d];return a}(u,a[4],a[8]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,8)==="DATATYPE"?(a="DATATYPE",d+=8):(a=null,k===0&&i('"DATATYPE"'));a===null&&(e.substr(d,8)==="datatype"?(a="datatype",d+=8):(a=null,k===0&&i('"datatype"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==
null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"datatype"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,5)==="BOUND"?(a="BOUND",d+=5):(a=null,k===0&&i('"BOUND"'));a===null&&(e.substr(d,
5)==="bound"?(a="bound",d+=5):(a=null,k===0&&i('"bound"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=M(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=
null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"bound"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,3)==="IRI"?(a="IRI",d+=3):(a=null,k===0&&i('"IRI"'));a===null&&(e.substr(d,3)==="iri"?(a="iri",d+=3):(a=null,k===0&&i('"iri"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==
null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"iri"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,3)==="URI"?(a="URI",d+=3):(a=null,k===0&&i('"URI"'));a===
null&&(e.substr(d,3)==="uri"?(a="uri",d+=3):(a=null,k===0&&i('"uri"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,
d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"uri"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,5)==="BNODE"?(a="BNODE",d+=5):(a=null,k===0&&i('"BNODE"'));a===null&&(e.substr(d,5)==="bnode"?(a="bnode",d+=5):(a=null,k===0&&i('"bnode"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null){n=d;e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("'));if(c!==null){f=[];for(h=l();h!==null;)f.push(h),
h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?c=[c,f,h,g,m]:(c=null,d=n)):(c=null,d=n)}else c=null,d=n;else c=null,d=n}else c=null,d=n;c===null&&(c=ha());c!==null?a=[a,b,c]:(a=null,d=w)}else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"bnode"};d.args=b.length===5?[b[2]]:null;return d}(u,a[2]));a===null&&(d=u);if(a===
null){w=u=d;e.substr(d,8)==="COALESCE"?(a="COALESCE",d+=8):(a=null,k===0&&i('"COALESCE"'));a===null&&(e.substr(d,8)==="coalesce"?(a="coalesce",d+=8):(a=null,k===0&&i('"coalesce"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(c=xb(),c!==null?a=[a,b,c]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"coalesce"};d.args=b;return d}(u,a[2]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,2)==="IF"?
(a="IF",d+=2):(a=null,k===0&&i('"IF"'));a===null&&(e.substr(d,2)==="if"?(a="if",d+=2):(a=null,k===0&&i('"if"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(e.charCodeAt(d)===44?(m=",",d++):(m=null,k===0&&i('","')),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(n=
H(),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();if(s!==null)if(e.charCodeAt(d)===44?(o=",",d++):(o=null,k===0&&i('","')),o!==null){q=[];for(t=l();t!==null;)q.push(t),t=l();if(q!==null)if(t=H(),t!==null){z=[];for(G=l();G!==null;)z.push(G),G=l();z!==null?(e.charCodeAt(d)===41?(G=")",d++):(G=null,k===0&&i('")"')),G!==null?a=[a,b,c,f,h,g,m,r,n,s,o,q,t,z,G]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;
else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b,d,e){a={token:"expression",expressionType:"builtincall",builtincall:"if"};a.args=[b,d,e];return a}(u,a[4],a[8],a[12]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,9)==="ISLITERAL"?(a="ISLITERAL",d+=9):(a=null,k===0&&i('"ISLITERAL"'));a===null&&(e.substr(d,9)==="isliteral"?(a="isliteral",d+=9):(a=null,k===0&&i('"isliteral"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=
l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"isliteral"};
d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,7)==="ISBLANK"?(a="ISBLANK",d+=7):(a=null,k===0&&i('"ISBLANK"'));a===null&&(e.substr(d,7)==="isblank"?(a="isblank",d+=7):(a=null,k===0&&i('"isblank"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===
41?(m=")",d++):(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"isblank"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,8)==="SAMETERM"?(a="SAMETERM",d+=8):(a=null,k===0&&i('"SAMETERM"'));a===null&&(e.substr(d,8)==="sameterm"?(a="sameterm",d+=8):(a=null,k===0&&i('"sameterm"')));
if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(e.charCodeAt(d)===44?(m=",",d++):(m=null,k===0&&i('","')),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(n=H(),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();s!==null?(e.charCodeAt(d)===41?(o=")",d++):(o=null,k===
0&&i('")"')),o!==null?a=[a,b,c,f,h,g,m,r,n,s,o]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"builtincall",builtincall:"sameterm"};a.args=[b,d];return a}(u,a[4],a[8]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,5)==="ISURI"?(a="ISURI",d+=5):(a=null,k===0&&i('"ISURI"'));a===null&&(e.substr(d,5)==="isuri"?(a=
"isuri",d+=5):(a=null,k===0&&i('"isuri"')),a===null&&(e.substr(d,5)==="ISIRI"?(a="ISIRI",d+=5):(a=null,k===0&&i('"ISIRI"')),a===null&&(e.substr(d,5)==="isiri"?(a="isiri",d+=5):(a=null,k===0&&i('"isiri"')))));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(e.charCodeAt(d)===41?(m=")",d++):
(m=null,k===0&&i('")"')),m!==null?a=[a,b,c,f,h,g,m]:(a=null,d=w)):(a=null,d=w)}else a=null,d=w;else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"isuri"};d.args=[b];return d}(u,a[4]));a===null&&(d=u);if(a===null){w=u=d;e.substr(d,7)==="custom:"?(a="custom:",d+=7):(a=null,k===0&&i('"custom:"'));a===null&&(e.substr(d,7)==="CUSTOM:"?(a="CUSTOM:",d+=7):(a=null,k===0&&i('"CUSTOM:"')));if(a!==null){/^[a-zA-Z0-9_]/.test(e.charAt(d))?
(c=e.charAt(d),d++):(c=null,k===0&&i("[a-zA-Z0-9_]"));if(c!==null)for(b=[];c!==null;)b.push(c),/^[a-zA-Z0-9_]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[a-zA-Z0-9_]"));else b=null;if(b!==null){c=[];for(f=l();f!==null;)c.push(f),f=l();if(c!==null)if(e.charCodeAt(d)===40?(f="(",d++):(f=null,k===0&&i('"("')),f!==null){h=[];n=d;g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=H(),m!==null?(e.charCodeAt(d)===44?(r=",",d++):(r=null,k===0&&i('","')),r!==null?g=[g,m,r]:(g=null,d=n)):(g=
null,d=n)):(g=null,d=n);for(;g!==null;){h.push(g);n=d;g=[];for(m=l();m!==null;)g.push(m),m=l();g!==null?(m=H(),m!==null?(e.charCodeAt(d)===44?(r=",",d++):(r=null,k===0&&i('","')),r!==null?g=[g,m,r]:(g=null,d=n)):(g=null,d=n)):(g=null,d=n)}if(h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(m=H(),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();r!==null?(e.charCodeAt(d)===41?(n=")",d++):(n=null,k===0&&i('")"')),n!==null?a=[a,b,c,f,h,g,m,r,n]:(a=null,d=w)):(a=null,d=w)}else a=null,
d=w;else a=null,d=w}else a=null,d=w}else a=null,d=w;else a=null,d=w}else a=null,d=w}else a=null,d=w;a!==null&&(a=function(a,b,d,e){a={token:"expression",expressionType:"custom"};a.name=b.join("");for(var b=[],c=0;c<d.length;c++)b.push(d[c][1]);b.push(e);a.args=b;return a}(u,a[1],a[4],a[6]));a===null&&(d=u);a===null&&(a=Mb(),a===null&&(a=Nb(),a===null&&(a=Ob())))}}}}}}}}}}}}}}k--;k===0&&a===null&&i("[106] BuiltInCall");return a}function Mb(){var a,b,c,f,h,g,m,r,n,s,o,q,t,z,u,G;k++;u=z=d;e.substr(d,
5)==="REGEX"?(a="REGEX",d+=5):(a=null,k===0&&i('"REGEX"'));a===null&&(e.substr(d,5)==="regex"?(a="regex",d+=5):(a=null,k===0&&i('"regex"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(h=H(),h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(e.charCodeAt(d)===44?(m=",",d++):(m=null,k===0&&i('","')),m!==null){r=[];for(n=l();n!==null;)r.push(n),
n=l();if(r!==null)if(n=H(),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();if(s!==null){G=d;e.charCodeAt(d)===44?(o=",",d++):(o=null,k===0&&i('","'));if(o!==null){q=[];for(t=l();t!==null;)q.push(t),t=l();q!==null?(t=H(),t!==null?o=[o,q,t]:(o=null,d=G)):(o=null,d=G)}else o=null,d=G;o=o!==null?o:"";if(o!==null){q=[];for(t=l();t!==null;)q.push(t),t=l();q!==null?(e.charCodeAt(d)===41?(t=")",d++):(t=null,k===0&&i('")"')),t!==null?a=[a,b,c,f,h,g,m,r,n,s,o,q,t]:(a=null,d=u)):(a=null,d=u)}else a=null,
d=u}else a=null,d=u}else a=null,d=u;else a=null,d=u}else a=null,d=u;else a=null,d=u}else a=null,d=u;else a=null,d=u}else a=null,d=u;else a=null,d=u}else a=null,d=u;a!==null&&(a=function(a,b,d,e){a={token:"expression",expressionType:"regex"};a.text=b;a.pattern=d;a.flags=e[2];return a}(z,a[4],a[8],a[10]));a===null&&(d=z);k--;k===0&&a===null&&i("[107] RegexExpression");return a}function Nb(){var a,b,c,f,h;k++;h=f=d;e.substr(d,6)==="EXISTS"?(a="EXISTS",d+=6):(a=null,k===0&&i('"EXISTS"'));a===null&&(e.substr(d,
6)==="exists"?(a="exists",d+=6):(a=null,k===0&&i('"exists"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(c=S(),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=function(a,b){var d={token:"expression",expressionType:"builtincall",builtincall:"exists"};d.args=[b];return d}(f,a[2]));a===null&&(d=f);k--;k===0&&a===null&&i("[108] ExistsFunc");return a}function Ob(){var a,b,c,f,h,g,m;k++;m=g=d;e.substr(d,3)==="NOT"?(a="NOT",d+=3):(a=null,k===0&&i('"NOT"'));
a===null&&(e.substr(d,3)==="not"?(a="not",d+=3):(a=null,k===0&&i('"not"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.substr(d,6)==="EXISTS"?(c="EXISTS",d+=6):(c=null,k===0&&i('"EXISTS"')),c===null&&(e.substr(d,6)==="exists"?(c="exists",d+=6):(c=null,k===0&&i('"exists"'))),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();f!==null?(h=S(),h!==null?a=[a,b,c,f,h]:(a=null,d=m)):(a=null,d=m)}else a=null,d=m;else a=null,d=m}else a=null,d=m;a!==null&&(a=function(a,b){var d=
{token:"expression",expressionType:"builtincall",builtincall:"notexists"};d.args=[b];return d}(g,a[4]));a===null&&(d=g);k--;k===0&&a===null&&i("[109] NotExistsFunc");return a}function Lb(){var a,b,c,f,h,g,m,r,n,s,o,q,t;k++;t=q=d;e.substr(d,5)==="COUNT"?(a="COUNT",d+=5):(a=null,k===0&&i('"COUNT"'));a===null&&(e.substr(d,5)==="count"?(a="count",d+=5):(a=null,k===0&&i('"count"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),
c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.substr(d,8)==="DISTINCT"?(h="DISTINCT",d+=8):(h=null,k===0&&i('"DISTINCT"')),h===null&&(e.substr(d,8)==="distinct"?(h="distinct",d+=8):(h=null,k===0&&i('"distinct"'))),h=h!==null?h:"",h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(e.charCodeAt(d)===42?(m="*",d++):(m=null,k===0&&i('"*"')),m===null&&(m=H()),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(e.charCodeAt(d)===41?(n=")",d++):(n=null,
k===0&&i('")"')),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();s!==null?a=[a,b,c,f,h,g,m,r,n,s]:(a=null,d=t)}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"aggregate",aggregateType:"count"};a.distinct=b!=""?"DISTINCT":b;a.expression=d;return a}(q,a[4],a[6]));a===null&&(d=q);if(a===null){t=q=d;e.substr(d,3)==="SUM"?(a="SUM",d+=3):(a=
null,k===0&&i('"SUM"'));a===null&&(e.substr(d,3)==="sum"?(a="sum",d+=3):(a=null,k===0&&i('"sum"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.substr(d,8)==="DISTINCT"?(h="DISTINCT",d+=8):(h=null,k===0&&i('"DISTINCT"')),h===null&&(e.substr(d,8)==="distinct"?(h="distinct",d+=8):(h=null,k===0&&i('"distinct"'))),h=h!==null?h:"",h!==null){g=[];for(m=l();m!==
null;)g.push(m),m=l();if(g!==null)if(m=H(),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(e.charCodeAt(d)===41?(n=")",d++):(n=null,k===0&&i('")"')),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();s!==null?a=[a,b,c,f,h,g,m,r,n,s]:(a=null,d=t)}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"aggregate",aggregateType:"sum"};
a.distinct=b!=""?"DISTINCT":b;a.expression=d;return a}(q,a[4],a[6]));a===null&&(d=q);if(a===null){t=q=d;e.substr(d,3)==="MIN"?(a="MIN",d+=3):(a=null,k===0&&i('"MIN"'));a===null&&(e.substr(d,3)==="min"?(a="min",d+=3):(a=null,k===0&&i('"min"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.substr(d,8)==="DISTINCT"?(h="DISTINCT",d+=8):(h=null,k===0&&i('"DISTINCT"')),
h===null&&(e.substr(d,8)==="distinct"?(h="distinct",d+=8):(h=null,k===0&&i('"distinct"'))),h=h!==null?h:"",h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(m=H(),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(e.charCodeAt(d)===41?(n=")",d++):(n=null,k===0&&i('")"')),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();s!==null?a=[a,b,c,f,h,g,m,r,n,s]:(a=null,d=t)}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=
null,d=t;else a=null,d=t}else a=null,d=t;a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"aggregate",aggregateType:"min"};a.distinct=b!=""?"DISTINCT":b;a.expression=d;return a}(q,a[4],a[6]));a===null&&(d=q);if(a===null){t=q=d;e.substr(d,3)==="MAX"?(a="MAX",d+=3):(a=null,k===0&&i('"MAX"'));a===null&&(e.substr(d,3)==="max"?(a="max",d+=3):(a=null,k===0&&i('"max"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&
i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.substr(d,8)==="DISTINCT"?(h="DISTINCT",d+=8):(h=null,k===0&&i('"DISTINCT"')),h===null&&(e.substr(d,8)==="distinct"?(h="distinct",d+=8):(h=null,k===0&&i('"distinct"'))),h=h!==null?h:"",h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(m=H(),m!==null){r=[];for(n=l();n!==null;)r.push(n),n=l();if(r!==null)if(e.charCodeAt(d)===41?(n=")",d++):(n=null,k===0&&i('")"')),n!==null){s=[];for(o=l();o!==null;)s.push(o),
o=l();s!==null?a=[a,b,c,f,h,g,m,r,n,s]:(a=null,d=t)}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"aggregate",aggregateType:"max"};a.distinct=b!=""?"DISTINCT":b;a.expression=d;return a}(q,a[4],a[6]));a===null&&(d=q);if(a===null){t=q=d;e.substr(d,3)==="AVG"?(a="AVG",d+=3):(a=null,k===0&&i('"AVG"'));a===null&&(e.substr(d,3)==="avg"?(a="avg",
d+=3):(a=null,k===0&&i('"avg"')));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();if(b!==null)if(e.charCodeAt(d)===40?(c="(",d++):(c=null,k===0&&i('"("')),c!==null){f=[];for(h=l();h!==null;)f.push(h),h=l();if(f!==null)if(e.substr(d,8)==="DISTINCT"?(h="DISTINCT",d+=8):(h=null,k===0&&i('"DISTINCT"')),h===null&&(e.substr(d,8)==="distinct"?(h="distinct",d+=8):(h=null,k===0&&i('"distinct"'))),h=h!==null?h:"",h!==null){g=[];for(m=l();m!==null;)g.push(m),m=l();if(g!==null)if(m=H(),m!==null){r=[];for(n=
l();n!==null;)r.push(n),n=l();if(r!==null)if(e.charCodeAt(d)===41?(n=")",d++):(n=null,k===0&&i('")"')),n!==null){s=[];for(o=l();o!==null;)s.push(o),o=l();s!==null?a=[a,b,c,f,h,g,m,r,n,s]:(a=null,d=t)}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;else a=null,d=t}else a=null,d=t;a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"aggregate",aggregateType:"avg"};a.distinct=b!=""?"DISTINCT":b;a.expression=d;return a}(q,a[4],
a[6]));a===null&&(d=q)}}}}k--;k===0&&a===null&&i("[110] Aggregate");return a}function Kb(){var a,b,e,c;k++;c=e=d;a=N();a!==null?(b=eb(),b=b!==null?b:"",b!==null?a=[a,b]:(a=null,d=c)):(a=null,d=c);a!==null&&(a=function(a,b,d){a={token:"expression",expressionType:"irireforfunction"};a.iriref=b;a.args=d.value;return a}(e,a[0],a[1]));a===null&&(d=e);k--;k===0&&a===null&&i("[117] IRIrefOrFunction");return a}function Fa(){var a,b,c,f,h,g;k++;h=f=d;a=Pb();a!==null?(b=Qb(),b===null&&(g=d,e.substr(d,2)===
"^^"?(b="^^",d+=2):(b=null,k===0&&i('"^^"')),b!==null?(c=N(),c!==null?b=[b,c]:(b=null,d=g)):(b=null,d=g)),b=b!==null?b:"",b!==null?a=[a,b]:(a=null,d=h)):(a=null,d=h);a!==null&&(a=function(a,b,d){return typeof d==="string"&&d.length>0?{token:"literal",value:b.value,lang:d.slice(1),type:null}:typeof d==="object"?(d.shift(),{token:"literal",value:b.value,lang:null,type:d[0]}):{token:"literal",value:b.value,lang:null,type:null}}(f,a[0],a[1]));a===null&&(d=f);k--;k===0&&a===null&&i("[112] RDFLiteral");
return a}function Ga(){var a;k++;a=Rb();a===null&&(a=Sb(),a===null&&(a=oa()));k--;k===0&&a===null&&i("[113] NumericLiteral");return a}function Rb(){var a;k++;a=Qa();a===null&&(a=Ra(),a===null&&(a=$()));k--;k===0&&a===null&&i("[114] NumericLiteralUnsigned");return a}function Sb(){var a;k++;a=Tb();a===null&&(a=Ub(),a===null&&(a=Vb()));k--;k===0&&a===null&&i("[115] NumericLiteralPositive");return a}function oa(){var a;k++;a=Wb();a===null&&(a=Xb(),a===null&&(a=Yb()));k--;k===0&&a===null&&i("[116] NumericLiteralNegative");
return a}function Ha(){var a,b;k++;b=d;e.substr(d,4)==="TRUE"?(a="TRUE",d+=4):(a=null,k===0&&i('"TRUE"'));a===null&&(e.substr(d,4)==="true"?(a="true",d+=4):(a=null,k===0&&i('"true"')));a!==null&&(a={token:"literal",lang:null,type:"http://www.w3.org/2001/XMLSchema#boolean",value:!0});a===null&&(d=b);a===null&&(b=d,e.substr(d,5)==="FALSE"?(a="FALSE",d+=5):(a=null,k===0&&i('"FALSE"')),a===null&&(e.substr(d,5)==="false"?(a="false",d+=5):(a=null,k===0&&i('"false"'))),a!==null&&(a={token:"literal",lang:null,
type:"http://www.w3.org/2001/XMLSchema#boolean",value:!1}),a===null&&(d=b));k--;k===0&&a===null&&i("[117] BooleanLiteral");return a}function Pb(){var a,b;k++;b=d;a=Zb();a!==null&&(a={token:"string",value:a});a===null&&(d=b);a===null&&(b=d,a=$b(),a!==null&&(a={token:"string",value:a}),a===null&&(d=b),a===null&&(b=d,a=ac(),a!==null&&(a={token:"string",value:a}),a===null&&(d=b),a===null&&(b=d,a=bc(),a!==null&&(a={token:"string",value:a}),a===null&&(d=b))));k--;k===0&&a===null&&i("[118] String");return a}
function N(){var a,b;k++;b=d;a=Ba();a!==null&&(a={token:"uri",prefix:null,suffix:null,value:a});a===null&&(d=b);a===null&&(b=d,a=cc(),a===null&&(d=b));k--;k===0&&a===null&&i("[119] IRIref");return a}function cc(){var a,b;k++;b=d;a=dc();a!==null&&(a={token:"uri",prefix:a[0],suffix:a[1],value:null});a===null&&(d=b);a===null&&(b=d,a=Ca(),a!==null&&(a={token:"uri",prefix:a,suffix:"",value:null}),a===null&&(d=b));k--;k===0&&a===null&&i("[120] PrefixedName");return a}function Jb(){var a,b;k++;b=d;a=ec();
a!==null&&(a={token:"blank",value:a});a===null&&(d=b);a===null&&(b=d,a=fc(),a!==null&&(aa++,a={token:"blank",value:"_:"+aa}),a===null&&(d=b));k--;k===0&&a===null&&i("[121] BlankNode");return a}function Ba(){var a,b,c,f,h;k++;h=f=d;e.charCodeAt(d)===60?(a="<",d++):(a=null,k===0&&i('"<"'));if(a!==null){b=[];/^[^<>"{}|^`\\]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i('[^<>"{}|^`\\\\]'));for(;c!==null;)b.push(c),/^[^<>"{}|^`\\]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i('[^<>"{}|^`\\\\]'));
b!==null?(e.charCodeAt(d)===62?(c=">",d++):(c=null,k===0&&i('">"')),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=a[1].join(""));a===null&&(d=f);k--;k===0&&a===null&&i("[122] IRI_REF");return a}function Ca(){var a,b,c,f;k++;f=c=d;a=gc();a=a!==null?a:"";a!==null?(e.charCodeAt(d)===58?(b=":",d++):(b=null,k===0&&i('":"')),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=a[0]);a===null&&(d=c);k--;k===0&&a===null&&i("[123] PNAME_NS");return a}function dc(){var a,b,
e,c;k++;c=e=d;a=Ca();a!==null?(b=ib(),b!==null?a=[a,b]:(a=null,d=c)):(a=null,d=c);a!==null&&(a=[a[0],a[1]]);a===null&&(d=e);k--;k===0&&a===null&&i("[124] PNAME_LN");return a}function ec(){var a,b,c,f;k++;f=c=d;e.substr(d,2)==="_:"?(a="_:",d+=2):(a=null,k===0&&i('"_:"'));a!==null?(b=ib(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=a[1]);a===null&&(d=c);k--;k===0&&a===null&&i("[125] BLANK_NODE_LABEL");return a}function Hb(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===63?(a="?",d++):(a=null,
k===0&&i('"?"'));a!==null?(b=jb(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=a[1]);a===null&&(d=c);k--;k===0&&a===null&&i("[126] VAR1");return a}function Ib(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===36?(a="$",d++):(a=null,k===0&&i('"$"'));a!==null?(b=jb(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=a[1]);a===null&&(d=c);k--;k===0&&a===null&&i("[127] VAR2");return a}function Qb(){var a,b,c,f,h,g,m,r,n;k++;r=m=d;e.charCodeAt(d)===64?(a="@",d++):(a=null,k===0&&i('"@"'));if(a!==
null){/^[a-zA-Z]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[a-zA-Z]"));if(c!==null)for(b=[];c!==null;)b.push(c),/^[a-zA-Z]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[a-zA-Z]"));else b=null;if(b!==null){c=[];n=d;e.charCodeAt(d)===45?(f="-",d++):(f=null,k===0&&i('"-"'));if(f!==null){/^[a-zA-Z0-9]/.test(e.charAt(d))?(g=e.charAt(d),d++):(g=null,k===0&&i("[a-zA-Z0-9]"));if(g!==null)for(h=[];g!==null;)h.push(g),/^[a-zA-Z0-9]/.test(e.charAt(d))?(g=e.charAt(d),d++):(g=null,k===
0&&i("[a-zA-Z0-9]"));else h=null;h!==null?f=[f,h]:(f=null,d=n)}else f=null,d=n;for(;f!==null;)if(c.push(f),n=d,e.charCodeAt(d)===45?(f="-",d++):(f=null,k===0&&i('"-"')),f!==null){/^[a-zA-Z0-9]/.test(e.charAt(d))?(g=e.charAt(d),d++):(g=null,k===0&&i("[a-zA-Z0-9]"));if(g!==null)for(h=[];g!==null;)h.push(g),/^[a-zA-Z0-9]/.test(e.charAt(d))?(g=e.charAt(d),d++):(g=null,k===0&&i("[a-zA-Z0-9]"));else h=null;h!==null?f=[f,h]:(f=null,d=n)}else f=null,d=n;c!==null?a=[a,b,c]:(a=null,d=r)}else a=null,d=r}else a=
null,d=r;a!==null&&(a=a[2].length===0?("@"+a[1].join("")).toLowerCase():("@"+a[1].join("")+"-"+a[2][0][1].join("")).toLowerCase());a===null&&(d=m);k--;k===0&&a===null&&i("[128] LANGTAG");return a}function $(){var a,b,c;k++;c=d;/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));if(b!==null)for(a=[];b!==null;)a.push(b),/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));else a=null;a!==null&&(a=function(a,b){var d={token:"literal",lang:null,type:"http://www.w3.org/2001/XMLSchema#integer"};
d.value=V(b);return d}(c,a));a===null&&(d=c);k--;k===0&&a===null&&i("[129] INTEGER");return a}function Ra(){var a,b,c,f,h,g;k++;g=h=d;/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));if(b!==null)for(a=[];b!==null;)a.push(b),/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));else a=null;if(a!==null)if(e.charCodeAt(d)===46?(b=".",d++):(b=null,k===0&&i('"."')),b!==null){c=[];/^[0-9]/.test(e.charAt(d))?(f=e.charAt(d),d++):(f=null,k===0&&i("[0-9]"));for(;f!==
null;)c.push(f),/^[0-9]/.test(e.charAt(d))?(f=e.charAt(d),d++):(f=null,k===0&&i("[0-9]"));c!==null?a=[a,b,c]:(a=null,d=g)}else a=null,d=g;else a=null,d=g;a!==null&&(a=function(a,b,d,e){a={token:"literal",lang:null,type:"http://www.w3.org/2001/XMLSchema#decimal"};a.value=V([b,d,e]);return a}(h,a[0],a[1],a[2]));a===null&&(d=h);if(a===null){g=h=d;e.charCodeAt(d)===46?(a=".",d++):(a=null,k===0&&i('"."'));if(a!==null){/^[0-9]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[0-9]"));if(c!==null)for(b=
[];c!==null;)b.push(c),/^[0-9]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[0-9]"));else b=null;b!==null?a=[a,b]:(a=null,d=g)}else a=null,d=g;a!==null&&(a=function(a,b,d){a={token:"literal",lang:null,type:"http://www.w3.org/2001/XMLSchema#decimal"};a.value=V([b,d]);return a}(h,a[0],a[1]));a===null&&(d=h)}k--;k===0&&a===null&&i("[130] DECIMAL");return a}function Qa(){var a,b,c,f,h,g;k++;g=h=d;/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));if(b!==null)for(a=[];b!==
null;)a.push(b),/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));else a=null;if(a!==null)if(e.charCodeAt(d)===46?(b=".",d++):(b=null,k===0&&i('"."')),b!==null){c=[];/^[0-9]/.test(e.charAt(d))?(f=e.charAt(d),d++):(f=null,k===0&&i("[0-9]"));for(;f!==null;)c.push(f),/^[0-9]/.test(e.charAt(d))?(f=e.charAt(d),d++):(f=null,k===0&&i("[0-9]"));c!==null?(f=Sa(),f!==null?a=[a,b,c,f]:(a=null,d=g)):(a=null,d=g)}else a=null,d=g;else a=null,d=g;a!==null&&(a=function(a,b,d,e,c){a={token:"literal",
lang:null,type:"http://www.w3.org/2001/XMLSchema#double"};a.value=V([b,d,e,c]);return a}(h,a[0],a[1],a[2],a[3]));a===null&&(d=h);if(a===null){g=h=d;e.charCodeAt(d)===46?(a=".",d++):(a=null,k===0&&i('"."'));if(a!==null){/^[0-9]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[0-9]"));if(c!==null)for(b=[];c!==null;)b.push(c),/^[0-9]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[0-9]"));else b=null;b!==null?(c=Sa(),c!==null?a=[a,b,c]:(a=null,d=g)):(a=null,d=g)}else a=null,d=g;a!==
null&&(a=function(a,b,d,e){a={token:"literal",lang:null,type:"http://www.w3.org/2001/XMLSchema#double"};a.value=V([b,d,e]);return a}(h,a[0],a[1],a[2]));a===null&&(d=h);if(a===null){g=h=d;/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));if(b!==null)for(a=[];b!==null;)a.push(b),/^[0-9]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[0-9]"));else a=null;a!==null?(b=Sa(),b!==null?a=[a,b]:(a=null,d=g)):(a=null,d=g);a!==null&&(a=function(a,b,d){a={token:"literal",lang:null,
type:"http://www.w3.org/2001/XMLSchema#double"};a.value=V([b,d]);return a}(h,a[0],a[1]));a===null&&(d=h)}}k--;k===0&&a===null&&i("[131] DOUBLE");return a}function Vb(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===43?(a="+",d++):(a=null,k===0&&i('"+"'));a!==null?(b=$(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=function(a,b){b.value="+"+b.value;return b}(c,a[1]));a===null&&(d=c);k--;k===0&&a===null&&i("[132] INTEGER_POSITIVE");return a}function Ub(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===
43?(a="+",d++):(a=null,k===0&&i('"+"'));a!==null?(b=Ra(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=function(a,b){b.value="+"+b.value;return b}(c,a[1]));a===null&&(d=c);k--;k===0&&a===null&&i("[133] DECIMAL_POSITIVE");return a}function Tb(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===43?(a="+",d++):(a=null,k===0&&i('"+"'));a!==null?(b=Qa(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=function(a,b){b.value="+"+b.value;return b}(c,a[1]));a===null&&(d=c);k--;k===0&&a===null&&i("[134] DOUBLE_POSITIVE");
return a}function Yb(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===45?(a="-",d++):(a=null,k===0&&i('"-"'));a!==null?(b=$(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=function(a,b){b.value="-"+b.value;return b}(c,a[1]));a===null&&(d=c);k--;k===0&&a===null&&i("[135] INTEGER_NEGATIVE");return a}function Xb(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===45?(a="-",d++):(a=null,k===0&&i('"-"'));a!==null?(b=Ra(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=function(a,b){b.value="-"+b.value;
return b}(c,a[1]));a===null&&(d=c);k--;k===0&&a===null&&i("[136] DECIMAL_NEGATIVE");return a}function Wb(){var a,b,c,f;k++;f=c=d;e.charCodeAt(d)===45?(a="-",d++):(a=null,k===0&&i('"-"'));a!==null?(b=Qa(),b!==null?a=[a,b]:(a=null,d=f)):(a=null,d=f);a!==null&&(a=function(a,b){b.value="-"+b.value;return b}(c,a[1]));a===null&&(d=c);k--;k===0&&a===null&&i("[137] DOUBLE_NEGATIVE");return a}function Sa(){var a,b,c,f,h,g;k++;g=h=d;/^[eE]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[eE]"));if(a!==
null)if(/^[+\-]/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[+\\-]")),b=b!==null?b:"",b!==null){/^[0-9]/.test(e.charAt(d))?(f=e.charAt(d),d++):(f=null,k===0&&i("[0-9]"));if(f!==null)for(c=[];f!==null;)c.push(f),/^[0-9]/.test(e.charAt(d))?(f=e.charAt(d),d++):(f=null,k===0&&i("[0-9]"));else c=null;c!==null?a=[a,b,c]:(a=null,d=g)}else a=null,d=g;else a=null,d=g;a!==null&&(a=V([a[0],a[1],a[2]]));a===null&&(d=h);k--;k===0&&a===null&&i("[138] EXPONENT");return a}function ac(){var a,b,c,f,h;
k++;h=f=d;e.charCodeAt(d)===39?(a="'",d++):(a=null,k===0&&i('"\'"'));if(a!==null){b=[];/^[^'\\\n\r]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[^'\\\\\\n\\r]"));for(c===null&&(c=ba());c!==null;)b.push(c),/^[^'\\\n\r]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[^'\\\\\\n\\r]")),c===null&&(c=ba());b!==null?(e.charCodeAt(d)===39?(c="'",d++):(c=null,k===0&&i('"\'"')),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=V(a[1]));a===null&&(d=f);k--;k===
0&&a===null&&i("[139] STRING_LITERAL1");return a}function bc(){var a,b,c,f,h;k++;h=f=d;e.charCodeAt(d)===34?(a='"',d++):(a=null,k===0&&i('"\\""'));if(a!==null){b=[];/^[^"\\\n\r]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i('[^"\\\\\\n\\r]'));for(c===null&&(c=ba());c!==null;)b.push(c),/^[^"\\\n\r]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i('[^"\\\\\\n\\r]')),c===null&&(c=ba());b!==null?(e.charCodeAt(d)===34?(c='"',d++):(c=null,k===0&&i('"\\""')),c!==null?a=[a,b,c]:(a=null,d=
h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=V(a[1]));a===null&&(d=f);k--;k===0&&a===null&&i("[140] STRING_LITERAL2");return a}function Zb(){var a,b,c,f,h;k++;h=f=d;e.substr(d,3)==="'''"?(a="'''",d+=3):(a=null,k===0&&i("\"'''\""));if(a!==null){b=[];/^[^'\\]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[^'\\\\]"));for(c===null&&(c=ba());c!==null;)b.push(c),/^[^'\\]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[^'\\\\]")),c===null&&(c=ba());b!==null?(e.substr(d,3)==="'''"?(c=
"'''",d+=3):(c=null,k===0&&i("\"'''\"")),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=V(a[1]));a===null&&(d=f);k--;k===0&&a===null&&i("[141] STRING_LITERAL_LONG1");return a}function $b(){var a,b,c,f,h;k++;h=f=d;e.substr(d,3)==='"""'?(a='"""',d+=3):(a=null,k===0&&i('"\\"\\"\\""'));if(a!==null){b=[];/^[^"\\]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i('[^"\\\\]'));for(c===null&&(c=ba());c!==null;)b.push(c),/^[^"\\]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=
null,k===0&&i('[^"\\\\]')),c===null&&(c=ba());b!==null?(e.substr(d,3)==='"""'?(c='"""',d+=3):(c=null,k===0&&i('"\\"\\"\\""')),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a=V(a[1]));a===null&&(d=f);k--;k===0&&a===null&&i("[142] STRING_LITERAL_LONG2");return a}function ba(){var a,b,c;k++;c=d;e.charCodeAt(d)===92?(a="\\",d++):(a=null,k===0&&i('"\\\\"'));a!==null?(/^[tbnrf"']/.test(e.charAt(d))?(b=e.charAt(d),d++):(b=null,k===0&&i("[tbnrf\"']")),b!==null?a=[a,b]:(a=null,d=
c)):(a=null,d=c);k--;k===0&&a===null&&i("[143] ECHAR");return a}function ha(){var a,b,c,f,h;k++;h=f=d;e.charCodeAt(d)===40?(a="(",d++):(a=null,k===0&&i('"("'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(e.charCodeAt(d)===41?(c=")",d++):(c=null,k===0&&i('")"')),c!==null?a=[a,b,c]:(a=null,d=h)):(a=null,d=h)}else a=null,d=h;a!==null&&(a={token:"triplesnodecollection",triplesContext:[],chainSubject:[{token:"uri",value:"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"}]});a===null&&
(d=f);k--;k===0&&a===null&&i("[144] NIL");return a}function l(){var a;k++;/^[ ]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[ ]"));a===null&&(/^[\t]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\t]")),a===null&&(/^[\r]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\r]")),a===null&&(/^[\n]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\n]")),a===null&&(a=hc()))));k--;k===0&&a===null&&i("[145] WS");return a}function hc(){var a,b,c,f;k++;f=d;e.charCodeAt(d)===
35?(a="#",d++):(a=null,k===0&&i('"#"'));if(a!==null){b=[];/^[^\n\r]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[^\\n\\r]"));for(;c!==null;)b.push(c),/^[^\n\r]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[^\\n\\r]"));b!==null?a=[a,b]:(a=null,d=f)}else a=null,d=f;k--;k===0&&a===null&&i(" COMMENT");return a}function fc(){var a,b,c,f;k++;f=d;e.charCodeAt(d)===91?(a="[",d++):(a=null,k===0&&i('"["'));if(a!==null){b=[];for(c=l();c!==null;)b.push(c),c=l();b!==null?(e.charCodeAt(d)===
93?(c="]",d++):(c=null,k===0&&i('"]"')),c!==null?a=[a,b,c]:(a=null,d=f)):(a=null,d=f)}else a=null,d=f;k--;k===0&&a===null&&i("[146] ANON");return a}function kb(){var a;k++;/^[A-Z]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[A-Z]"));a===null&&(/^[a-z]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[a-z]")),a===null&&(/^[\xC0-\xD6]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\xC0-\\xD6]")),a===null&&(/^[\xD8-\xF6]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,
k===0&&i("[\\xD8-\\xF6]")),a===null&&(/^[\xF8-\u02FF]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\xF8-\\u02FF]")),a===null&&(/^[\u0370-\u037D]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u0370-\\u037D]")),a===null&&(/^[\u037F-\u1FFF]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u037F-\\u1FFF]")),a===null&&(/^[\u200C-\u200D]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u200C-\\u200D]")),a===null&&(/^[\u2070-\u218F]/.test(e.charAt(d))?(a=
e.charAt(d),d++):(a=null,k===0&&i("[\\u2070-\\u218F]")),a===null&&(/^[\u2C00-\u2FEF]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u2C00-\\u2FEF]")),a===null&&(/^[\u3001-\uD7FF]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u3001-\\uD7FF]")),a===null&&(/^[\uF900-\uFDCF]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\uF900-\\uFDCF]")),a===null&&(/^[\uFDF0-\uFFFD]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\uFDF0-\\uFFFD]")),a===null&&(/^[\u1000-\uEFFF]/.test(e.charAt(d))?
(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u1000-\\uEFFF]")))))))))))))));k--;k===0&&a===null&&i("[147] PN_CHARS_BASE");return a}function pa(){var a;k++;a=kb();a===null&&(e.charCodeAt(d)===95?(a="_",d++):(a=null,k===0&&i('"_"')));k--;k===0&&a===null&&i("[148] PN_CHARS_U");return a}function jb(){var a,b,c,f,h;k++;h=f=d;a=pa();a===null&&(/^[0-9]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[0-9]")));if(a!==null){b=[];c=pa();c===null&&(/^[0-9]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,
k===0&&i("[0-9]")),c===null&&(/^[\xB7]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[\\xB7]")),c===null&&(/^[\u0300-\u036F]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[\\u0300-\\u036F]")),c===null&&(/^[\u203F-\u2040]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[\\u203F-\\u2040]"))))));for(;c!==null;)b.push(c),c=pa(),c===null&&(/^[0-9]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[0-9]")),c===null&&(/^[\xB7]/.test(e.charAt(d))?(c=e.charAt(d),d++):
(c=null,k===0&&i("[\\xB7]")),c===null&&(/^[\u0300-\u036F]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[\\u0300-\\u036F]")),c===null&&(/^[\u203F-\u2040]/.test(e.charAt(d))?(c=e.charAt(d),d++):(c=null,k===0&&i("[\\u203F-\\u2040]"))))));b!==null?a=[a,b]:(a=null,d=h)}else a=null,d=h;a!==null&&(a=a[0]+a[1].join(""));a===null&&(d=f);k--;k===0&&a===null&&i("[149] VARNAME");return a}function ya(){var a;k++;a=pa();a===null&&(e.charCodeAt(d)===45?(a="-",d++):(a=null,k===0&&i('"-"')),a===null&&
(/^[0-9]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[0-9]")),a===null&&(/^[\xB7]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\xB7]")),a===null&&(/^[\u0300-\u036F]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u0300-\\u036F]")),a===null&&(/^[\u203F-\u2040]/.test(e.charAt(d))?(a=e.charAt(d),d++):(a=null,k===0&&i("[\\u203F-\\u2040]")))))));k--;k===0&&a===null&&i("[150] PN_CHARS");return a}function gc(){var a,b,c,f,h;k++;h=f=d;a=kb();if(a!==null){b=[];c=ya();
c===null&&(e.charCodeAt(d)===46?(c=".",d++):(c=null,k===0&&i('"."')));for(;c!==null;)b.push(c),c=ya(),c===null&&(e.charCodeAt(d)===46?(c=".",d++):(c=null,k===0&&i('"."')));b!==null?a=[a,b]:(a=null,d=h)}else a=null,d=h;a!==null&&(a=function(a,b,d){if(d[d.length-1]==".")throw Error("Wrong PN_PREFIX, cannot finish with '.'");else return b+d.join("")}(f,a[0],a[1]));a===null&&(d=f);k--;k===0&&a===null&&i("[151] PN_PREFIX");return a}function ib(){var a,b,c,f,h;k++;h=f=d;a=pa();a===null&&(/^[0-9]/.test(e.charAt(d))?
(a=e.charAt(d),d++):(a=null,k===0&&i("[0-9]")));if(a!==null){b=[];for(c=ya();c!==null;)b.push(c),c=ya();b!==null?a=[a,b]:(a=null,d=h)}else a=null,d=h;a!==null&&(a=a[0]+a[1].join(""));a===null&&(d=f);k--;k===0&&a===null&&i("[152] PN_LOCAL");return a}function lb(a){a.sort();for(var b=null,d=[],c=0;c<a.length;c++)a[c]!==b&&(d.push(a[c]),b=a[c]);return d}function jc(){for(var a=1,b=1,c=!1,f=0;f<Math.max(d,sa);f++){var h=e.charAt(f);h==="\n"?(c||a++,b=1,c=!1):h==="\r"||h==="\u2028"||h==="\u2029"?(a++,
b=1,c=!0):(b++,c=!1)}return{line:a,column:b}}var ca={SPARQL:function(){var a;a=h();a===null&&(a=R());return a},Query:h,Prologue:f,BaseDecl:g,PrefixDecl:o,SelectQuery:t,SubSelect:q,SelectClause:u,ConstructQuery:v,DescribeQuery:x,AskQuery:A,DatasetClause:m,DefaultGraphClause:r,NamedGraphClause:z,WhereClause:s,SolutionModifier:G,GroupClause:U,GroupCondition:y,HavingClause:B,OrderClause:D,OrderCondition:C,LimitOffsetClauses:I,LimitClause:J,OffsetClause:K,BindingsClause:L,BindingValue:O,Update:R,Update1:W,
Load:X,Clear:Z,Drop:da,Create:ja,InsertData:ka,DeleteData:qa,DeleteWhere:ra,Modify:za,DeleteClause:mb,InsertClause:Wa,UsingClause:Xa,GraphRef:Aa,GraphRefAll:Ya,QuadPattern:Ua,QuadData:Va,Quads:Za,QuadsNotTriples:$a,TriplesTemplate:la,GroupGraphPattern:S,GroupGraphPatternSub:pb,TriplesBlock:ua,GraphPatternNotTriples:db,OptionalGraphPattern:sb,GraphGraphPattern:ub,ServiceGraphPattern:vb,MinusGraphPattern:tb,GroupOrUnionGraphPattern:rb,Filter:wb,Constraint:ta,FunctionCall:bb,ArgList:eb,ExpressionList:xb,
ConstructTemplate:ob,ConstructTriples:fb,TriplesSameSubject:cb,PropertyListNotEmpty:va,PropertyList:yb,ObjectList:ia,Verb:Ka,TriplesSameSubjectPath:qb,PropertyListNotEmptyPath:zb,PropertyListPath:Ab,VerbPath:La,PathAlternative:gb,PathSequence:Ma,PathElt:hb,PathEltOrInverse:Na,PathMod:Cb,PathPrimary:Bb,PathNegatedPropertySet:Db,PathOneInPropertySet:wa,TriplesNode:Ja,BlankNodePropertyList:Fb,Collection:Eb,GraphNode:ma,VarOrTerm:Ia,VarOrIRIref:ga,Var:M,GraphTerm:Gb,ConditionalOrExpression:H,ConditionalAndExpression:Oa,
RelationalExpression:Pa,AdditiveExpression:Q,MultiplicativeExpression:na,UnaryExpression:Y,PrimaryExpression:xa,BrackettedExpression:Ea,BuiltInCall:Da,RegexExpression:Mb,ExistsFunc:Nb,NotExistsFunc:Ob,Aggregate:Lb,IRIrefOrFunction:Kb,RDFLiteral:Fa,NumericLiteral:Ga,NumericLiteralUnsigned:Rb,NumericLiteralPositive:Sb,NumericLiteralNegative:oa,BooleanLiteral:Ha,String:Pb,IRIref:N,PrefixedName:cc,BlankNode:Jb,IRI_REF:Ba,PNAME_NS:Ca,PNAME_LN:dc,BLANK_NODE_LABEL:ec,VAR1:Hb,VAR2:Ib,LANGTAG:Qb,INTEGER:$,
DECIMAL:Ra,DOUBLE:Qa,INTEGER_POSITIVE:Vb,DECIMAL_POSITIVE:Ub,DOUBLE_POSITIVE:Tb,INTEGER_NEGATIVE:Yb,DECIMAL_NEGATIVE:Xb,DOUBLE_NEGATIVE:Wb,EXPONENT:Sa,STRING_LITERAL1:ac,STRING_LITERAL2:bc,STRING_LITERAL_LONG1:Zb,STRING_LITERAL_LONG2:$b,ECHAR:ba,NIL:ha,WS:l,COMMENT:hc,ANON:fc,PN_CHARS_BASE:kb,PN_CHARS_U:pa,VARNAME:jb,PN_CHARS:ya,PN_PREFIX:gc,PN_LOCAL:ib};if(b!==void 0){if(ca[b]===void 0)throw Error("Invalid rule name: "+a(b)+".");}else b="SPARQL";var d=0,k=0,sa=0,ab=[],V=function(a){for(var b="",
d=0;d<a.length;d++)b+=typeof a[d]==="string"?a[d]:a[d].join("");return b},aa=0,nb=function(a){for(var b="",d=0;d<a.length;d++)b+=a[d];return b.toUpperCase()},ca=ca[b]();if(ca===null||d!==e.length){var ca=Math.max(d,sa),kc=ca<e.length?e.charAt(ca):null,ic=jc();throw new this.SyntaxError(lb(ab),kc,ca,ic.line,ic.column);}return ca},toSource:function(){return this._source},SyntaxError:function(b,c,i,h,f){this.name="SyntaxError";this.expected=b;this.found=c;this.message=function(b,c){var e,f;switch(b.length){case 0:e=
"end of input";break;case 1:e=b[0];break;default:e=b.slice(0,b.length-1).join(", ")+" or "+b[b.length-1]}f=c?a(c):"end of input";return"Expected "+e+" but "+f+" found."}(b,c);this.offset=i;this.line=h;this.column=f}};b.SyntaxError.prototype=Error.prototype;return b}();var za=function(){var a={RDFSink_uniqueURI:function(){return"https://github.com/antoniogarrote/rdfstore-js/vocabulary/unique#"},graph:null,Util:{ArrayIndexOf:function(a,e,c){c||(c=0);var i=a.length;for(c<0&&(c=i+c);c<i;c++)if(a[c]===
e)return c;return-1}}};if(typeof a.Util.uri=="undefined")a.Util.uri={};a.Util.uri.join=function(a,e){var a=a||"",c=e.indexOf("#");c>0&&(e=e.slice(0,c));if(a.length==0)return e;if(a.indexOf("#")==0)return e+a;if(a.indexOf(":")>=0)return a;var i=e.indexOf(":");if(e=="")return a;if(i<0)return alert("Invalid base: "+e+" in join with "+a),a;c=e.slice(0,i+1);if(a.indexOf("//")==0)return c+a;if(e.indexOf("//",i)==i+1){var h=e.indexOf("/",i+3);if(h<0)return e.length-i-3>0?e+"/"+a:c+a}else if(h=e.indexOf("/",
i+1),h<0)return e.length-i-1>0?e+"/"+a:c+a;if(a.indexOf("/")==0)return e.slice(0,h)+a;var i=e.slice(h),f=i.lastIndexOf("/");if(f<0)return c+a;f>=0&&f<i.length-1&&(i=i.slice(0,f+1));for(i+=a;i.match(/[^\/]*\/\.\.\//);)i=i.replace(/[^\/]*\/\.\.\//,"");i=i.replace(/\.\//g,"");i=i.replace(/\/\.$/,"/");return e.slice(0,h)+i};a.Empty=function(){return this};a.Empty.prototype.termType="empty";a.Empty.prototype.toString=function(){return"()"};a.Empty.prototype.toQuads=function(){return{uri:"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"}};
a.Symbol=function(a){this.value=this.uri=a;return this};a.Symbol.prototype.termType="symbol";a.Symbol.prototype.toString=function(){return"<"+this.uri+">"};a.Symbol.prototype.toQuads=function(){return{token:"uri",prefix:null,suffix:null,value:this.uri}};a.Symbol.prototype.XSDboolean=new a.Symbol("http://www.w3.org/2001/XMLSchema#boolean");a.Symbol.prototype.XSDdecimal=new a.Symbol("http://www.w3.org/2001/XMLSchema#decimal");a.Symbol.prototype.XSDfloat=new a.Symbol("http://www.w3.org/2001/XMLSchema#float");
a.Symbol.prototype.XSDinteger=new a.Symbol("http://www.w3.org/2001/XMLSchema#integer");a.Symbol.prototype.XSDdateTime=new a.Symbol("http://www.w3.org/2001/XMLSchema#dateTime");a.Symbol.prototype.integer=new a.Symbol("http://www.w3.org/2001/XMLSchema#integer");typeof a.NextId!="undefined"?a.log.error("Attempt to re-zero existing blank node id counter at "+a.NextId):a.NextId=0;a.NTAnonymousNodePrefix="_:";a.BlankNode=function(b){this.id=a.NextId++;this.value=b?b:this.id.toString();return this};a.BlankNode.prototype.termType=
"bnode";a.BlankNode.prototype.toString=function(){return a.NTAnonymousNodePrefix+this.id};a.BlankNode.prototype.toString=a.BlankNode.prototype.toNT;a.BlankNode.prototype.toQuads=function(){return{blank:a.NTAnonymousNodePrefix+this.id}};a.Literal=function(a,e,c){this.value=a;this.lang=e==""||e==null?void 0:e;this.datatype=c==null?void 0:c;return this};a.Literal.prototype.termType="literal";a.Literal.prototype.toNT=function(){var a=this.value;if(typeof a!="string"){if(typeof a=="number")return""+a;
throw Error("Value of RDF literal is not string: "+a);}a=a.replace(/\\/g,"\\\\");a=a.replace(/\"/g,'\\"');a=a.replace(/\n/g,"\\n");a='"'+a+'"';this.datatype&&(a=a+"^^"+this.datatype.toNT());this.lang&&(a=a+"@"+this.lang);return a};a.Literal.prototype.toQuads=function(){var a=this.value;if(typeof a!="string"){if(typeof a=="number")return""+a;throw Error("Value of RDF literal is not string: "+a);}a=a.replace(/\\/g,"\\\\");a=a.replace(/\"/g,'\\"');a=a.replace(/\n/g,"\\n");a='"'+a+'"';this.datatype&&
(a=a+"^^<"+this.datatype.value+">");this.lang&&(a=a+"@"+this.lang);return{literal:a}};a.Collection=function(){this.id=a.NextId++;this.elements=[];this.closed=!1};a.Collection.idCounter=0;a.Collection.prototype.termType="collection";a.Collection.prototype.toNT=function(){return a.NTAnonymousNodePrefix+this.id};a.Collection.prototype.toQuads=function(){var b=[],e="_:list"+a.Collection.idCounter;a.Collection.idCounter++;for(var c={uri:"http://www.w3.org/1999/02/22-rdf-syntax-ns#first"},i={uri:"http://www.w3.org/1999/02/22-rdf-syntax-ns#rest"},
h={uri:"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"},f,g={blank:e+"p"+o},o=0;o<this.elements.length;o++)f=g,g=o<this.elements.length-1?{blank:e+"p"+(o+1)}:h,b.push({subject:f,predicate:c,object:this.elements[o].toQuads(),graph:a.graph}),b.push({subject:f,predicate:i,object:g,graph:a.graph});return b};a.Collection.prototype.append=function(a){this.elements.push(a)};a.Collection.prototype.unshift=function(a){this.elements.unshift(a)};a.Collection.prototype.shift=function(){return this.elements.shift()};
a.Collection.prototype.close=function(){this.closed=!0};a.term=function(b){if(typeof b=="object")if(b instanceof Date){var e=function(a){return(""+(100+a)).slice(1,3)};return new a.Literal(""+b.getUTCFullYear()+"-"+e(b.getUTCMonth()+1)+"-"+e(b.getUTCDate())+"T"+e(b.getUTCHours())+":"+e(b.getUTCMinutes())+":"+e(b.getUTCSeconds())+"Z",void 0,a.Symbol.prototype.XSDdateTime)}else if(b instanceof Array){for(var e=new a.Collection,c=0;c<b.length;c++)e.append(a.term(b[c]));return e}else return b;if(typeof b==
"string")return new a.Literal(b);if(typeof b=="number")return e=(""+b).indexOf("e")>=0?a.Symbol.prototype.XSDfloat:(""+b).indexOf(".")>=0?a.Symbol.prototype.XSDdecimal:a.Symbol.prototype.XSDinteger,new a.Literal(b,void 0,e);if(typeof b=="boolean")return new a.Literal(b?"1":"0",void 0,a.Symbol.prototype.XSDboolean);if(typeof b!="undefined")throw"Can't make term from "+b+" of type "+typeof b;};a.Statement=function(b,e,c,i){this.subject=a.term(b);this.predicate=a.term(e);this.object=a.term(c);if(typeof i!=
"undefined")this.why=i;return this};a.st=function(b,e,c,i){return new a.Statement(b,e,c,i)};a.Statement.prototype.toNT=function(){return this.subject.toNT()+" "+this.predicate.toNT()+" "+this.object.toNT()+" ."};a.Statement.prototype.toQuads=function(){var b=this.object.toQuads();if(b.constructor===Array){var e=b[0].subject;b.push({subject:this.subject.toQuads(),predicate:this.predicate.toQuads(),object:e,graph:a.graph});return b}else return{subject:this.subject.toQuads(),predicate:this.predicate.toQuads(),
object:this.object.toQuads(),graph:a.graph}};a.Formula=function(){this.statements=[];return this};a.Formula.prototype.termType="formula";a.Formula.prototype.toNT=function(){return"{"+this.statements.join("\n")+"}"};a.Formula.prototype.toQuads=function(){for(var a=[],e=0;e<this.statements.length;e++){var c=this.statements[e].toQuads();c.constructor===Array?a=a.concat(c):a.push(c)}return a};a.Formula.prototype.add=function(b,e,c,i){this.statements.push(new a.Statement(b,e,c,i))};a.Formula.prototype.sym=
function(b){return new a.Symbol(b)};a.sym=function(b){return new a.Symbol(b)};a.Formula.prototype.literal=function(b,e,c){if(c!=null&&c.value!=null&&c.value.indexOf("http://")===-1)for(var i in this.namespaces)if(c.value.indexOf(i)===0){c.value=this.namespaces[i]+c.value.split(i+":")[1];break}return new a.Literal(""+b,e,c)};a.lit=a.Formula.prototype.literal;a.Formula.prototype.bnode=function(b){return new a.BlankNode(b)};a.Formula.prototype.formula=function(){return new a.Formula};a.Formula.prototype.collection=
function(){return new a.Collection};a.Formula.prototype.list=function(b){li=new a.Collection;if(b)for(var e=0;e<b.length;e++)li.append(b[e]);return li};a.Graph=function(){return new a.IndexedFormula};a.N3Parser=function(){function b(b,c,e,i,g,n,o,t){typeof c=="undefined"&&(c=null);typeof e=="undefined"&&(e="");typeof i=="undefined"&&(i=null);typeof g=="undefined"&&(g="");typeof o=="undefined"&&(o="");typeof t=="undefined"&&(t=null);this._bindings=new f([]);this._flags=o;e&&e!=""&&(q(e.indexOf(":")>=
0,"Document URI not absolute: "+e),this._bindings[""]=e+"#");this._store=b;g&&b.setGenPrefix(g);this._thisDoc=e;this.source=b.sym(e);this.previousLine=this.startOfLine=this.statementCount=this.lines=0;this._genPrefix=g;this.keywords=new h(["a","this","bind","has","is","of","true","false"]);this.keywordsSet=0;this._anonymousNodes=new f([]);this._variables=new f([]);this._parentVariables=new f([]);this._reason=t;this._reason2=null;if(u)this._reason2=why_BecauseOfData(b.sym(e),this._reason);this._baseURI=
i?i:e?e:null;q(!this._baseURI||this._baseURI.indexOf(":")>=0);if(!this._genPrefix)this._genPrefix=this._thisDoc?this._thisDoc+"#_g":a.RDFSink_uniqueURI();this._context=this._formula=c==null?this._thisDoc?b.formula(e+"#_formula"):b.formula():c;this._parentContext=null}function e(a,b,c,e,f){return"Line "+(b+1)+" of <"+a+">: Bad syntax: "+f+'\nat: "'+g(c,e,e+30)+'"'}var c={encode:function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",c=0;c<a.length;c++){var e=a.charCodeAt(c);e<128?b+=String.fromCharCode(e):
(e>127&&e<2048?b+=String.fromCharCode(e>>6|192):(b+=String.fromCharCode(e>>12|224),b+=String.fromCharCode(e>>6&63|128)),b+=String.fromCharCode(e&63|128))}return b},decode:function(a){for(var b="",c=0;c<a.length;){var e=a.charCodeAt(c);e<128?(b+=String.fromCharCode(e),c++):e>191&&e<224?(b+=String.fromCharCode((e&31)<<6|a.charCodeAt(c+1)&63),c+=2):(b+=String.fromCharCode((e&15)<<12|(a.charCodeAt(c+1)&63)<<6|a.charCodeAt(c+2)&63),c+=3)}return b}},i=function(a){return a},h=function(a){return a},f=function(a){if(a.length>
0)throw"missing.js: oops nnonempty dict not imp";return[]},g=function(a,b,c){if(typeof a.slice=="undefined")throw"@@ mising.js: No .slice function for "+a+" of type "+typeof a;return typeof c=="undefined"||c==null?a.slice(b):a.slice(b,c)},o=Error("dummy error stop iteration"),t=function(a){this.last=0;this.li=a;this.next=function(){if(this.last==this.li.length)throw o;return this.li[this.last++]};return this},q=function(a,b){if(!a){if(b)throw"python Assertion failed: "+b;throw"(python) Assertion failed.";
}};String.prototype.encode=function(a){if(a!="utf-8")throw"UTF8_converter: can only do utf-8";return c.encode(this)};String.prototype.decode=function(a){if(a!="utf-8")throw"UTF8_converter: can only do utf-8";return this};var u=0,v=RegExp("^([-+]?[0-9]+)(\\.[0-9]+)?(e[-+]?[0-9]+)?","g"),x=RegExp('[\\\\\\r\\n\\"]',"g"),A=RegExp("^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)?","g");b.prototype.here=function(a){return this._genPrefix+"_L"+this.lines+"C"+(a-this.startOfLine+1)};b.prototype.formula=function(){return this._formula};
b.prototype.loadStream=function(a){return this.loadBuf(a.read())};b.prototype.loadBuf=function(a){this.startDoc();this.feed(a);return this.endDoc()};b.prototype.feed=function(a){var b=a.decode("utf-8"),a=[],c=b.length,e=0;numChunks=c/524288;for(var f=0;f<numChunks+1;f++)e+524288<c?a.push(b.substring(e,e+524288)):a.push(b.substring(e,c)),e+=524288;for(f=b=0;f>=0;)if(c=this.skipSpace(a[b],f),c<0)if(b==a.length-1)break;else b++,f=0;else{f=c;try{f=this.directiveOrStatement(a[b],c)}catch(h){if(b==a.length-
1)throw h;c=f;f=-1}f<0&&(f=a[b].substring(c,a[b].length),b++,a[b]=f+a[b],f=0)}};b.prototype.directiveOrStatement=function(a,b){var c=this.skipSpace(a,b);if(c<0)return c;var e=this.directive(a,c);if(e>=0)return this.checkDot(a,e);e=this.statement(a,c);return e>=0?this.checkDot(a,e):e};b.prototype.tok=function(b,c,e){if(g(c,e,e+1)=="@")e+=1;else if(a.Util.ArrayIndexOf(this.keywords,b)<0)return-1;var f=e+b.length;return g(c,e,f)==b&&"\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~".indexOf(c.charAt(f))>=0?f:
-1};b.prototype.directive=function(b,c){var f=this.skipSpace(b,c);if(f<0)return f;var i=new h([]),f=this.tok("bind",b,c);if(f>0)throw e(this._thisDoc,this.lines,b,c,"keyword bind is obsolete: use @prefix");f=this.tok("keywords",b,c);if(f>0){c=this.commaSeparatedList(b,f,i,!1);if(c<0)throw e(this._thisDoc,this.lines,b,c,"'@keywords' needs comma separated list of words");this.setKeywords(g(i,null,null));return c}f=this.tok("forAll",b,c);if(f>0){c=this.commaSeparatedList(b,f,i,!0);if(c<0)throw e(this._thisDoc,
this.lines,b,c,"Bad variable list after @forAll");f=new t(i);try{for(;;){var u=f.next();if(a.Util.ArrayIndexOf(this._variables,u)<0||a.Util.ArrayIndexOf(this._parentVariables,u)>=0)this._variables[u]=this._context.newUniversal(u)}}catch(v){if(v!=o)throw v;}return c}f=this.tok("forSome",b,c);if(f>0){c=this.commaSeparatedList(b,f,i,this.uri_ref2);if(c<0)throw e(this._thisDoc,this.lines,b,c,"Bad variable list after @forSome");f=new t(i);try{for(;;)u=f.next(),this._context.declareExistential(u)}catch(y){if(y!=
o)throw y;}return c}f=this.tok("prefix",b,c);if(f>=0){u=new h([]);c=this.qname(b,f,u);if(c<0)throw e(this._thisDoc,this.lines,b,f,"expected qname after @prefix");f=this.uri_ref2(b,c,u);if(f<0)throw e(this._thisDoc,this.lines,b,c,"expected <uriref> after @prefix _qname_");i=u[1].uri;this._baseURI?i=a.Util.uri.join(i,this._baseURI):q(i.indexOf(":")>=0,"With no base URI, cannot handle relative URI for NS");q(i.indexOf(":")>=0);this._bindings[u[0][0]]=i;this.bind(u[0][0],encodeURI(i));return f}f=this.tok("base",
b,c);if(f>=0){u=new h([]);c=this.uri_ref2(b,f,u);if(c<0)throw e(this._thisDoc,this.lines,b,f,"expected <uri> after @base ");i=u[0].uri;if(this._baseURI)i=a.Util.uri.join(i,this._baseURI);else throw e(this._thisDoc,this.lines,b,f,"With no previous base URI, cannot use relative URI in @base <"+i+">");q(i.indexOf(":")>=0);this._baseURI=i;return c}return-1};b.prototype.bind=function(a,b){this._store.setPrefixForURI(a,b);a!=""&&this._store.setPrefixForURI(a,b)};b.prototype.setKeywords=function(a){a==
null?this.keywordsSet=0:(this.keywords=a,this.keywordsSet=1)};b.prototype.startDoc=function(){};b.prototype.endDoc=function(){return this._formula};b.prototype.makeStatement=function(a){a[0].add(a[2],a[1],a[3],this.source);this.statementCount+=1};b.prototype.statement=function(a,b){var c=new h([]),b=this.object(a,b,c);if(b<0)return b;c=this.property_list(a,b,c[0]);if(c<0)throw e(this._thisDoc,this.lines,a,b,"expected propertylist");return c};b.prototype.subject=function(a,b,c){return this.item(a,
b,c)};b.prototype.verb=function(a,b,c){var f=this.skipSpace(a,b);if(f<0)return f;var o=new h([]),f=this.tok("has",a,b);if(f>=0){b=this.prop(a,f,o);if(b<0)throw e(this._thisDoc,this.lines,a,f,"expected property after 'has'");c.push(new i(["->",o[0]]));return b}f=this.tok("is",a,b);if(f>=0){b=this.prop(a,f,o);if(b<0)throw e(this._thisDoc,this.lines,a,f,"expected <property> after 'is'");f=this.skipSpace(a,b);if(f<0)throw e(this._thisDoc,this.lines,a,b,"End of file found, expected property after 'is'");
b=f;f=this.tok("of",a,b);if(f<0)throw e(this._thisDoc,this.lines,a,b,"expected 'of' after 'is' <prop>");c.push(new i(["<-",o[0]]));return f}f=this.tok("a",a,b);if(f>=0)return c.push(new i(["->",this._store.sym("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")])),f;if(g(a,b,b+2)=="<=")return c.push(new i(["<-",this._store.sym("http://www.w3.org/2000/10/swap/log#implies")])),b+2;if(g(a,b,b+1)=="="){if(g(a,b+1,b+2)==">")return c.push(new i(["->",this._store.sym("http://www.w3.org/2000/10/swap/log#implies")])),
b+2;c.push(new i(["->",this._store.sym("http://www.w3.org/2002/07/owl#sameAs")]));return b+1}if(g(a,b,b+2)==":=")return c.push(new i(["->","http://www.w3.org/2000/10/swap/log#becomes"])),b+2;f=this.prop(a,b,o);if(f>=0)return c.push(new i(["->",o[0]])),f;if(g(a,b,b+2)==">-"||g(a,b,b+2)=="<-")throw e(this._thisDoc,this.lines,a,f,">- ... -> syntax is obsolete.");return-1};b.prototype.prop=function(a,b,c){return this.item(a,b,c)};b.prototype.item=function(a,b,c){return this.path(a,b,c)};b.prototype.blankNode=
function(a){return this._context.bnode(a,this._reason2)};b.prototype.path=function(a,b,c){b=this.nodeOrLiteral(a,b,c);if(b<0)return b;for(;"!^.".indexOf(g(a,b,b+1))>=0;){var f=g(a,b,b+1);if(f=="."){var h=g(a,b+1,b+2);if(!h||"\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(h)>=0&&":?<[{(".indexOf(h)<0)break}var h=c.pop(),o=this.blankNode(this.here(b)),b=this.node(a,b+1,c);if(b<0)throw e(this._thisDoc,this.lines,a,b,"EOF found in middle of path syntax");var q=c.pop();f=="^"?this.makeStatement(new i([this._context,
q,o,h])):this.makeStatement(new i([this._context,q,h,o]));c.push(o)}return b};b.prototype.anonymousNode=function(a){var b=this._anonymousNodes[a];if(b)return b;b=this._store.bnode(this._context,this._reason2);return this._anonymousNodes[a]=b};b.prototype.node=function(a,b,c,s){typeof s=="undefined"&&(s=null);var q=s,s=this.skipSpace(a,b);if(s<0)return s;b=s;s=g(a,b,b+1);if(s=="["){var u=this.here(b),s=this.skipSpace(a,b+1);if(s<0)throw e(this._thisDoc,this.lines,a,b,"EOF after '['");if(g(a,s,s+1)==
"="){var b=s+1,y=new h([]),s=this.objectList(a,b,y);if(s>=0){q=y[0];if(y.length>1){y=new t(y);try{for(;;){var v=y.next();this.makeStatement(new i([this._context,this._store.sym("http://www.w3.org/2002/07/owl#sameAs"),q,v]))}}catch(F){if(F!=o)throw F;}}s=this.skipSpace(a,s);if(s<0)throw e(this._thisDoc,this.lines,a,b,"EOF when objectList expected after [ = ");g(a,s,s+1)==";"&&(s+=1)}else throw e(this._thisDoc,this.lines,a,b,"objectList expected after [= ");}q==null&&(q=this.blankNode(u));b=this.property_list(a,
s,q);if(b<0)throw e(this._thisDoc,this.lines,a,s,"property_list expected");s=this.skipSpace(a,b);if(s<0)throw e(this._thisDoc,this.lines,a,b,"EOF when ']' expected after [ <propertyList>");if(g(a,s,s+1)!="]")throw e(this._thisDoc,this.lines,a,s,"']' expected");c.push(q);return s+1}if(s=="{"){s=g(a,b+1,b+2);if(s=="$"){b+=1;s=b+1;q=new h([]);for(u=!0;;){b=this.skipSpace(a,s);if(b<0)throw e(this._thisDoc,this.lines,a,b,"needed '$}', found end.");if(g(a,b,b+2)=="$}"){s=b+2;break}if(u)u=!1;else if(g(a,
b,b+1)==",")b+=1;else throw e(this._thisDoc,this.lines,a,b,"expected: ','");v=new h([]);s=this.item(a,b,v);if(s<0)throw e(this._thisDoc,this.lines,a,b,"expected item in set or '$}'");q.push(v[0])}c.push(this._store.newSet(q,this._context))}else{s=b+1;v=this._parentContext;this._parentContext=this._context;u=this._anonymousNodes;y=this._parentVariables;this._parentVariables=this._variables;this._anonymousNodes=new f([]);this._variables=this._variables.slice();var x=this._reason2;this._reason2=null;
q==null&&(q=this._store.formula());for(this._context=q;;){b=this.skipSpace(a,s);if(b<0)throw e(this._thisDoc,this.lines,a,b,"needed '}', found end.");if(g(a,b,b+1)=="}"){s=b+1;break}s=this.directiveOrStatement(a,b);if(s<0)throw e(this._thisDoc,this.lines,a,b,"expected statement or '}'");}this._anonymousNodes=u;this._variables=this._parentVariables;this._parentVariables=y;this._context=this._parentContext;this._reason2=x;this._parentContext=v;c.push(q.close())}return s}if(s=="("){u=this._store.list;
s=g(a,b+1,b+2);if(s=="$")u=this._store.newSet,b+=1;s=b+1;for(q=new h([]);;){b=this.skipSpace(a,s);if(b<0)throw e(this._thisDoc,this.lines,a,b,"needed ')', found end.");if(g(a,b,b+1)==")"){s=b+1;break}v=new h([]);s=this.item(a,b,v);if(s<0)throw e(this._thisDoc,this.lines,a,b,"expected item in list or ')'");q.push(v[0])}c.push(u(q,this._context));return s}s=this.tok("this",a,b);if(s>=0)throw e(this._thisDoc,this.lines,a,b,"Keyword 'this' was ancient N3. Now use @forSome and @forAll keywords.");s=this.tok("true",
a,b);if(s>=0)return c.push(!0),s;s=this.tok("false",a,b);return s>=0?(c.push(!1),s):q==null&&(s=this.uri_ref2(a,b,c),s>=0)?s:-1};b.prototype.property_list=function(a,b,c){for(;;){var f=this.skipSpace(a,b);if(f<0)throw e(this._thisDoc,this.lines,a,b,"EOF found when expected verb in property list");if(g(a,f,f+2)==":-"){var b=f+2,q=new h([]),f=this.node(a,b,q,c);if(f<0)throw e(this._thisDoc,this.lines,a,b,"bad {} or () or [] node after :- ");b=f}else{b=f;q=new h([]);f=this.verb(a,b,q);if(f<=0)return b;
var u=new h([]),b=this.objectList(a,f,u);if(b<0)throw e(this._thisDoc,this.lines,a,f,"objectList expected");f=new t(u);try{for(;;){var v=f.next(),F=q[0],x=F[1];F[0]=="->"?this.makeStatement(new i([this._context,x,c,v])):this.makeStatement(new i([this._context,x,v,c]))}}catch(ea){if(ea!=o)throw ea;}f=this.skipSpace(a,b);if(f<0)throw e(this._thisDoc,this.lines,a,f,"EOF found in list of objects");if(g(a,b,b+1)!=";")return b;b+=1}}};b.prototype.commaSeparatedList=function(a,b,c,f){var h=this.skipSpace(a,
b);if(h<0)throw e(this._thisDoc,this.lines,a,h,"EOF found expecting comma sep list");if(a.charAt(h)==".")return b;h=f?this.uri_ref2(a,h,c):this.bareWord(a,h,c);if(h<0)return-1;for(;;){b=this.skipSpace(a,h);if(b<0)return b;h=g(a,b,b+1);if(h!=",")return h!="."?-1:b;h=f?this.uri_ref2(a,b+1,c):this.bareWord(a,b+1,c);if(h<0)throw e(this._thisDoc,this.lines,a,h,"bad list content");}};b.prototype.objectList=function(a,b,c){b=this.object(a,b,c);if(b<0)return-1;for(;;){b=this.skipSpace(a,b);if(b<0)throw e(this._thisDoc,
this.lines,a,b,"EOF found after object");if(g(a,b,b+1)!=",")return b;b=this.object(a,b+1,c);if(b<0)return b}};b.prototype.checkDot=function(a,b){var c=this.skipSpace(a,b);if(c<0)return c;if(g(a,c,c+1)==".")return c+1;if(g(a,c,c+1)=="}")return c;if(g(a,c,c+1)=="]")return c;throw e(this._thisDoc,this.lines,a,c,"expected '.' or '}' or ']' at end of statement");};b.prototype.uri_ref2=function(b,c,f){var i=new h([]),o=this.qname(b,c,i);if(o>=0){var t=i[0],i=t[0],t=t[1];if(i==null){q(0,"not used?");var u=
this._baseURI+"#"}else if(u=this._bindings[i],!u){if(i=="_")return f.push(this.anonymousNode(t)),o;throw e(this._thisDoc,this.lines,b,c,"Prefix "+i+" not bound.");}b=this._store.sym(u+t);a.Util.ArrayIndexOf(this._variables,b)>=0?f.push(this._variables[b]):f.push(b);return o}c=this.skipSpace(b,c);if(c<0)return-1;if(b.charAt(c)=="?")return i=new h([]),o=this.variable(b,c,i),o>0?(f.push(i[0]),o):-1;else if(b.charAt(c)=="<"){c+=1;for(i=c;c<b.length;){if(b.charAt(c)==">")return o=g(b,i,c),this._baseURI?
o=a.Util.uri.join(o,this._baseURI):q(o.indexOf(":")>=0,"With no base URI, cannot deal with relative URIs"),g(b,c-1,c)=="#"&&g(o,-1,null)!="#"&&(o+="#"),b=this._store.sym(o),a.Util.ArrayIndexOf(this._variables,b)>=0?f.push(this._variables[b]):f.push(b),c+1;c+=1}throw e(this._thisDoc,this.lines,b,o,"unterminated URI reference");}else if(this.keywordsSet){i=new h([]);o=this.bareWord(b,c,i);if(o<0)return-1;if(a.Util.ArrayIndexOf(this.keywords,i[0])>=0)throw e(this._thisDoc,this.lines,b,c,'Keyword "'+
i[0]+'" not allowed here.');f.push(this._store.sym(this._bindings[""]+i[0]));return o}else return-1};b.prototype.skipSpace=function(a,b){for(var c=a,e=b?b:0;e<a.length;e++)if(" \n\r\t\u000c\u000b\u00a0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000".indexOf(a.charAt(e))===-1)if(a.charAt(e)==="#")a=a.slice(b).replace(/^[^\n]*\n/,""),b=0,e=-1;else break;val=c.length-a.length+e;return val===c.length?-1:val};b.prototype.variable=function(a,b,c){var f=this.skipSpace(a,
b);if(f<0)return-1;if(g(a,f,f+1)!="?")return-1;f+=1;b=f;if("0123456789-".indexOf(a.charAt(f))>=0)throw e(this._thisDoc,this.lines,a,f,"Varible name can't start with '"+a.charAt(f)+"s'");for(;b<a.length&&"\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(a.charAt(b))<0;)b+=1;if(this._parentContext==null)throw e(this._thisDoc,this.lines,a,f,"Can't use ?xxx syntax for variable in outermost level: "+g(a,f-1,b));c.push(this._store.variable(g(a,f,b)));return b};b.prototype.bareWord=function(a,b,c){var e=
this.skipSpace(a,b);if(e<0)return-1;b=a.charAt(e);if("0123456789-".indexOf(b)>=0)return-1;if("\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(b)>=0)return-1;for(b=e;b<a.length&&"\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(a.charAt(b))<0;)b+=1;c.push(g(a,e,b));return b};b.prototype.qname=function(b,c,e){c=this.skipSpace(b,c);if(c<0)return-1;var f=b.charAt(c);if("0123456789-+".indexOf(f)>=0)return-1;if("\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(f)<0){var h=f;for(c+=1;c<b.length;)if(f=b.charAt(c),
"\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(f)<0)h+=f,c+=1;else break}else h="";if(c<b.length&&b.charAt(c)==":"){var g=h;c+=1;for(h="";c<b.length;)if(f=b.charAt(c),"\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~:".indexOf(f)<0)h+=f,c+=1;else break;e.push(new i([g,h]));return c}else return h&&this.keywordsSet&&a.Util.ArrayIndexOf(this.keywords,h)<0?(e.push(new i(["",h])),c):-1};b.prototype.object=function(a,b,c){var e=this.subject(a,b,c);if(e>=0)return e;else{e=this.skipSpace(a,b);if(e<0)return-1;else b=
e;return a.charAt(b)=='"'?(e=g(a,b,b+3)=='"""'?'"""':'"',b+=e.length,a=this.strconst(a,b,e),e=a[0],c.push(this._store.literal(a[1])),e):-1}};b.prototype.nodeOrLiteral=function(a,b,c){var f=this.node(a,b,c);if(f>=0)return f;else{f=this.skipSpace(a,b);if(f<0)return-1;else b=f;if("-+0987654321".indexOf(a.charAt(b))>=0){v.lastIndex=0;var i=v.exec(a.slice(b));if(i==null)throw e(this._thisDoc,this.lines,a,b,"Bad number syntax");var f=b+v.lastIndex,o=g(a,b,f);o.indexOf("e")>=0?c.push(this._store.literal(parseFloat(o),
void 0,this._store.sym("http://www.w3.org/2001/XMLSchema#double"))):g(a,b,f).indexOf(".")>=0?c.push(this._store.literal(parseFloat(o),void 0,this._store.sym("http://www.w3.org/2001/XMLSchema#decimal"))):c.push(this._store.literal(parseInt(o),void 0,this._store.sym("http://www.w3.org/2001/XMLSchema#integer")));return f}if(a.charAt(b)=='"'){f=g(a,b,b+3)=='"""'?'"""':'"';b+=f.length;var o=null,q=this.strconst(a,b,f),f=q[0],q=q[1],i=null;if(g(a,f,f+1)=="@"){A.lastIndex=0;i=A.exec(a.slice(f+1));if(i==
null)throw e(this._thisDoc,startline,a,b,"Bad language code syntax on string literal, after @");b=A.lastIndex+f+1;i=g(a,f+1,b);f=b}g(a,f,f+2)=="^^"&&(b=new h([]),f=this.uri_ref2(a,f+2,b),o=b[0]);c.push(this._store.literal(q,i,o));return f}else return-1}};b.prototype.strconst=function(a,b,c){for(var f=b,h="",o=this.lines;f<a.length;){b=f+c.length;if(g(a,f,b)==c)return new i([b,h]);if(a.charAt(f)=='"')h+='"',f+=1;else{x.lastIndex=0;if(!x.exec(a.slice(f)))throw e(this._thisDoc,o,a,f,"Closing quote missing in string at ^ in "+
g(a,f-20,f)+"^"+g(a,f,f+20));b=f+x.lastIndex-1;h+=g(a,f,b);var q=a.charAt(b);if(q=='"')f=b;else if(q=="\r")f=b+1;else if(q=="\n"){if(c=='"')throw e(this._thisDoc,o,a,b,"newline found in string literal");this.lines+=1;h+=q;f=b+1;this.previousLine=this.startOfLine;this.startOfLine=f}else if(q=="\\"){f=b+1;q=g(a,f,f+1);if(!q)throw e(this._thisDoc,o,a,b,"unterminated string literal (2)");var t='abfrtvn\\"'.indexOf(q);if(t>=0)q='a\u0008\u000c\r\t\u000b\n\\"'.charAt(t),h+=q,f+=1;else if(q=="u")q=this.uEscape(a,
f+1,o),f=q[0],q=q[1],h+=q;else if(q=="U")q=this.UEscape(a,f+1,o),f=q[0],q=q[1],h+=q;else throw e(this._thisDoc,this.lines,a,b,"bad escape");}}}throw e(this._thisDoc,this.lines,a,b,"unterminated string literal");};b.prototype.uEscape=function(a,b,c){for(var f=b,h=0,o=0;h<4;){var q=g(a,f,f+1).toLowerCase();f+=1;if(q=="")throw e(this._thisDoc,c,a,b,"unterminated string literal(3)");q="0123456789abcdef".indexOf(q);if(q<0)throw e(this._thisDoc,c,a,b,"bad string literal hex escape");o=o*16+q;h+=1}a=String.fromCharCode(o);
return new i([f,a])};b.prototype.UEscape=function(a,b,c){for(var f=b,h=0,o="\\U";h<8;){var q=g(a,f,f+1).toLowerCase();f+=1;if(q=="")throw e(this._thisDoc,c,a,b,"unterminated string literal(3)");if("0123456789abcdef".indexOf(q)<0)throw e(this._thisDoc,c,a,b,"bad string literal hex escape");o+=q;h+=1}a="0x"+g(o,2,10)-0;a=String.fromCharCode(a);return new i([f,a])};return function(a,c,e,f,h,i,g,n){return new b(a,c,e,f,h,i,g,n)}}();a.IndexedFormula=function(){function b(b,c){if(typeof c!="object"){if(typeof c==
"string")return new a.Literal(c);if(typeof c=="number")return new a.Literal(c);if(typeof c=="boolean")return new a.Literal(c?"1":"0",void 0,a.Symbol.prototype.XSDboolean);else if(typeof c=="number")return new a.Literal(""+c);else if(typeof c=="undefined")return;else throw"Can't make Term from "+c+" of type "+typeof c;}return c}a.IndexedFormula=function(){this.statements=[];this.propertyActions=[];this.classActions=[];this.redirections=[];this.aliases=[];this.HTTPRedirects=[];this.subjectIndex=[];
this.predicateIndex=[];this.objectIndex=[];this.whyIndex=[];this.index=[this.subjectIndex,this.predicateIndex,this.objectIndex,this.whyIndex];this.namespaces={}};a.IndexedFormula.prototype=new a.Formula;a.IndexedFormula.prototype.constructor=a.IndexedFormula;a.IndexedFormula.SuperClass=a.Formula;a.IndexedFormula.prototype.setPrefixForURI=function(a,b){a=="tab"&&this.namespaces.tab||(this.namespaces[a]=b)};a.IndexedFormula.prototype.register=function(a,b){this.namespaces[a]=b};a.IndexedFormula.prototype.canon=
function(a){return a};a.IndexedFormula.prototype.add=function(e,c,i,h){h==void 0&&(h=this.fetcher?this.fetcher.appNode:this.sym("chrome:theSession"));e=b(this,e);c=b(this,c);i=b(this,i);h=b(this,h);e=new a.Statement(e,c,i,h);this.statements.push(e);return e};a.IndexedFormula.prototype.formula=function(b){return new a.IndexedFormula(b)};return a.IndexedFormula}();a.parse=function(b,e,c,i){try{if(i=="text/n3"||i=="text/turtle"){a.graph=c;a.N3Parser(e,e,null,null,null,null,"",null).loadBuf(b);return}}catch(h){throw"Error trying to parse N3 data:"+
h;}throw"Don't know how to parse "+i+" yet";};return a}(),ka={parser:{}};ka.parser.parse=function(a,b){var e=new za.Graph;try{za.parse(a,e,b,"text/n3")}catch(c){throw c;}return e.toQuads()};var u={defaultContext:{rdf:"http://www.w3.org/1999/02/22-rdf-syntax-ns#",rdfs:"http://www.w3.org/2000/01/rdf-schema#",owl:"http://www.w3.org/2002/07/owl#",xsd:"http://www.w3.org/2001/XMLSchema#",dcterms:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cal:"http://www.w3.org/2002/12/cal/ical#",vcard:"http://www.w3.org/2006/vcard/ns# ",
geo:"http://www.w3.org/2003/01/geo/wgs84_pos#",cc:"http://creativecommons.org/ns#",sioc:"http://rdfs.org/sioc/ns#",doap:"http://usefulinc.com/ns/doap#",com:"http://purl.org/commerce#",ps:"http://purl.org/payswarm#",gr:"http://purl.org/goodrelations/v1#",sig:"http://purl.org/signature#",ccard:"http://purl.org/commerce/creditcard#"},UrisMap:function(){this.defaultNs="";this.interfaceProperties=["get","remove","set","setDefault","addAll","resolve","shrink"]}};u.UrisMap.prototype.values=function(){var a=
{},b;for(b in this)!v.include(this.interfaceProperties,b)&&typeof this[b]!=="function"&&b!=="defaultNs"&&b!=="interfaceProperties"&&(a[b]=this[b]);return a};u.UrisMap.prototype.get=function(a){if(a.indexOf(" ")!=-1)throw"Prefix must not contain any whitespaces";return this[a]};u.UrisMap.prototype.remove=function(a){if(a.indexOf(" ")!=-1)throw"Prefix must not contain any whitespaces";delete this[a];return null};u.UrisMap.prototype.set=function(a,b){if(a.indexOf(" ")!=-1)throw"Prefix must not contain any whitespaces";
this[a]=b};u.UrisMap.prototype.setDefault=function(a){this.defaultNs=a};u.UrisMap.prototype.addAll=function(a,b){for(var e in a)v.include(this.interfaceProperties,e)||(this[e]!=null?b===!0&&(this[e]=a[e]):this[e]=a[e]);return this};u.UrisMap.prototype.resolve=function(a){var b=a.split(":"),a=b[0],b=b[1];return a===""?this.defaultNs==null?null:this.defaultNs+b:this[a]!=null?this[a]+b:null};u.UrisMap.prototype.shrink=function(a){for(var b in this){var e=this[b];if(a.indexOf(e)===0&&e!==""&&b!="defaultNs")return a=
a.split(e)[1],b+":"+a}return a};u.Profile=function(){this.prefixes=new u.UrisMap;this.terms=new u.UrisMap};u.Profile.prototype.importProfile=function(a,b){this.prefixes.addAll(a.prefixes,b);this.terms.addAll(a.terms,b)};u.Profile.prototype.resolve=function(a){return a.indexOf(":")!=-1?this.prefixes.resolve(a):this.terms[a]!=null?this.terms.resolve(a):null};u.Profile.prototype.setDefaultPrefix=function(a){this.prefixes.setDefault(a)};u.Profile.prototype.setDefaultVocabulary=function(a){this.terms.setDefault(a)};
u.Profile.prototype.setPrefix=function(a,b){this.prefixes.set(a,b)};u.Profile.prototype.setTerm=function(a,b){this.terms.set(a,b)};u.RDFEnvironment=function(){this.blankNodeCounter=0;var a=this;this.filters={s:function(a){return function(b){return b.subject.equals(a)}},p:function(a){return function(b){return b.predicate.equals(a)}},o:function(a){return function(b){return b.object.equals(a)}},sp:function(a,b){return function(i){return i.subject.equals(a)&&i.predicate.equals(b)}},so:function(a,b){return function(i){return i.subject.equals(a)&&
i.object.equals(b)}},po:function(a,b){return function(i){return i.predicate.equals(a)&&i.object.equals(b)}},spo:function(a,b,i){return function(h){return h.subject.equals(a)&&h.predicate.equals(b)&&h.object.equals(i)}},describes:function(a){return function(b){return b.subject.equals(a)||b.object.equals(a)}},type:function(b){var c=a.resolve("rdf:type");return function(a){return a.predicate.equals(c)&&a.object.equals(b)}}};for(var b in u.defaultContext)this.prefixes.set(b,u.defaultContext[b])};v["extends"](u.Profile,
u.RDFEnvironment);u.RDFEnvironment.prototype.createBlankNode=function(){var a=new u.BlankNode(this.blankNodeCounter);this.blankNodeCounter++;return a};u.RDFEnvironment.prototype.createNamedNode=function(a){var b=this.resolve(a);return b!=null?new u.NamedNode(b):new u.NamedNode(a)};u.RDFEnvironment.prototype.createLiteral=function(a,b,e){return e!=null?new u.Literal(a,b,e.toString()):new u.Literal(a,b,e)};u.RDFEnvironment.prototype.createTriple=function(a,b,e){return new u.Triple(a,b,e)};u.RDFEnvironment.prototype.createGraph=
function(a){var b=new u.Graph;if(a!=null)for(var e=0;e<a.length;e++)b.add(a[e]);return b};u.RDFEnvironment.prototype.createAction=function(a,b){return function(e){return a(e)?b(e):e}};u.RDFEnvironment.prototype.createProfile=function(a){return a===!0?new u.RDFEnvironment.Profile:(a=new u.RDFEnvironment.Profile,a.importProfile(this),a)};u.RDFEnvironment.prototype.createTermMap=function(a){if(a===!0)return new u.UrisMap;else{var a=this.terms.values(),b=new u.UrisMap,e;for(e in a)b[e]=a[e];return b}};
u.RDFEnvironment.prototype.createPrefixMap=function(a){if(a===!0)return new u.UrisMap;else{var a=this.prefixes.values(),b=new u.UrisMap,e;for(e in a)b[e]=a[e];return b}};u.RDFNode=function(a){this.interfaceName=a;this.attributes=["interfaceName","nominalValue"]};u.RDFNode.prototype.equals=function(a){if(a.interfaceName==null)return this.valueOf()==a;else{for(var b in this.attributes){var e=this.attributes[b];if(this[e]!=a[e])return!1}return!0}};u.BlankNode=function(a){u.RDFNode.call(this,"BlankNode");
this.nominalValue="_:"+a;this.bnodeId=a};v["extends"](u.RDFNode,u.BlankNode);u.BlankNode.prototype.toString=function(){return this.nominalValue};u.BlankNode.prototype.toNT=function(){return this.nominalValue};u.BlankNode.prototype.valueOf=function(){return this.nominalValue};u.Literal=function(a,b,e){u.RDFNode.call(this,"Literal");this.nominalValue=a;if(b!=null)this.language=b;else if(e!=null)this.datatype=e};v["extends"](u.RDFNode,u.Literal);u.Literal.prototype.toString=function(){var a='"'+this.nominalValue+
'"';if(this.language!=null)a=a+"@"+this.language;else if(this.datatype!=null||this.type)a=a+"^^<"+(this.datatype||this.type)+">";return a};u.Literal.prototype.toNT=function(){return this.toString()};u.Literal.prototype.valueOf=function(){return g.effectiveTypeValue({token:"literal",type:this.type||this.datatype,value:this.nominalValue,language:this.language})};u.NamedNode=function(a){u.RDFNode.call(this,"NamedNode");this.nominalValue=a.value!=null?a.value:a};v["extends"](u.RDFNode,u.NamedNode);u.NamedNode.prototype.toString=
function(){return this.nominalValue};u.NamedNode.prototype.toNT=function(){return"<"+this.toString()+">"};u.NamedNode.prototype.valueOf=function(){return this.nominalValue};u.Triple=function(a,b,e){this.subject=a;this.predicate=b;this.object=e};u.Triple.prototype.equals=function(a){return this.subject.equals(a.subject)&&this.predicate.equals(a.predicate)&&this.object.equals(a.object)};u.Triple.prototype.toString=function(){return this.subject.toNT()+" "+this.predicate.toNT()+" "+this.object.toNT()+
" . \r\n"};u.Graph=function(){this.triples=[];this.duplicates={};this.actions=[];this.length=0};u.Graph.prototype.add=function(a){for(var b=0;b<this.actions.length;b++)a=this.actions[b](a);b=a.subject.toString()+a.predicate.toString()+a.object.toString();this.duplicates[b]||(this.duplicates[b]=!0,this.triples.push(a));this.length=this.triples.length;return this};u.Graph.prototype.addAction=function(a,b){this.actions.push(a);if(b==!0)for(var e=0;e<this.triples.length;e++)this.triples[e]=a(this.triples[e]);
return this};u.Graph.prototype.addAll=function(a){for(var a=a.toArray(),b=0;b<a.length;b++)this.add(a[b]);this.length=this.triples.length;return this};u.Graph.prototype.remove=function(a){for(var b=null,e=0;e<this.triples.length;e++)if(this.triples[e].equals(a)){delete this.duplicates[a.subject.toString()+a.predicate.toString()+a.object.toString()];b=e;break}b!=null&&this.triples.splice(b,1);this.length=this.triples.length;return this};u.Graph.prototype.toArray=function(){return this.triples};u.Graph.prototype.some=
function(a){for(var b=0;b<this.triples.length;b++)if(a(this.triples[b],this)===!0)return!0;return!1};u.Graph.prototype.every=function(a){for(var b=0;b<this.triples.length;b++)if(a(this.triples[b],this)===!1)return!1;return!0};u.Graph.prototype.filter=function(a){for(var b=new u.Graph,e=0;e<this.triples.length;e++)a(this.triples[e],this)===!0&&b.add(this.triples[e]);return b};u.Graph.prototype.forEach=function(a){for(var b=0;b<this.triples.length;b++)a(this.triples[b],this)};u.Graph.prototype.merge=
function(){for(var a=new u.Graph,b=0;b<this.triples.length;b++)a.add(this.triples[b]);return a};u.Graph.prototype.match=function(a,b,e,c){for(var i=new u.Graph,h=0,f=0;f<this.triples.length;f++){var g=this.triples[f];if(a==null||g.subject.equals(a))if(b==null||g.predicate.equals(b))if(e==null||g.object.equals(e))if(c==null||h<c)h++,i.add(g);else break}return i};u.Graph.prototype.removeMatches=function(a,b,e){for(var c=[],i=0;i<this.triples.length;i++){var h=this.triples[i];if(a==null||h.subject.equals(a))if(b==
null||h.predicate.equals(b))(e==null||h.object.equals(e))&&c.push(h)}for(i=0;i<c.length;i++)this.remove(c[i]);return this};u.Graph.prototype.toNT=function(){var a="";this.forEach(function(b){a+=b.toString()});return a};u.buildRDFResource=function(a,b,e,c){return a.token==="blank"?u.buildBlankNode(a,b,e,c):a.token==="literal"?u.buildLiteral(a,b,e,c):a.token==="uri"?u.buildNamedNode(a,b,e,c):a.token==="var"?(a=b[a.value],a!=null?u.buildRDFResource(a,b,e,c):null):null};u.buildBlankNode=function(a){if(a.valuetmp!=
null)a.value=a.valuetmp;if(a.value.indexOf("_:")===0)a.value=a.value.split("_:")[1];return new u.BlankNode(a.value)};u.buildLiteral=function(a){return new u.Literal(a.value,a.lang,a.type)};u.buildNamedNode=function(a,b,e,c){if(a.value==null&&a.prefix!=null)b=e.resolveNsInEnvironment(a.prefix,c),a.value=b+a.suffix;return new u.NamedNode(a)};u.rdf=new u.RDFEnvironment;var g={checkFilters:function(a,b,e,c,i,h){var f=a.filter,n=[];if(f==null||a.length!=null)return b;for(a=0;a<f.length;a++){for(var b=
g.run(f[a].value,b,e,c,i,h),o=[],t=0;t<b.length;t++)b[t].__nullify__!=null?n.push(b[t]):o.push(b[t]);b=o}return b.concat(n)}};g.boundVars=function(a){if(a.expressionType!=null){var b=a.expressionType;if(b=="relationalexpression")return b=a.op2,g.boundVars(a.op1)+g.boundVars(b);else if(b=="conditionalor"||b=="conditionaland"){for(var e=[],b=0;b<a.operands;b++)e=e.concat(g.boundVars(a.operands[b]));return e}else if(b=="builtincall")if(a.args==null)return[];else{e=[];for(b=0;b<a.args.length;b++)e=e.concat(g.boundVars(a.args[b]));
return e}else if(b=="multiplicativeexpression"){e=g.boundVars(a.factor);for(b=0;b<a.factors.length;b++)e=e.concat(g.boundVars(a.factors[b].expression));return e}else if(b=="additiveexpression"){e=g.boundVars(a.summand);for(b=0;b<a.summands.length;b++)e=e.concat(g.boundVars(a.summands[b].expression));return e}else if(b=="regex")return e=g.boundVars(a.expression1),e.concat(g.boundVars(a.expression2));else if(b=="unaryexpression")return g.boundVars(a.expression);else if(b=="atomic")return a.primaryexpression==
"var"?[a.value]:[]}else throw console.log("ERROR"),console.log(a),"Cannot find bound expressions in a no expression token";};g.run=function(a,b,e,c,i,h){for(var f=h.copyDenormalizedBindings(b,i.outCache),n=[],o=0;o<b.length;o++){var t=g.runFilter(a,f[o],h,c,i),t=g.ebv(t);g.isEbvError(t)?e&&(t={__nullify__:!0,bindings:b[o]},n.push(t)):t===!0?n.push(b[o]):e&&(t={__nullify__:!0,bindings:b[o]},n.push(t))}return n};g.collect=function(a,b,e,c,i){for(var h=i.copyDenormalizedBindings(b,c.outCache),f=[],n=
0;n<h.length;n++){var o=g.runFilter(a,h[n],i,e,c);f.push({binding:b[n],value:o})}return f};g.runDistinct=function(){};g.runAggregator=function(a,b,e,c,i){if(b==null||b.length===0)return g.ebvError();else if(a.token==="variable"&&a.kind=="var")return b[0][a.value.value];else if(a.token==="variable"&&a.kind==="aliased")if(a.expression.expressionType==="atomic"&&a.expression.primaryexpression==="var")return b[0][a.expression.value.value];else if(a.expression.expressionType==="aggregate")if(a.expression.aggregateType===
"max"){for(var h=null,f=0;f<b.length;f++){var n=b[f],n=g.runFilter(a.expression.expression,n,e,c,i);g.isEbvError(n)||(h===null?h=n:g.runLtFunction(h,n).value===!0&&(h=n))}return h===null?g.ebvError():h}else if(a.expression.aggregateType==="min"){h=null;for(f=0;f<b.length;f++)n=b[f],n=g.runFilter(a.expression.expression,n,e,c,i),g.isEbvError(n)||(h===null?h=n:g.runGtFunction(h,n).value===!0&&(h=n));return h===null?g.ebvError():h}else if(a.expression.aggregateType==="count"){var h={},o=0;if(a.expression.expression===
"*")if(a.expression.distinct!=null&&a.expression.distinct!="")for(f=0;f<b.length;f++){var n=b[f],t=v.hashTerm(n);h[t]==null&&(h[t]=!0,o++)}else o=b.length;else for(f=0;f<b.length;f++)n=b[f],n=g.runFilter(a.expression.expression,n,e,c,i),g.isEbvError(n)||(a.expression.distinct!=null&&a.expression.distinct!=""?(t=v.hashTerm(n),h[t]==null&&(h[t]=!0,o++)):o++);return{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:""+o}}else if(a.expression.aggregateType==="avg"){for(var h={},q=
{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:"0"},f=o=0;f<b.length;f++)n=b[f],n=g.runFilter(a.expression.expression,n,e,c,i),g.isEbvError(n)||(a.expression.distinct!=null&&a.expression.distinct!=""?(t=v.hashTerm(n),h[t]==null&&(h[t]=!0,g.isNumeric(n)&&(q=g.runSumFunction(q,n),o++))):g.isNumeric(n)&&(q=g.runSumFunction(q,n),o++));a=g.runDivFunction(q,{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:""+o});a.value=""+a.value;return a}else if(a.expression.aggregateType===
"sum"){h={};q={token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:"0"};for(f=0;f<b.length;f++)n=b[f],n=g.runFilter(a.expression.expression,n,e,c,i),g.isEbvError(n)||(a.expression.distinct!=null&&a.expression.distinct!=""?(t=v.hashTerm(n),h[t]==null&&(h[t]=!0,g.isNumeric(n)&&(q=g.runSumFunction(q,n)))):g.isNumeric(n)&&(q=g.runSumFunction(q,n)));q.value=""+q.value;return q}else return n=g.runFilter(aggregate.expression,b[0],c,{blanks:{},outCache:{}})};g.runFilter=function(a,b,e,c,
i){if(a.expressionType!=null){var h=a.expressionType;if(h=="relationalexpression"){var h=g.runFilter(a.op1,b,e,c,i),f=g.runFilter(a.op2,b,e,c,i);return g.runRelationalFilter(a,h,f,b,e,c,i)}else if(h=="conditionalor")return g.runOrFunction(a,b,e,c,i);else if(h=="conditionaland")return g.runAndFunction(a,b,e,c,i);else if(h=="additiveexpression")return g.runAddition(a.summand,a.summands,b,e,c,i);else if(h=="builtincall")return g.runBuiltInCall(a.builtincall,a.args,b,e,c,i);else if(h=="multiplicativeexpression")return g.runMultiplication(a.factor,
a.factors,b,e,c,i);else if(h=="unaryexpression")return g.runUnaryExpression(a.unaryexpression,a.expression,b,e,c,i);else if(h=="irireforfunction")return g.runIriRefOrFunction(a.iriref,a.args,b,e,c,i);else if(h=="regex")return g.runRegex(a.text,a.pattern,a.flags,b,e,c,i);else if(h=="custom")return g.runBuiltInCall(a.name,a.args,b,e,c,i);else if(h=="atomic")if(a.primaryexpression=="var")return b[a.value.value];else{if(typeof a.value=="object"&&!(a.value.type==null||typeof a.value.type!="object"))a.value.type=
v.lexicalFormBaseUri(a.value.type,i);return a.value}else throw"Unknown filter expression type";}else throw"Cannot find bound expressions in a no expression token";};g.isRDFTerm=function(a){return a==null?!1:a.token&&a.token=="literal"||a.token&&a.token=="uri"||a.token&&a.token=="blank"?!0:!1};g.RDFTermEquality=function(a,b,e,c){return a.token==="literal"&&b.token==="literal"?a.lang==b.lang&&a.type==b.type&&a.value==b.value?!0:a.type!=null&&b.type!=null?g.ebvError():g.isSimpleLiteral(a)&&b.type!=null?
g.ebvError():g.isSimpleLiteral(b)&&a.type!=null?g.ebvError():!1:a.token==="uri"&&b.token==="uri"?v.lexicalFormBaseUri(a,c)==v.lexicalFormBaseUri(b,c):a.token==="blank"&&b.token==="blank"?a.value==b.value:!1};g.isInteger=function(a){return a==null?!1:a.token==="literal"?a.type=="http://www.w3.org/2001/XMLSchema#integer"||a.type=="http://www.w3.org/2001/XMLSchema#decimal"||a.type=="http://www.w3.org/2001/XMLSchema#double"||a.type=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"||a.type=="http://www.w3.org/2001/XMLSchema#negativeInteger"||
a.type=="http://www.w3.org/2001/XMLSchema#long"||a.type=="http://www.w3.org/2001/XMLSchema#int"||a.type=="http://www.w3.org/2001/XMLSchema#short"||a.type=="http://www.w3.org/2001/XMLSchema#byte"||a.type=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedLong"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedInt"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedShort"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedByte"||a.type=="http://www.w3.org/2001/XMLSchema#positiveInteger"?
!0:!1:!1};g.isFloat=function(a){return a==null?!1:a.token==="literal"?a.type=="http://www.w3.org/2001/XMLSchema#float"?!0:!1:!1};g.isDecimal=function(a){return a==null?!1:a.token==="literal"?a.type=="http://www.w3.org/2001/XMLSchema#decimal"?!0:!1:!1};g.isDouble=function(a){return a==null?!1:a.token==="literal"?a.type=="http://www.w3.org/2001/XMLSchema#double"?!0:!1:!1};g.isNumeric=function(a){return a==null?!1:a.token==="literal"?a.type=="http://www.w3.org/2001/XMLSchema#integer"||a.type=="http://www.w3.org/2001/XMLSchema#decimal"||
a.type=="http://www.w3.org/2001/XMLSchema#float"||a.type=="http://www.w3.org/2001/XMLSchema#double"||a.type=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"||a.type=="http://www.w3.org/2001/XMLSchema#negativeInteger"||a.type=="http://www.w3.org/2001/XMLSchema#long"||a.type=="http://www.w3.org/2001/XMLSchema#int"||a.type=="http://www.w3.org/2001/XMLSchema#short"||a.type=="http://www.w3.org/2001/XMLSchema#byte"||a.type=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedLong"||
a.type=="http://www.w3.org/2001/XMLSchema#unsignedInt"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedShort"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedByte"||a.type=="http://www.w3.org/2001/XMLSchema#positiveInteger"?!0:!1:!1};g.isSimpleLiteral=function(a){return a&&a.token=="literal"?a.type==null&&a.lang==null?!0:!1:!1};g.isXsdType=function(a,b){return b&&b.token=="literal"?b.type=="http://www.w3.org/2001/XMLSchema#"+a:!1};g.ebv=function(a){if(a==null||g.isEbvError(a))return g.ebvError();
else if(a.token&&a.token==="literal")if(a.type=="http://www.w3.org/2001/XMLSchema#integer"||a.type=="http://www.w3.org/2001/XMLSchema#decimal"||a.type=="http://www.w3.org/2001/XMLSchema#double"||a.type=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"||a.type=="http://www.w3.org/2001/XMLSchema#negativeInteger"||a.type=="http://www.w3.org/2001/XMLSchema#long"||a.type=="http://www.w3.org/2001/XMLSchema#int"||a.type=="http://www.w3.org/2001/XMLSchema#short"||a.type=="http://www.w3.org/2001/XMLSchema#byte"||
a.type=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedLong"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedInt"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedShort"||a.type=="http://www.w3.org/2001/XMLSchema#unsignedByte"||a.type=="http://www.w3.org/2001/XMLSchema#positiveInteger"){var b=parseFloat(a.value);return isNaN(b)?!1:parseFloat(a.value)!=0}else return a.type==="http://www.w3.org/2001/XMLSchema#boolean"?a.value==="true"||
a.value===!0||a.value==="True":a.type==="http://www.w3.org/2001/XMLSchema#string"?a.value!="":a.type==="http://www.w3.org/2001/XMLSchema#dateTime"?new Date(a.value)!=null:g.isEbvError(a)?a:a.type==null?a.value!=""?!0:!1:g.ebvError();else return a.value===!0};g.effectiveBooleanValue=g.ebv;g.ebvTrue=function(){return{token:"literal",type:"http://www.w3.org/2001/XMLSchema#boolean",value:!0}};g.ebvFalse=function(){return{token:"literal",type:"http://www.w3.org/2001/XMLSchema#boolean",value:!1}};g.ebvError=
function(){return{token:"literal",type:"https://github.com/antoniogarrote/js-tools/types#error",value:null}};g.isEbvError=function(a){return typeof a=="object"&&a!=null?a.type==="https://github.com/antoniogarrote/js-tools/types#error":!1};g.ebvBoolean=function(a){return g.isEbvError(a)?a:a===!0?g.ebvTrue():g.ebvFalse()};g.runRelationalFilter=function(a,b,e,c,i,h,f){a=a.operator;if(a==="=")return g.runEqualityFunction(b,e,c,i,h,f);else if(a==="!="){b=g.runEqualityFunction(b,e,c,i,h,f);if(!g.isEbvError(b))b.value=
!b.value;return b}else if(a==="<")return g.runLtFunction(b,e,c);else if(a===">")return g.runGtFunction(b,e,c);else if(a==="<=")return g.runLtEqFunction(b,e,c);else if(a===">=")return g.runGtEqFunction(b,e,c);else throw"Error applying relational filter, unknown operator";};g.effectiveTypeValue=function(a){if(a.token=="literal")if(a.type=="http://www.w3.org/2001/XMLSchema#integer")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#decimal")return a=parseFloat(a.value);else if(a.type==
"http://www.w3.org/2001/XMLSchema#float")return a=parseFloat(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#double")return a=parseFloat(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger")return a=parseFloat(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#negativeInteger")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#long")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#int")return a=parseInt(a.value);
else if(a.type=="http://www.w3.org/2001/XMLSchema#short")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#byte")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#unsignedLong")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#unsignedInt")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#unsignedShort")return a=
parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#unsignedByte")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#positiveInteger")return a=parseInt(a.value);else if(a.type=="http://www.w3.org/2001/XMLSchema#date"||a.type=="http://www.w3.org/2001/XMLSchema#dateTime")try{return v.parseISO8601(a.value)}catch(b){return null}else return a.type=="http://www.w3.org/2001/XMLSchema#boolean"?a.value===!0||a.value==="true"||a.value==="1"||a.value===1||a.value===
!0?!0:a.value===!1||a.value==="false"||a.value==="0"||a.value===0||a.value===!1?!1:void 0:a.type=="http://www.w3.org/2001/XMLSchema#string"?a.value===null||a.value===void 0?void 0:""+a.value:a.value;else throw console.log("not implemented yet"),"value not supported in operations yet";};g.runOrFunction=function(a,b,e,c,i){for(var h=null,f=0;f<a.operands.length;f++){var n=g.runFilter(a.operands[f],b,e,c,i);g.isEbvError(n)==!1&&(n=g.ebv(n));h==null?h=n:g.isEbvError(n)?h=g.isEbvError(h)?g.ebvError():
h===!0?!0:g.ebvError():n===!0?h=!0:g.isEbvError(h)&&(h=g.ebvError())}return g.ebvBoolean(h)};g.runAndFunction=function(a,b,e,c,i){for(var h=null,f=0;f<a.operands.length;f++){var n=g.runFilter(a.operands[f],b,e,c,i);g.isEbvError(n)==!1&&(n=g.ebv(n));h==null?h=n:g.isEbvError(n)?h=g.isEbvError(h)?g.ebvError():h===!0?g.ebvError():!1:n===!0?g.isEbvError(h)&&(h=g.ebvError()):h=!1}return g.ebvBoolean(h)};g.runEqualityFunction=function(a,b,e,c,i,h){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();
if(g.isNumeric(a)&&g.isNumeric(b))return e=g.effectiveTypeValue(a),i=g.effectiveTypeValue(b),isNaN(e)||isNaN(i)?g.ebvBoolean(g.RDFTermEquality(a,b,c,h)):g.ebvBoolean(e==i);else if((g.isSimpleLiteral(a)||g.isXsdType("string",a))&&(g.isSimpleLiteral(b)||g.isXsdType("string",b)))return g.ebvBoolean(g.effectiveTypeValue(a)==g.effectiveTypeValue(b));else if(g.isXsdType("boolean",a)&&g.isXsdType("boolean",b))return g.ebvBoolean(g.effectiveTypeValue(a)==g.effectiveTypeValue(b));else if((g.isXsdType("dateTime",
a)||g.isXsdType("date",a))&&(g.isXsdType("dateTime",b)||g.isXsdType("date",b))){if(g.isXsdType("dateTime",a)&&g.isXsdType("date",b))return g.ebvFalse();if(g.isXsdType("date",a)&&g.isXsdType("dateTime",b))return g.ebvFalse();a=v.compareDateComponents(a.value,b.value);return a!=null?a==0?g.ebvTrue():g.ebvFalse():g.ebvError()}else return g.isRDFTerm(a)&&g.isRDFTerm(b)?g.ebvBoolean(g.RDFTermEquality(a,b,c,h)):g.ebvFalse()};g.runGtFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();
if(g.isNumeric(a)&&g.isNumeric(b))return g.ebvBoolean(g.effectiveTypeValue(a)>g.effectiveTypeValue(b));else if(g.isSimpleLiteral(a)&&g.isSimpleLiteral(b))return g.ebvBoolean(g.effectiveTypeValue(a)>g.effectiveTypeValue(b));else if(g.isXsdType("string",a)&&g.isXsdType("string",b))return g.ebvBoolean(g.effectiveTypeValue(a)>g.effectiveTypeValue(b));else if(g.isXsdType("boolean",a)&&g.isXsdType("boolean",b))return g.ebvBoolean(g.effectiveTypeValue(a)>g.effectiveTypeValue(b));else if((g.isXsdType("dateTime",
a)||g.isXsdType("date",a))&&(g.isXsdType("dateTime",b)||g.isXsdType("date",b))){if(g.isXsdType("dateTime",a)&&g.isXsdType("date",b))return g.ebvFalse();if(g.isXsdType("date",a)&&g.isXsdType("dateTime",b))return g.ebvFalse();var e=v.compareDateComponents(a.value,b.value);return e!=null?e==1?g.ebvTrue():g.ebvFalse():g.ebvError()}else return g.ebvFalse()};g.runTotalGtFunction=function(a,b){return g.isEbvError(a)||g.isEbvError(b)?g.ebvError():g.isNumeric(a)&&g.isNumeric(b)||g.isSimpleLiteral(a)&&g.isSimpleLiteral(b)||
g.isXsdType("string",a)&&g.isSimpleLiteral("string",b)||g.isXsdType("boolean",a)&&g.isSimpleLiteral("boolean",b)||g.isXsdType("dateTime",a)&&g.isSimpleLiteral("dateTime",b)?g.runGtFunction(a,b,[]):a.token&&a.token==="uri"&&b.token&&b.token==="uri"?g.ebvBoolean(a.value>b.value):a.token&&a.token==="literal"&&b.token&&b.token==="literal"?g.ebvBoolean(""+a.value+a.type+a.lang>""+b.value+b.type+b.lang):a.token&&a.token==="blank"&&b.token&&b.token==="blank"?g.ebvBoolean(a.value>b.value):a.value&&b.value?
g.ebvBoolean(a.value>b.value):g.ebvTrue()};g.runLtFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();if(g.isNumeric(a)&&g.isNumeric(b))return g.ebvBoolean(g.effectiveTypeValue(a)<g.effectiveTypeValue(b));else if(g.isSimpleLiteral(a)&&g.isSimpleLiteral(b))return g.ebvBoolean(g.effectiveTypeValue(a)<g.effectiveTypeValue(b));else if(g.isXsdType("string",a)&&g.isXsdType("string",b))return g.ebvBoolean(g.effectiveTypeValue(a)<g.effectiveTypeValue(b));else if(g.isXsdType("boolean",
a)&&g.isXsdType("boolean",b))return g.ebvBoolean(g.effectiveTypeValue(a)<g.effectiveTypeValue(b));else if((g.isXsdType("dateTime",a)||g.isXsdType("date",a))&&(g.isXsdType("dateTime",b)||g.isXsdType("date",b))){if(g.isXsdType("dateTime",a)&&g.isXsdType("date",b))return g.ebvFalse();if(g.isXsdType("date",a)&&g.isXsdType("dateTime",b))return g.ebvFalse();var e=v.compareDateComponents(a.value,b.value);return e!=null?e==-1?g.ebvTrue():g.ebvFalse():g.ebvError()}else return g.ebvFalse()};g.runGtEqFunction=
function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();if(g.isNumeric(a)&&g.isNumeric(b))return g.ebvBoolean(g.effectiveTypeValue(a)>=g.effectiveTypeValue(b));else if(g.isSimpleLiteral(a)&&g.isSimpleLiteral(b))return g.ebvBoolean(g.effectiveTypeValue(a)>=g.effectiveTypeValue(b));else if(g.isXsdType("string",a)&&g.isXsdType("string",b))return g.ebvBoolean(g.effectiveTypeValue(a)>=g.effectiveTypeValue(b));else if(g.isXsdType("boolean",a)&&g.isXsdType("boolean",b))return g.ebvBoolean(g.effectiveTypeValue(a)>=
g.effectiveTypeValue(b));else if((g.isXsdType("dateTime",a)||g.isXsdType("date",a))&&(g.isXsdType("dateTime",b)||g.isXsdType("date",b))){if(g.isXsdType("dateTime",a)&&g.isXsdType("date",b))return g.ebvFalse();if(g.isXsdType("date",a)&&g.isXsdType("dateTime",b))return g.ebvFalse();var e=v.compareDateComponents(a.value,b.value);return e!=null?e!=-1?g.ebvTrue():g.ebvFalse():g.ebvError()}else return g.ebvFalse()};g.runLtEqFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();
if(g.isNumeric(a)&&g.isNumeric(b))return g.ebvBoolean(g.effectiveTypeValue(a)<=g.effectiveTypeValue(b));else if(g.isSimpleLiteral(a)&&g.isSimpleLiteral(b))return g.ebvBoolean(g.effectiveTypeValue(a)<=g.effectiveTypeValue(b));else if(g.isXsdType("string",a)&&g.isXsdType("string",b))return g.ebvBoolean(g.effectiveTypeValue(a)<=g.effectiveTypeValue(b));else if(g.isXsdType("boolean",a)&&g.isXsdType("boolean",b))return g.ebvBoolean(g.effectiveTypeValue(a)<=g.effectiveTypeValue(b));else if((g.isXsdType("dateTime",
a)||g.isXsdType("date",a))&&(g.isXsdType("dateTime",b)||g.isXsdType("date",b))){if(g.isXsdType("dateTime",a)&&g.isXsdType("date",b))return g.ebvFalse();if(g.isXsdType("date",a)&&g.isXsdType("dateTime",b))return g.ebvFalse();var e=v.compareDateComponents(a.value,b.value);return e!=null?e!=1?g.ebvTrue():g.ebvFalse():g.ebvError()}else return g.ebvFalse()};g.runAddition=function(a,b,e,c,i,h){var f=g.runFilter(a,e,c,i,h);if(g.isEbvError(f))return g.ebvError();a=f;if(g.isNumeric(f)){for(f=0;f<b.length;f++){var n=
g.runFilter(b[f].expression,e,c,i,h);if(g.isNumeric(n))b[f].operator==="+"?a=g.runSumFunction(a,n):b[f].operator==="-"&&(a=g.runSubFunction(a,n));else return g.ebvFalse()}return a}else return g.ebvFalse()};g.runSumFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();var e=g.effectiveTypeValue(a)+g.effectiveTypeValue(b);return g.isDouble(a)||g.isDouble(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#double",value:e}:g.isFloat(a)||g.isFloat(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#float",
value:e}:g.isDecimal(a)||g.isDecimal(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#decimal",value:e}:{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:e}};g.runSubFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();var e=g.effectiveTypeValue(a)-g.effectiveTypeValue(b);return g.isDouble(a)||g.isDouble(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#double",value:e}:g.isFloat(a)||g.isFloat(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#float",
value:e}:g.isDecimal(a)||g.isDecimal(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#decimal",value:e}:{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:e}};g.runMultiplication=function(a,b,e,c,i,h){a=g.runFilter(a,e,c,i,h);if(g.isEbvError(a))return a;var f=a;if(g.isNumeric(a)){for(var n=0;n<b.length;n++){var o=g.runFilter(b[n].expression,e,c,i,h);if(g.isEbvError(o))return a;if(g.isNumeric(o))b[n].operator==="*"?f=g.runMulFunction(f,o):b[n].operator==="/"&&(f=g.runDivFunction(f,
o));else return g.ebvFalse()}return f}else return g.ebvFalse()};g.runMulFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();var e=g.effectiveTypeValue(a)*g.effectiveTypeValue(b);return g.isDouble(a)||g.isDouble(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#double",value:e}:g.isFloat(a)||g.isFloat(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#float",value:e}:g.isDecimal(a)||g.isDecimal(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#decimal",
value:e}:{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:e}};g.runDivFunction=function(a,b){if(g.isEbvError(a)||g.isEbvError(b))return g.ebvError();var e=g.effectiveTypeValue(a)/g.effectiveTypeValue(b);return g.isDouble(a)||g.isDouble(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#double",value:e}:g.isFloat(a)||g.isFloat(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#float",value:e}:g.isDecimal(a)||g.isDecimal(b)?{token:"literal",type:"http://www.w3.org/2001/XMLSchema#decimal",
value:e}:{token:"literal",type:"http://www.w3.org/2001/XMLSchema#integer",value:e}};g.runBuiltInCall=function(a,b,e,c,i,h){if(a==="notexists"||a==="exists"){var f=JSON.parse(JSON.stringify(b[0])),f=c.abstractQueryTree.parseSelect({pattern:f},e),f=c.abstractQueryTree.bind(f.pattern,e),e=c.executeSelectUnit([{kind:"*"}],i,f,h);return a==="exists"?g.ebvBoolean(e.length!==0):g.ebvBoolean(e.length===0)}else{for(var f=[],n=0;n<b.length;n++)if(b[n].token==="var")f.push(b[n]);else{var o=g.runFilter(b[n],
e,c,i,h);if(g.isEbvError(o))return o;f.push(o)}if(a==="str")return f[0].token==="literal"?{token:"literal",type:null,value:""+f[0].value}:f[0].token==="uri"?{token:"literal",type:null,value:f[0].value}:g.ebvFalse();else if(a==="lang")return f[0].token==="literal"?f[0].lang!=null?{token:"literal",value:""+f[0].lang}:{token:"literal",value:""}:g.ebvError();else if(a==="datatype")return f[0].token==="literal"?(a=f[0],a.type!=null?typeof a.type==="string"?{token:"uri",value:a.type,prefix:null,suffix:null}:
a.type:a.lang==null?{token:"uri",value:"http://www.w3.org/2001/XMLSchema#string",prefix:null,suffix:null}:g.ebvError()):g.ebvError();else if(a==="isliteral")return f[0].token==="literal"?g.ebvTrue():g.ebvFalse();else if(a==="isblank")return f[0].token==="blank"?g.ebvTrue():g.ebvFalse();else if(a==="isuri"||a==="isiri")return f[0].token==="uri"?g.ebvTrue():g.ebvFalse();else if(a==="sameterm")return a=g.RDFTermEquality(f[0],f[1],c,h),g.isEbvError(a)&&(a=!1),g.ebvBoolean(a);else if(a==="langmatches")return a=
f[0],e=f[1],a.token==="literal"&&e.token==="literal"?e.value==="*"&&a.value!=""?g.ebvTrue():g.ebvBoolean(a.value.toLowerCase().indexOf(e.value.toLowerCase())===0):g.ebvError();else if(a==="bound")return a=f[0].value,a==null?g.ebvError():e[a]!=null?g.ebvTrue():g.ebvFalse();else if(c.customFns[a]!=null)return c.customFns[a](g,f);else throw"Builtin call "+a+" not implemented yet";}};g.runUnaryExpression=function(a,b,e,c,i,h){b=g.runFilter(b,e,c,i,h);if(g.isEbvError(b))return b;if(a==="!"){var f=g.ebv(b);
return g.isEbvError(f)?g.ebvFalse():g.ebvBoolean(!f)}else if(a==="+")return g.isNumeric(b)?b:g.ebvError();else if(a==="-")if(g.isNumeric(b)){a={};for(f in b)a[f]=b[f];a.value=-a.value;return a}else return g.ebvError()};g.runRegex=function(a,b,e,c,i,h,f){if(a!=null)a=g.runFilter(a,c,i,h,f);else return g.ebvError();if(b!=null)b=g.runFilter(b,c,i,h,f);else return g.ebvError();e!=null&&(e=g.runFilter(e,c,i,h,f));if(b!=null&&b.token==="literal"&&(e==null||e.token==="literal"))b=b.value,e=e==null?null:
e.value;else return g.ebvError();if(a!=null&&a.token=="var")if(c[a.value]!=null)a=c[a.value];else return g.ebvError();else if(a!=null&&a.token==="literal")if(a.type==null||g.isXsdType("string",a))a=a.value;else return g.ebvError();else return g.ebvError();return(e==null?RegExp(b):RegExp(b,e.toLowerCase())).exec(a)?g.ebvTrue():g.ebvFalse()};g.normalizeLiteralDatatype=function(a,b,e){if(!(a.value.type==null||typeof a.value.type!="object"))a.value.type=v.lexicalFormBaseUri(a.value.type,e);return a};
g.runIriRefOrFunction=function(a,b,e,c,i,h){if(b==null)return a;else{for(var f=[],n=0;n<b.length;n++)f.push(g.runFilter(b[n],e,c,i,h));a=v.lexicalFormBaseUri(a,h);if(a=="http://www.w3.org/2001/XMLSchema#integer"||a=="http://www.w3.org/2001/XMLSchema#decimal"||a=="http://www.w3.org/2001/XMLSchema#double"||a=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"||a=="http://www.w3.org/2001/XMLSchema#negativeInteger"||a=="http://www.w3.org/2001/XMLSchema#long"||a=="http://www.w3.org/2001/XMLSchema#int"||
a=="http://www.w3.org/2001/XMLSchema#short"||a=="http://www.w3.org/2001/XMLSchema#byte"||a=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"||a=="http://www.w3.org/2001/XMLSchema#unsignedLong"||a=="http://www.w3.org/2001/XMLSchema#unsignedInt"||a=="http://www.w3.org/2001/XMLSchema#unsignedShort"||a=="http://www.w3.org/2001/XMLSchema#unsignedByte"||a=="http://www.w3.org/2001/XMLSchema#positiveInteger")if(f=f[0],f.token==="literal")if(f=g.normalizeLiteralDatatype(f,c,h),f.type=="http://www.w3.org/2001/XMLSchema#integer"||
f.type=="http://www.w3.org/2001/XMLSchema#decimal"||f.type=="http://www.w3.org/2001/XMLSchema#double"||f.type=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"||f.type=="http://www.w3.org/2001/XMLSchema#negativeInteger"||f.type=="http://www.w3.org/2001/XMLSchema#long"||f.type=="http://www.w3.org/2001/XMLSchema#int"||f.type=="http://www.w3.org/2001/XMLSchema#short"||f.type=="http://www.w3.org/2001/XMLSchema#byte"||f.type=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedLong"||
f.type=="http://www.w3.org/2001/XMLSchema#unsignedInt"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedShort"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedByte"||f.type=="http://www.w3.org/2001/XMLSchema#positiveInteger")return f.type=a,f;else if(f.type=="http://www.w3.org/2001/XMLSchema#boolean")return g.ebv(f)==!0?(f.type=a,f.value=1):(f.type=a,f.value=0),f;else if(f.type=="http://www.w3.org/2001/XMLSchema#float"||f.type=="http://www.w3.org/2001/XMLSchema#double")return f.type=a,f.value=
parseInt(f.value),f;else if(f.type=="http://www.w3.org/2001/XMLSchema#string"||f.type==null){if(f.value.split(".").length>2)return g.ebvError();else if(f.value.split("-").length>2)return g.ebvError();else if(f.value.split("/").length>2)return g.ebvError();else if(f.value.split("+").length>2)return g.ebvError();if(a=="http://www.w3.org/2001/XMLSchema#decimal"&&(f.value.indexOf("e")!=-1||f.value.indexOf("E")!=-1))return g.ebvError();if(a=="http://www.w3.org/2001/XMLSchema#int"||a=="http://www.w3.org/2001/XMLSchema#integer")if(f.value.indexOf("e")!=
-1||f.value.indexOf("E")!=-1||f.value.indexOf(".")!=-1)return g.ebvError();try{return f.value=parseInt(parseFloat(f.value)),isNaN(f.value)?g.ebvError():(f.type=a,f)}catch(o){return g.ebvError()}}else return g.ebvError();else return g.ebvError();else if(a=="http://www.w3.org/2001/XMLSchema#boolean")return f=f[0],f.token==="literal"&&f.type==null?f.value==="true"||f.value==="1"?g.ebvTrue():f.value==="false"||f.value==="0"?g.ebvFalse():g.ebvError():f.token==="literal"?g.isEbvError(f)?f:g.ebvBoolean(f):
g.ebvError();else if(a=="http://www.w3.org/2001/XMLSchema#string")if(f=f[0],f.token==="literal")if(f=g.normalizeLiteralDatatype(f,c,h),f.type=="http://www.w3.org/2001/XMLSchema#integer"||f.type=="http://www.w3.org/2001/XMLSchema#decimal"||f.type=="http://www.w3.org/2001/XMLSchema#double"||f.type=="http://www.w3.org/2001/XMLSchema#nonPositiveInteger"||f.type=="http://www.w3.org/2001/XMLSchema#negativeInteger"||f.type=="http://www.w3.org/2001/XMLSchema#long"||f.type=="http://www.w3.org/2001/XMLSchema#int"||
f.type=="http://www.w3.org/2001/XMLSchema#short"||f.type=="http://www.w3.org/2001/XMLSchema#byte"||f.type=="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedLong"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedInt"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedShort"||f.type=="http://www.w3.org/2001/XMLSchema#unsignedByte"||f.type=="http://www.w3.org/2001/XMLSchema#positiveInteger"||f.type=="http://www.w3.org/2001/XMLSchema#float")return f.type=
a,f.value=""+f.value,f;else if(f.type=="http://www.w3.org/2001/XMLSchema#string")return f;else if(f.type=="http://www.w3.org/2001/XMLSchema#boolean")return g.ebv(f)?(f.type=a,f.value="true"):(f.type=a,f.value="false"),f;else if(f.type=="http://www.w3.org/2001/XMLSchema#dateTime"||f.type=="http://www.w3.org/2001/XMLSchema#date"){f.type=a;if(typeof f.value!="string")f.value=v.iso8601(f.value);return f}else return f.type==null?(f.value=""+f.value,f.type=a,f):g.ebvError();else return f.token==="uri"?
{token:"literal",value:v.lexicalFormBaseUri(f,h),type:a,lang:null}:g.ebvError();else if(a=="http://www.w3.org/2001/XMLSchema#dateTime"||a=="http://www.w3.org/2001/XMLSchema#date")if(f=f[0],f.type=="http://www.w3.org/2001/XMLSchema#dateTime"||f.type=="http://www.w3.org/2001/XMLSchema#date")return f;else if(f.type=="http://www.w3.org/2001/XMLSchema#string"||f.type==null)try{return f.value=v.iso8601(v.parseStrictISO8601(f.value)),f.type=a,f}catch(t){return g.ebvError()}else return g.ebvError();else if(a==
"http://www.w3.org/2001/XMLSchema#float")if(f=f[0],f.token==="literal")if(f=g.normalizeLiteralDatatype(f,c,h),f.type=="http://www.w3.org/2001/XMLSchema#decimal"||f.type=="http://www.w3.org/2001/XMLSchema#int")return f.type=a,f.value=parseFloat(f.value),f;else if(f.type=="http://www.w3.org/2001/XMLSchema#boolean")return g.ebv(f)==!0?(f.type=a,f.value=1):(f.type=a,f.value=0),f;else if(f.type=="http://www.w3.org/2001/XMLSchema#float"||f.type=="http://www.w3.org/2001/XMLSchema#double")return f.type=a,
f.value=parseFloat(f.value),f;else if(f.type=="http://www.w3.org/2001/XMLSchema#string")try{return f.value=parseFloat(f.value),isNaN(f.value)?g.ebvError():(f.type=a,f)}catch(q){return g.ebvError()}else if(f.type==null){if(f.value.split(".").length>2)return g.ebvError();else if(f.value.split("-").length>2)return g.ebvError();else if(f.value.split("/").length>2)return g.ebvError();else if(f.value.split("+").length>2)return g.ebvError();try{return f.value=parseFloat(f.value),isNaN(f.value)?g.ebvError():
(f.type=a,f)}catch(u){return g.ebvError()}}else return g.ebvError();else return g.ebvError();else return g.ebvError()}};var A={variablesInBGP:function(a){var b=a.variables;if(b)return b;var e=a.value||a,b=[],c;for(c in e)e[c]&&e[c].token==="var"?b.push(e[c].value):e[c]&&e[c].token==="blank"&&b.push("blank:"+e[c].value);return a.variables=b},connected:function(a,b){for(var e="/"+a.vars.join("/")+"/",c=0;c<b.vars.length;c++)if(e.indexOf("/"+b.vars[c]+"/")!=-1)return!0;return!1},variablesIntersectionBGP:function(a,
b){for(var e=A.variablesInBGP(a).sort(),c=A.variablesInBGP(b).sort(),i=0,h=0,f=[];i<e.length&&h<c.length;)e[i]===c[h]?(f.push(e[i]),i++,h++):e[i]<c[h]?i++:h++;return f},executeAndBGPsGroups:function(a){for(var b={},e={},c=0,i=0;i<a.length;i++){var h=a[i],f={},g={},o=[],t;for(t in h)t!="_cost"&&(h[t].token==="var"?o.push(h[t].value):h[t].token==="blank"&&o.push(h[t].value));var q=!1,u={},v;for(v in e){for(var x=e[v],q=!1,A=0;A<o.length;A++)if(x.indexOf("/"+o[A]+"/")!=-1){q=!0;break}q?u[v]=!0:(f[v]=
b[v],g[v]=e[v])}if(q){var q=[],A=x="",m;for(m in u)x+=m,q=q.concat(b[m]),A=e[m];A=A+o.join("/")+"/";q.push(h);f[x]=q;g[x]=A}else f[c]=[h],g[c]="/"+o.join("/")+"/",c++;b=f;e=g}a=[];for(c in b)a.push(b[c]);return a},intersectionSize:function(a,b){for(var e=b.i.split("_"),c=0;c<e.length;c++)if(e[c]!=""&&a.i.indexOf("_"+e[c]+"_")!=-1)return 1;return 0},createJoinTree:function(a,b){for(var e="/"+a.vars.join("/")+"/",c=a.vars.concat([]),i=[],h=0;h<b.vars.length;h++)e.indexOf("/"+b.vars[h]+"/")!=-1?b.vars[h].indexOf("_:")==
0?i.push("blank:"+b.vars[h]):i.push(b.vars[h]):c.push(b.vars[h]);for(var f=b.i.split("_"),g=a.i.split("_"),e={},h=0;h<f.length;h++)f[h]!=""&&(e[f[h]]=!0);for(h=0;h<g.length;h++)g[h]!=""&&(e[g[h]]=!0);var h=[],o;for(o in e)h.push(o);return{left:a,right:b,cost:a.cost+b.cost,i:"_"+h.sort().join("_")+"_",vars:c,join:i}}};A.executeBushyTree=function(a,b,e,c){if(a.left==null)return A.executeEmptyJoinBGP(a.right,b,e,c);else if(a.right==null)return A.executeEmptyJoinBGP(a.left,b,e,c);else{var i=A.executeBushyTree(a.left,
b,e,c);if(i!=null)return b=A.executeBushyTree(a.right,b,e,c),b!=null?A.joinBindings2(a.join,i,b):null}};A.executeAndBGPsDPSize=function(a,b,e,c){for(var i=A.executeAndBGPsGroups(a),a=[],h=0;h<i.length;h++){var f=i[h];e.computeCosts(f,c);var g={},o={},t={},q=1,u=null,v={};t["1"]=[];for(var x=0;x<f.length;x++){var q=[],C;for(C in f[x])C!="_cost"&&(f[x][C].token==="var"?q.push(f[x][C].value):f[x][C].token==="blank"&&q.push(f[x][C].value));o["_"+x+"_"]={left:f[x],right:null,cost:f[x]._cost,i:"_"+x+"_",
vars:q};q={left:f[x],right:null,cost:f[x]._cost,i:"_"+x+"_",vars:q};g["_"+x+"_"]=q;delete f[x]._cost;v["_"+x+"_"]=!0;t["1"].push("_"+x+"_");if(u==null||u.cost>q.cost)u=q}for(var m=2;m<=f.length;m++)for(var r=1;r<m;r++)for(var z=t[""+r]||[],s=t[""+(m-r)]||[],x=0;x<z.length;x++)for(var G=0;G<s.length;G++)if(z[x]!==s[G]){var B=o[z[x]],y=o[s[G]];if(A.intersectionSize(B,y)==0&&A.connected(B,y)&&(q=m,y=A.createJoinTree(g[B.i],g[y.i]),!v[y.i])){v[y.i]=!0;var D=y.cost+1;if(g[y.i]!=null)D=g[y.i].cost;B=t[m]||
[];B.push(y.i);o[y.i]=y;t[m]=B;D>y.cost&&(q===m&&(u=y),g[y.i]=y)}}a.push(u)}B=null;for(h=0;h<a.length;h++)C=A.executeBushyTree(a[h],b,e,c),B=B==null?C:A.crossProductBindings(B,C);return B};A.executeEmptyJoinBGP=function(a,b,e,c){return A.executeBGPDatasets(a,b,e,c)};A.executeBGPDatasets=function(a,b,e,c){var i={};if(a.graph==null){for(var h=[],f=0;f<b.implicit.length;f++)if(i[b.implicit[f].oid]==null){i[b.implicit[f].oid]=!0;a.graph=b.implicit[f];var g=e.rangeQuery(a,c),g=A.buildBindingsFromRange(g,
a);h.push(g)}return a=A.unionManyBindings(h)}else if(a.graph.token==="var"){for(var o=a.graph.value,h=[],f=0;f<b.named.length;f++)if(i[b.named[f].oid]==null)if(i[b.named[f].oid]=!0,a.graph=b.named[f],g=e.rangeQuery(a,c),g!=null){for(var g=A.buildBindingsFromRange(g,a),t=0;t<g.length;t++)g[t][o]=b.named[f].oid;h.push(g)}else return null;return a=A.unionManyBindings(h||[])}else return g=e.rangeQuery(a,c),g!=null?g=A.buildBindingsFromRange(g,a):null};A.buildBindingsFromRange=function(a,b){A.variablesInBGP(b);
var e={},c=b.value||b,e={};for(o in c)c[o]&&c[o].token==="var"?e[o]=c[o].value:c[o]&&c[o].token==="blank"&&(e[o]="blank:"+c[o].value);c=[];if(a!=null)for(var i=0;i<a.length;i++){var h={},f=a[i],g=!1,o;for(o in e){var t=f[o];if(h[e[o]]==null||h[e[o]]===t)h[e[o]]=t;else{g=!0;break}}g||c.push(h)}return c};A.areCompatibleBindings=function(a,b){for(var e in a)if(b[e]!=null&&b[e]!=a[e])return!1;return!0};A.mergeBindings=function(a,b){var e={},c;for(c in a)e[c]=a[c];for(c in b)e[c]=b[c];return e};A.joinBindings2=
function(a,b,e){for(var c={},i,h,f,g,o=[],t=0;t<b.length;t++){i=b[t];g=c;for(var q=0;q<a.length;q++)h=a[q],h=i[h],q==a.length-1?(f=g[h]||[],f.push(i),g[h]=f):(f=g[h]||{},g=g[h]=f)}for(t=0;t<e.length;t++){i=e[t];g=c;for(q=0;q<a.length;q++)if(h=a[q],h=i[h],g[h]!=null)if(q==a.length-1)for(b=0;b<g[h].length;b++)o.push(A.mergeBindings(g[h][b],i));else g=g[h]}return o};A.joinBindings=function(a,b){for(var e=[],c=0;c<a.length;c++)for(var i=a[c],h=0;h<b.length;h++){var f=b[h];A.areCompatibleBindings(i,f)&&
e.push(A.mergeBindings(i,f))}return e};A.augmentMissingBindings=function(a,b){for(var e in b)a[e]==null&&(a[e]=null);return a};A.leftOuterJoinBindings=function(a,b){for(var e=[],c=0;c<a.length;c++){for(var i=a[c],h=!1,f=0;f<b.length;f++){var g=b[f];A.areCompatibleBindings(i,g)&&(h=!0,e.push(A.mergeBindings(i,g)))}h===!1&&(A.augmentMissingBindings(i,g),e.push(i))}return e};A.crossProductBindings=function(a,b){for(var e=[],c=0;c<a.length;c++)for(var i=a[c],h=0;h<b.length;h++)e.push(A.mergeBindings(i,
b[h]));return e};A.unionBindings=function(a,b){return a.concat(b)};A.unionManyBindings=function(a){for(var b=[],e=0;e<a.length;e++)b=A.unionBindings(b,a[e]);return b};var B={},da=A;B.QueryEngine=function(a){if(arguments.length!=0)this.backend=a.backend,this.lexicon=a.lexicon,this.eventsOnBatchLoad=a.eventsOnBatchLoad||!1,this.defaultPrefixes={},this.abstractQueryTree=new K.AbstractQueryTree,this.rdfLoader=new X.RDFLoader(a.communication),this.callbacksBackend=new D.CallbacksBackend(this),this.customFns=
a.customFns||{}};B.QueryEngine.prototype.setCustomFunctions=function(a){this.customFns=a};B.QueryEngine.prototype.registerNsInEnvironment=function(a,b){var e=[];if(a!=null&&a.prefixes!=null)e=a.prefixes;var c={},i;for(i in this.defaultPrefixes)c[i]=this.defaultPrefixes[i];for(i=0;i<e.length;i++){var h=e[i];if(h.token==="prefix")c[h.prefix]=h.local}b.namespaces=c;b.base=a!=null&&a.base&&typeof a.base==="object"?a.base.value:null};B.QueryEngine.prototype.applyModifier=function(a,b){if(a=="DISTINCT"){for(var e=
{},c=[],i=0;i<b.length;i++){var h=b[i],f="",g;for(g in h){var o=h[g];o==null?f=f+g+"null":o.token=="literal"?(o.value!=null&&(f+=o.value),o.lang!=null&&(f+=o.lang),o.type!=null&&(f+=o.type)):f=o.value?f+g+o.value:f+g+o}e[f]==null&&(c.push(h),e[f]=!0)}return c}else return b};B.QueryEngine.prototype.applyLimitOffset=function(a,b,e){if(b==null&&a==null)return e;a==null&&(a=0);b=b==null?e.length:a+b;return e.slice(a,b)};B.QueryEngine.prototype.applySingleOrderBy=function(a,b,e,c){for(var i=[],h=0;h<a.length;h++){var f=
g.collect(a[h].expression,[b],e,c,this);i.push(f[0].value)}return{binding:b,value:i}};B.QueryEngine.prototype.applyOrderBy=function(a,b,e,c){var i=this,h=[];if(a!=null&&a.length>0){for(var f=0;f<b.length;f++){var g=i.applySingleOrderBy(a,b[f],e,c);h.push(g)}h.sort(function(b,e){return i.compareFilteredBindings(b,e,a,c)});b=[];for(f=0;f<h.length;f++)b.push(h[f].binding)}return b};B.QueryEngine.prototype.compareFilteredBindings=function(a,b,e,c){for(var i=0;;){if(i==a.value.length)return 0;var h=e[i].direction;
if(a.value[i]==null&&b.value[i]==null)i++;else{if(a.value[i]==null)a={value:!1};else if(b.value[i]==null)a={value:!0};else if(a.value[i].token==="blank"&&b.value[i].token==="blank"){i++;continue}else if(a.value[i].token==="blank")a={value:!1};else if(b.value[i].token==="blank")a={value:!0};else if(a.value[i].token==="uri"&&b.value[i].token==="uri")if(g.runEqualityFunction(a.value[i],b.value[i],[],this,c).value==!0){i++;continue}else a=g.runTotalGtFunction(a.value[i],b.value[i],[]);else if(a.value[i].token===
"uri")a={value:!1};else if(b.value[i].token==="uri")a={value:!0};else if(a.value[i].token==="literal"&&b.value[i].token==="literal"&&a.value[i].type==null&&b.value[i].type==null)if(g.runEqualityFunction(a.value[i],b.value[i],[],this,c).value==!0){i++;continue}else a=g.runTotalGtFunction(a.value[i],b.value[i],[]);else if(a.value[i].token==="literal"&&a.value[i].type==null)a={value:!1};else if(b.value[i].token==="literal"&&b.value[i].type==null)a={value:!0};else if(g.runEqualityFunction(a.value[i],
b.value[i],[],this,c).value==!0){i++;continue}else a=g.runTotalGtFunction(a.value[i],b.value[i],[]);return a.value==!0?h==="ASC"?1:-1:h==="ASC"?-1:1}}};B.QueryEngine.prototype.removeDefaultGraphBindings=function(a,b){for(var e=[],c={},i=0;i<b.named.length;i++)c[b.named[i].oid]=!0;for(i=0;i<b.implicit.length;i++)c[b.implicit[i].oid]==null&&e.push(b.implicit[i].oid);e=[];for(i=0;i<a.length;i++){var h=a[i],f=!1,g;for(g in h){for(var o=0;o<c.length;o++)if(h[g]===c[o]){f=!0;break}if(f)break}f||e.push(h)}return e};
B.QueryEngine.prototype.aggregateBindings=function(a,b,e,c){for(var b=this.copyDenormalizedBindings(b,c.outCache),i={},h=0;h<a.length;h++){var f=g.runAggregator(a[h],b,this,e,c);a[h].alias?i[a[h].alias.value]=f:i[a[h].value.value]=f}return i};B.QueryEngine.prototype.projectBindings=function(a,b,e){if(a[0].kind==="*")return b;else{for(var c=[],i=0;i<b.length;i++){for(var h=b[i],f={},n=!0,o=0;o<a.length;o++)if(a[o].token=="variable"&&a[o].kind!="aliased")f[a[o].value.value]=h[a[o].value.value];else if(a[o].token==
"variable"&&a[o].kind=="aliased"){var t=g.runFilter(a[o].expression,h,this,e,{blanks:{},outCache:{}});if(g.isEbvError(t)){n=!1;break}else f[a[o].alias.value]=t}n===!0&&c.push(f)}return c}};B.QueryEngine.prototype.resolveNsInEnvironment=function(a,b){return b.namespaces[a]};B.QueryEngine.prototype.termCost=function(a,b){if(a.token==="uri"){var e=v.lexicalFormBaseUri(a,b);return e==null?0:this.lexicon.resolveUriCost(e)}else return a.token==="literal"?this.lexicon.resolveLiteralCost(v.lexicalFormLiteral(a,
b)):a.token==="blank"?this.lexicon.resolveBlankCost(a.value):a.token==="var"?this.lexicon.oidCounter/3:null};B.QueryEngine.prototype.normalizeTerm=function(a,b,e){if(a.token==="uri")return b=v.lexicalFormBaseUri(a,b),b==null?null:e?this.lexicon.registerUri(b):this.lexicon.resolveUri(b);else if(a.token==="literal")return b=v.lexicalFormLiteral(a,b),a=e?this.lexicon.registerLiteral(b):this.lexicon.resolveLiteral(b);else if(a.token==="blank"){var c=a.value,a=b.blanks[c];a==null&&(a=e?this.lexicon.registerBlank(c):
this.lexicon.resolveBlank(c),b.blanks[c]=a);return a}else return a.token==="var"?a.value:null};B.QueryEngine.prototype.normalizeDatasets=function(a,b){for(var e=0;e<a.length;e++){var c=a[e];if(c.value===this.lexicon.defaultGraphUri)c.oid=this.lexicon.defaultGraphOid;else{var i=this.normalizeTerm(c,b,!1);if(i!=null)c.oid=i;else return null}}return!0};B.QueryEngine.prototype.normalizeQuad=function(a,b,e){var c=null,i=null,h=c=null,f;if(a.graph==null)h=0;else if(f=this.normalizeTerm(a.graph,b,e),f!=
null)h=f,e===!0&&a.graph.token!="var"&&this.lexicon.registerGraph(f);else return null;f=this.normalizeTerm(a.subject,b,e);if(f!=null)c=f;else return null;f=this.normalizeTerm(a.predicate,b,e);if(f!=null)i=f;else return null;f=this.normalizeTerm(a.object,b,e);return f==null?null:{subject:c,predicate:i,object:f,graph:h}};B.QueryEngine.prototype.quadCost=function(a,b){var e=null,c=null,i=null,h=null,h=a.graph==null?this.lexicon.oidCounter/4:this.termCost(a.graph,b),e=this.termCost(a.subject,b),c=this.termCost(a.predicate,
b),i=this.termCost(a.object,b);return h+e+c+i};B.QueryEngine.prototype.denormalizeBindingsList=function(a,b){for(var e=[],c=0;c<a.length;c++){var i=this.denormalizeBindings(a[c],b);e.push(i)}return e};B.QueryEngine.prototype.copyDenormalizedBindings=function(a,b){for(var e=[],c=0;c<a.length;c++){for(var i={},h=a[c],f=v.keys(h),g=0;g<f.length;g++){var o=h[f[g]];if(o==null)i[f[g]]=null;else if(typeof o==="object")i[f[g]]=o;else{var t=b[o];t==null&&(t=this.lexicon.retrieve(o),b[o]=t);i[f[g]]=t}}e.push(i)}return e};
B.QueryEngine.prototype.denormalizeBindings=function(a,b){for(var e=v.keys(a),c=b.outCache,i=0;i<e.length;i++){var h=a[e[i]];if(h==null)a[e[i]]=null;else if(c[h]!=null)a[e[i]]=c[h];else{var f=this.lexicon.retrieve(h);a[e[i]]=f;f.token==="blank"&&(b.blanks[f.value]=h)}}return a};B.QueryEngine.prototype.execute=function(a,b,e,c){a=v.normalizeUnicodeLiterals(a);a=this.abstractQueryTree.parseQueryString(a);if(a==null)b(!1,"Error parsing query string");else if(a.token==="query"&&a.kind=="update"){this.callbacksBackend.startGraphModification();
var i=this;this.executeUpdate(a,function(a,c){i.lexicon.updateAfterWrite&&i.lexicon.updateAfterWrite();a?i.callbacksBackend.endGraphModification(function(){b(a,c)}):(i.callbacksBackend.cancelGraphModification(),b(a,c))})}else a.token==="query"&&a.kind=="query"&&this.executeQuery(a,b,e,c)};B.QueryEngine.prototype.executeQuery=function(a,b,e,c){var i=a.units,h=this,f={blanks:{},outCache:{}};this.registerNsInEnvironment(a.prologue,f);var g=h.abstractQueryTree.parseExecutableUnit(i[0]);if(g.kind==="select")this.executeSelect(g,
f,e,c,function(a,c){a?typeof c==="object"&&c.denorm===!0?b(!0,c.bindings):(c=h.denormalizeBindingsList(c,f),c!=null?b(!0,c):b(!1,c)):b(!1,c)});else if(g.kind==="ask")g.projection=[{token:"variable",kind:"*"}],this.executeSelect(g,f,e,c,function(a,c){a?a?c.length>0?b(!0,!0):b(!0,!1):b(!1,c):b(!1,c)});else if(g.kind==="construct")g.projection=[{token:"variable",kind:"*"}],h=this,this.executeSelect(g,f,e,c,function(a,c){if(a)if(a)if(c=h.denormalizeBindingsList(c,f),c!=null){var e=new u.Graph;if(g.template==
null)g.template={triplesContext:g.pattern};for(var i=1,v=[],x=0;x<c.length;x++){for(var A=c[x],m=0;m<v.length;m++)delete v[m].valuetmp;for(m=0;m<g.template.triplesContext.length;m++){for(var r=["subject","predicate","object"],z=g.template.triplesContext[m],s=0;s<r.length;s++){var B=r[s];if(z[B].token==="blank"&&!(z[B].valuetmp&&z[B].valuetmp!=null)){var C="_:b"+i;i++;z[B].valuetmp=C;v.push(z[B])}}r=u.buildRDFResource(z.subject,A,h,f);s=u.buildRDFResource(z.predicate,A,h,f);z=u.buildRDFResource(z.object,
A,h,f);r!=null&&s!=null&&z!=null&&(s=new u.Triple(r,s,z),e.add(s))}}b(!0,e)}else b(!1,c);else b(!1,c);else b(!1,c)})};B.QueryEngine.prototype.executeSelect=function(a,b,e,c,i){if(a.kind==="select"||a.kind==="ask"||a.kind==="construct"||a.kind==="modify"){var h=a.projection,f=a.dataset,g=a.modifier,o=a.limit,t=a.offset,q=a.order;if(e!=null||c!=null)f.implicit=e||[],f.named=c||[];f.implicit!=null&&f.implicit.length===0&&f.named!=null&&f.named.length===0&&f.implicit.push(this.lexicon.defaultGraphUriTerm);
if(this.normalizeDatasets(f.implicit.concat(f.named),b)!=null)if(c=this.executeSelectUnit(h,f,a.pattern,b),c!=null){if(a.group!=null&&a.group===""){for(var u=!1,e=0;e<a.projection.length;e++)if(a.projection[e].expression!=null&&a.projection[e].expression.expressionType==="aggregate"){u=!0;break}if(u===!0)a.group="singleGroup"}if(a.group&&a.group!="")if(this.checkGroupSemantics(a.group,h)){o=this.groupSolution(c,a.group,f,b);t=[];for(e=0;e<o.length;e++)g=this.aggregateBindings(h,o[e],f,b),t.push(g);
i(!0,{bindings:t,denorm:!0})}else i(!1,"Incompatible Group and Projection variables");else b=this.applyOrderBy(q,c,f,b),h=this.projectBindings(h,b,f),h=this.applyModifier(g,h),f=this.removeDefaultGraphBindings(this.applyLimitOffset(t,o,h),f),i(!0,f)}else i(!1,c);else i(!1,"Error normalizing datasets")}else i(!1,"Cannot execute "+a.kind+" query as a select query")};B.QueryEngine.prototype.groupSolution=function(a,b,e,c){var i=[],h=[],f=!1;if(b==="singleGroup")return[a];else{for(var n=0;n<a.length;n++){for(var o=
a[n],t=!0,q=0;q<b.length;q++){var u=b[q],v=null;if(u.token==="var")v=u.value,f==!1&&i.push(v);else if(u.token==="aliased_expression")if(v=u.alias.value,f==!1&&i.push(v),u.expression.primaryexpression==="var")o[u.alias.value]=o[u.expression.value.value];else if(v=this.copyDenormalizedBindings([o],c.outCache),v=g.runFilter(u.expression,v[0],this,e,c),g.isEbvError(v))t=!1;else{if(v.value!=null)v.value=""+v.value;o[u.alias.value]=v}else v=this.copyDenormalizedBindings([o],c.outCache),v=g.runFilter(u,
v[0],this,c),g.isEbvError(v)?t=!1:(o["groupCondition"+env._i]=v,v="groupCondition"+env._i,f==!1&&i.push(v))}f==!1&&(f=!0);t===!0&&h.push(o)}a={};for(n=0;n<h.length;n++){b=h[n];e="";for(q=0;q<i.length;q++)c=b[i[q]],e+=typeof c==="object"?c.value:c;a[e]==null?a[e]=[b]:a[e].push(b)}var i=[],x;for(x in a)i.push(a[x]);return i}};B.QueryEngine.prototype.executeSelectUnit=function(a,b,e,c){return e.kind==="BGP"?this.executeAndBGP(a,b,e,c):e.kind==="UNION"?this.executeUNION(a,b,e.value,c):e.kind==="JOIN"?
this.executeJOIN(a,b,e,c):e.kind==="LEFT_JOIN"?this.executeLEFT_JOIN(a,b,e,c):e.kind==="FILTER"?(a=this.executeSelectUnit(a,b,e.value,c),a!=null?a=g.checkFilters(e,a,!1,b,c,this):[]):e.kind==="EMPTY_PATTERN"?[]:e.kind==="ZERO_OR_MORE_PATH"||e.kind==="ONE_OR_MORE_PATH"?this.executeZeroOrMorePath(e,b,c):(console.log("Cannot execute query pattern "+e.kind+". Not implemented yet."),null)};B.QueryEngine.prototype.executeZeroOrMorePath=function(a,b,e){var c=[];a.x.token==="var"&&c.push({token:"variable",
kind:"var",value:a.x.value});a.y.token==="var"&&c.push({token:"variable",kind:"var",value:a.y.value});c.length===0&&c.push({token:"variable",kind:"*"});if(a.x.token==="var"&&a.y.token==="var"){var i=this.executeAndBGP(c,b,a.path,e),h={},c=[],f,g,o,t,q=a.x.value;g=a.x;for(var u=a.path,F=0;F<i.length;F++)if(f=i[F][q],h[f]==null){t=this.lexicon.retrieve(f);a.x=t;a.path=this.abstractQueryTree.replace(u,g,t,e);u=v.clone(a.path);g=this.executeZeroOrMorePath(a,b,e);for(var x=0;x<g.length;x++)o=g[x],o[q]=
f,c.push(o);g=t}return c}else if(a.x.token!=="var"&&a.y.token==="var"){h={};f=!0;t=[];for(q=[];f==!0||t.length!==0;){f===!0?(i=this.executeAndBGP(c,b,a.path,e),g=a.x,f=!1):(u=this.lexicon.retrieve(t.pop()),i=a.path,i=this.abstractQueryTree.replace(i,g,u,e),i=this.executeAndBGP(c,b,i,e),g=u);for(F=0;F<i.length;F++)u=i[F][a.y.value],h[u]!==!0&&(o={},o[a.y.value]=u,q.push(o),h[u]=!0,t.push(u))}return q}else throw"Kind of path not supported!";};B.QueryEngine.prototype.executeUNION=function(a,b,e,c){var i=
e[0],h=e[1],f=null,n=null;if(e.length!=2)throw"SPARQL algebra UNION with more than two components";f=this.executeSelectUnit(a,b,i,c);if(f==null)return null;n=this.executeSelectUnit(a,b,h,c);if(n==null)return null;a=da.unionBindings(f,n);return a=g.checkFilters(e,a,!1,b,c,this)};B.QueryEngine.prototype.executeAndBGP=function(a,b,e,c){a=da.executeAndBGPsDPSize(e.value,b,this,c);return a!=null?g.checkFilters(e,a,!1,b,c,this):null};B.QueryEngine.prototype.executeLEFT_JOIN=function(a,b,e,c){var i=e.rvalue,
h=null,f=null,h=this.executeSelectUnit(a,b,e.lvalue,c);if(h==null)return null;f=this.executeSelectUnit(a,b,i,c);if(f==null)return null;a=da.leftOuterJoinBindings(h,f);b=g.checkFilters(e,a,!0,b,c,this);if(h.length>1&&f.length>1){var e=[],c={},n;for(n in h[0])c[n]=!0;for(n in f[0])c[n]!=!0&&e.push(n);h=[];f={};for(c=0;c<b.length;c++)if(b[c].__nullify__===!0){for(i=0;i<e.length;i++)b[c].bindings[e[i]]=null;i=[];a=[];for(n in b[c].bindings)b[c].bindings[n]!=null&&(i.push(n+b[c].bindings[n]),i.sort(),
a.push(i.join("")));if(f[i.join("")]==null){for(i=0;i<a.length;i++)f[a[i]]=!0;h.push(b[c].bindings)}}else for(n in h.push(b[c]),i=[],b[c])i.push(n+b[c][n]),i.sort(),f[i.join("")]=!0;return h}else return b};B.QueryEngine.prototype.executeJOIN=function(a,b,e,c){var i=e.lvalue,h=e.rvalue,f=null,n=null,f=this.executeSelectUnit(a,b,i,c);if(f==null)return null;n=this.executeSelectUnit(a,b,h,c);if(n==null)return null;a=null;if(f.length===0||n.length===0)a=[];else{var a={},o=[],t;for(t in f[0])a[t]=!1;for(t in n[0])a[t]===
!1&&o.push(t);a=o.length==0?da.joinBindings(f,n):this.abstractQueryTree.treeWithUnion(i)||this.abstractQueryTree.treeWithUnion(h)?da.joinBindings(f,n):da.joinBindings2(o,f,n)}return a=g.checkFilters(e,a,!1,b,c,this)};B.QueryEngine.prototype.rangeQuery=function(a,b){var e=this.normalizeQuad(a,b,!1);return e!=null?(e=this.backend.range(new R.Pattern(e)),e==null||e.length==0?[]:e):(console.log("ERROR normalizing quad"),null)};B.QueryEngine.prototype.executeUpdate=function(a,b){var e=a.units,c=this,i=
{blanks:{},outCache:{}};this.registerNsInEnvironment(a.prologue,i);for(var h=0;h<e.length;h++){var f=c.abstractQueryTree.parseExecutableUnit(e[h]);if(f.kind==="insertdata"){for(var g=0;g<f.quads.length;g++){var o=f.quads[g];if(c._executeQuadInsert(o,i)!==!0)return b(!1,error)}b(!0)}else if(f.kind==="deletedata"){for(g=0;g<f.quads.length;g++)o=f.quads[g],this._executeQuadDelete(o,i);b(!0)}else if(f.kind==="modify")this._executeModifyQuery(f,i,b);else if(f.kind==="create")b(!0);else if(f.kind==="load")g=
{uri:v.lexicalFormBaseUri(f.sourceGraph,i)},f.destinyGraph!=null&&(g={uri:v.lexicalFormBaseUri(f.destinyGraph,i)}),c=this,this.rdfLoader.load(f.sourceGraph.value,g,function(a,e){a==!1?(console.log("Error loading graph"),console.log(e),b(!1,"error batch loading quads")):(e=c.batchLoad(e),b(e!=null,e||"error batch loading quads"))});else if(f.kind==="drop")this._executeClearGraph(f.destinyGraph,i,b);else if(f.kind==="clear")this._executeClearGraph(f.destinyGraph,i,b);else throw Error("not supported execution unit");
}};B.QueryEngine.prototype.batchLoad=function(a,b){var e=null,c=null,i=null,h=null,f=0,g=!0,o={},t,q;this.eventsOnBatchLoad&&this.callbacksBackend.startGraphModification();for(var u=0;u<a.length;u++){q=a[u];if(q.subject.uri||q.subject.token==="uri"){if(t=this.lexicon.registerUri(q.subject.uri||q.subject.value),q.subject.uri!=null)q.subject={token:"uri",value:q.subject.uri},delete q.subject.uri}else if(q.subject.literal||q.subject.token==="literal"){if(t=this.lexicon.registerLiteral(q.subject.literal||
q.subject.value),q.subject.literal!=null)q.subject=this.lexicon.parseLiteral(q.subject.literal),delete q.subject.literal}else if(t=o[q.subject.blank||q.subject.value],t==null&&(t=this.lexicon.registerBlank(q.subject.blank||q.subject.value),o[q.subject.blank||q.subject.value]=t),q.subject.token==null)q.subject.token="blank",q.subject.value=q.subject.blank,delete q.subject.blank;e=t;if(q.predicate.uri||q.predicate.token==="uri"){if(t=this.lexicon.registerUri(q.predicate.uri||q.predicate.value),q.predicate.uri!=
null)q.predicate={token:"uri",value:q.predicate.uri},delete q.subject.uri}else if(q.predicate.literal||q.predicate.token==="literal"){if(t=this.lexicon.registerLiteral(q.predicate.literal||q.predicate.value),q.predicate.literal!=null)q.predicate=this.lexicon.parseLiteral(q.predicate.literal),delete q.predicate.literal}else if(t=o[q.predicate.blank||q.predicate.value],t==null&&(t=this.lexicon.registerBlank(q.predicate.blank||q.predicate.value),o[q.predicate.blank||q.predicate.value]=t),q.predicate.token==
null)q.predicate.token="blank",q.predicate.value=q.predicate.blank,delete q.predicate.blank;c=t;if(q.object.uri||q.object.token==="uri"){if(t=this.lexicon.registerUri(q.object.uri||q.object.value),q.object.uri!=null)q.object={token:"uri",value:q.object.uri},delete q.subject.uri}else if(q.object.literal||q.object.token==="literal"){if(q.object.token==="literal")q.object.value=q.object.type!=null?'"'+q.object.value+'"^^<'+q.object.type+">":q.object.lang!=null?'"'+q.object.value+'"@'+q.object.lang:'"'+
q.object.value+'"';t=this.lexicon.registerLiteral(q.object.literal||q.object.value);if(q.object.literal!=null)q.object=this.lexicon.parseLiteral(q.object.literal),delete q.object.literal}else if(t=o[q.object.blank||q.object.value],t==null&&(t=this.lexicon.registerBlank(q.object.blank||q.object.value),o[q.object.blank||q.object.value]=t),q.object.token==null)q.object.token="blank",q.object.value=q.object.blank,delete q.object.blank;i=t;if(q.graph.uri||q.graph.token==="uri"){t=this.lexicon.registerUri(q.graph.uri||
q.graph.value);if(q.graph.uri!=null)q.graph={token:"uri",value:q.graph.uri},delete q.subject.uri;this.lexicon.registerGraph(t)}else if(q.graph.literal||q.graph.token==="literal"){if(t=this.lexicon.registerLiteral(q.graph.literal||q.graph.value),q.predicate.literal!=null)q.predicate=this.lexicon.parseLiteral(q.predicate.literal),delete q.predicate.literal}else if(t=o[q.graph.blank||q.graph.value],t==null&&(t=this.lexicon.registerBlank(q.graph.blank||q.graph.value),o[q.graph.blank||q.graph.value]=t),
q.graph.token==null)q.graph.token="blank",q.graph.value=q.graph.blank,delete q.graph.blank;h=t;t=q;q={subject:e,predicate:c,object:i,graph:h};e=new R.NodeKey(q);c=this.backend.search(e);if(!c)if(c=this.backend.index(e),c==!0)this.eventsOnBatchLoad&&this.callbacksBackend.nextGraphModification(D.added,[t,q]),f+=1;else{g=!1;break}}this.lexicon.updateAfterWrite!=null&&this.lexicon.updateAfterWrite();var v=function(){g?b&&b(!0,f):b&&b(!1,null)};this.eventsOnBatchLoad?this.callbacksBackend.endGraphModification(function(){v()}):
v();return g?f:null};B.QueryEngine.prototype.computeCosts=function(a,b){for(var e=0;e<a.length;e++)a[e]._cost=this.quadCost(a[e],b);return a};B.QueryEngine.prototype._executeModifyQuery=function(a,b,e){var c=this,i=!0,h=null,f=["subject","predicate","object","graph"];a.insert=a.insert==null?[]:a.insert;a["delete"]=a["delete"]==null?[]:a["delete"];v.seq(function(e){var f=[],g=[];a["with"]!=null&&f.push(a["with"]);if(a.using!=null)for(var g=[],q=0;q<a.using.length;q++){var u=a.using[q];u.kind==="named"?
g.push(u.uri):f.push(u.uri)}a.dataset={};a.projection=[{token:"variable",kind:"*"}];c.executeSelect(a,b,f,g,function(a,f){a?(f=c.denormalizeBindingsList(f,b),f!=null?h=f:i=!1):i=!1;return e()})},function(e){var g=a["with"];if(i){for(var t=[],q=0;q<a["delete"].length;q++)for(var u=a["delete"][q],v=0;v<h.length;v++){for(var x={},A=h[v],m=0;m<f.length;m++){var r=f[m];r=="graph"&&u[r]==null?x.graph=g:x[r]=u[r].token==="var"?A[u[r].value]:u[r]}t.push(x)}for(v=0;v<t.length;v++)x=t[v],c._executeQuadDelete(x,
b)}e()},function(e){var g=a["with"];if(i){for(var t=[],q=0;q<a.insert.length;q++)for(var u=a.insert[q],v=0;v<h.length;v++){for(var x={},A=h[v],m=0;m<f.length;m++){var r=f[m];r=="graph"&&u[r]==null?x.graph=g:x[r]=u[r].token==="var"?A[u[r].value]:u[r]}t.push(x)}for(q=0;q<t.length;q++)x=t[q],c._executeQuadInsert(x,b)}e()})(function(){e(i)})};B.QueryEngine.prototype._executeQuadInsert=function(a,b){var e=this.normalizeQuad(a,b,!0);if(e!=null){var c=new R.NodeKey(e),i=this.backend.search(c);return i?i:
(i=this.backend.index(c),i==!0?(this.callbacksBackend.nextGraphModification(D.added,[a,e]),!0):(console.log("ERROR inserting quad"),!1))}else return console.log("ERROR normalizing quad"),!1};B.QueryEngine.prototype._executeQuadDelete=function(a,b){var e=this.normalizeQuad(a,b,!1);if(e!=null){var c=new R.NodeKey(e);this.backend["delete"](c);return this.lexicon.unregister(a,c)==!0?(this.callbacksBackend.nextGraphModification(D.deleted,[a,e]),!0):(console.log("ERROR unregistering quad"),!1)}else return console.log("ERROR normalizing quad"),
!1};B.QueryEngine.prototype._executeClearGraph=function(a,b,e){if(a==="default")this.execute("DELETE { ?s ?p ?o } WHERE { ?s ?p ?o }",e);else if(a==="named"){var c=this,i=this.lexicon.registeredGraphs(!0);if(i!=null){var h=!1;v.repeat(0,i.length,function(a,b){var e=i[b._i],g=arguments.callee;h?a(g,b):c.execute("DELETE { GRAPH <"+e+"> { ?s ?p ?o } } WHERE { GRAPH <"+e+"> { ?s ?p ?o } }",function(c){h=!c;a(g,b)})},function(){e(!h)})}else e(!1,"Error deleting named graphs")}else a==="all"?(c=this,this.execute("CLEAR DEFAULT",
function(a,b){a?c.execute("CLEAR NAMED",e):e(!1,b)})):a.token=="uri"?(a=v.lexicalFormBaseUri(a,b),a!=null?this.execute("DELETE { GRAPH <"+a+"> { ?s ?p ?o } } WHERE { GRAPH <"+a+"> { ?s ?p ?o } }",e):e(!1,"wrong graph URI")):e(!1,"wrong graph URI")};B.QueryEngine.prototype.checkGroupSemantics=function(a,b){if(a==="singleGroup")return!0;for(var e={},c=0;c<a.length;c++){var i=a[c];i.token==="var"?e[i.value]=!0:i.token==="aliased_expression"&&(e[i.alias.value]=!0)}for(c=0;c<b.length;c++)if(i=b[c],i.kind===
"var"){if(e[i.value.value]==null)return!1}else if(i.kind==="aliased"&&i.expression&&i.expression.primaryexpression==="var"&&e[i.expression.value.value]==null)return!1;return!0};B.QueryEngine.prototype.registerDefaultNamespace=function(a,b){this.defaultPrefixes[a]=b};var D={ANYTHING:{token:"var",value:"_"},added:"added",deleted:"deleted",eventsFlushed:"eventsFlushed",CallbacksBackend:function(a){this.aqt=new K.AbstractQueryTree;this.engine=a;this.indexMap={};this.observersMap={};this.queriesIndexMap=
{};this.emptyNotificationsMap={};this.queriesList=[];this.pendingQueries=[];this.matchedQueries=[];this.updateInProgress=null;this.indices=["SPOG","GP","OGS","POG","GSP","OS"];this.componentOrders={SPOG:["subject","predicate","object","graph"],GP:["graph","predicate","subject","object"],OGS:["object","graph","subject","predicate"],POG:["predicate","object","graph","subject"],GSP:["graph","subject","predicate","object"],OS:["object","subject","predicate","graph"]};this.callbackCounter=0;this.callbacksMap=
{};this.callbacksInverseMap={};this.queryCounter=0;this.queriesMap={};this.queriesCallbacksMap={};this.queriesInverseMap={};for(a=0;a<this.indices.length;a++){var b=this.indices[a];this.indexMap[b]={};this.queriesIndexMap[b]={}}}};D.CallbacksBackend.prototype.startGraphModification=function(){this.pendingQueries=[].concat(this.queriesList);this.matchedQueries=[];if(this.updateInProgress==null)this.updateInProgress={added:[],deleted:[]}};D.CallbacksBackend.prototype.nextGraphModification=function(a,
b){this.updateInProgress[a].push(b)};D.CallbacksBackend.prototype.endGraphModification=function(a){var b=this;if(this.updateInProgress!=null){var e=b.updateInProgress;b.updateInProgress=null;this.sendNotification(D.deleted,e[D.deleted],function(){b.sendNotification(D.added,e[D.added],function(){b.sendEmptyNotification(D.eventsFlushed,null,function(){b.dispatchQueries(function(){a(!0)})})})})}else a(!0)};D.CallbacksBackend.prototype.cancelGraphModification=function(){this.updateInProgress=null};D.CallbacksBackend.prototype.sendNotification=
function(a,b,e){for(var c={},i=0;i<b.length;i++){var h=b[i],f;for(f in this.indexMap){var g=this.indexMap[f],o=this.componentOrders[f];this._searchCallbacksInIndex(g,o,a,h,c);this.pendingQueries.length!=0&&(g=this.queriesIndexMap[f],this._searchQueriesInIndex(g,o,h))}}this.dispatchNotifications(c);e!=null&&e(!0)};D.CallbacksBackend.prototype.sendEmptyNotification=function(a,b,e){for(var c=this.emptyNotificationsMap[a]||[],i=0;i<c.length;i++)c[i](a,b);e()};D.CallbacksBackend.prototype.dispatchNotifications=
function(a){for(var b in a){var e=this.callbacksMap[b],c=a[b][D.deleted];if(c!=null)try{e(D.deleted,c)}catch(i){}for(var h in a[b])if(h!=D.deleted)try{e(h,a[b][h])}catch(f){}}};D.CallbacksBackend.prototype._searchCallbacksInIndex=function(a,b,e,c,i){for(var h=c[1],c=c[0],f=0;f<b.length+1;f++){for(var g=a._||[],o=[],t=0;t<g.length;t++){var q=g[t];this.callbacksMap[q]!=null&&(i[q]=i[q]||{},i[q][e]=i[q][e]||[],i[q][e].push(c),o.push(q))}a._=o;g=b[f];if(a[""+h[g]]!=null)a=a[""+h[g]];else break}};D.CallbacksBackend.prototype.subscribeEmpty=
function(a,b){var e=this.emptyNotificationsMap[a]||[];e.push(b);this.emptyNotificationsMap[a]=e};D.CallbacksBackend.prototype.unsubscribeEmpty=function(a,b){var e=this.emptyNotificationsMap[a];e!=null&&(e=v.remove(e,b));this.emptyNotificationsMap[a]=e};D.CallbacksBackend.prototype.subscribe=function(a,b,e,c,i,h){a=this._tokenizeComponents(a,b,e,c);b={blanks:{},outCache:{}};this.engine.registerNsInEnvironment(null,b);a=this.engine.normalizeQuad(a,b,!0);e=this._indexForPattern(new R.Pattern(a));b=this.componentOrders[e];
e=this.indexMap[e];for(c=0;c<b.length;c++){var f=a[b[c]];if(f==="_"){e._==null&&(e._=[]);this.callbackCounter++;e._.push(this.callbackCounter);this.callbacksMap[this.callbackCounter]=i;this.callbacksInverseMap[i]=this.callbackCounter;break}else c===b.length-1?(e[f]=e[f]||{_:[]},this.callbackCounter++,e[f]._.push(this.callbackCounter),this.callbacksMap[this.callbackCounter]=i,this.callbacksInverseMap[i]=this.callbackCounter):(e[f]=e[f]||{},e=e[f])}h!=null&&h(!0)};D.CallbacksBackend.prototype.unsubscribe=
function(a){var b=this.callbacksInverseMap[a];b!=null&&(delete this.callbacksInverseMap[a],delete this.callbacksMap[b])};D.CallbacksBackend.prototype._tokenizeComponents=function(a,b,e,c){var i={};i.subject=a==null?D.ANYTHING:a.indexOf("_:")==0?{token:"blank",value:a}:{token:"uri",value:a};i.predicate=b==null?D.ANYTHING:{token:"uri",value:b};i.object=e==null?D.ANYTHING:{token:"uri",value:e};i.graph=c==null?D.ANYTHING:{token:"uri",value:c};return i};D.CallbacksBackend.prototype._indexForPattern=function(a){for(var a=
a.indexKey,b=this.indices,e=0;e<b.length;e++)for(var c=b[e],i=this.componentOrders[c],h=0;h<i.length;h++){if(v.include(a,i[h])===!1)break;if(h==a.length-1)return c}return"SPOG"};D.CallbacksBackend.prototype.observeNode=function(){var a,b,e,c;arguments.length===4?(a=arguments[0],b=arguments[1],e=arguments[2],c=arguments[3]):(a=arguments[0],b=this.engine.lexicon.defaultGraphUri,e=arguments[1],c=arguments[2]);b="CONSTRUCT { <"+a+"> ?p ?o } WHERE { GRAPH <"+b+"> { <"+a+"> ?p ?o } }";var i=this,h={blanks:{},
outCache:{}};this.engine.registerNsInEnvironment(null,h);var f=[];this.engine.execute(b,function(b,g){if(b){var t=!1,q=function(a,b){if(a==="eventsFlushed"&&t){t=!1;try{e(g)}catch(c){}}else if(a!=="eventsFlushed"){t=!0;for(var n=0;n<b.length;n++){var m=b[n],q=u.buildRDFResource(m.subject,f,i.engine,h),v=u.buildRDFResource(m.predicate,f,i.engine,h),m=u.buildRDFResource(m.object,f,i.engine,h);q!=null&&v!=null&&m!=null&&(m=new u.Triple(q,v,m),a===D.added?g.add(m):a===D.deleted&&g.remove(m))}}};i.observersMap[e]=
q;i.subscribeEmpty(D.eventsFlushed,q);i.subscribe(a,null,null,null,q,function(){try{e(g)}catch(a){}c&&c(!0)})}else c&&c(!1)})};D.CallbacksBackend.prototype.stopObservingNode=function(a){return(a=this.observersMap[a])?(this.unsubscribe(a),this.unsubscribeEmpty(D.eventsFlushed,a),!0):!1};D.CallbacksBackend.prototype.observeQuery=function(a,b,e){var c=this.aqt.collectBasicTriples(this.aqt.parseSelect(this.aqt.parseQueryString(a).units[0])),i={blanks:{},outCache:{}};this.engine.registerNsInEnvironment(null,
i);var h,f,g,o=this.queryCounter;this.queryCounter++;this.queriesMap[o]=a;this.queriesInverseMap[a]=o;this.queriesList.push(o);this.queriesCallbacksMap[o]=b;for(var t=0;t<c.length;t++){f=c[t];if(f.graph==null)f.graph=this.engine.lexicon.defaultGraphUriTerm;f=this.engine.normalizeQuad(f,i,!0);h=new R.Pattern(f);g=this._indexForPattern(h);h=this.componentOrders[g];g=this.queriesIndexMap[g];for(var q=0;q<h.length;q++){var u=f[h[q]];if(typeof u==="string"){g._==null&&(g._=[]);g._.push(o);break}else q===
h.length-1?(g[u]=g[u]||{_:[]},g[u]._.push(o)):(g[u]=g[u]||{},g=g[u])}}this.engine.execute(a,function(a,c){a?b(c):console.log("ERROR in query callback "+c)});e!=null&&e()};D.CallbacksBackend.prototype.stopObservingQuery=function(a){var b=this.queriesInverseMap[a];if(b!=null)delete this.queriesInverseMap[a],delete this.queriesMap[b],this.queriesList=v.remove(this.queriesList,b)};D.CallbacksBackend.prototype._searchQueriesInIndex=function(a,b,e){for(var e=e[1],c=0;c<b.length+1;c++){for(var i=a._||[],
h=[],f=0;f<i.length;f++){var g=i[f];v.include(this.pendingQueries,g)&&(v.remove(this.pendingQueries,g),this.matchedQueries.push(g));this.queriesMap[g]!=null&&h.push(g)}a._=h;i=b[c];if(a[""+e[i]]!=null)a=a[""+e[i]];else break}};D.CallbacksBackend.prototype.dispatchQueries=function(a){var b=this,e,c,i,h,f={};v.repeat(0,this.matchedQueries.length,function(a,g){e=arguments.callee;i=b.matchedQueries[g._i];f[i]==null?(f[i]=!0,c=b.queriesMap[i],h=b.queriesCallbacksMap[i],v.recur(function(){b.engine.execute(c,
function(b,c){if(b)try{h(c)}catch(f){}a(e,g)})})):a(e,g)},function(){a()})};var J={};try{typeof Worker=="undefined"&&(Worker=null)}catch(lc){Worker=null}if(Worker)J.RDFStoreClient=function(a,b,e){console.log("trying to load "+a);this.connection=Worker.Worker?new Worker.Worker(a):new Worker(a);this.callbacksCounter=1;var c=this;this.rdf=u.rdf;console.log("The worker");console.log(this.connection);c=this;this.connection.onmessage=function(a){c.receive(a)};this.observingCallbacks={};this.callbacks={0:{cb:function(a,
b){a===!0?e(!0,c):e(!1,b)},fn:"create"}};this.connection.postMessage({fn:"create",args:b,callback:"0"})},J.RDFStoreClient.prototype.receive=function(a){a=a.data||a;if(a.fn==="workerRequest:NetworkTransport:load"){var b=this,e=a.callback,a=a.arguments.concat(function(a,c){b.connection.postMessage({fn:"workerRequestResponse",results:[a,c],callback:e})});O.load.apply(O,a)}else{var c=this.callbacks[a.callback];c&&(c.fn==="create"||c.fn==="execute"||c.fn==="insert"||c.fn=="graph"||c.fn==="node"||c.fn===
"insert"||c.fn==="delete"||c.fn==="clear"||c.fn==="load"||c.fn==="startObservingQueryEndCb"||c.fn==="registeredGraphs"?(delete this.callbacks[a.callback],c.cb(a.success,a.result)):c.fn==="startObservingQuery"?c.cb(a.result):c.fn==="startObservingNode"?c.cb(a.result):c.fn==="subscribe"&&c.cb(a.event,a.result))}},J.RDFStoreClient.prototype.registerCallback=function(a,b){var e=""+this.callbacksCounter;this.callbacks[e]={fn:a,cb:b};this.callbacksCounter++;return e},J.RDFStoreClient.prototype.execute=
function(){if(arguments.length===3)this.executeWithEnvironment(arguments[0],arguments[1],arguments[2]);else if(arguments.length===4)this.executeWithEnvironment(arguments[0],arguments[1],arguments[2],arguments[3]);else{var a,b;arguments.length===1?(a=arguments[0],b=function(){}):arguments.length===2&&(a=arguments[0],b=arguments[1]);b=this.registerCallback("execute",b);this.connection.postMessage({fn:"execute",args:[a],callback:b})}},J.RDFStoreClient.prototype.insert=function(){var a,b,e;if(arguments.length===
1)b=arguments[0],this.connection.postMessage({fn:"insert",args:[b]});else if(arguments.length===2)b=arguments[0],e=arguments[1]||function(){},e=this.registerCallback("insert",e),this.connection.postMessage({fn:"insert",args:[b],callback:e});else if(arguments.length===3)b=arguments[0],a=arguments[1],e=arguments[2]||function(){},e=this.registerCallback("insert",e),this.connection.postMessage({fn:"insert",args:[b,a],callback:e});else throw"The triples to insert, an optional graph and callback must be provided";
},J.RDFStoreClient.prototype.graph=function(){var a=null,b=null;if(arguments.length===1)b=arguments[0]||function(){};else if(arguments.length===2)b=arguments[1]||function(){},a=arguments[0];else throw"An optional graph URI and a callback function must be provided";var e=this,c=this.registerCallback("insert",function(a,c){if(a){for(var f,g=0;g<c.triples.length;g++)f=c.triples[g],c.triples[g]=new u.Triple(e.adaptJSInterface(f.subject),e.adaptJSInterface(f.predicate),e.adaptJSInterface(f.object));b(a,
e.rdf.createGraph(c.triples))}else b(a,c)});a==null?this.connection.postMessage({fn:"graph",args:[],callback:c}):this.connection.postMessage({fn:"graph",args:[a],callback:c})},J.RDFStoreClient.prototype.node=function(){var a=null,b=null,e=null;if(arguments.length===2)e=arguments[0],b=arguments[1]||function(){};else if(arguments.length===3)e=arguments[0],a=arguments[1],b=arguments[2]||function(){};else throw"An optional graph URI and a callback function must be provided";var c=this,g=this.registerCallback("insert",
function(a,e){if(a){for(var g,i=0;i<e.triples.length;i++)g=e.triples[i],e.triples[i]=new u.Triple(c.adaptJSInterface(g.subject),c.adaptJSInterface(g.predicate),c.adaptJSInterface(g.object));b(a,c.rdf.createGraph(e.triples))}else b(a,e)});a==null?this.connection.postMessage({fn:"node",args:[e],callback:g}):this.connection.postMessage({fn:"node",args:[e,a],callback:g})},J.RDFStoreClient.prototype.setPrefix=function(a,b){this.rdf.setPrefix(a,b);this.connection.postMessage({fn:"rdf/setPrefix",args:[a,
b],callback:null})},J.RDFStoreClient.prototype.setDefaultPrefix=function(a){this.rdf.setDefaultPrefix(a);this.connection.postMessage({fn:"rdf/setDefaultPrefix",args:[a],callback:null})},J.RDFStoreClient.prototype["delete"]=function(){var a,b,e;if(arguments.length===1)b=arguments[0],this.connection.postMessage({fn:"delete",args:[b]});else if(arguments.length===2)b=arguments[0],e=arguments[1]||function(){},e=this.registerCallback("delete",e),this.connection.postMessage({fn:"delete",args:[b],callback:e});
else if(arguments.length===3)b=arguments[0],a=arguments[1],e=arguments[2]||function(){},e=this.registerCallback("delete",e),this.connection.postMessage({fn:"delete",args:[b,a],callback:e});else throw"The triples to delete, an optional graph and callback must be provided";},J.RDFStoreClient.prototype.clear=function(){var a,b;if(arguments.length===1)b=arguments[0]||function(){},b=this.registerCallback("clear",b),this.connection.postMessage({fn:"clear",args:[],callback:b});else if(arguments.length===
2)a=arguments[0],b=arguments[1]||function(){},b=this.registerCallback("clear",b),this.connection.postMessage({fn:"clear",args:[a],callback:b});else throw"The optional graph and a callback must be provided";},J.RDFStoreClient.prototype.setBatchLoadEvents=function(a){this.connection.postMessage({fn:"setBatchLoadEvents",args:[a]})},J.RDFStoreClient.prototype.registerDefaultNamespace=function(a,b){this.connection.postMessage({fn:"registerDefaultNamespace",args:[a,b]})},J.RDFStoreClient.prototype.registerDefaultProfileNamespaces=
function(){this.connection.postMessage({fn:"registerDefaultProfileNamespaces",args:[]})},J.RDFStoreClient.prototype.load=function(){var a,b,e,c;if(arguments.length===3)a=arguments[0],b=arguments[1],c=arguments[2]||function(){},c=this.registerCallback("load",c),this.connection.postMessage({fn:"load",args:[a,b],callback:c});else if(arguments.length===4)a=arguments[0],b=arguments[1],e=arguments[2],c=arguments[3]||function(){},c=this.registerCallback("load",c),this.connection.postMessage({fn:"load",args:[a,
b,e],callback:c});else if(arguments.length===2)throw"The mediaType of the parser, the data a callback and an optional graph must be provided";},J.RDFStoreClient.prototype.startObservingQuery=function(a,b,e){e!=null?(b=this.registerCallback("startObservingQuery",b),this.observingCallbacks[a]=b,e=this.registerCallback("startObservingQueryEndCb",e),this.connection.postMessage({fn:"startObservingQuery",args:[a],callback:[b,e]})):(b=this.registerCallback("startObservingQuery",b),this.observingCallbacks[a]=
b,this.connection.postMessage({fn:"startObservingQuery",args:[a],callback:[b]}))},J.RDFStoreClient.prototype.stopObservingQuery=function(a){var b=this.observingCallbacks[a];delete this.observingCallbacks[a];delete this.callbacks[b];this.connection.postMessage({fn:"stopObservingQuery",args:[a],callback:[]})},J.RDFStoreClient.prototype.startObservingNode=function(){var a,b,e;if(arguments.length===2){a=arguments[0];e=arguments[1];var c=this,g=this.registerCallback("startObservingNode",function(a){for(var b,
g=0;g<a.triples.length;g++)b=a.triples[g],a.triples[g]=new u.Triple(c.adaptJSInterface(b.subject),c.adaptJSInterface(b.predicate),c.adaptJSInterface(b.object));e(c.rdf.createGraph(a.triples))});this.observingCallbacks[e]=g;this.connection.postMessage({fn:"startObservingNode",args:[a],callback:g})}else arguments.length===3&&(a=arguments[0],b=arguments[1],e=arguments[2],c=this,g=this.registerCallback("startObservingNode",function(a){for(var b,g=0;g<a.triples.length;g++)b=a.triples[g],a.triples[g]=new u.Triple(c.adaptJSInterface(b.subject),
c.adaptJSInterface(b.predicate),c.adaptJSInterface(b.object));e(c.rdf.createGraph(a.triples))}),this.observingCallbacks[e]=g,this.connection.postMessage({fn:"startObservingNode",args:[a,b],callback:g}))},J.RDFStoreClient.prototype.stopObservingNode=function(a){var b=this.observingCallbacks[a];delete this.observingCallbacks[a];delete this.callbacks[b];this.connection.postMessage({fn:"stopObservingNode",args:[b],callback:[]})},J.RDFStoreClient.prototype.subscribe=function(a,b,e,c,g){var h=this,f=this.registerCallback("subscribe",
function(a,b){for(var c,e=0;e<b.length;e++)c=b[e],b[e]=new u.Triple(h.adaptJSInterface(c.subject),h.adaptJSInterface(c.predicate),h.adaptJSInterface(c.object));g(a,b)});this.observingCallbacks[g]=f;this.connection.postMessage({fn:"subscribe",args:[a,b,e,c],callback:f})},J.RDFStoreClient.prototype.unsubscribe=function(a){var b=this.observingCallbacks[a];delete this.observingCallbacks[a];delete this.callbacks[b];this.connection.postMessage({fn:"unsubscribe",args:[b],callback:[]})},J.RDFStoreClient.prototype.registeredGraphs=
function(a){var b=this;this.connection.postMessage({fn:"registeredGraphs",args:[],callback:this.registerCallback("registeredGraphs",function(e,c){if(e)for(var g=0;g<c.length;g++)c[g]=b.adaptJSInterface(c[g]);a(e,c)})})},J.RDFStoreClient.prototype.adaptJSInterface=function(a){if(a.interfaceName==="BlankNode")return new u.BlankNode(a.bnodeId);else if(a.interfaceName==="Literal")return new u.Literal(a.nominalValue,a.language,a.datatype);else if(a.interfaceName==="NamedNode")return new u.NamedNode(a.nominalValue)},
J.RDFStoreClient.prototype.isWebWorkerConnection=!0;var C={},lb={MongodbQueryEngine:function(){throw"MongoDB backend not supported in the browser version";}};C.VERSION="0.7.0";C.connect=function(){var a,b,e;arguments.length==1&&(a=__dirname,b={},e=arguments[0]);arguments.length==2?(typeof arguments[0]==="string"?(a=arguments[0],b={}):(a=__dirname+"/index.js",b=arguments[0]),e=arguments[1]):(a=arguments[0],b=arguments[1],e=arguments[2]);try{Worker?new J.RDFStoreClient(a,b,function(a,b){e(a,b)}):C.create(b,
function(a){e(!1,a)})}catch(c){C.create(b,function(a){e(!1,a)})}};C.create=function(){return arguments.length==1?new C.Store(arguments[0]):arguments.length==2?new C.Store(arguments[0],arguments[1]):new C.Store};C.Store=function(a,b){var e=null,c=null;if(arguments.length==0)c={};else if(arguments.length==1)c={},e=a;else if(arguments.length>1)c=a,e=b;else throw"An optional argument map and a callback must be provided";c.treeOrder==null&&(c.treeOrder=15);this.functionMap={};var g=this;this.customFns=
{};c.engine==="mongodb"?(this.isMongodb=!0,this.engine=new lb.MongodbQueryEngine(c),this.engine.readConfiguration(function(){c.overwrite===!0?g.engine.clean(function(){e(g)}):e(g)})):new L.Lexicon(function(a){c.overwrite===!0&&a.clear();new W.QuadBackend(c,function(b){c.overwrite===!0&&b.clear();c.backend=b;c.lexicon=a;g.engine=new B.QueryEngine(c);e&&e(g)})},c.name)};C.Store.prototype.rdf=u.rdf;C.Store.prototype.rdf.api=u;C.Store.prototype.registerCustomFunction=function(a,b){this.customFns[a]=b;
this.engine.setCustomFunctions(this.customFns)};C.Store.prototype.execute=function(){if(arguments.length===3)this.executeWithEnvironment(arguments[0],arguments[1],arguments[2]);else if(arguments.length===4)this.executeWithEnvironment(arguments[0],arguments[1],arguments[2],arguments[3]);else{var a,b;arguments.length===1?(a=arguments[0],b=function(){}):arguments.length===2&&(a=arguments[0],b=arguments[1]);this.engine.execute(a,b)}};C.Store.prototype.executeWithEnvironment=function(){var a,b,e;if(arguments.length===
3){a=arguments[0];var c=function(){};b=arguments[1];e=arguments[2]}else arguments.length===4&&(a=arguments[0],c=arguments[3],b=arguments[1],e=arguments[2]);for(var g=[],h=[],f=0;f<b.length;f++)g.push({token:"uri",value:b[f]});for(f=0;f<e.length;f++)h.push({token:"uri",value:e[f]});this.engine.execute(a,c,g,h)};C.Store.prototype.graph=function(){var a=null,b=null;if(arguments.length===1)b=arguments[0]||function(){},a=this.engine.lexicon.defaultGraphUri;else if(arguments.length===2)b=arguments[1]||
function(){},a=arguments[0];else throw"An optional graph URI and a callback function must be provided";this.rdf.resolve(a)!=null&&(a=this.rdf.resolve(a));this.engine.execute("CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <"+a+"> { ?s ?p ?o } }",b)};C.Store.prototype.node=function(){var a=null,b=null,e=null;if(arguments.length===2)e=arguments[0],b=arguments[1]||function(){},a=this.engine.lexicon.defaultGraphUri;else if(arguments.length===3)e=arguments[0],a=arguments[1],b=arguments[2]||function(){};else throw"An optional graph URI, node URI and a callback function must be provided";
this.rdf.resolve(a)!=null&&(a=this.rdf.resolve(a));this.rdf.resolve(e)!=null&&(e=this.rdf.resolve(e));this.engine.execute("CONSTRUCT { <"+e+"> ?p ?o } WHERE { GRAPH <"+a+"> { <"+e+"> ?p ?o } }",b)};C.Store.prototype.startObservingNode=function(){var a,b,e;arguments.length===2?(a=arguments[0],e=arguments[1],this.engine.callbacksBackend.observeNode(a,e,function(){})):arguments.length===3&&(a=arguments[0],b=arguments[1],e=arguments[2],this.engine.callbacksBackend.observeNode(a,b,e,function(){}))};C.Store.prototype.stopObservingNode=
function(a){this.engine.callbacksBackend.stopObservingNode(a)};C.Store.prototype.startObservingQuery=function(a,b,e){e!=null?this.engine.callbacksBackend.observeQuery(a,b,e):this.engine.callbacksBackend.observeQuery(a,b,function(){})};C.Store.prototype.stopObservingQuery=function(a){this.engine.callbacksBackend.stopObservingQuery(a)};C.Store.prototype.subscribe=function(a,b,e,c,g){var h=this,f=function(a,b){for(var c=[],e={blanks:{},outCache:{}},f=[],v=0;v<b.length;v++){var x=b[v],A=u.buildRDFResource(x.subject,
f,h.engine,e),m=u.buildRDFResource(x.predicate,f,h.engine,e),x=u.buildRDFResource(x.object,f,h.engine,e);A!=null&&m!=null&&x!=null&&(x=new u.Triple(A,m,x),c.push(x))}g(a,c)};this.functionMap[g]=f;this.engine.callbacksBackend.subscribe(a,b,e,c,f,function(){})};C.Store.prototype.unsubscribe=function(a){this.engine.callbacksBackend.unsubscribe(this.functionMap[a]);delete this.functionMap[a]};C.Store.prototype.setPrefix=function(a,b){this.rdf.setPrefix(a,b)};C.Store.prototype.setDefaultPrefix=function(a){this.rdf.setDefaultPrefix(a)};
C.Store.prototype.insert=function(){var a,b,e;if(arguments.length===1)b=arguments[0];else if(arguments.length===2)a=this.rdf.createNamedNode(this.engine.lexicon.defaultGraphUri),b=arguments[0],e=arguments[1]||function(){};else if(arguments.length===3)b=arguments[0],a=this.rdf.createNamedNode(arguments[1]),e=arguments[2]||function(){};else throw"The triples to insert, an optional graph and callback must be provided";var c="",g=this;b.forEach(function(a){c=c+g._nodeToQuery(a.subject)+g._nodeToQuery(a.predicate)+
g._nodeToQuery(a.object)+"."});c=a!=null?"INSERT DATA { GRAPH "+this._nodeToQuery(a)+" { "+c+" } }":"INSERT DATA { "+this._nodeToQuery(a)+" { "+c+" }";this.engine.execute(c,e)};C.Store.prototype._nodeToQuery=function(a){if(a.interfaceName==="NamedNode"){var b=this.rdf.resolve(a.valueOf());return b!=null?"<"+b+">":"<"+a.valueOf()+">"}else{if(a.interfaceName!=="")if(a.lang!=null)return'"'+a.valueOf()+'"@'+a.lang;else if(a.datatype!=null)return'"'+a.valueOf()+'"^^<'+a.datatype+">";return a.toString()}};
C.Store.prototype["delete"]=function(){var a,b,e;if(arguments.length===1)b=arguments[0];else if(arguments.length===2)a=this.rdf.createNamedNode(this.engine.lexicon.defaultGraphUri),b=arguments[0],e=arguments[1]||function(){};else if(arguments.length===3)b=arguments[0],a=this.rdf.createNamedNode(arguments[1]),e=arguments[2]||function(){};else throw"The triples to delete, an optional graph and callback must be provided";var c="",g=this;b.forEach(function(a){c=c+g._nodeToQuery(a.subject)+g._nodeToQuery(a.predicate)+
g._nodeToQuery(a.object)+"."});c=a!=null?"DELETE DATA { GRAPH "+this._nodeToQuery(a)+" { "+c+" } }":"DELETE DATA { "+this._nodeToQuery(a)+" { "+c+" }";this.engine.execute(c,e)};C.Store.prototype.clear=function(){var a,b;if(arguments.length===0)a=this.rdf.createNamedNode(this.engine.lexicon.defaultGraphUri),b=function(){};else if(arguments.length===1)a=this.rdf.createNamedNode(this.engine.lexicon.defaultGraphUri),b=arguments[0]||function(){};else if(arguments.length===2)a=this.rdf.createNamedNode(arguments[0]),
b=arguments[1]||function(){};else throw"The optional graph and a callback must be provided";this.engine.execute("CLEAR GRAPH "+this._nodeToQuery(a),b)};C.Store.prototype.setBatchLoadEvents=function(a){this.engine.eventsOnBatchLoad=a};C.Store.prototype.registerDefaultNamespace=function(a,b){this.rdf.prefixes.set(a,b);this.engine.registerDefaultNamespace(a,b)};C.Store.prototype.registerDefaultProfileNamespaces=function(){var a=this.rdf.prefixes.values(),b;for(b in a)this.registerDefaultNamespace(b,
a[b])};C.Store.prototype.load=function(){var a,b,e,c;if(arguments.length===3)e=this.rdf.createNamedNode(this.engine.lexicon.defaultGraphUri),a=arguments[0],b=arguments[1],c=arguments[2]||function(){};else if(arguments.length===4)a=arguments[0],b=arguments[1],e=this.rdf.createNamedNode(arguments[2]),c=arguments[3]||function(){};else if(arguments.length===2)throw"The mediaType of the parser, the data a callback and an optional graph must be provided";if(a==="remote")b=this.rdf.createNamedNode(b),this.engine.execute("LOAD <"+
b.valueOf()+"> INTO GRAPH <"+e.valueOf()+">",c);else if(b&&typeof b==="string"&&b.indexOf("file://")===0){a=this.engine.rdfLoader.parsers[a];var g=this;this.engine.rdfLoader.loadFromFile(a,{token:"uri",value:e.valueOf()},b,function(a,b){a?g.engine.batchLoad(b,c):c(a,b)})}else a=this.engine.rdfLoader.parsers[a],g=this,this.engine.rdfLoader.tryToParse(a,{token:"uri",value:e.valueOf()},b,function(a,b){a?g.engine.batchLoad(b,c):c(a,b)})};C.Store.prototype.registerParser=function(a,b){this.engine.rdfLoader.registerParser(a,
b)};C.Store.prototype.registeredGraphs=function(a){if(this.isMongodb)this.engine.registeredGraphs(!0,function(b){for(var c=[],e=0;e<b.length;e++){var g=new u.NamedNode(b[e]);c.push(g)}return a(!0,c)});else{for(var b=this.engine.lexicon.registeredGraphs(!0),e=[],c=0;c<b.length;c++){var g=new u.NamedNode(b[c]);e.push(g)}return a(!0,e)}};C.Store.prototype._nodeToQuery=function(a){if(a.interfaceName==="NamedNode"){var b=this.rdf.resolve(a.valueOf());return b!=null?"<"+b+">":"<"+a.valueOf()+">"}else return a.toString()};
C.Store.prototype.getNetworkTransport=function(){return O};C.Store.prototype.setNetworkTransport=function(a){O=a};C.Store.prototype.close=function(a){a==null&&(a=function(){});this.engine.close?this.engine.close(a):a()};RDFStoreWorker={observingCallbacks:{},workerCallbacksCounter:0,workerCallbacks:{}};RDFStoreWorker.registerCallback=function(a){var b=""+RDFStoreWorker.workerCallbacksCounter;RDFStoreWorker.workerCallbacksCounter++;RDFStoreWorker.workerCallbacks[b]=a;return b};RDFStoreWorker.handleCreate=
function(a,b){typeof O!="undefined"&&O!=null&&(O={load:function(a,b,e){var f=RDFStoreWorker.registerCallback(function(a){e.apply(e,a)});postMessage({fn:"workerRequest:NetworkTransport:load",callback:f,arguments:[a,b]})},loadFromFile:function(){}});var e=[a];e.push(function(a){RDFStoreWorker.store=a;postMessage({callback:b,result:"created",success:!0})});C.create.apply(C,e)};RDFStoreWorker.receive=function(a){var b=a.data||a;if(b.fn==="workerRequestResponse"){var e=b.callback,c=RDFStoreWorker.workerCallbacks[e];
c!=null&&(delete RDFStoreWorker.workerCallbacks[e],c(b.results))}else if(b.fn==="create"&&b.args!=null)RDFStoreWorker.handleCreate(b.args,b.callback);else if(b.fn==="setBatchLoadEvents")RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args);else if(b.fn==="registerDefaultNamespace")RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args);else if(b.fn==="registerDefaultProfileNamespaces")RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args);else if((b.fn==="execute"||b.fn==="executeWithEnvironment"||
b.fn==="graph"||b.fn==="node"||b.fn==="clear"||b.fn==="load")&&b.args!=null){b.args.push(function(a,c){b.callback!=null&&postMessage({callback:b.callback,result:c,success:a})});try{RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args)}catch(g){console.log("Error executing method through connection"),console.log(g)}}else if((b.fn==="insert"||b.fn==="delete")&&b.args!=null)try{b.args.push(function(a,c){b.callback!=null&&postMessage({callback:b.callback,result:c,success:a})});c=b.args[0];for(a=
0;a<c.triples.length;a++)e=c.triples[a],c.triples[a]=new u.Triple(RDFStoreWorker.adaptJSInterface(e.subject),RDFStoreWorker.adaptJSInterface(e.predicate),RDFStoreWorker.adaptJSInterface(e.object));b.args[1].interfaceName!=null&&(b.args[1]=RDFStoreWorker.adaptJSInterface(b.args[1]));b.args[0]=RDFStoreWorker.store.rdf.createGraph(c.triples);RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args)}catch(h){console.log("Error executing method through connection"),console.log(h)}else b.fn==="rdf/setPrefix"&&
b.args!=null?RDFStoreWorker.store.rdf.setPrefix(b.args[0],b.args[1]):b.fn==="rdf/setDefaultPrefix"&&b.args!=null?RDFStoreWorker.store.rdf.setDefaultPrefix(b.args[0]):b.fn==="startObservingQuery"&&b.args!=null?(e=function(a,c){postMessage({callback:b.callback[0],result:c,success:a})},RDFStoreWorker.observingCallbacks[b.args[0]]=e,b.args.push(e),b.args.push(function(a,c){b.callback&&b.callback[1]!=null&&postMessage({callback:b.callback[1],result:c,success:a})}),RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,
b.args)):b.fn==="stopObservingQuery"?((e=RDFStoreWorker.observingCallbacks[b.args[0]])&&RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,[e]),delete RDFStoreWorker.observingCallbacks[b.args[0]]):b.fn==="startObservingNode"&&b.args!=null?(e=function(a){postMessage({callback:b.callback,result:a})},RDFStoreWorker.observingCallbacks[b.callback]=e,b.args.push(e),RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args)):b.fn==="stopObservingNode"&&b.args!=null?((e=RDFStoreWorker.observingCallbacks[b.args[0]])&&
RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,[e]),delete RDFStoreWorker.observingCallbacks[b.args[0]]):b.fn==="subscribe"&&b.args!=null?(e=function(a,c){postMessage({callback:b.callback,event:a,result:c})},RDFStoreWorker.observingCallbacks[b.callback]=e,b.args.push(e),RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,b.args)):b.fn==="stopObservingNode"&&b.args!=null?((e=RDFStoreWorker.observingCallbacks[b.args[0]])&&RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,[e]),delete RDFStoreWorker.observingCallbacks[b.args[0]]):
b.fn==="registeredGraphs"&&b.args!=null&&RDFStoreWorker.store[b.fn].apply(RDFStoreWorker.store,[function(a,c){b.callback!=null&&postMessage({callback:b.callback,result:c,success:a})}])};RDFStoreWorker.adaptJSInterface=function(a){if(a.interfaceName==="BlankNode")return new u.BlankNode(a.bnodeId);else if(a.interfaceName==="Literal")return new u.Literal(a.nominalValue,a.language,a.datatype);else if(a.interfaceName==="NamedNode")return new u.NamedNode(a.nominalValue)};onmessage=RDFStoreWorker.receive;
try{window.rdfstore=C}catch(mc){}})();