n3 2.7.6 → 2.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ var Al=Object.create;var rr=Object.defineProperty,Nl=Object.defineProperties,vl=
20
20
  ]`)}}list(e){let r=e&&e.length||0,i=new Array(r);for(let n=0;n<r;n++)i[n]=this._encodeObject(e[n]);return new Ve(`(${i.join(" ")})`)}end(e){this._subject!==null&&(this._write(this._inDefaultGraph?`.
21
21
  `:`
22
22
  }
23
- `),this._subject=null),this._write=this._blockedWrite;let r=e&&((i,n)=>{r=null,e(i,n)});if(this._endStream)try{return this._outputStream.end(r)}catch(i){}r&&r()}};function us(t){let e=Fu[t];return e===void 0&&(t.length===1?(e=t.charCodeAt(0).toString(16),e="\\u0000".substr(0,6-e.length)+e):(e=((t.charCodeAt(0)-55296)*1024+t.charCodeAt(1)+9216).toString(16),e="\\U00000000".substr(0,10-e.length)+e)),e}var En=ir(Wr());var xn=Symbol("iter"),j=Symbol("size");function lp(t,e,r,i){let n=t&&t[e],s=n&&n[r];return!!s&&i in s}function Pt(t,e,r=4){let i=t[j]||0;for(let n in e)n in t?r!==0&&(t[n]=Pt(t[n],e[n],r-1)):(i++,t[n]=r===0?null:Pt(Object.create(null),e[n],r-1));return r<=2&&(t[j]=i),t}function ml(t,e,r=4){let i=!1,n=0;r<=2&&e[j]<t[j]&&([t,e]=[e,t]);for(let s in t)if(s in e){let o=r===0?null:ml(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}function xl(t,e,r=4){let i=!1,n=0;for(let s in t)if(!(s in e))i=i||Object.create(null),i[s]=r===0?null:Pt({},t[s],r-1),n++;else if(r!==0){let o=xl(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}var Zt=class{constructor(e={}){this._id=1,this._ids=Object.create(null),this._ids[""]=1,this._entities=Object.create(null),this._entities[1]="",this._blankNodeIndex=0,this._factory=e.factory||z}_termFromId(e){if(e[0]==="."){let r=this._entities,i=e.split(".");return this._factory.quad(this._termFromId(r[i[1]]),this._termFromId(r[i[2]]),this._termFromId(r[i[3]]),i[4]&&this._termFromId(r[i[4]]))}return Le(e,this._factory)}_termToNumericId(e){if(e.termType==="Quad"){let r=this._termToNumericId(e.subject),i=this._termToNumericId(e.predicate),n=this._termToNumericId(e.object),s;return r&&i&&n&&(xe(e.graph)||(s=this._termToNumericId(e.graph)))&&this._ids[s?`.${r}.${i}.${n}.${s}`:`.${r}.${i}.${n}`]}return this._ids[we(e)]}_termToNewNumericId(e){let r=e&&e.termType==="Quad"?`.${this._termToNewNumericId(e.subject)}.${this._termToNewNumericId(e.predicate)}.${this._termToNewNumericId(e.object)}${xe(e.graph)?"":`.${this._termToNewNumericId(e.graph)}`}`:we(e);return this._ids[r]||(this._ids[this._entities[++this._id]=r]=this._id)}createBlankNode(e){let r,i;if(e)for(r=e=`_:${e}`,i=1;this._ids[r];)r=e+i++;else do r=`_:b${this._blankNodeIndex++}`;while(this._ids[r]);return this._ids[r]=++this._id,this._entities[this._id]=r,this._factory.blankNode(r.substr(2))}},$e=class t{constructor(e,r){this._size=0,this._graphs=Object.create(null),!r&&e&&!e[0]&&typeof e.match!="function"&&(r=e,e=null),r=r||{},this._factory=r.factory||z,this._entityIndex=r.entityIndex||new Zt({factory:this._factory}),this._entities=this._entityIndex._entities,this._termFromId=this._entityIndex._termFromId.bind(this._entityIndex),this._termToNumericId=this._entityIndex._termToNumericId.bind(this._entityIndex),this._termToNewNumericId=this._entityIndex._termToNewNumericId.bind(this._entityIndex),e&&this.addAll(e)}get size(){let e=this._size;if(e!==null)return e;e=0;let r=this._graphs,i,n;for(let s in r)for(let o in i=r[s].subjects)for(let a in n=i[o])e+=n[a][j];return this._size=e}_addToIndex(e,r,i,n){let s=e[r];s||(e[r]=s={[j]:0},e[j]++);let o=s[i];o||(s[i]=o={[j]:0},s[j]++);let a=n in o;return a||(o[n]=null,o[j]++),!a}_removeFromIndex(e,r,i,n){let s=e[r],o=s[i];delete o[n],--o[j]===0&&(delete s[i],--s[j]===0&&(delete e[r],e[j]--))}*_findInIndex(e,r,i,n,s,o,a,l){let u=this._entities,c=this._termFromId(u[l]),f={subject:null,predicate:null,object:null};if(n){let d=e[r],_=d&&d[i];if(!_||!(n in _))return;f[s]=this._termFromId(u[r]),f[o]=this._termFromId(u[i]),f[a]=this._termFromId(u[n]),yield this._factory.quad(f.subject,f.predicate,f.object,c);return}if(r&&!(r in e))return;let p=r?null:Object.keys(e);for(let d=0,_=r||p[0];_;_=p&&p[++d]){let b=e[_];if(!b)continue;if(f[s]=this._termFromId(u[_]),i&&!(i in b))return;let y=i?null:Object.keys(b);for(let m=0,I=i||y[0];I;I=y&&y[++m]){let R=b[I];if(!R)continue;f[o]=this._termFromId(u[I]);let g=Object.keys(R);for(let E=0;E<g.length;E++)f[a]=this._termFromId(u[g[E]]),yield this._factory.quad(f.subject,f.predicate,f.object,c)}}}_loop(e,r){for(let i in e)r(i)}_loopByKey0(e,r,i){let n,s;if(n=e[r])for(s in n)i(s)}_loopByKey1(e,r,i){let n,s;for(n in e)s=e[n],s[r]&&i(n)}_loopBy2Keys(e,r,i,n){let s,o,a;if((s=e[r])&&(o=s[i]))for(a in o)n(a)}_loopByKey0Deep(e,r,i){let n,s,o,a;if(n=e[r])for(o in n){s=n[o];for(a in s)i(a)}}_countInIndex(e,r,i,n){let s=0,o,a;if(r){if(!(o=e[r]))return 0;if(i)return(a=o[i])?n?n in a?1:0:a[j]:0;for(let l in o)s+=o[l][j];return s}for(let l in e){o=e[l];for(let u in o)s+=o[u][j]}return s}_getGraphs(e){return e=e===""?1:e&&(this._termToNumericId(e)||-1),typeof e!="number"?this._graphs:{[e]:this._graphs[e]}}_uniqueEntities(e){let r=Object.create(null);return i=>{i in r||(r[i]=!0,e(this._termFromId(this._entities[i],this._factory)))}}add(e){return this.addQuad(e),this}addQuad(e,r,i,n){r||(n=e.graph,i=e.object,r=e.predicate,e=e.subject),n=n?this._termToNewNumericId(n):1;let s=this._graphs[n];return s||(s=this._graphs[n]={subjects:{[j]:0},predicates:{[j]:0},objects:{[j]:0}},Object.freeze(s)),e=this._termToNewNumericId(e),r=this._termToNewNumericId(r),i=this._termToNewNumericId(i),this._addToIndex(s.subjects,e,r,i)?(this._addToIndex(s.predicates,r,i,e),this._addToIndex(s.objects,i,e,r),this._size=null,!0):!1}addQuads(e){for(let r=0;r<e.length;r++)this.addQuad(e[r])}delete(e){return this.removeQuad(e),this}has(e,r,i,n){if(e&&e.subject&&({subject:e,predicate:r,object:i,graph:n}=e),e&&r&&i&&n!==void 0&&n!==null){let s=this._termToNumericId(e),o=this._termToNumericId(r),a=this._termToNumericId(i),l=n===""||xe(n)?1:this._termToNumericId(n),u=l&&this._graphs[l];return!!s&&!!o&&!!a&&!!u&&lp(u.subjects,s,o,a)}return!this.readQuads(e,r,i,n).next().done}import(e){return e.on("data",r=>{this.addQuad(r)}),e}removeQuad(e,r,i,n){r||({subject:e,predicate:r,object:i,graph:n}=e),n=n?this._termToNumericId(n):1;let s=this._graphs,o,a,l;return!(e=e&&this._termToNumericId(e))||!(r=r&&this._termToNumericId(r))||!(i=i&&this._termToNumericId(i))||!(o=s[n])||!(a=o.subjects[e])||!(l=a[r])||!(i in l)?!1:(this._removeFromIndex(o.subjects,e,r,i),this._removeFromIndex(o.predicates,r,i,e),this._removeFromIndex(o.objects,i,e,r),this._size!==null&&this._size--,o.subjects[j]===0&&delete s[n],!0)}removeQuads(e){for(let r=0;r<e.length;r++)this.removeQuad(e[r])}remove(e){return e.on("data",r=>{this.removeQuad(r)}),e}removeMatches(e,r,i,n){let s=new En.Readable({objectMode:!0}),o=this.readQuads(e,r,i,n);return s._read=a=>{for(;--a>=0;){let{done:l,value:u}=o.next();if(l){s.push(null);return}s.push(u)}},this.remove(s)}deleteGraph(e){return this.removeMatches(null,null,null,e)}getQuads(e,r,i,n){return[...this.readQuads(e,r,i,n)]}*readQuads(e,r,i,n){let s=this._getGraphs(n),o,a,l,u;if(!(e&&!(a=this._termToNumericId(e))||r&&!(l=this._termToNumericId(r))||i&&!(u=this._termToNumericId(i))))for(let c in s)(o=s[c])&&(a?u?yield*re(this._findInIndex(o.objects,u,a,l,"object","subject","predicate",c)):yield*re(this._findInIndex(o.subjects,a,l,null,"subject","predicate","object",c)):l?yield*re(this._findInIndex(o.predicates,l,u,null,"predicate","object","subject",c)):u?yield*re(this._findInIndex(o.objects,u,null,null,"object","subject","predicate",c)):yield*re(this._findInIndex(o.subjects,null,null,null,"subject","predicate","object",c)))}match(e,r,i,n){return new Me(this,e,r,i,n,{entityIndex:this._entityIndex})}countQuads(e,r,i,n){let s=this._getGraphs(n),o=0,a,l,u,c;if(e&&!(l=this._termToNumericId(e))||r&&!(u=this._termToNumericId(r))||i&&!(c=this._termToNumericId(i)))return 0;for(let f in s)(a=s[f])&&(e?i?o+=this._countInIndex(a.objects,c,l,u):o+=this._countInIndex(a.subjects,l,u,c):r?o+=this._countInIndex(a.predicates,u,c,l):o+=this._countInIndex(a.objects,c,l,u));return o}forEach(e,r,i,n,s){this.some(o=>(e(o,this),!1),r,i,n,s)}every(e,r,i,n,s){return!this.some(o=>!e(o,this),r,i,n,s)}some(e,r,i,n,s){for(let o of this.readQuads(r,i,n,s))if(e(o,this))return!0;return!1}getSubjects(e,r,i){let n=[];return this.forSubjects(s=>{n.push(s)},e,r,i),n}forSubjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.predicates,a,l,e):this._loopByKey1(o.subjects,a,e):l?this._loopByKey0(o.objects,l,e):this._loop(o.subjects,e))}getPredicates(e,r,i){let n=[];return this.forPredicates(s=>{n.push(s)},e,r,i),n}forPredicates(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.objects,l,a,e):this._loopByKey0(o.subjects,a,e):l?this._loopByKey1(o.predicates,l,e):this._loop(o.predicates,e))}getObjects(e,r,i){let n=[];return this.forObjects(s=>{n.push(s)},e,r,i),n}forObjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.subjects,a,l,e):this._loopByKey0Deep(o.subjects,a,e):l?this._loopByKey0(o.predicates,l,e):this._loop(o.objects,e))}getGraphs(e,r,i){let n=[];return this.forGraphs(s=>{n.push(s)},e,r,i),n}forGraphs(e,r,i,n){for(let s in this._graphs)this.some(o=>(e(o.graph),!0),r,i,n,this._termFromId(this._entities[s]))}createBlankNode(e){return this._entityIndex.createBlankNode(e)}extractLists({remove:e=!1,ignoreErrors:r=!1}={}){let i=Object.create(null),n=r?(()=>!0):((a,l)=>{throw new Error(`${a.value} ${l}`)}),s=this.getQuads(null,A.rdf.rest,A.rdf.nil,null),o=e?[...s]:[];return s.forEach(a=>{let l=[],u=!1,c,f,p=a.graph,d=a.subject;for(;d&&!u;){let _=this.getQuads(null,null,d,null),b=this.getQuads(d,null,null,null),y,m=null,I=null,R=null;for(let g=0;g<b.length&&!u;g++)y=b[g],y.graph.equals(p)?c?u=n(d,"has non-list arcs out"):y.predicate.value===A.rdf.first?m?u=n(d,"has multiple rdf:first arcs"):o.push(m=y):y.predicate.value===A.rdf.rest?I?u=n(d,"has multiple rdf:rest arcs"):o.push(I=y):_.length?u=n(d,"can't be subject and object"):(c=y,f="subject"):u=n(d,"not confined to single graph");for(let g=0;g<_.length&&!u;++g)y=_[g],c?u=n(d,"can't have coreferences"):y.predicate.value===A.rdf.rest?R?u=n(d,"has incoming rdf:rest arcs"):R=y:(c=y,f="object");m?l.unshift(m.object):u=n(d,"has no list head"),d=R&&R.subject}u?e=!1:c&&(i[c[f].value]=l)}),e&&this.removeQuads(o),i}addAll(e){if(e instanceof Me&&(e=e.filtered),Array.isArray(e))this.addQuads(e);else if(e instanceof t&&e._entityIndex===this._entityIndex)e._size!==0&&(this._graphs=Pt(this._graphs,e._graphs),this._size=null);else for(let r of e)this.add(r);return this}contains(e){if(e instanceof Me&&(e=e.filtered),e===this)return!0;if(!(e instanceof t)||this._entityIndex!==e._entityIndex)return e.every(u=>this.has(u));let r=this._graphs,i=e._graphs,n,s,o,a,l;for(let u in i){if(!(n=r[u]))return!1;n=n.subjects;for(let c in s=i[u].subjects){if(!(o=n[c]))return!1;for(let f in a=s[c]){if(!(l=o[f]))return!1;for(let p in a[f])if(!(p in l))return!1}}}return!0}deleteMatches(e,r,i,n){for(let s of this.match(e,r,i,n))this.removeQuad(s);return this}difference(e){if(e&&e instanceof Me&&(e=e.filtered),e===this)return new t({entityIndex:this._entityIndex});if(e instanceof t&&e._entityIndex===this._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=xl(this._graphs,e._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>!e.has(r))}equals(e){return e instanceof Me&&(e=e.filtered),e===this||this.size===e.size&&this.contains(e)}filter(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)e(i,this)&&r.add(i);return r}intersection(e){if(e instanceof Me&&(e=e.filtered),e===this){let r=new t({entityIndex:this._entityIndex});return r._graphs=Pt(Object.create(null),this._graphs),r._size=this._size,r}else if(e instanceof t&&this._entityIndex===e._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=ml(e._graphs,this._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>e.has(r))}map(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)r.add(e(i,this));return r}reduce(e,r){let i=this.readQuads(),n=r===void 0?i.next().value:r;for(let s of i)n=e(n,s,this);return n}toArray(){return this.getQuads()}toCanonical(){throw new Error("not implemented")}toStream(){return this.match()}toString(){return new oe().quadsToString(this)}union(e){let r=new t({entityIndex:this._entityIndex});return r._graphs=Pt(Object.create(null),this._graphs),r._size=this._size,r.addAll(e),r}[Symbol.iterator](){return this.readQuads()}};function pe(t,e,r=0){let i=e[r];if(i&&!(i in t))return!1;let n=!1,s=0;for(let o in i?{[i]:t[i]}:t){let a=r===2?null:pe(t[o],e,r+1);a!==!1&&(n=n||Object.create(null),n[o]=a,s++)}return n&&(n[j]=s),n}var Me=class t extends En.Readable{constructor(e,r,i,n,s,o){super({objectMode:!0}),Object.assign(this,{n3Store:e,subject:r,predicate:i,object:n,graph:s,options:o})}get filtered(){if(!this._filtered){let{n3Store:e,graph:r,object:i,predicate:n,subject:s}=this,o=this._filtered=new $e({factory:e._factory,entityIndex:this.options.entityIndex}),a,l,u;if(s&&!(a=o._termToNumericId(s))||n&&!(l=o._termToNumericId(n))||i&&!(u=o._termToNumericId(i)))return o;let c=e._getGraphs(r);for(let f in c){let p,d,_,b;(b=c[f])&&(!a&&l?(d=pe(b.predicates,[l,u,a]))&&(p=pe(b.subjects,[a,l,u]),_=pe(b.objects,[u,a,l])):u?(_=pe(b.objects,[u,a,l]))&&(p=pe(b.subjects,[a,l,u]),d=pe(b.predicates,[l,u,a])):(p=pe(b.subjects,[a,l,u]))&&(d=pe(b.predicates,[l,u,a]),_=pe(b.objects,[u,a,l])),p&&(o._graphs[f]={subjects:p,predicates:d,objects:_}))}o._size=null}return this._filtered}get size(){return this.filtered.size}_read(e){e>0&&!this[xn]&&(this[xn]=this[Symbol.iterator]());let r=this[xn];for(;--e>=0;){let{done:i,value:n}=r.next();if(i){this.push(null);return}this.push(n)}}addAll(e){return this.filtered.addAll(e)}contains(e){return this.filtered.contains(e)}deleteMatches(e,r,i,n){return this.filtered.deleteMatches(e,r,i,n)}difference(e){return this.filtered.difference(e)}equals(e){return this.filtered.equals(e)}every(e,r,i,n,s){return this.filtered.every(e,r,i,n,s)}filter(e){return this.filtered.filter(e)}forEach(e,r,i,n,s){return this.filtered.forEach(e,r,i,n,s)}import(e){return this.filtered.import(e)}intersection(e){return this.filtered.intersection(e)}map(e){return this.filtered.map(e)}some(e,r,i,n,s){return this.filtered.some(e,r,i,n,s)}toCanonical(){return this.filtered.toCanonical()}toStream(){return this._filtered?this._filtered.toStream():this.n3Store.match(this.subject,this.predicate,this.object,this.graph)}union(e){return this._filtered?this._filtered.union(e):this.n3Store.match(this.subject,this.predicate,this.object,this.graph).addAll(e)}toArray(){return this._filtered?this._filtered.toArray():this.n3Store.getQuads(this.subject,this.predicate,this.object,this.graph)}reduce(e,r){return this.filtered.reduce(e,r)}toString(){return new oe().quadsToString(this)}add(e){return this.filtered.add(e)}delete(e){return this.filtered.delete(e)}has(e){return this.filtered.has(e)}match(e,r,i,n){return new t(this.filtered,e,r,i,n,this.options)}[Symbol.iterator](){return this._filtered?this._filtered[Symbol.iterator]():this.n3Store.readQuads(this.subject,this.predicate,this.object,this.graph)}};var Xt=class{dataset(e){return new $e(e)}};function Sl(t){let e=[];for(let{subject:r,object:i}of t.match(null,z.namedNode("http://www.w3.org/2000/10/swap/log#implies"),null,z.defaultGraph())){let n=[...t.match(null,null,null,r)],s=[...t.match(null,null,null,i)];e.push({premise:n,conclusion:s})}return e}var Jt=class{constructor(e,r={}){this._store=e,this._maxDerivations=r.maxDerivations===void 0?1/0:r.maxDerivations,this._maxPremiseDepth=r.maxPremiseDepth===void 0?1/0:r.maxPremiseDepth}_add(e,r,i,n,s,o){if(this._store._addToIndex(n.subjects,e,r,i)){if(this._store._addToIndex(n.predicates,r,i,e),this._store._addToIndex(n.objects,i,e,r),++this._derivations>this._maxDerivations)throw new Error(`Reasoning exceeded the maximum of ${this._maxDerivations} derivations`);o(s)}}_emit(e,r,i){let n=e.conclusion;for(let s=0;s<n.length;s++){let o=n[s];this._add(o.subject.value,o.predicate.value,o.object.value,r,o,i)}}_evaluatePremise(e,r,i,n=0){let s,o,[a,l,u]=e.premise[n].value,c=r[e.premise[n].content],f=n===e.premise.length-1;if(!(s=a.value)){for(s in c)o=c[s],a.value=Number(s),this._evaluateLevel1(e,r,i,n,f,l,u,o);a.value=null}else(o=c[s])&&this._evaluateLevel1(e,r,i,n,f,l,u,o)}_evaluateLevel1(e,r,i,n,s,o,a,l){let u,c;if(!(u=o.value)){for(u in l)c=l[u],o.value=Number(u),this._evaluateLevel2(e,r,i,n,s,a,c);o.value=null}else(c=l[u])&&this._evaluateLevel2(e,r,i,n,s,a,c)}_evaluateLevel2(e,r,i,n,s,o,a){let l;if(!(l=o.value)){for(l in a)o.value=Number(l),s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1);o.value=null}else s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1)}_evaluateRules(e,r,i){for(let n=0;n<e.length;n++)this._evaluatePremise(e[n],r,i)}_reasonGraphNaive(e,r){let i=[];function n(a){a.next&&a.next.forEach(l=>{i.push([a.subject.value,a.predicate.value,a.object.value,l])})}let s=a=>{for(let l=0;l<a.length;l++){let u=a[l];this._add(u.subject.value,u.predicate.value,u.object.value,r,u,n)}};this._evaluateRules(e,r,n);let o;for(;(o=i.pop())!==void 0;){let[a,l,u,c]=o,f=c.basePremise.subject.value;f||(c.basePremise.subject.value=a);let p=c.basePremise.predicate.value;p||(c.basePremise.predicate.value=l);let d=c.basePremise.object.value;d||(c.basePremise.object.value=u),c.premise.length===0?s(c.conclusion):this._evaluatePremise(c,r,n),f||(c.basePremise.subject.value=null),p||(c.basePremise.predicate.value=null),d||(c.basePremise.object.value=null)}}_createRule({premise:e,conclusion:r}){let i={},n=o=>o.termType==="Variable"?i[o.value]=i[o.value]||{}:{value:this._store._termToNewNumericId(o)},s=o=>({subject:n(o.subject),predicate:n(o.predicate),object:n(o.object)});return{premise:e.map(o=>s(o)),conclusion:r.map(o=>s(o)),variables:Object.values(i)}}reason(e){this._derivations=0,Array.isArray(e)||(e=Sl(e)),e=e.map(i=>this._createRule(i));for(let i of e)if(i.premise.length>this._maxPremiseDepth)throw new Error(`Reasoning rule exceeds the maximum premise depth of ${this._maxPremiseDepth}`);for(let i of e)for(let n of e)for(let s=0;s<n.premise.length;s++){let o=n.premise[s];for(let a of i.conclusion){if(Sn(o.subject,a.subject)&&Sn(o.predicate,a.predicate)&&Sn(o.object,a.object)){let l=new Set,u=[];o.subject.value=o.subject.value||1,o.object.value=o.object.value||1,o.predicate.value=o.predicate.value||1;for(let c=0;c<n.premise.length;c++)c!==s&&u.push(El(n.premise[c],l));(a.next=a.next||[]).push({premise:u,conclusion:n.conclusion,basePremise:o})}for(let l=0;l<n.variables.length;l++)n.variables[l].value=null}}for(let i of e){let n=new Set;i.premise=i.premise.map(s=>El(s,n))}let r=this._store._getGraphs();try{for(let i in r)this._reasonGraphNaive(e,r[i])}finally{this._store._size=null}}};function El({subject:t,predicate:e,object:r},i){let n=t.value||i.has(t)||(i.add(t),!1),s=e.value||i.has(e)||(i.add(e),!1),o=r.value||i.has(r)||(i.add(r),!1);return!n&&s?{content:"predicates",value:[e,r,t]}:o?{content:"objects",value:[r,t,e]}:{content:"subjects",value:[t,e,r]}}function Sn(t,e){return t.value===null&&(t.value=e.value),t.value===e.value}var Il=ir(Wr());var er=class extends Il.Transform{constructor(e){super({decodeStrings:!0}),this._readableState.objectMode=!0;let r=new me(e),i,n,s={onQuad:(o,a)=>{o&&this.emit("error",o)||a&&this.push(a)},onPrefix:(o,a)=>{this.emit("prefix",o,a)}};e&&e.comments&&(s.onComment=o=>{this.emit("comment",o)}),r.parse({on:(o,a)=>{switch(o){case"data":i=a;break;case"end":n=a;break}}},s),this._transform=(o,a,l)=>{i(o),l()},this._flush=o=>{n(),o()}}import(e){return e.on("error",r=>{this.emit("error",r)}),typeof e.pipe=="function"?e.pipe(this):(e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()})),this}};var Rl=ir(Wr());var up=16*1024,fp=20,tr=class extends Rl.Transform{constructor(e){super({encoding:"utf8",writableObjectMode:!0}),this._buffer="",this._flushTimer=null,this._flushDelay=e&&e.flushDelay!==void 0?e.flushDelay:fp;let r=this._writer=new oe({write:(s,o,a)=>{this._buffer+=s,this._buffer.length>=up?this._pushBuffer():this._flushTimer===null&&this._armFlushTimer(),a&&a()},end:s=>{this._pushBuffer(),this.push(null),s&&s()}},e),i=null,n=s=>{let o=i;i=null,s&&this._pushBuffer(),o(s)};this._transform=(s,o,a)=>{i=a,r.addQuad(s,n)},this._flush=s=>{r.end(s)}}_pushBuffer(){this._clearFlushTimer(),this._buffer!==""&&(this.push(this._buffer),this._buffer="")}_armFlushTimer(){this._flushTimer=setTimeout(()=>{this._flushTimer=null,this._pushBuffer()},this._flushDelay),this._flushTimer.unref&&this._flushTimer.unref()}_clearFlushTimer(){this._flushTimer!==null&&(clearTimeout(this._flushTimer),this._flushTimer=null)}_destroy(e,r){this._clearFlushTimer(),super._destroy(e,r)}import(e){return e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this._pushBuffer(),this.emit("error",r)}),e.on("prefix",(r,i)=>{this._writer.addPrefix(r,i)}),this}};var Wb={Lexer:We,Parser:me,Writer:oe,Store:$e,StoreFactory:Xt,EntityIndex:Zt,StreamParser:er,StreamWriter:tr,Util:ii,Reasoner:Jt,BaseIRI:Ge,DataFactory:z,Term:H,NamedNode:ct,Literal:ge,BlankNode:Ft,Variable:Bt,DefaultGraph:Ct,Quad:Fe,Triple:Fe,termFromId:Le,termToId:we};export{Ge as BaseIRI,Ft as BlankNode,z as DataFactory,Ct as DefaultGraph,Zt as EntityIndex,We as Lexer,ge as Literal,ct as NamedNode,me as Parser,Fe as Quad,Jt as Reasoner,$e as Store,Xt as StoreFactory,er as StreamParser,tr as StreamWriter,H as Term,Fe as Triple,ii as Util,Bt as Variable,oe as Writer,Wb as default,Sl as getRulesFromDataset,Le as termFromId,we as termToId};
23
+ `),this._subject=null),this._write=this._blockedWrite;let r=e&&((i,n)=>{r=null,e(i,n)});if(this._endStream)try{return this._outputStream.end(r)}catch(i){}r&&r()}};function us(t){let e=Fu[t];return e===void 0&&(t.length===1?(e=t.charCodeAt(0).toString(16),e="\\u0000".substr(0,6-e.length)+e):(e=((t.charCodeAt(0)-55296)*1024+t.charCodeAt(1)+9216).toString(16),e="\\U00000000".substr(0,10-e.length)+e)),e}var En=ir(Wr());var xn=Symbol("iter"),j=Symbol("size");function lp(t,e,r,i){let n=t&&t[e],s=n&&n[r];return!!s&&i in s}function Pt(t,e,r=4){let i=t[j]||0;for(let n in e)n in t?r!==0&&(t[n]=Pt(t[n],e[n],r-1)):(i++,t[n]=r===0?null:Pt(Object.create(null),e[n],r-1));return r<=2&&(t[j]=i),t}function ml(t,e,r=4){let i=!1,n=0;r<=2&&e[j]<t[j]&&([t,e]=[e,t]);for(let s in t)if(s in e){let o=r===0?null:ml(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}function xl(t,e,r=4){let i=!1,n=0;for(let s in t)if(!(s in e))i=i||Object.create(null),i[s]=r===0?null:Pt({},t[s],r-1),n++;else if(r!==0){let o=xl(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}var Zt=class{constructor(e={}){this._id=1,this._ids=Object.create(null),this._ids[""]=1,this._entities=Object.create(null),this._entities[1]="",this._blankNodeIndex=0,this._factory=e.factory||z}_termFromId(e){if(e[0]==="."){let r=this._entities,i=e.split(".");return this._factory.quad(this._termFromId(r[i[1]]),this._termFromId(r[i[2]]),this._termFromId(r[i[3]]),i[4]&&this._termFromId(r[i[4]]))}return Le(e,this._factory)}_termToNumericId(e){if(e.termType==="Quad"){let r=this._termToNumericId(e.subject),i=this._termToNumericId(e.predicate),n=this._termToNumericId(e.object),s;return r&&i&&n&&(xe(e.graph)||(s=this._termToNumericId(e.graph)))&&this._ids[s?`.${r}.${i}.${n}.${s}`:`.${r}.${i}.${n}`]}return this._ids[we(e)]}_termToNewNumericId(e){let r=e&&e.termType==="Quad"?`.${this._termToNewNumericId(e.subject)}.${this._termToNewNumericId(e.predicate)}.${this._termToNewNumericId(e.object)}${xe(e.graph)?"":`.${this._termToNewNumericId(e.graph)}`}`:we(e);return this._ids[r]||(this._ids[this._entities[++this._id]=r]=this._id)}createBlankNode(e){let r,i;if(e)for(r=e=`_:${e}`,i=1;this._ids[r];)r=e+i++;else do r=`_:b${this._blankNodeIndex++}`;while(this._ids[r]);return this._ids[r]=++this._id,this._entities[this._id]=r,this._factory.blankNode(r.substr(2))}},$e=class t{constructor(e,r){this._size=0,this._graphs=Object.create(null),!r&&e&&!e[0]&&typeof e.match!="function"&&(r=e,e=null),r=r||{},this._factory=r.factory||z,this._entityIndex=r.entityIndex||new Zt({factory:this._factory}),this._entities=this._entityIndex._entities,this._termFromId=this._entityIndex._termFromId.bind(this._entityIndex),this._termToNumericId=this._entityIndex._termToNumericId.bind(this._entityIndex),this._termToNewNumericId=this._entityIndex._termToNewNumericId.bind(this._entityIndex),e&&this.addAll(e)}get size(){let e=this._size;if(e!==null)return e;e=0;let r=this._graphs,i,n;for(let s in r)for(let o in i=r[s].subjects)for(let a in n=i[o])e+=n[a][j];return this._size=e}_addToIndex(e,r,i,n){let s=e[r];s||(e[r]=s={[j]:0},e[j]++);let o=s[i];o||(s[i]=o={[j]:0},s[j]++);let a=n in o;return a||(o[n]=null,o[j]++),!a}_removeFromIndex(e,r,i,n){let s=e[r],o=s[i];delete o[n],--o[j]===0&&(delete s[i],--s[j]===0&&(delete e[r],e[j]--))}*_findInIndex(e,r,i,n,s,o,a,l){let u=this._entities,c=this._termFromId(u[l]),f={subject:null,predicate:null,object:null};if(n){let d=e[r],_=d&&d[i];if(!_||!(n in _))return;f[s]=this._termFromId(u[r]),f[o]=this._termFromId(u[i]),f[a]=this._termFromId(u[n]),yield this._factory.quad(f.subject,f.predicate,f.object,c);return}if(r&&!(r in e))return;let p=r?null:Object.keys(e);for(let d=0,_=r||p[0];_;_=p&&p[++d]){let b=e[_];if(!b)continue;if(f[s]=this._termFromId(u[_]),i&&!(i in b))return;let y=i?null:Object.keys(b);for(let m=0,I=i||y[0];I;I=y&&y[++m]){let R=b[I];if(!R)continue;f[o]=this._termFromId(u[I]);let g=Object.keys(R);for(let E=0;E<g.length;E++)f[a]=this._termFromId(u[g[E]]),yield this._factory.quad(f.subject,f.predicate,f.object,c)}}}_loop(e,r){for(let i in e)r(i)}_loopByKey0(e,r,i){let n,s;if(n=e[r])for(s in n)i(s)}_loopByKey1(e,r,i){let n,s;for(n in e)s=e[n],s[r]&&i(n)}_loopBy2Keys(e,r,i,n){let s,o,a;if((s=e[r])&&(o=s[i]))for(a in o)n(a)}_loopByKey0Deep(e,r,i){let n,s,o,a;if(n=e[r])for(o in n){s=n[o];for(a in s)i(a)}}_countInIndex(e,r,i,n){let s=0,o,a;if(r){if(!(o=e[r]))return 0;if(i)return(a=o[i])?n?n in a?1:0:a[j]:0;for(let l in o)s+=o[l][j];return s}for(let l in e){o=e[l];for(let u in o)s+=o[u][j]}return s}_getGraphs(e){return e=e===""?1:e&&(this._termToNumericId(e)||-1),typeof e!="number"?this._graphs:{[e]:this._graphs[e]}}_uniqueEntities(e){let r=Object.create(null);return i=>{i in r||(r[i]=!0,e(this._termFromId(this._entities[i],this._factory)))}}add(e){return this.addQuad(e),this}addQuad(e,r,i,n){r||(n=e.graph,i=e.object,r=e.predicate,e=e.subject),n=n?this._termToNewNumericId(n):1;let s=this._graphs[n];return s||(s=this._graphs[n]={subjects:{[j]:0},predicates:{[j]:0},objects:{[j]:0}},Object.freeze(s)),e=this._termToNewNumericId(e),r=this._termToNewNumericId(r),i=this._termToNewNumericId(i),this._addToIndex(s.subjects,e,r,i)?(this._addToIndex(s.predicates,r,i,e),this._addToIndex(s.objects,i,e,r),this._size=null,!0):!1}addQuads(e){for(let r=0;r<e.length;r++)this.addQuad(e[r])}delete(e){return this.removeQuad(e),this}has(e,r,i,n){if(e&&e.subject&&({subject:e,predicate:r,object:i,graph:n}=e),e&&r&&i&&n!==void 0&&n!==null){let s=this._termToNumericId(e),o=this._termToNumericId(r),a=this._termToNumericId(i),l=n===""||xe(n)?1:this._termToNumericId(n),u=l&&this._graphs[l];return!!s&&!!o&&!!a&&!!u&&lp(u.subjects,s,o,a)}return!this.readQuads(e,r,i,n).next().done}import(e){return e.on("data",r=>{this.addQuad(r)}),e}removeQuad(e,r,i,n){r||({subject:e,predicate:r,object:i,graph:n}=e),n=n?this._termToNumericId(n):1;let s=this._graphs,o,a,l;return!(e=e&&this._termToNumericId(e))||!(r=r&&this._termToNumericId(r))||!(i=i&&this._termToNumericId(i))||!(o=s[n])||!(a=o.subjects[e])||!(l=a[r])||!(i in l)?!1:(this._removeFromIndex(o.subjects,e,r,i),this._removeFromIndex(o.predicates,r,i,e),this._removeFromIndex(o.objects,i,e,r),this._size!==null&&this._size--,o.subjects[j]===0&&delete s[n],!0)}removeQuads(e){for(let r=0;r<e.length;r++)this.removeQuad(e[r])}remove(e){return e.on("data",r=>{this.removeQuad(r)}),e}removeMatches(e,r,i,n){let s=new En.Readable({objectMode:!0}),o=this.readQuads(e,r,i,n);return s._read=a=>{for(;--a>=0;){let{done:l,value:u}=o.next();if(l){s.push(null);return}s.push(u)}},this.remove(s)}deleteGraph(e){return this.removeMatches(null,null,null,e)}getQuads(e,r,i,n){return[...this.readQuads(e,r,i,n)]}*readQuads(e,r,i,n){let s=this._getGraphs(n),o,a,l,u;if(!(e&&!(a=this._termToNumericId(e))||r&&!(l=this._termToNumericId(r))||i&&!(u=this._termToNumericId(i))))for(let c in s)(o=s[c])&&(a?u?yield*re(this._findInIndex(o.objects,u,a,l,"object","subject","predicate",c)):yield*re(this._findInIndex(o.subjects,a,l,null,"subject","predicate","object",c)):l?yield*re(this._findInIndex(o.predicates,l,u,null,"predicate","object","subject",c)):u?yield*re(this._findInIndex(o.objects,u,null,null,"object","subject","predicate",c)):yield*re(this._findInIndex(o.subjects,null,null,null,"subject","predicate","object",c)))}match(e,r,i,n){return new Me(this,e,r,i,n,{entityIndex:this._entityIndex})}countQuads(e,r,i,n){let s=this._getGraphs(n),o=0,a,l,u,c;if(e&&!(l=this._termToNumericId(e))||r&&!(u=this._termToNumericId(r))||i&&!(c=this._termToNumericId(i)))return 0;for(let f in s)(a=s[f])&&(e?i?o+=this._countInIndex(a.objects,c,l,u):o+=this._countInIndex(a.subjects,l,u,c):r?o+=this._countInIndex(a.predicates,u,c,l):o+=this._countInIndex(a.objects,c,l,u));return o}forEach(e,r,i,n,s){this.some(o=>(e(o,this),!1),r,i,n,s)}every(e,r,i,n,s){return!this.some(o=>!e(o,this),r,i,n,s)}some(e,r,i,n,s){for(let o of this.readQuads(r,i,n,s))if(e(o,this))return!0;return!1}getSubjects(e,r,i){let n=[];return this.forSubjects(s=>{n.push(s)},e,r,i),n}forSubjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.predicates,a,l,e):this._loopByKey1(o.subjects,a,e):l?this._loopByKey0(o.objects,l,e):this._loop(o.subjects,e))}getPredicates(e,r,i){let n=[];return this.forPredicates(s=>{n.push(s)},e,r,i),n}forPredicates(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.objects,l,a,e):this._loopByKey0(o.subjects,a,e):l?this._loopByKey1(o.predicates,l,e):this._loop(o.predicates,e))}getObjects(e,r,i){let n=[];return this.forObjects(s=>{n.push(s)},e,r,i),n}forObjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.subjects,a,l,e):this._loopByKey0Deep(o.subjects,a,e):l?this._loopByKey0(o.predicates,l,e):this._loop(o.objects,e))}getGraphs(e,r,i){let n=[];return this.forGraphs(s=>{n.push(s)},e,r,i),n}forGraphs(e,r,i,n){for(let s in this._graphs)this.some(o=>(e(o.graph),!0),r,i,n,this._termFromId(this._entities[s]))}createBlankNode(e){return this._entityIndex.createBlankNode(e)}extractLists({remove:e=!1,ignoreErrors:r=!1}={}){let i=Object.create(null),n=r?(()=>!0):((a,l)=>{throw new Error(`${a.value} ${l}`)}),s=this.getQuads(null,A.rdf.rest,A.rdf.nil,null),o=e?[...s]:[];return s.forEach(a=>{let l=[],u=!1,c,f,p=a.graph,d=a.subject;for(;d&&!u;){let _=this.getQuads(null,null,d,null),b=this.getQuads(d,null,null,null),y,m=null,I=null,R=null;for(let g=0;g<b.length&&!u;g++)y=b[g],y.graph.equals(p)?c?u=n(d,"has non-list arcs out"):y.predicate.value===A.rdf.first?m?u=n(d,"has multiple rdf:first arcs"):o.push(m=y):y.predicate.value===A.rdf.rest?I?u=n(d,"has multiple rdf:rest arcs"):o.push(I=y):_.length?u=n(d,"can't be subject and object"):(c=y,f="subject"):u=n(d,"not confined to single graph");for(let g=0;g<_.length&&!u;++g)y=_[g],c?u=n(d,"can't have coreferences"):y.predicate.value===A.rdf.rest?R?u=n(d,"has incoming rdf:rest arcs"):R=y:(c=y,f="object");m?l.unshift(m.object):u=n(d,"has no list head"),d=R&&R.subject}u?e=!1:c&&(i[c[f].value]=l)}),e&&this.removeQuads(o),i}addAll(e){if(e instanceof Me&&(e=e.filtered),Array.isArray(e))this.addQuads(e);else if(e instanceof t&&e._entityIndex===this._entityIndex)e._size!==0&&(this._graphs=Pt(this._graphs,e._graphs),this._size=null);else for(let r of e)this.add(r);return this}contains(e){if(e instanceof Me&&(e=e.filtered),e===this)return!0;if(!(e instanceof t)||this._entityIndex!==e._entityIndex)return e.every(u=>this.has(u));let r=this._graphs,i=e._graphs,n,s,o,a,l;for(let u in i){if(!(n=r[u]))return!1;n=n.subjects;for(let c in s=i[u].subjects){if(!(o=n[c]))return!1;for(let f in a=s[c]){if(!(l=o[f]))return!1;for(let p in a[f])if(!(p in l))return!1}}}return!0}deleteMatches(e,r,i,n){for(let s of this.match(e,r,i,n))this.removeQuad(s);return this}difference(e){if(e&&e instanceof Me&&(e=e.filtered),e===this)return new t({entityIndex:this._entityIndex});if(e instanceof t&&e._entityIndex===this._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=xl(this._graphs,e._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>!e.has(r))}equals(e){return e instanceof Me&&(e=e.filtered),e===this||this.size===e.size&&this.contains(e)}filter(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)e(i,this)&&r.add(i);return r}intersection(e){if(e instanceof Me&&(e=e.filtered),e===this){let r=new t({entityIndex:this._entityIndex});return r._graphs=Pt(Object.create(null),this._graphs),r._size=this._size,r}else if(e instanceof t&&this._entityIndex===e._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=ml(e._graphs,this._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>e.has(r))}map(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)r.add(e(i,this));return r}reduce(e,r){let i=this.readQuads(),n=r===void 0?i.next().value:r;for(let s of i)n=e(n,s,this);return n}toArray(){return this.getQuads()}toCanonical(){throw new Error("not implemented")}toStream(){return this.match()}toString(){return new oe().quadsToString(this)}union(e){let r=new t({entityIndex:this._entityIndex});return r._graphs=Pt(Object.create(null),this._graphs),r._size=this._size,r.addAll(e),r}[Symbol.iterator](){return this.readQuads()}};function pe(t,e,r=0){let i=e[r];if(i&&!(i in t))return!1;let n=!1,s=0;for(let o in i?{[i]:t[i]}:t){let a=r===2?null:pe(t[o],e,r+1);a!==!1&&(n=n||Object.create(null),n[o]=a,s++)}return n&&(n[j]=s),n}var Me=class t extends En.Readable{constructor(e,r,i,n,s,o){super({objectMode:!0}),Object.assign(this,{n3Store:e,subject:r,predicate:i,object:n,graph:s,options:o})}get filtered(){if(!this._filtered){let{n3Store:e,graph:r,object:i,predicate:n,subject:s}=this,o=this._filtered=new $e({factory:e._factory,entityIndex:this.options.entityIndex}),a,l,u;if(s&&!(a=o._termToNumericId(s))||n&&!(l=o._termToNumericId(n))||i&&!(u=o._termToNumericId(i)))return o;let c=e._getGraphs(r);for(let f in c){let p,d,_,b;(b=c[f])&&(!a&&l?(d=pe(b.predicates,[l,u,a]))&&(p=pe(b.subjects,[a,l,u]),_=pe(b.objects,[u,a,l])):u?(_=pe(b.objects,[u,a,l]))&&(p=pe(b.subjects,[a,l,u]),d=pe(b.predicates,[l,u,a])):(p=pe(b.subjects,[a,l,u]))&&(d=pe(b.predicates,[l,u,a]),_=pe(b.objects,[u,a,l])),p&&(o._graphs[f]={subjects:p,predicates:d,objects:_}))}o._size=null}return this._filtered}get size(){return this.filtered.size}_read(e){e>0&&!this[xn]&&(this[xn]=this[Symbol.iterator]());let r=this[xn];for(;--e>=0;){let{done:i,value:n}=r.next();if(i){this.push(null);return}this.push(n)}}addAll(e){return this.filtered.addAll(e)}contains(e){return this.filtered.contains(e)}deleteMatches(e,r,i,n){return this.filtered.deleteMatches(e,r,i,n)}difference(e){return this.filtered.difference(e)}equals(e){return this.filtered.equals(e)}every(e,r,i,n,s){return this.filtered.every(e,r,i,n,s)}filter(e){return this.filtered.filter(e)}forEach(e,r,i,n,s){return this.filtered.forEach(e,r,i,n,s)}import(e){return this.filtered.import(e)}intersection(e){return this.filtered.intersection(e)}map(e){return this.filtered.map(e)}some(e,r,i,n,s){return this.filtered.some(e,r,i,n,s)}toCanonical(){return this.filtered.toCanonical()}toStream(){return this._filtered?this._filtered.toStream():this.n3Store.match(this.subject,this.predicate,this.object,this.graph)}union(e){return this._filtered?this._filtered.union(e):this.n3Store.match(this.subject,this.predicate,this.object,this.graph).addAll(e)}toArray(){return this._filtered?this._filtered.toArray():this.n3Store.getQuads(this.subject,this.predicate,this.object,this.graph)}reduce(e,r){return this.filtered.reduce(e,r)}toString(){return new oe().quadsToString(this)}add(e){return this.filtered.add(e)}delete(e){return this.filtered.delete(e)}has(e){return this.filtered.has(e)}match(e,r,i,n){return new t(this.filtered,e,r,i,n,this.options)}[Symbol.iterator](){return this._filtered?this._filtered[Symbol.iterator]():this.n3Store.readQuads(this.subject,this.predicate,this.object,this.graph)}};var Xt=class{dataset(e){return new $e(e)}};function Sl(t){let e=[];for(let{subject:r,object:i}of t.match(null,z.namedNode("http://www.w3.org/2000/10/swap/log#implies"),null,z.defaultGraph())){let n=[...t.match(null,null,null,r)],s=[...t.match(null,null,null,i)];e.push({premise:n,conclusion:s})}return e}var Jt=class{constructor(e,r={}){this._store=e,this._maxDerivations=r.maxDerivations===void 0?1/0:r.maxDerivations,this._maxPremiseDepth=r.maxPremiseDepth===void 0?1/0:r.maxPremiseDepth}_add(e,r,i,n,s,o){if(this._store._addToIndex(n.subjects,e,r,i)){if(this._store._addToIndex(n.predicates,r,i,e),this._store._addToIndex(n.objects,i,e,r),++this._derivations>this._maxDerivations)throw new Error(`Reasoning exceeded the maximum of ${this._maxDerivations} derivations`);o(s)}}_emit(e,r,i){let n=e.conclusion;for(let s=0;s<n.length;s++){let o=n[s];this._add(o.subject.value,o.predicate.value,o.object.value,r,o,i)}}_evaluatePremise(e,r,i,n=0){let s,o,[a,l,u]=e.premise[n].value,c=r[e.premise[n].content],f=n===e.premise.length-1;if(!(s=a.value)){for(s in c)o=c[s],a.value=Number(s),this._evaluateLevel1(e,r,i,n,f,l,u,o);a.value=null}else(o=c[s])&&this._evaluateLevel1(e,r,i,n,f,l,u,o)}_evaluateLevel1(e,r,i,n,s,o,a,l){let u,c;if(!(u=o.value)){for(u in l)c=l[u],o.value=Number(u),this._evaluateLevel2(e,r,i,n,s,a,c);o.value=null}else(c=l[u])&&this._evaluateLevel2(e,r,i,n,s,a,c)}_evaluateLevel2(e,r,i,n,s,o,a){let l;if(!(l=o.value)){for(l in a)o.value=Number(l),s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1);o.value=null}else s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1)}_evaluateRules(e,r,i){for(let n=0;n<e.length;n++)this._evaluatePremise(e[n],r,i)}_reasonGraphNaive(e,r){let i=[];function n(a){a.next&&a.next.forEach(l=>{i.push([a.subject.value,a.predicate.value,a.object.value,l])})}let s=a=>{for(let l=0;l<a.length;l++){let u=a[l];this._add(u.subject.value,u.predicate.value,u.object.value,r,u,n)}};this._evaluateRules(e,r,n);let o;for(;(o=i.pop())!==void 0;){let[a,l,u,c]=o,f=c.basePremise.subject.value;f||(c.basePremise.subject.value=a);let p=c.basePremise.predicate.value;p||(c.basePremise.predicate.value=l);let d=c.basePremise.object.value;d||(c.basePremise.object.value=u),c.premise.length===0?s(c.conclusion):this._evaluatePremise(c,r,n),f||(c.basePremise.subject.value=null),p||(c.basePremise.predicate.value=null),d||(c.basePremise.object.value=null)}}_createRule({premise:e,conclusion:r}){let i={},n=o=>o.termType==="Variable"?i[o.value]=i[o.value]||{}:{value:this._store._termToNewNumericId(o)},s=o=>({subject:n(o.subject),predicate:n(o.predicate),object:n(o.object)});return{premise:e.map(o=>s(o)),conclusion:r.map(o=>s(o)),variables:Object.values(i)}}reason(e){this._derivations=0,Array.isArray(e)||(e=Sl(e)),e=e.map(i=>this._createRule(i));for(let i of e)if(i.premise.length>this._maxPremiseDepth)throw new Error(`Reasoning rule exceeds the maximum premise depth of ${this._maxPremiseDepth}`);for(let i of e)for(let n of e)for(let s=0;s<n.premise.length;s++){let o=n.premise[s];for(let a of i.conclusion){if(Sn(o.subject,a.subject)&&Sn(o.predicate,a.predicate)&&Sn(o.object,a.object)){let l=new Set,u=[];o.subject.value=o.subject.value||1,o.object.value=o.object.value||1,o.predicate.value=o.predicate.value||1;for(let c=0;c<n.premise.length;c++)c!==s&&u.push(El(n.premise[c],l));(a.next=a.next||[]).push({premise:u,conclusion:n.conclusion,basePremise:o})}for(let l=0;l<n.variables.length;l++)n.variables[l].value=null}}for(let i of e){let n=new Set;i.premise=i.premise.map(s=>El(s,n))}let r=this._store._getGraphs();try{for(let i in r)this._reasonGraphNaive(e,r[i])}finally{this._store._size=null}}};function El({subject:t,predicate:e,object:r},i){let n=t.value||i.has(t)||(i.add(t),!1),s=e.value||i.has(e)||(i.add(e),!1),o=r.value||i.has(r)||(i.add(r),!1);return!n&&s?{content:"predicates",value:[e,r,t]}:o?{content:"objects",value:[r,t,e]}:{content:"subjects",value:[t,e,r]}}function Sn(t,e){return t.value===null&&(t.value=e.value),t.value===e.value}var Il=ir(Wr());var er=class extends Il.Transform{constructor(e){super({decodeStrings:!0,readableObjectMode:!0});let r=new me(e),i,n,s={onQuad:(o,a)=>{o&&this.emit("error",o)||a&&this.push(a)},onPrefix:(o,a)=>{this.emit("prefix",o,a)}};e&&e.comments&&(s.onComment=o=>{this.emit("comment",o)}),r.parse({on:(o,a)=>{switch(o){case"data":i=a;break;case"end":n=a;break}}},s),this._transform=(o,a,l)=>{i(o),l()},this._flush=o=>{n(),o()}}import(e){return e.on("error",r=>{this.emit("error",r)}),typeof e.pipe=="function"?e.pipe(this):(e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()})),this}};var Rl=ir(Wr());var up=16*1024,fp=20,tr=class extends Rl.Transform{constructor(e){super({encoding:"utf8",writableObjectMode:!0}),this._buffer="",this._flushTimer=null,this._flushDelay=e&&e.flushDelay!==void 0?e.flushDelay:fp;let r=this._writer=new oe({write:(s,o,a)=>{this._buffer+=s,this._buffer.length>=up?this._pushBuffer():this._flushTimer===null&&this._armFlushTimer(),a&&a()},end:s=>{this._pushBuffer(),this.push(null),s&&s()}},e),i=null,n=s=>{let o=i;i=null,s&&this._pushBuffer(),o(s)};this._transform=(s,o,a)=>{i=a,r.addQuad(s,n)},this._flush=s=>{r.end(s)}}_pushBuffer(){this._clearFlushTimer(),this._buffer!==""&&(this.push(this._buffer),this._buffer="")}_armFlushTimer(){this._flushTimer=setTimeout(()=>{this._flushTimer=null,this._pushBuffer()},this._flushDelay),this._flushTimer.unref&&this._flushTimer.unref()}_clearFlushTimer(){this._flushTimer!==null&&(clearTimeout(this._flushTimer),this._flushTimer=null)}_destroy(e,r){this._clearFlushTimer(),super._destroy(e,r)}import(e){return e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this._pushBuffer(),this.emit("error",r)}),e.on("prefix",(r,i)=>{this._writer.addPrefix(r,i)}),this}};var Wb={Lexer:We,Parser:me,Writer:oe,Store:$e,StoreFactory:Xt,EntityIndex:Zt,StreamParser:er,StreamWriter:tr,Util:ii,Reasoner:Jt,BaseIRI:Ge,DataFactory:z,Term:H,NamedNode:ct,Literal:ge,BlankNode:Ft,Variable:Bt,DefaultGraph:Ct,Quad:Fe,Triple:Fe,termFromId:Le,termToId:we};export{Ge as BaseIRI,Ft as BlankNode,z as DataFactory,Ct as DefaultGraph,Zt as EntityIndex,We as Lexer,ge as Literal,ct as NamedNode,me as Parser,Fe as Quad,Jt as Reasoner,$e as Store,Xt as StoreFactory,er as StreamParser,tr as StreamWriter,H as Term,Fe as Triple,ii as Util,Bt as Variable,oe as Writer,Wb as default,Sl as getRulesFromDataset,Le as termFromId,we as termToId};
24
24
  /*! Bundled license information:
25
25
 
26
26
  ieee754/index.js:
package/browser/n3.min.js CHANGED
@@ -20,7 +20,7 @@ var N3=(()=>{var vl=Object.create;var $t=Object.defineProperty,Pl=Object.defineP
20
20
  ]`)}}list(e){let r=e&&e.length||0,i=new Array(r);for(let n=0;n<r;n++)i[n]=this._encodeObject(e[n]);return new Qe(`(${i.join(" ")})`)}end(e){this._subject!==null&&(this._write(this._inDefaultGraph?`.
21
21
  `:`
22
22
  }
23
- `),this._subject=null),this._write=this._blockedWrite;let r=e&&((i,n)=>{r=null,e(i,n)});if(this._endStream)try{return this._outputStream.end(r)}catch(i){}r&&r()}};function ds(t){let e=Bu[t];return e===void 0&&(t.length===1?(e=t.charCodeAt(0).toString(16),e="\\u0000".substr(0,6-e.length)+e):(e=((t.charCodeAt(0)-55296)*1024+t.charCodeAt(1)+9216).toString(16),e="\\U00000000".substr(0,10-e.length)+e)),e}var En=ir(Gr());var xn=Symbol("iter"),j=Symbol("size");function up(t,e,r,i){let n=t&&t[e],s=n&&n[r];return!!s&&i in s}function Ft(t,e,r=4){let i=t[j]||0;for(let n in e)n in t?r!==0&&(t[n]=Ft(t[n],e[n],r-1)):(i++,t[n]=r===0?null:Ft(Object.create(null),e[n],r-1));return r<=2&&(t[j]=i),t}function Sl(t,e,r=4){let i=!1,n=0;r<=2&&e[j]<t[j]&&([t,e]=[e,t]);for(let s in t)if(s in e){let o=r===0?null:Sl(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}function Il(t,e,r=4){let i=!1,n=0;for(let s in t)if(!(s in e))i=i||Object.create(null),i[s]=r===0?null:Ft({},t[s],r-1),n++;else if(r!==0){let o=Il(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}var Bt=class{constructor(e={}){this._id=1,this._ids=Object.create(null),this._ids[""]=1,this._entities=Object.create(null),this._entities[1]="",this._blankNodeIndex=0,this._factory=e.factory||W}_termFromId(e){if(e[0]==="."){let r=this._entities,i=e.split(".");return this._factory.quad(this._termFromId(r[i[1]]),this._termFromId(r[i[2]]),this._termFromId(r[i[3]]),i[4]&&this._termFromId(r[i[4]]))}return xe(e,this._factory)}_termToNumericId(e){if(e.termType==="Quad"){let r=this._termToNumericId(e.subject),i=this._termToNumericId(e.predicate),n=this._termToNumericId(e.object),s;return r&&i&&n&&(Se(e.graph)||(s=this._termToNumericId(e.graph)))&&this._ids[s?`.${r}.${i}.${n}.${s}`:`.${r}.${i}.${n}`]}return this._ids[le(e)]}_termToNewNumericId(e){let r=e&&e.termType==="Quad"?`.${this._termToNewNumericId(e.subject)}.${this._termToNewNumericId(e.predicate)}.${this._termToNewNumericId(e.object)}${Se(e.graph)?"":`.${this._termToNewNumericId(e.graph)}`}`:le(e);return this._ids[r]||(this._ids[this._entities[++this._id]=r]=this._id)}createBlankNode(e){let r,i;if(e)for(r=e=`_:${e}`,i=1;this._ids[r];)r=e+i++;else do r=`_:b${this._blankNodeIndex++}`;while(this._ids[r]);return this._ids[r]=++this._id,this._entities[this._id]=r,this._factory.blankNode(r.substr(2))}},Pe=class t{constructor(e,r){this._size=0,this._graphs=Object.create(null),!r&&e&&!e[0]&&typeof e.match!="function"&&(r=e,e=null),r=r||{},this._factory=r.factory||W,this._entityIndex=r.entityIndex||new Bt({factory:this._factory}),this._entities=this._entityIndex._entities,this._termFromId=this._entityIndex._termFromId.bind(this._entityIndex),this._termToNumericId=this._entityIndex._termToNumericId.bind(this._entityIndex),this._termToNewNumericId=this._entityIndex._termToNewNumericId.bind(this._entityIndex),e&&this.addAll(e)}get size(){let e=this._size;if(e!==null)return e;e=0;let r=this._graphs,i,n;for(let s in r)for(let o in i=r[s].subjects)for(let a in n=i[o])e+=n[a][j];return this._size=e}_addToIndex(e,r,i,n){let s=e[r];s||(e[r]=s={[j]:0},e[j]++);let o=s[i];o||(s[i]=o={[j]:0},s[j]++);let a=n in o;return a||(o[n]=null,o[j]++),!a}_removeFromIndex(e,r,i,n){let s=e[r],o=s[i];delete o[n],--o[j]===0&&(delete s[i],--s[j]===0&&(delete e[r],e[j]--))}*_findInIndex(e,r,i,n,s,o,a,l){let u=this._entities,c=this._termFromId(u[l]),f={subject:null,predicate:null,object:null};if(n){let d=e[r],_=d&&d[i];if(!_||!(n in _))return;f[s]=this._termFromId(u[r]),f[o]=this._termFromId(u[i]),f[a]=this._termFromId(u[n]),yield this._factory.quad(f.subject,f.predicate,f.object,c);return}if(r&&!(r in e))return;let p=r?null:Object.keys(e);for(let d=0,_=r||p[0];_;_=p&&p[++d]){let b=e[_];if(!b)continue;if(f[s]=this._termFromId(u[_]),i&&!(i in b))return;let y=i?null:Object.keys(b);for(let m=0,I=i||y[0];I;I=y&&y[++m]){let R=b[I];if(!R)continue;f[o]=this._termFromId(u[I]);let g=Object.keys(R);for(let E=0;E<g.length;E++)f[a]=this._termFromId(u[g[E]]),yield this._factory.quad(f.subject,f.predicate,f.object,c)}}}_loop(e,r){for(let i in e)r(i)}_loopByKey0(e,r,i){let n,s;if(n=e[r])for(s in n)i(s)}_loopByKey1(e,r,i){let n,s;for(n in e)s=e[n],s[r]&&i(n)}_loopBy2Keys(e,r,i,n){let s,o,a;if((s=e[r])&&(o=s[i]))for(a in o)n(a)}_loopByKey0Deep(e,r,i){let n,s,o,a;if(n=e[r])for(o in n){s=n[o];for(a in s)i(a)}}_countInIndex(e,r,i,n){let s=0,o,a;if(r){if(!(o=e[r]))return 0;if(i)return(a=o[i])?n?n in a?1:0:a[j]:0;for(let l in o)s+=o[l][j];return s}for(let l in e){o=e[l];for(let u in o)s+=o[u][j]}return s}_getGraphs(e){return e=e===""?1:e&&(this._termToNumericId(e)||-1),typeof e!="number"?this._graphs:{[e]:this._graphs[e]}}_uniqueEntities(e){let r=Object.create(null);return i=>{i in r||(r[i]=!0,e(this._termFromId(this._entities[i],this._factory)))}}add(e){return this.addQuad(e),this}addQuad(e,r,i,n){r||(n=e.graph,i=e.object,r=e.predicate,e=e.subject),n=n?this._termToNewNumericId(n):1;let s=this._graphs[n];return s||(s=this._graphs[n]={subjects:{[j]:0},predicates:{[j]:0},objects:{[j]:0}},Object.freeze(s)),e=this._termToNewNumericId(e),r=this._termToNewNumericId(r),i=this._termToNewNumericId(i),this._addToIndex(s.subjects,e,r,i)?(this._addToIndex(s.predicates,r,i,e),this._addToIndex(s.objects,i,e,r),this._size=null,!0):!1}addQuads(e){for(let r=0;r<e.length;r++)this.addQuad(e[r])}delete(e){return this.removeQuad(e),this}has(e,r,i,n){if(e&&e.subject&&({subject:e,predicate:r,object:i,graph:n}=e),e&&r&&i&&n!==void 0&&n!==null){let s=this._termToNumericId(e),o=this._termToNumericId(r),a=this._termToNumericId(i),l=n===""||Se(n)?1:this._termToNumericId(n),u=l&&this._graphs[l];return!!s&&!!o&&!!a&&!!u&&up(u.subjects,s,o,a)}return!this.readQuads(e,r,i,n).next().done}import(e){return e.on("data",r=>{this.addQuad(r)}),e}removeQuad(e,r,i,n){r||({subject:e,predicate:r,object:i,graph:n}=e),n=n?this._termToNumericId(n):1;let s=this._graphs,o,a,l;return!(e=e&&this._termToNumericId(e))||!(r=r&&this._termToNumericId(r))||!(i=i&&this._termToNumericId(i))||!(o=s[n])||!(a=o.subjects[e])||!(l=a[r])||!(i in l)?!1:(this._removeFromIndex(o.subjects,e,r,i),this._removeFromIndex(o.predicates,r,i,e),this._removeFromIndex(o.objects,i,e,r),this._size!==null&&this._size--,o.subjects[j]===0&&delete s[n],!0)}removeQuads(e){for(let r=0;r<e.length;r++)this.removeQuad(e[r])}remove(e){return e.on("data",r=>{this.removeQuad(r)}),e}removeMatches(e,r,i,n){let s=new En.Readable({objectMode:!0}),o=this.readQuads(e,r,i,n);return s._read=a=>{for(;--a>=0;){let{done:l,value:u}=o.next();if(l){s.push(null);return}s.push(u)}},this.remove(s)}deleteGraph(e){return this.removeMatches(null,null,null,e)}getQuads(e,r,i,n){return[...this.readQuads(e,r,i,n)]}*readQuads(e,r,i,n){let s=this._getGraphs(n),o,a,l,u;if(!(e&&!(a=this._termToNumericId(e))||r&&!(l=this._termToNumericId(r))||i&&!(u=this._termToNumericId(i))))for(let c in s)(o=s[c])&&(a?u?yield*ie(this._findInIndex(o.objects,u,a,l,"object","subject","predicate",c)):yield*ie(this._findInIndex(o.subjects,a,l,null,"subject","predicate","object",c)):l?yield*ie(this._findInIndex(o.predicates,l,u,null,"predicate","object","subject",c)):u?yield*ie(this._findInIndex(o.objects,u,null,null,"object","subject","predicate",c)):yield*ie(this._findInIndex(o.subjects,null,null,null,"subject","predicate","object",c)))}match(e,r,i,n){return new qe(this,e,r,i,n,{entityIndex:this._entityIndex})}countQuads(e,r,i,n){let s=this._getGraphs(n),o=0,a,l,u,c;if(e&&!(l=this._termToNumericId(e))||r&&!(u=this._termToNumericId(r))||i&&!(c=this._termToNumericId(i)))return 0;for(let f in s)(a=s[f])&&(e?i?o+=this._countInIndex(a.objects,c,l,u):o+=this._countInIndex(a.subjects,l,u,c):r?o+=this._countInIndex(a.predicates,u,c,l):o+=this._countInIndex(a.objects,c,l,u));return o}forEach(e,r,i,n,s){this.some(o=>(e(o,this),!1),r,i,n,s)}every(e,r,i,n,s){return!this.some(o=>!e(o,this),r,i,n,s)}some(e,r,i,n,s){for(let o of this.readQuads(r,i,n,s))if(e(o,this))return!0;return!1}getSubjects(e,r,i){let n=[];return this.forSubjects(s=>{n.push(s)},e,r,i),n}forSubjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.predicates,a,l,e):this._loopByKey1(o.subjects,a,e):l?this._loopByKey0(o.objects,l,e):this._loop(o.subjects,e))}getPredicates(e,r,i){let n=[];return this.forPredicates(s=>{n.push(s)},e,r,i),n}forPredicates(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.objects,l,a,e):this._loopByKey0(o.subjects,a,e):l?this._loopByKey1(o.predicates,l,e):this._loop(o.predicates,e))}getObjects(e,r,i){let n=[];return this.forObjects(s=>{n.push(s)},e,r,i),n}forObjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.subjects,a,l,e):this._loopByKey0Deep(o.subjects,a,e):l?this._loopByKey0(o.predicates,l,e):this._loop(o.objects,e))}getGraphs(e,r,i){let n=[];return this.forGraphs(s=>{n.push(s)},e,r,i),n}forGraphs(e,r,i,n){for(let s in this._graphs)this.some(o=>(e(o.graph),!0),r,i,n,this._termFromId(this._entities[s]))}createBlankNode(e){return this._entityIndex.createBlankNode(e)}extractLists({remove:e=!1,ignoreErrors:r=!1}={}){let i=Object.create(null),n=r?(()=>!0):((a,l)=>{throw new Error(`${a.value} ${l}`)}),s=this.getQuads(null,A.rdf.rest,A.rdf.nil,null),o=e?[...s]:[];return s.forEach(a=>{let l=[],u=!1,c,f,p=a.graph,d=a.subject;for(;d&&!u;){let _=this.getQuads(null,null,d,null),b=this.getQuads(d,null,null,null),y,m=null,I=null,R=null;for(let g=0;g<b.length&&!u;g++)y=b[g],y.graph.equals(p)?c?u=n(d,"has non-list arcs out"):y.predicate.value===A.rdf.first?m?u=n(d,"has multiple rdf:first arcs"):o.push(m=y):y.predicate.value===A.rdf.rest?I?u=n(d,"has multiple rdf:rest arcs"):o.push(I=y):_.length?u=n(d,"can't be subject and object"):(c=y,f="subject"):u=n(d,"not confined to single graph");for(let g=0;g<_.length&&!u;++g)y=_[g],c?u=n(d,"can't have coreferences"):y.predicate.value===A.rdf.rest?R?u=n(d,"has incoming rdf:rest arcs"):R=y:(c=y,f="object");m?l.unshift(m.object):u=n(d,"has no list head"),d=R&&R.subject}u?e=!1:c&&(i[c[f].value]=l)}),e&&this.removeQuads(o),i}addAll(e){if(e instanceof qe&&(e=e.filtered),Array.isArray(e))this.addQuads(e);else if(e instanceof t&&e._entityIndex===this._entityIndex)e._size!==0&&(this._graphs=Ft(this._graphs,e._graphs),this._size=null);else for(let r of e)this.add(r);return this}contains(e){if(e instanceof qe&&(e=e.filtered),e===this)return!0;if(!(e instanceof t)||this._entityIndex!==e._entityIndex)return e.every(u=>this.has(u));let r=this._graphs,i=e._graphs,n,s,o,a,l;for(let u in i){if(!(n=r[u]))return!1;n=n.subjects;for(let c in s=i[u].subjects){if(!(o=n[c]))return!1;for(let f in a=s[c]){if(!(l=o[f]))return!1;for(let p in a[f])if(!(p in l))return!1}}}return!0}deleteMatches(e,r,i,n){for(let s of this.match(e,r,i,n))this.removeQuad(s);return this}difference(e){if(e&&e instanceof qe&&(e=e.filtered),e===this)return new t({entityIndex:this._entityIndex});if(e instanceof t&&e._entityIndex===this._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=Il(this._graphs,e._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>!e.has(r))}equals(e){return e instanceof qe&&(e=e.filtered),e===this||this.size===e.size&&this.contains(e)}filter(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)e(i,this)&&r.add(i);return r}intersection(e){if(e instanceof qe&&(e=e.filtered),e===this){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ft(Object.create(null),this._graphs),r._size=this._size,r}else if(e instanceof t&&this._entityIndex===e._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=Sl(e._graphs,this._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>e.has(r))}map(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)r.add(e(i,this));return r}reduce(e,r){let i=this.readQuads(),n=r===void 0?i.next().value:r;for(let s of i)n=e(n,s,this);return n}toArray(){return this.getQuads()}toCanonical(){throw new Error("not implemented")}toStream(){return this.match()}toString(){return new ee().quadsToString(this)}union(e){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ft(Object.create(null),this._graphs),r._size=this._size,r.addAll(e),r}[Symbol.iterator](){return this.readQuads()}};function ge(t,e,r=0){let i=e[r];if(i&&!(i in t))return!1;let n=!1,s=0;for(let o in i?{[i]:t[i]}:t){let a=r===2?null:ge(t[o],e,r+1);a!==!1&&(n=n||Object.create(null),n[o]=a,s++)}return n&&(n[j]=s),n}var qe=class t extends En.Readable{constructor(e,r,i,n,s,o){super({objectMode:!0}),Object.assign(this,{n3Store:e,subject:r,predicate:i,object:n,graph:s,options:o})}get filtered(){if(!this._filtered){let{n3Store:e,graph:r,object:i,predicate:n,subject:s}=this,o=this._filtered=new Pe({factory:e._factory,entityIndex:this.options.entityIndex}),a,l,u;if(s&&!(a=o._termToNumericId(s))||n&&!(l=o._termToNumericId(n))||i&&!(u=o._termToNumericId(i)))return o;let c=e._getGraphs(r);for(let f in c){let p,d,_,b;(b=c[f])&&(!a&&l?(d=ge(b.predicates,[l,u,a]))&&(p=ge(b.subjects,[a,l,u]),_=ge(b.objects,[u,a,l])):u?(_=ge(b.objects,[u,a,l]))&&(p=ge(b.subjects,[a,l,u]),d=ge(b.predicates,[l,u,a])):(p=ge(b.subjects,[a,l,u]))&&(d=ge(b.predicates,[l,u,a]),_=ge(b.objects,[u,a,l])),p&&(o._graphs[f]={subjects:p,predicates:d,objects:_}))}o._size=null}return this._filtered}get size(){return this.filtered.size}_read(e){e>0&&!this[xn]&&(this[xn]=this[Symbol.iterator]());let r=this[xn];for(;--e>=0;){let{done:i,value:n}=r.next();if(i){this.push(null);return}this.push(n)}}addAll(e){return this.filtered.addAll(e)}contains(e){return this.filtered.contains(e)}deleteMatches(e,r,i,n){return this.filtered.deleteMatches(e,r,i,n)}difference(e){return this.filtered.difference(e)}equals(e){return this.filtered.equals(e)}every(e,r,i,n,s){return this.filtered.every(e,r,i,n,s)}filter(e){return this.filtered.filter(e)}forEach(e,r,i,n,s){return this.filtered.forEach(e,r,i,n,s)}import(e){return this.filtered.import(e)}intersection(e){return this.filtered.intersection(e)}map(e){return this.filtered.map(e)}some(e,r,i,n,s){return this.filtered.some(e,r,i,n,s)}toCanonical(){return this.filtered.toCanonical()}toStream(){return this._filtered?this._filtered.toStream():this.n3Store.match(this.subject,this.predicate,this.object,this.graph)}union(e){return this._filtered?this._filtered.union(e):this.n3Store.match(this.subject,this.predicate,this.object,this.graph).addAll(e)}toArray(){return this._filtered?this._filtered.toArray():this.n3Store.getQuads(this.subject,this.predicate,this.object,this.graph)}reduce(e,r){return this.filtered.reduce(e,r)}toString(){return new ee().quadsToString(this)}add(e){return this.filtered.add(e)}delete(e){return this.filtered.delete(e)}has(e){return this.filtered.has(e)}match(e,r,i,n){return new t(this.filtered,e,r,i,n,this.options)}[Symbol.iterator](){return this._filtered?this._filtered[Symbol.iterator]():this.n3Store.readQuads(this.subject,this.predicate,this.object,this.graph)}};var Ct=class{dataset(e){return new Pe(e)}};function In(t){let e=[];for(let{subject:r,object:i}of t.match(null,W.namedNode("http://www.w3.org/2000/10/swap/log#implies"),null,W.defaultGraph())){let n=[...t.match(null,null,null,r)],s=[...t.match(null,null,null,i)];e.push({premise:n,conclusion:s})}return e}var Dt=class{constructor(e,r={}){this._store=e,this._maxDerivations=r.maxDerivations===void 0?1/0:r.maxDerivations,this._maxPremiseDepth=r.maxPremiseDepth===void 0?1/0:r.maxPremiseDepth}_add(e,r,i,n,s,o){if(this._store._addToIndex(n.subjects,e,r,i)){if(this._store._addToIndex(n.predicates,r,i,e),this._store._addToIndex(n.objects,i,e,r),++this._derivations>this._maxDerivations)throw new Error(`Reasoning exceeded the maximum of ${this._maxDerivations} derivations`);o(s)}}_emit(e,r,i){let n=e.conclusion;for(let s=0;s<n.length;s++){let o=n[s];this._add(o.subject.value,o.predicate.value,o.object.value,r,o,i)}}_evaluatePremise(e,r,i,n=0){let s,o,[a,l,u]=e.premise[n].value,c=r[e.premise[n].content],f=n===e.premise.length-1;if(!(s=a.value)){for(s in c)o=c[s],a.value=Number(s),this._evaluateLevel1(e,r,i,n,f,l,u,o);a.value=null}else(o=c[s])&&this._evaluateLevel1(e,r,i,n,f,l,u,o)}_evaluateLevel1(e,r,i,n,s,o,a,l){let u,c;if(!(u=o.value)){for(u in l)c=l[u],o.value=Number(u),this._evaluateLevel2(e,r,i,n,s,a,c);o.value=null}else(c=l[u])&&this._evaluateLevel2(e,r,i,n,s,a,c)}_evaluateLevel2(e,r,i,n,s,o,a){let l;if(!(l=o.value)){for(l in a)o.value=Number(l),s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1);o.value=null}else s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1)}_evaluateRules(e,r,i){for(let n=0;n<e.length;n++)this._evaluatePremise(e[n],r,i)}_reasonGraphNaive(e,r){let i=[];function n(a){a.next&&a.next.forEach(l=>{i.push([a.subject.value,a.predicate.value,a.object.value,l])})}let s=a=>{for(let l=0;l<a.length;l++){let u=a[l];this._add(u.subject.value,u.predicate.value,u.object.value,r,u,n)}};this._evaluateRules(e,r,n);let o;for(;(o=i.pop())!==void 0;){let[a,l,u,c]=o,f=c.basePremise.subject.value;f||(c.basePremise.subject.value=a);let p=c.basePremise.predicate.value;p||(c.basePremise.predicate.value=l);let d=c.basePremise.object.value;d||(c.basePremise.object.value=u),c.premise.length===0?s(c.conclusion):this._evaluatePremise(c,r,n),f||(c.basePremise.subject.value=null),p||(c.basePremise.predicate.value=null),d||(c.basePremise.object.value=null)}}_createRule({premise:e,conclusion:r}){let i={},n=o=>o.termType==="Variable"?i[o.value]=i[o.value]||{}:{value:this._store._termToNewNumericId(o)},s=o=>({subject:n(o.subject),predicate:n(o.predicate),object:n(o.object)});return{premise:e.map(o=>s(o)),conclusion:r.map(o=>s(o)),variables:Object.values(i)}}reason(e){this._derivations=0,Array.isArray(e)||(e=In(e)),e=e.map(i=>this._createRule(i));for(let i of e)if(i.premise.length>this._maxPremiseDepth)throw new Error(`Reasoning rule exceeds the maximum premise depth of ${this._maxPremiseDepth}`);for(let i of e)for(let n of e)for(let s=0;s<n.premise.length;s++){let o=n.premise[s];for(let a of i.conclusion){if(Sn(o.subject,a.subject)&&Sn(o.predicate,a.predicate)&&Sn(o.object,a.object)){let l=new Set,u=[];o.subject.value=o.subject.value||1,o.object.value=o.object.value||1,o.predicate.value=o.predicate.value||1;for(let c=0;c<n.premise.length;c++)c!==s&&u.push(Rl(n.premise[c],l));(a.next=a.next||[]).push({premise:u,conclusion:n.conclusion,basePremise:o})}for(let l=0;l<n.variables.length;l++)n.variables[l].value=null}}for(let i of e){let n=new Set;i.premise=i.premise.map(s=>Rl(s,n))}let r=this._store._getGraphs();try{for(let i in r)this._reasonGraphNaive(e,r[i])}finally{this._store._size=null}}};function Rl({subject:t,predicate:e,object:r},i){let n=t.value||i.has(t)||(i.add(t),!1),s=e.value||i.has(e)||(i.add(e),!1),o=r.value||i.has(r)||(i.add(r),!1);return!n&&s?{content:"predicates",value:[e,r,t]}:o?{content:"objects",value:[r,t,e]}:{content:"subjects",value:[t,e,r]}}function Sn(t,e){return t.value===null&&(t.value=e.value),t.value===e.value}var Tl=ir(Gr());var Ot=class extends Tl.Transform{constructor(e){super({decodeStrings:!0}),this._readableState.objectMode=!0;let r=new ue(e),i,n,s={onQuad:(o,a)=>{o&&this.emit("error",o)||a&&this.push(a)},onPrefix:(o,a)=>{this.emit("prefix",o,a)}};e&&e.comments&&(s.onComment=o=>{this.emit("comment",o)}),r.parse({on:(o,a)=>{switch(o){case"data":i=a;break;case"end":n=a;break}}},s),this._transform=(o,a,l)=>{i(o),l()},this._flush=o=>{n(),o()}}import(e){return e.on("error",r=>{this.emit("error",r)}),typeof e.pipe=="function"?e.pipe(this):(e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()})),this}};var Al=ir(Gr());var fp=16*1024,cp=20,Mt=class extends Al.Transform{constructor(e){super({encoding:"utf8",writableObjectMode:!0}),this._buffer="",this._flushTimer=null,this._flushDelay=e&&e.flushDelay!==void 0?e.flushDelay:cp;let r=this._writer=new ee({write:(s,o,a)=>{this._buffer+=s,this._buffer.length>=fp?this._pushBuffer():this._flushTimer===null&&this._armFlushTimer(),a&&a()},end:s=>{this._pushBuffer(),this.push(null),s&&s()}},e),i=null,n=s=>{let o=i;i=null,s&&this._pushBuffer(),o(s)};this._transform=(s,o,a)=>{i=a,r.addQuad(s,n)},this._flush=s=>{r.end(s)}}_pushBuffer(){this._clearFlushTimer(),this._buffer!==""&&(this.push(this._buffer),this._buffer="")}_armFlushTimer(){this._flushTimer=setTimeout(()=>{this._flushTimer=null,this._pushBuffer()},this._flushDelay),this._flushTimer.unref&&this._flushTimer.unref()}_clearFlushTimer(){this._flushTimer!==null&&(clearTimeout(this._flushTimer),this._flushTimer=null)}_destroy(e,r){this._clearFlushTimer(),super._destroy(e,r)}import(e){return e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this._pushBuffer(),this.emit("error",r)}),e.on("prefix",(r,i)=>{this._writer.addPrefix(r,i)}),this}};var dp={Lexer:Be,Parser:ue,Writer:ee,Store:Pe,StoreFactory:Ct,EntityIndex:Bt,StreamParser:Ot,StreamWriter:Mt,Util:ur,Reasoner:Dt,BaseIRI:De,DataFactory:W,Term:U,NamedNode:Ve,Literal:ae,BlankNode:dt,Variable:ht,DefaultGraph:_t,Quad:Ee,Triple:Ee,termFromId:xe,termToId:le};return Ol(hp);})();
23
+ `),this._subject=null),this._write=this._blockedWrite;let r=e&&((i,n)=>{r=null,e(i,n)});if(this._endStream)try{return this._outputStream.end(r)}catch(i){}r&&r()}};function ds(t){let e=Bu[t];return e===void 0&&(t.length===1?(e=t.charCodeAt(0).toString(16),e="\\u0000".substr(0,6-e.length)+e):(e=((t.charCodeAt(0)-55296)*1024+t.charCodeAt(1)+9216).toString(16),e="\\U00000000".substr(0,10-e.length)+e)),e}var En=ir(Gr());var xn=Symbol("iter"),j=Symbol("size");function up(t,e,r,i){let n=t&&t[e],s=n&&n[r];return!!s&&i in s}function Ft(t,e,r=4){let i=t[j]||0;for(let n in e)n in t?r!==0&&(t[n]=Ft(t[n],e[n],r-1)):(i++,t[n]=r===0?null:Ft(Object.create(null),e[n],r-1));return r<=2&&(t[j]=i),t}function Sl(t,e,r=4){let i=!1,n=0;r<=2&&e[j]<t[j]&&([t,e]=[e,t]);for(let s in t)if(s in e){let o=r===0?null:Sl(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}function Il(t,e,r=4){let i=!1,n=0;for(let s in t)if(!(s in e))i=i||Object.create(null),i[s]=r===0?null:Ft({},t[s],r-1),n++;else if(r!==0){let o=Il(t[s],e[s],r-1);if(o!==!1)i=i||Object.create(null),i[s]=o,n++;else if(r===3)return!1}return r<=2&&i&&(i[j]=n),i}var Bt=class{constructor(e={}){this._id=1,this._ids=Object.create(null),this._ids[""]=1,this._entities=Object.create(null),this._entities[1]="",this._blankNodeIndex=0,this._factory=e.factory||W}_termFromId(e){if(e[0]==="."){let r=this._entities,i=e.split(".");return this._factory.quad(this._termFromId(r[i[1]]),this._termFromId(r[i[2]]),this._termFromId(r[i[3]]),i[4]&&this._termFromId(r[i[4]]))}return xe(e,this._factory)}_termToNumericId(e){if(e.termType==="Quad"){let r=this._termToNumericId(e.subject),i=this._termToNumericId(e.predicate),n=this._termToNumericId(e.object),s;return r&&i&&n&&(Se(e.graph)||(s=this._termToNumericId(e.graph)))&&this._ids[s?`.${r}.${i}.${n}.${s}`:`.${r}.${i}.${n}`]}return this._ids[le(e)]}_termToNewNumericId(e){let r=e&&e.termType==="Quad"?`.${this._termToNewNumericId(e.subject)}.${this._termToNewNumericId(e.predicate)}.${this._termToNewNumericId(e.object)}${Se(e.graph)?"":`.${this._termToNewNumericId(e.graph)}`}`:le(e);return this._ids[r]||(this._ids[this._entities[++this._id]=r]=this._id)}createBlankNode(e){let r,i;if(e)for(r=e=`_:${e}`,i=1;this._ids[r];)r=e+i++;else do r=`_:b${this._blankNodeIndex++}`;while(this._ids[r]);return this._ids[r]=++this._id,this._entities[this._id]=r,this._factory.blankNode(r.substr(2))}},Pe=class t{constructor(e,r){this._size=0,this._graphs=Object.create(null),!r&&e&&!e[0]&&typeof e.match!="function"&&(r=e,e=null),r=r||{},this._factory=r.factory||W,this._entityIndex=r.entityIndex||new Bt({factory:this._factory}),this._entities=this._entityIndex._entities,this._termFromId=this._entityIndex._termFromId.bind(this._entityIndex),this._termToNumericId=this._entityIndex._termToNumericId.bind(this._entityIndex),this._termToNewNumericId=this._entityIndex._termToNewNumericId.bind(this._entityIndex),e&&this.addAll(e)}get size(){let e=this._size;if(e!==null)return e;e=0;let r=this._graphs,i,n;for(let s in r)for(let o in i=r[s].subjects)for(let a in n=i[o])e+=n[a][j];return this._size=e}_addToIndex(e,r,i,n){let s=e[r];s||(e[r]=s={[j]:0},e[j]++);let o=s[i];o||(s[i]=o={[j]:0},s[j]++);let a=n in o;return a||(o[n]=null,o[j]++),!a}_removeFromIndex(e,r,i,n){let s=e[r],o=s[i];delete o[n],--o[j]===0&&(delete s[i],--s[j]===0&&(delete e[r],e[j]--))}*_findInIndex(e,r,i,n,s,o,a,l){let u=this._entities,c=this._termFromId(u[l]),f={subject:null,predicate:null,object:null};if(n){let d=e[r],_=d&&d[i];if(!_||!(n in _))return;f[s]=this._termFromId(u[r]),f[o]=this._termFromId(u[i]),f[a]=this._termFromId(u[n]),yield this._factory.quad(f.subject,f.predicate,f.object,c);return}if(r&&!(r in e))return;let p=r?null:Object.keys(e);for(let d=0,_=r||p[0];_;_=p&&p[++d]){let b=e[_];if(!b)continue;if(f[s]=this._termFromId(u[_]),i&&!(i in b))return;let y=i?null:Object.keys(b);for(let m=0,I=i||y[0];I;I=y&&y[++m]){let R=b[I];if(!R)continue;f[o]=this._termFromId(u[I]);let g=Object.keys(R);for(let E=0;E<g.length;E++)f[a]=this._termFromId(u[g[E]]),yield this._factory.quad(f.subject,f.predicate,f.object,c)}}}_loop(e,r){for(let i in e)r(i)}_loopByKey0(e,r,i){let n,s;if(n=e[r])for(s in n)i(s)}_loopByKey1(e,r,i){let n,s;for(n in e)s=e[n],s[r]&&i(n)}_loopBy2Keys(e,r,i,n){let s,o,a;if((s=e[r])&&(o=s[i]))for(a in o)n(a)}_loopByKey0Deep(e,r,i){let n,s,o,a;if(n=e[r])for(o in n){s=n[o];for(a in s)i(a)}}_countInIndex(e,r,i,n){let s=0,o,a;if(r){if(!(o=e[r]))return 0;if(i)return(a=o[i])?n?n in a?1:0:a[j]:0;for(let l in o)s+=o[l][j];return s}for(let l in e){o=e[l];for(let u in o)s+=o[u][j]}return s}_getGraphs(e){return e=e===""?1:e&&(this._termToNumericId(e)||-1),typeof e!="number"?this._graphs:{[e]:this._graphs[e]}}_uniqueEntities(e){let r=Object.create(null);return i=>{i in r||(r[i]=!0,e(this._termFromId(this._entities[i],this._factory)))}}add(e){return this.addQuad(e),this}addQuad(e,r,i,n){r||(n=e.graph,i=e.object,r=e.predicate,e=e.subject),n=n?this._termToNewNumericId(n):1;let s=this._graphs[n];return s||(s=this._graphs[n]={subjects:{[j]:0},predicates:{[j]:0},objects:{[j]:0}},Object.freeze(s)),e=this._termToNewNumericId(e),r=this._termToNewNumericId(r),i=this._termToNewNumericId(i),this._addToIndex(s.subjects,e,r,i)?(this._addToIndex(s.predicates,r,i,e),this._addToIndex(s.objects,i,e,r),this._size=null,!0):!1}addQuads(e){for(let r=0;r<e.length;r++)this.addQuad(e[r])}delete(e){return this.removeQuad(e),this}has(e,r,i,n){if(e&&e.subject&&({subject:e,predicate:r,object:i,graph:n}=e),e&&r&&i&&n!==void 0&&n!==null){let s=this._termToNumericId(e),o=this._termToNumericId(r),a=this._termToNumericId(i),l=n===""||Se(n)?1:this._termToNumericId(n),u=l&&this._graphs[l];return!!s&&!!o&&!!a&&!!u&&up(u.subjects,s,o,a)}return!this.readQuads(e,r,i,n).next().done}import(e){return e.on("data",r=>{this.addQuad(r)}),e}removeQuad(e,r,i,n){r||({subject:e,predicate:r,object:i,graph:n}=e),n=n?this._termToNumericId(n):1;let s=this._graphs,o,a,l;return!(e=e&&this._termToNumericId(e))||!(r=r&&this._termToNumericId(r))||!(i=i&&this._termToNumericId(i))||!(o=s[n])||!(a=o.subjects[e])||!(l=a[r])||!(i in l)?!1:(this._removeFromIndex(o.subjects,e,r,i),this._removeFromIndex(o.predicates,r,i,e),this._removeFromIndex(o.objects,i,e,r),this._size!==null&&this._size--,o.subjects[j]===0&&delete s[n],!0)}removeQuads(e){for(let r=0;r<e.length;r++)this.removeQuad(e[r])}remove(e){return e.on("data",r=>{this.removeQuad(r)}),e}removeMatches(e,r,i,n){let s=new En.Readable({objectMode:!0}),o=this.readQuads(e,r,i,n);return s._read=a=>{for(;--a>=0;){let{done:l,value:u}=o.next();if(l){s.push(null);return}s.push(u)}},this.remove(s)}deleteGraph(e){return this.removeMatches(null,null,null,e)}getQuads(e,r,i,n){return[...this.readQuads(e,r,i,n)]}*readQuads(e,r,i,n){let s=this._getGraphs(n),o,a,l,u;if(!(e&&!(a=this._termToNumericId(e))||r&&!(l=this._termToNumericId(r))||i&&!(u=this._termToNumericId(i))))for(let c in s)(o=s[c])&&(a?u?yield*ie(this._findInIndex(o.objects,u,a,l,"object","subject","predicate",c)):yield*ie(this._findInIndex(o.subjects,a,l,null,"subject","predicate","object",c)):l?yield*ie(this._findInIndex(o.predicates,l,u,null,"predicate","object","subject",c)):u?yield*ie(this._findInIndex(o.objects,u,null,null,"object","subject","predicate",c)):yield*ie(this._findInIndex(o.subjects,null,null,null,"subject","predicate","object",c)))}match(e,r,i,n){return new qe(this,e,r,i,n,{entityIndex:this._entityIndex})}countQuads(e,r,i,n){let s=this._getGraphs(n),o=0,a,l,u,c;if(e&&!(l=this._termToNumericId(e))||r&&!(u=this._termToNumericId(r))||i&&!(c=this._termToNumericId(i)))return 0;for(let f in s)(a=s[f])&&(e?i?o+=this._countInIndex(a.objects,c,l,u):o+=this._countInIndex(a.subjects,l,u,c):r?o+=this._countInIndex(a.predicates,u,c,l):o+=this._countInIndex(a.objects,c,l,u));return o}forEach(e,r,i,n,s){this.some(o=>(e(o,this),!1),r,i,n,s)}every(e,r,i,n,s){return!this.some(o=>!e(o,this),r,i,n,s)}some(e,r,i,n,s){for(let o of this.readQuads(r,i,n,s))if(e(o,this))return!0;return!1}getSubjects(e,r,i){let n=[];return this.forSubjects(s=>{n.push(s)},e,r,i),n}forSubjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.predicates,a,l,e):this._loopByKey1(o.subjects,a,e):l?this._loopByKey0(o.objects,l,e):this._loop(o.subjects,e))}getPredicates(e,r,i){let n=[];return this.forPredicates(s=>{n.push(s)},e,r,i),n}forPredicates(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.objects,l,a,e):this._loopByKey0(o.subjects,a,e):l?this._loopByKey1(o.predicates,l,e):this._loop(o.predicates,e))}getObjects(e,r,i){let n=[];return this.forObjects(s=>{n.push(s)},e,r,i),n}forObjects(e,r,i,n){let s=this._getGraphs(n),o,a,l;if(e=this._uniqueEntities(e),!(r&&!(a=this._termToNumericId(r))||i&&!(l=this._termToNumericId(i))))for(n in s)(o=s[n])&&(a?l?this._loopBy2Keys(o.subjects,a,l,e):this._loopByKey0Deep(o.subjects,a,e):l?this._loopByKey0(o.predicates,l,e):this._loop(o.objects,e))}getGraphs(e,r,i){let n=[];return this.forGraphs(s=>{n.push(s)},e,r,i),n}forGraphs(e,r,i,n){for(let s in this._graphs)this.some(o=>(e(o.graph),!0),r,i,n,this._termFromId(this._entities[s]))}createBlankNode(e){return this._entityIndex.createBlankNode(e)}extractLists({remove:e=!1,ignoreErrors:r=!1}={}){let i=Object.create(null),n=r?(()=>!0):((a,l)=>{throw new Error(`${a.value} ${l}`)}),s=this.getQuads(null,A.rdf.rest,A.rdf.nil,null),o=e?[...s]:[];return s.forEach(a=>{let l=[],u=!1,c,f,p=a.graph,d=a.subject;for(;d&&!u;){let _=this.getQuads(null,null,d,null),b=this.getQuads(d,null,null,null),y,m=null,I=null,R=null;for(let g=0;g<b.length&&!u;g++)y=b[g],y.graph.equals(p)?c?u=n(d,"has non-list arcs out"):y.predicate.value===A.rdf.first?m?u=n(d,"has multiple rdf:first arcs"):o.push(m=y):y.predicate.value===A.rdf.rest?I?u=n(d,"has multiple rdf:rest arcs"):o.push(I=y):_.length?u=n(d,"can't be subject and object"):(c=y,f="subject"):u=n(d,"not confined to single graph");for(let g=0;g<_.length&&!u;++g)y=_[g],c?u=n(d,"can't have coreferences"):y.predicate.value===A.rdf.rest?R?u=n(d,"has incoming rdf:rest arcs"):R=y:(c=y,f="object");m?l.unshift(m.object):u=n(d,"has no list head"),d=R&&R.subject}u?e=!1:c&&(i[c[f].value]=l)}),e&&this.removeQuads(o),i}addAll(e){if(e instanceof qe&&(e=e.filtered),Array.isArray(e))this.addQuads(e);else if(e instanceof t&&e._entityIndex===this._entityIndex)e._size!==0&&(this._graphs=Ft(this._graphs,e._graphs),this._size=null);else for(let r of e)this.add(r);return this}contains(e){if(e instanceof qe&&(e=e.filtered),e===this)return!0;if(!(e instanceof t)||this._entityIndex!==e._entityIndex)return e.every(u=>this.has(u));let r=this._graphs,i=e._graphs,n,s,o,a,l;for(let u in i){if(!(n=r[u]))return!1;n=n.subjects;for(let c in s=i[u].subjects){if(!(o=n[c]))return!1;for(let f in a=s[c]){if(!(l=o[f]))return!1;for(let p in a[f])if(!(p in l))return!1}}}return!0}deleteMatches(e,r,i,n){for(let s of this.match(e,r,i,n))this.removeQuad(s);return this}difference(e){if(e&&e instanceof qe&&(e=e.filtered),e===this)return new t({entityIndex:this._entityIndex});if(e instanceof t&&e._entityIndex===this._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=Il(this._graphs,e._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>!e.has(r))}equals(e){return e instanceof qe&&(e=e.filtered),e===this||this.size===e.size&&this.contains(e)}filter(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)e(i,this)&&r.add(i);return r}intersection(e){if(e instanceof qe&&(e=e.filtered),e===this){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ft(Object.create(null),this._graphs),r._size=this._size,r}else if(e instanceof t&&this._entityIndex===e._entityIndex){let r=new t({entityIndex:this._entityIndex}),i=Sl(e._graphs,this._graphs);return i&&(r._graphs=i,r._size=null),r}return this.filter(r=>e.has(r))}map(e){let r=new t({entityIndex:this._entityIndex});for(let i of this)r.add(e(i,this));return r}reduce(e,r){let i=this.readQuads(),n=r===void 0?i.next().value:r;for(let s of i)n=e(n,s,this);return n}toArray(){return this.getQuads()}toCanonical(){throw new Error("not implemented")}toStream(){return this.match()}toString(){return new ee().quadsToString(this)}union(e){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ft(Object.create(null),this._graphs),r._size=this._size,r.addAll(e),r}[Symbol.iterator](){return this.readQuads()}};function ge(t,e,r=0){let i=e[r];if(i&&!(i in t))return!1;let n=!1,s=0;for(let o in i?{[i]:t[i]}:t){let a=r===2?null:ge(t[o],e,r+1);a!==!1&&(n=n||Object.create(null),n[o]=a,s++)}return n&&(n[j]=s),n}var qe=class t extends En.Readable{constructor(e,r,i,n,s,o){super({objectMode:!0}),Object.assign(this,{n3Store:e,subject:r,predicate:i,object:n,graph:s,options:o})}get filtered(){if(!this._filtered){let{n3Store:e,graph:r,object:i,predicate:n,subject:s}=this,o=this._filtered=new Pe({factory:e._factory,entityIndex:this.options.entityIndex}),a,l,u;if(s&&!(a=o._termToNumericId(s))||n&&!(l=o._termToNumericId(n))||i&&!(u=o._termToNumericId(i)))return o;let c=e._getGraphs(r);for(let f in c){let p,d,_,b;(b=c[f])&&(!a&&l?(d=ge(b.predicates,[l,u,a]))&&(p=ge(b.subjects,[a,l,u]),_=ge(b.objects,[u,a,l])):u?(_=ge(b.objects,[u,a,l]))&&(p=ge(b.subjects,[a,l,u]),d=ge(b.predicates,[l,u,a])):(p=ge(b.subjects,[a,l,u]))&&(d=ge(b.predicates,[l,u,a]),_=ge(b.objects,[u,a,l])),p&&(o._graphs[f]={subjects:p,predicates:d,objects:_}))}o._size=null}return this._filtered}get size(){return this.filtered.size}_read(e){e>0&&!this[xn]&&(this[xn]=this[Symbol.iterator]());let r=this[xn];for(;--e>=0;){let{done:i,value:n}=r.next();if(i){this.push(null);return}this.push(n)}}addAll(e){return this.filtered.addAll(e)}contains(e){return this.filtered.contains(e)}deleteMatches(e,r,i,n){return this.filtered.deleteMatches(e,r,i,n)}difference(e){return this.filtered.difference(e)}equals(e){return this.filtered.equals(e)}every(e,r,i,n,s){return this.filtered.every(e,r,i,n,s)}filter(e){return this.filtered.filter(e)}forEach(e,r,i,n,s){return this.filtered.forEach(e,r,i,n,s)}import(e){return this.filtered.import(e)}intersection(e){return this.filtered.intersection(e)}map(e){return this.filtered.map(e)}some(e,r,i,n,s){return this.filtered.some(e,r,i,n,s)}toCanonical(){return this.filtered.toCanonical()}toStream(){return this._filtered?this._filtered.toStream():this.n3Store.match(this.subject,this.predicate,this.object,this.graph)}union(e){return this._filtered?this._filtered.union(e):this.n3Store.match(this.subject,this.predicate,this.object,this.graph).addAll(e)}toArray(){return this._filtered?this._filtered.toArray():this.n3Store.getQuads(this.subject,this.predicate,this.object,this.graph)}reduce(e,r){return this.filtered.reduce(e,r)}toString(){return new ee().quadsToString(this)}add(e){return this.filtered.add(e)}delete(e){return this.filtered.delete(e)}has(e){return this.filtered.has(e)}match(e,r,i,n){return new t(this.filtered,e,r,i,n,this.options)}[Symbol.iterator](){return this._filtered?this._filtered[Symbol.iterator]():this.n3Store.readQuads(this.subject,this.predicate,this.object,this.graph)}};var Ct=class{dataset(e){return new Pe(e)}};function In(t){let e=[];for(let{subject:r,object:i}of t.match(null,W.namedNode("http://www.w3.org/2000/10/swap/log#implies"),null,W.defaultGraph())){let n=[...t.match(null,null,null,r)],s=[...t.match(null,null,null,i)];e.push({premise:n,conclusion:s})}return e}var Dt=class{constructor(e,r={}){this._store=e,this._maxDerivations=r.maxDerivations===void 0?1/0:r.maxDerivations,this._maxPremiseDepth=r.maxPremiseDepth===void 0?1/0:r.maxPremiseDepth}_add(e,r,i,n,s,o){if(this._store._addToIndex(n.subjects,e,r,i)){if(this._store._addToIndex(n.predicates,r,i,e),this._store._addToIndex(n.objects,i,e,r),++this._derivations>this._maxDerivations)throw new Error(`Reasoning exceeded the maximum of ${this._maxDerivations} derivations`);o(s)}}_emit(e,r,i){let n=e.conclusion;for(let s=0;s<n.length;s++){let o=n[s];this._add(o.subject.value,o.predicate.value,o.object.value,r,o,i)}}_evaluatePremise(e,r,i,n=0){let s,o,[a,l,u]=e.premise[n].value,c=r[e.premise[n].content],f=n===e.premise.length-1;if(!(s=a.value)){for(s in c)o=c[s],a.value=Number(s),this._evaluateLevel1(e,r,i,n,f,l,u,o);a.value=null}else(o=c[s])&&this._evaluateLevel1(e,r,i,n,f,l,u,o)}_evaluateLevel1(e,r,i,n,s,o,a,l){let u,c;if(!(u=o.value)){for(u in l)c=l[u],o.value=Number(u),this._evaluateLevel2(e,r,i,n,s,a,c);o.value=null}else(c=l[u])&&this._evaluateLevel2(e,r,i,n,s,a,c)}_evaluateLevel2(e,r,i,n,s,o,a){let l;if(!(l=o.value)){for(l in a)o.value=Number(l),s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1);o.value=null}else s?this._emit(e,r,i):this._evaluatePremise(e,r,i,n+1)}_evaluateRules(e,r,i){for(let n=0;n<e.length;n++)this._evaluatePremise(e[n],r,i)}_reasonGraphNaive(e,r){let i=[];function n(a){a.next&&a.next.forEach(l=>{i.push([a.subject.value,a.predicate.value,a.object.value,l])})}let s=a=>{for(let l=0;l<a.length;l++){let u=a[l];this._add(u.subject.value,u.predicate.value,u.object.value,r,u,n)}};this._evaluateRules(e,r,n);let o;for(;(o=i.pop())!==void 0;){let[a,l,u,c]=o,f=c.basePremise.subject.value;f||(c.basePremise.subject.value=a);let p=c.basePremise.predicate.value;p||(c.basePremise.predicate.value=l);let d=c.basePremise.object.value;d||(c.basePremise.object.value=u),c.premise.length===0?s(c.conclusion):this._evaluatePremise(c,r,n),f||(c.basePremise.subject.value=null),p||(c.basePremise.predicate.value=null),d||(c.basePremise.object.value=null)}}_createRule({premise:e,conclusion:r}){let i={},n=o=>o.termType==="Variable"?i[o.value]=i[o.value]||{}:{value:this._store._termToNewNumericId(o)},s=o=>({subject:n(o.subject),predicate:n(o.predicate),object:n(o.object)});return{premise:e.map(o=>s(o)),conclusion:r.map(o=>s(o)),variables:Object.values(i)}}reason(e){this._derivations=0,Array.isArray(e)||(e=In(e)),e=e.map(i=>this._createRule(i));for(let i of e)if(i.premise.length>this._maxPremiseDepth)throw new Error(`Reasoning rule exceeds the maximum premise depth of ${this._maxPremiseDepth}`);for(let i of e)for(let n of e)for(let s=0;s<n.premise.length;s++){let o=n.premise[s];for(let a of i.conclusion){if(Sn(o.subject,a.subject)&&Sn(o.predicate,a.predicate)&&Sn(o.object,a.object)){let l=new Set,u=[];o.subject.value=o.subject.value||1,o.object.value=o.object.value||1,o.predicate.value=o.predicate.value||1;for(let c=0;c<n.premise.length;c++)c!==s&&u.push(Rl(n.premise[c],l));(a.next=a.next||[]).push({premise:u,conclusion:n.conclusion,basePremise:o})}for(let l=0;l<n.variables.length;l++)n.variables[l].value=null}}for(let i of e){let n=new Set;i.premise=i.premise.map(s=>Rl(s,n))}let r=this._store._getGraphs();try{for(let i in r)this._reasonGraphNaive(e,r[i])}finally{this._store._size=null}}};function Rl({subject:t,predicate:e,object:r},i){let n=t.value||i.has(t)||(i.add(t),!1),s=e.value||i.has(e)||(i.add(e),!1),o=r.value||i.has(r)||(i.add(r),!1);return!n&&s?{content:"predicates",value:[e,r,t]}:o?{content:"objects",value:[r,t,e]}:{content:"subjects",value:[t,e,r]}}function Sn(t,e){return t.value===null&&(t.value=e.value),t.value===e.value}var Tl=ir(Gr());var Ot=class extends Tl.Transform{constructor(e){super({decodeStrings:!0,readableObjectMode:!0});let r=new ue(e),i,n,s={onQuad:(o,a)=>{o&&this.emit("error",o)||a&&this.push(a)},onPrefix:(o,a)=>{this.emit("prefix",o,a)}};e&&e.comments&&(s.onComment=o=>{this.emit("comment",o)}),r.parse({on:(o,a)=>{switch(o){case"data":i=a;break;case"end":n=a;break}}},s),this._transform=(o,a,l)=>{i(o),l()},this._flush=o=>{n(),o()}}import(e){return e.on("error",r=>{this.emit("error",r)}),typeof e.pipe=="function"?e.pipe(this):(e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()})),this}};var Al=ir(Gr());var fp=16*1024,cp=20,Mt=class extends Al.Transform{constructor(e){super({encoding:"utf8",writableObjectMode:!0}),this._buffer="",this._flushTimer=null,this._flushDelay=e&&e.flushDelay!==void 0?e.flushDelay:cp;let r=this._writer=new ee({write:(s,o,a)=>{this._buffer+=s,this._buffer.length>=fp?this._pushBuffer():this._flushTimer===null&&this._armFlushTimer(),a&&a()},end:s=>{this._pushBuffer(),this.push(null),s&&s()}},e),i=null,n=s=>{let o=i;i=null,s&&this._pushBuffer(),o(s)};this._transform=(s,o,a)=>{i=a,r.addQuad(s,n)},this._flush=s=>{r.end(s)}}_pushBuffer(){this._clearFlushTimer(),this._buffer!==""&&(this.push(this._buffer),this._buffer="")}_armFlushTimer(){this._flushTimer=setTimeout(()=>{this._flushTimer=null,this._pushBuffer()},this._flushDelay),this._flushTimer.unref&&this._flushTimer.unref()}_clearFlushTimer(){this._flushTimer!==null&&(clearTimeout(this._flushTimer),this._flushTimer=null)}_destroy(e,r){this._clearFlushTimer(),super._destroy(e,r)}import(e){return e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this._pushBuffer(),this.emit("error",r)}),e.on("prefix",(r,i)=>{this._writer.addPrefix(r,i)}),this}};var dp={Lexer:Be,Parser:ue,Writer:ee,Store:Pe,StoreFactory:Ct,EntityIndex:Bt,StreamParser:Ot,StreamWriter:Mt,Util:ur,Reasoner:Dt,BaseIRI:De,DataFactory:W,Term:U,NamedNode:Ve,Literal:ae,BlankNode:dt,Variable:ht,DefaultGraph:_t,Quad:Ee,Triple:Ee,termFromId:xe,termToId:le};return Ol(hp);})();
24
24
  /*! Bundled license information:
25
25
 
26
26
  ieee754/index.js:
@@ -13,9 +13,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
13
13
  class N3StreamParser extends _readableStream.Transform {
14
14
  constructor(options) {
15
15
  super({
16
- decodeStrings: true
16
+ decodeStrings: true,
17
+ readableObjectMode: true
17
18
  });
18
- this._readableState.objectMode = true;
19
19
 
20
20
  // Set up parser with dummy stream to obtain `data` and `end` callbacks
21
21
  const parser = new _N3Parser.default(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.7.6",
3
+ "version": "2.7.7",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -5,8 +5,7 @@ import N3Parser from './N3Parser';
5
5
  // ## Constructor
6
6
  export default class N3StreamParser extends Transform {
7
7
  constructor(options) {
8
- super({ decodeStrings: true });
9
- this._readableState.objectMode = true;
8
+ super({ decodeStrings: true, readableObjectMode: true });
10
9
 
11
10
  // Set up parser with dummy stream to obtain `data` and `end` callbacks
12
11
  const parser = new N3Parser(options);