n3 2.2.8 → 2.2.9
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.
- package/browser/n3.esm.min.js +1 -1
- package/browser/n3.min.js +1 -1
- package/lib/N3Reasoner.js +57 -41
- package/package.json +1 -1
- package/src/N3Reasoner.js +62 -33
package/browser/n3.esm.min.js
CHANGED
|
@@ -19,7 +19,7 @@ var bl=Object.create;var Or=Object.defineProperty;var gl=Object.getOwnPropertyDe
|
|
|
19
19
|
]`)}}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 De(`(${i.join(" ")})`)}end(e){this._subject!==null&&(this._write(this._inDefaultGraph?`.
|
|
20
20
|
`:`
|
|
21
21
|
}
|
|
22
|
-
`),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{}r&&r()}};function Xn(t){let e=yu[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 pn=zt(Fr());var hn=Symbol("iter");function Qp(t,e,r,i){let n=t&&t[e],s=n&&n[r];return!!s&&i in s}function Ut(t,e,r=4){if(r===0)return Object.assign(t,e);for(let i in e)t[i]=Ut(t[i]||Object.create(null),e[i],r-1);return t}function ul(t,e,r=4){let i=!1;for(let n in t)if(n in e){let s=r===0?null:ul(t[n],e[n],r-1);if(s!==!1)i=i||Object.create(null),i[n]=s;else if(r===3)return!1}return i}function fl(t,e,r=4){let i=!1;for(let n in t)if(!(n in e))i=i||Object.create(null),i[n]=r===0?null:Ut({},t[n],r-1);else if(r!==0){let s=fl(t[n],e[n],r-1);if(s!==!1)i=i||Object.create(null),i[n]=s;else if(r===3)return!1}return i}var Wt=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 Se(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&&(pe(e.graph)||(s=this._termToNumericId(e.graph)))&&this._ids[s?`.${r}.${i}.${n}.${s}`:`.${r}.${i}.${n}`]}return this._ids[de(e)]}_termToNewNumericId(e){let r=e&&e.termType==="Quad"?`.${this._termToNewNumericId(e.subject)}.${this._termToNewNumericId(e.predicate)}.${this._termToNewNumericId(e.object)}${pe(e.graph)?"":`.${this._termToNewNumericId(e.graph)}`}`:de(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))}},je=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 Wt({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+=Object.keys(n[a]).length;return this._size=e}_addToIndex(e,r,i,n){let s=e[r]||(e[r]={}),o=s[i]||(s[i]={}),a=n in o;return a||(o[n]=null),!a}_removeFromIndex(e,r,i,n){let s=e[r],o=s[i];delete o[n];for(let a in o)return;delete s[i];for(let a in s)return;delete e[r]}*_findInIndex(e,r,i,n,s,o,a,l){let u,f,c,_=this._entities,h=this._termFromId(_[l]),b={subject:null,predicate:null,object:null};r&&((u=e,e={})[r]=u[r]);for(let p in e)if(f=e[p]){b[s]=this._termFromId(_[p]),i&&((u=f,f={})[i]=u[i]);for(let y in f)if(c=f[y]){b[o]=this._termFromId(_[y]);let g=n?n in c?[n]:[]:Object.keys(c);for(let E=0;E<g.length;E++)b[a]=this._termFromId(_[g[E]]),yield this._factory.quad(b.subject,b.predicate,b.object,h)}}}_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,l;r&&((o=e,e={})[r]=o[r]);for(let u in e)if(a=e[u]){i&&((o=a,a={})[i]=o[i]);for(let f in a)(l=a[f])&&(n?n in l&&s++:s+=Object.keys(l).length)}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:{},predicates:{},objects:{}},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===""||pe(n)?1:this._termToNumericId(n),u=l&&this._graphs[l];return!!s&&!!o&&!!a&&!!u&&Qp(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;if(!(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))return!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--;for(e in o.subjects)return!0;return 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 pn.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 f in s)(o=s[f])&&(a?u?yield*this._findInIndex(o.objects,u,a,l,"object","subject","predicate",f):yield*this._findInIndex(o.subjects,a,l,null,"subject","predicate","object",f):l?yield*this._findInIndex(o.predicates,l,u,null,"predicate","object","subject",f):u?yield*this._findInIndex(o.objects,u,null,null,"object","subject","predicate",f):yield*this._findInIndex(o.subjects,null,null,null,"subject","predicate","object",f))}match(e,r,i,n){return new ve(this,e,r,i,n,{entityIndex:this._entityIndex})}countQuads(e,r,i,n){let s=this._getGraphs(n),o=0,a,l,u,f;if(e&&!(l=this._termToNumericId(e))||r&&!(u=this._termToNumericId(r))||i&&!(f=this._termToNumericId(i)))return 0;for(let c in s)(a=s[c])&&(e?i?o+=this._countInIndex(a.objects,f,l,u):o+=this._countInIndex(a.subjects,l,u,f):r?o+=this._countInIndex(a.predicates,u,f,l):o+=this._countInIndex(a.objects,f,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,R.rdf.rest,R.rdf.nil,null),o=e?[...s]:[];return s.forEach(a=>{let l=[],u=!1,f,c,_=a.graph,h=a.subject;for(;h&&!u;){let b=this.getQuads(null,null,h,null),p=this.getQuads(h,null,null,null),y,g=null,E=null,A=null;for(let w=0;w<p.length&&!u;w++)y=p[w],y.graph.equals(_)?f?u=n(h,"has non-list arcs out"):y.predicate.value===R.rdf.first?g?u=n(h,"has multiple rdf:first arcs"):o.push(g=y):y.predicate.value===R.rdf.rest?E?u=n(h,"has multiple rdf:rest arcs"):o.push(E=y):b.length?u=n(h,"can't be subject and object"):(f=y,c="subject"):u=n(h,"not confined to single graph");for(let w=0;w<b.length&&!u;++w)y=b[w],f?u=n(h,"can't have coreferences"):y.predicate.value===R.rdf.rest?A?u=n(h,"has incoming rdf:rest arcs"):A=y:(f=y,c="object");g?l.unshift(g.object):u=n(h,"has no list head"),h=A&&A.subject}u?e=!1:f&&(i[f[c].value]=l)}),e&&this.removeQuads(o),i}addAll(e){if(e instanceof ve&&(e=e.filtered),Array.isArray(e))this.addQuads(e);else if(e instanceof t&&e._entityIndex===this._entityIndex)e._size!==0&&(this._graphs=Ut(this._graphs,e._graphs),this._size=null);else for(let r of e)this.add(r);return this}contains(e){if(e instanceof ve&&(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 f in s=i[u].subjects){if(!(o=n[f]))return!1;for(let c in a=s[f]){if(!(l=o[c]))return!1;for(let _ in a[c])if(!(_ 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 ve&&(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=fl(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 ve&&(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 ve&&(e=e.filtered),e===this){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ut(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=ul(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 Z().quadsToString(this)}union(e){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ut(Object.create(null),this._graphs),r._size=this._size,r.addAll(e),r}*[Symbol.iterator](){yield*this.readQuads()}};function le(t,e,r=0){let i=e[r];if(i&&!(i in t))return!1;let n=!1;for(let s in i?{[i]:t[i]}:t){let o=r===2?null:le(t[s],e,r+1);o!==!1&&(n=n||Object.create(null),n[s]=o)}return n}var ve=class t extends pn.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 je({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 f=e._getGraphs(r);for(let c in f){let _,h,b,p;(p=f[c])&&(!a&&l?(h=le(p.predicates,[l,u,a]))&&(_=le(p.subjects,[a,l,u]),b=le(p.objects,[u,a,l])):u?(b=le(p.objects,[u,a,l]))&&(_=le(p.subjects,[a,l,u]),h=le(p.predicates,[l,u,a])):(_=le(p.subjects,[a,l,u]))&&(h=le(p.predicates,[l,u,a]),b=le(p.objects,[u,a,l])),_&&(o._graphs[c]={subjects:_,predicates:h,objects:b}))}o._size=null}return this._filtered}get size(){return this.filtered.size}_read(e){e>0&&!this[hn]&&(this[hn]=this[Symbol.iterator]());let r=this[hn];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 Z().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](){yield*this._filtered||this.n3Store.readQuads(this.subject,this.predicate,this.object,this.graph)}};var Gt=class{dataset(e){return new je(e)}};function dl(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 Vt=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){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`);s()}}_evaluatePremise(e,r,i,n=0){let s,o,a,l,u,[f,c,_]=e.premise[n].value,h=r[e.premise[n].content],b=!(a=f.value);for(a in b?h:{[a]:h[a]})if(l=h[a]){b&&(f.value=Number(a)),s=!(a=c.value);for(a in s?l:{[a]:l[a]})if(u=l[a]){s&&(c.value=Number(a)),o=!(a=_.value);for(a in o?u:{[a]:u[a]})o&&(_.value=Number(a)),n===e.premise.length-1?e.conclusion.forEach(p=>{this._add(p.subject.value,p.predicate.value,p.object.value,r,()=>{i(p)})}):this._evaluatePremise(e,r,i,n+1);o&&(_.value=null)}s&&(c.value=null)}b&&(f.value=null)}_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=>{a.forEach(l=>{this._add(l.subject.value,l.predicate.value,l.object.value,r,()=>{n(l)})})};this._evaluateRules(e,r,n);let o;for(;(o=i.pop())!==void 0;){let[a,l,u,f]=o,c=f.basePremise.subject.value;c||(f.basePremise.subject.value=a);let _=f.basePremise.predicate.value;_||(f.basePremise.predicate.value=l);let h=f.basePremise.object.value;h||(f.basePremise.object.value=u),f.premise.length===0?s(f.conclusion):this._evaluatePremise(f,r,n),c||(f.basePremise.subject.value=null),_||(f.basePremise.predicate.value=null),h||(f.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=dl(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(_n(o.subject,a.subject)&&_n(o.predicate,a.predicate)&&_n(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 f=0;f<n.premise.length;f++)f!==s&&u.push(cl(n.premise[f],l));(a.next=a.next||[]).push({premise:u,conclusion:n.conclusion,basePremise:o})}n.variables.forEach(l=>{l.value=null})}}for(let i of e){let n=new Set;i.premise=i.premise.map(s=>cl(s,n))}let r=this._store._getGraphs();try{for(let i in r)this._reasonGraphNaive(e,r[i])}finally{this._store._size=null}}};function cl({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 _n(t,e){return t.value===null&&(t.value=e.value),t.value===e.value}var hl=zt(Fr());var Ht=class extends hl.Transform{constructor(e){super({decodeStrings:!0}),this._readableState.objectMode=!0;let r=new he(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("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this.emit("error",r)}),this}};var pl=zt(Fr());var Qt=class extends pl.Transform{constructor(e){super({encoding:"utf8",writableObjectMode:!0});let r=this._writer=new Z({write:(i,n,s)=>{this.push(i),s&&s()},end:i=>{this.push(null),i&&i()}},e);this._transform=(i,n,s)=>{r.addQuad(i,s)},this._flush=i=>{r.end(i)}}import(e){return e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this.emit("error",r)}),e.on("prefix",(r,i)=>{this._writer.addPrefix(r,i)}),this}};var gb={Lexer:Ce,Parser:he,Writer:Z,Store:je,StoreFactory:Gt,EntityIndex:Wt,StreamParser:Ht,StreamWriter:Qt,Util:Kr,Reasoner:Vt,BaseIRI:Me,DataFactory:W,Term:U,NamedNode:rt,Literal:ce,BlankNode:It,Variable:Rt,DefaultGraph:Tt,Quad:Ie,Triple:Ie,termFromId:Se,termToId:de};export{Me as BaseIRI,It as BlankNode,W as DataFactory,Tt as DefaultGraph,Wt as EntityIndex,Ce as Lexer,ce as Literal,rt as NamedNode,he as Parser,Ie as Quad,Vt as Reasoner,je as Store,Gt as StoreFactory,Ht as StreamParser,Qt as StreamWriter,U as Term,Ie as Triple,Kr as Util,Rt as Variable,Z as Writer,gb as default,dl as getRulesFromDataset,Se as termFromId,de as termToId};
|
|
22
|
+
`),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{}r&&r()}};function Xn(t){let e=yu[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 pn=zt(Fr());var hn=Symbol("iter");function Qp(t,e,r,i){let n=t&&t[e],s=n&&n[r];return!!s&&i in s}function Ut(t,e,r=4){if(r===0)return Object.assign(t,e);for(let i in e)t[i]=Ut(t[i]||Object.create(null),e[i],r-1);return t}function ul(t,e,r=4){let i=!1;for(let n in t)if(n in e){let s=r===0?null:ul(t[n],e[n],r-1);if(s!==!1)i=i||Object.create(null),i[n]=s;else if(r===3)return!1}return i}function fl(t,e,r=4){let i=!1;for(let n in t)if(!(n in e))i=i||Object.create(null),i[n]=r===0?null:Ut({},t[n],r-1);else if(r!==0){let s=fl(t[n],e[n],r-1);if(s!==!1)i=i||Object.create(null),i[n]=s;else if(r===3)return!1}return i}var Wt=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 Se(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&&(pe(e.graph)||(s=this._termToNumericId(e.graph)))&&this._ids[s?`.${r}.${i}.${n}.${s}`:`.${r}.${i}.${n}`]}return this._ids[de(e)]}_termToNewNumericId(e){let r=e&&e.termType==="Quad"?`.${this._termToNewNumericId(e.subject)}.${this._termToNewNumericId(e.predicate)}.${this._termToNewNumericId(e.object)}${pe(e.graph)?"":`.${this._termToNewNumericId(e.graph)}`}`:de(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))}},je=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 Wt({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+=Object.keys(n[a]).length;return this._size=e}_addToIndex(e,r,i,n){let s=e[r]||(e[r]={}),o=s[i]||(s[i]={}),a=n in o;return a||(o[n]=null),!a}_removeFromIndex(e,r,i,n){let s=e[r],o=s[i];delete o[n];for(let a in o)return;delete s[i];for(let a in s)return;delete e[r]}*_findInIndex(e,r,i,n,s,o,a,l){let u,f,c,_=this._entities,h=this._termFromId(_[l]),b={subject:null,predicate:null,object:null};r&&((u=e,e={})[r]=u[r]);for(let p in e)if(f=e[p]){b[s]=this._termFromId(_[p]),i&&((u=f,f={})[i]=u[i]);for(let y in f)if(c=f[y]){b[o]=this._termFromId(_[y]);let g=n?n in c?[n]:[]:Object.keys(c);for(let E=0;E<g.length;E++)b[a]=this._termFromId(_[g[E]]),yield this._factory.quad(b.subject,b.predicate,b.object,h)}}}_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,l;r&&((o=e,e={})[r]=o[r]);for(let u in e)if(a=e[u]){i&&((o=a,a={})[i]=o[i]);for(let f in a)(l=a[f])&&(n?n in l&&s++:s+=Object.keys(l).length)}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:{},predicates:{},objects:{}},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===""||pe(n)?1:this._termToNumericId(n),u=l&&this._graphs[l];return!!s&&!!o&&!!a&&!!u&&Qp(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;if(!(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))return!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--;for(e in o.subjects)return!0;return 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 pn.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 f in s)(o=s[f])&&(a?u?yield*this._findInIndex(o.objects,u,a,l,"object","subject","predicate",f):yield*this._findInIndex(o.subjects,a,l,null,"subject","predicate","object",f):l?yield*this._findInIndex(o.predicates,l,u,null,"predicate","object","subject",f):u?yield*this._findInIndex(o.objects,u,null,null,"object","subject","predicate",f):yield*this._findInIndex(o.subjects,null,null,null,"subject","predicate","object",f))}match(e,r,i,n){return new ve(this,e,r,i,n,{entityIndex:this._entityIndex})}countQuads(e,r,i,n){let s=this._getGraphs(n),o=0,a,l,u,f;if(e&&!(l=this._termToNumericId(e))||r&&!(u=this._termToNumericId(r))||i&&!(f=this._termToNumericId(i)))return 0;for(let c in s)(a=s[c])&&(e?i?o+=this._countInIndex(a.objects,f,l,u):o+=this._countInIndex(a.subjects,l,u,f):r?o+=this._countInIndex(a.predicates,u,f,l):o+=this._countInIndex(a.objects,f,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,R.rdf.rest,R.rdf.nil,null),o=e?[...s]:[];return s.forEach(a=>{let l=[],u=!1,f,c,_=a.graph,h=a.subject;for(;h&&!u;){let b=this.getQuads(null,null,h,null),p=this.getQuads(h,null,null,null),y,g=null,E=null,A=null;for(let w=0;w<p.length&&!u;w++)y=p[w],y.graph.equals(_)?f?u=n(h,"has non-list arcs out"):y.predicate.value===R.rdf.first?g?u=n(h,"has multiple rdf:first arcs"):o.push(g=y):y.predicate.value===R.rdf.rest?E?u=n(h,"has multiple rdf:rest arcs"):o.push(E=y):b.length?u=n(h,"can't be subject and object"):(f=y,c="subject"):u=n(h,"not confined to single graph");for(let w=0;w<b.length&&!u;++w)y=b[w],f?u=n(h,"can't have coreferences"):y.predicate.value===R.rdf.rest?A?u=n(h,"has incoming rdf:rest arcs"):A=y:(f=y,c="object");g?l.unshift(g.object):u=n(h,"has no list head"),h=A&&A.subject}u?e=!1:f&&(i[f[c].value]=l)}),e&&this.removeQuads(o),i}addAll(e){if(e instanceof ve&&(e=e.filtered),Array.isArray(e))this.addQuads(e);else if(e instanceof t&&e._entityIndex===this._entityIndex)e._size!==0&&(this._graphs=Ut(this._graphs,e._graphs),this._size=null);else for(let r of e)this.add(r);return this}contains(e){if(e instanceof ve&&(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 f in s=i[u].subjects){if(!(o=n[f]))return!1;for(let c in a=s[f]){if(!(l=o[c]))return!1;for(let _ in a[c])if(!(_ 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 ve&&(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=fl(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 ve&&(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 ve&&(e=e.filtered),e===this){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ut(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=ul(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 Z().quadsToString(this)}union(e){let r=new t({entityIndex:this._entityIndex});return r._graphs=Ut(Object.create(null),this._graphs),r._size=this._size,r.addAll(e),r}*[Symbol.iterator](){yield*this.readQuads()}};function le(t,e,r=0){let i=e[r];if(i&&!(i in t))return!1;let n=!1;for(let s in i?{[i]:t[i]}:t){let o=r===2?null:le(t[s],e,r+1);o!==!1&&(n=n||Object.create(null),n[s]=o)}return n}var ve=class t extends pn.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 je({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 f=e._getGraphs(r);for(let c in f){let _,h,b,p;(p=f[c])&&(!a&&l?(h=le(p.predicates,[l,u,a]))&&(_=le(p.subjects,[a,l,u]),b=le(p.objects,[u,a,l])):u?(b=le(p.objects,[u,a,l]))&&(_=le(p.subjects,[a,l,u]),h=le(p.predicates,[l,u,a])):(_=le(p.subjects,[a,l,u]))&&(h=le(p.predicates,[l,u,a]),b=le(p.objects,[u,a,l])),_&&(o._graphs[c]={subjects:_,predicates:h,objects:b}))}o._size=null}return this._filtered}get size(){return this.filtered.size}_read(e){e>0&&!this[hn]&&(this[hn]=this[Symbol.iterator]());let r=this[hn];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 Z().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](){yield*this._filtered||this.n3Store.readQuads(this.subject,this.predicate,this.object,this.graph)}};var Gt=class{dataset(e){return new je(e)}};function dl(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 Vt=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,f=r[e.premise[n].content],c=n===e.premise.length-1;if(!(s=a.value)){for(s in f)o=f[s],a.value=Number(s),this._evaluateLevel1(e,r,i,n,c,l,u,o);a.value=null}else(o=f[s])&&this._evaluateLevel1(e,r,i,n,c,l,u,o)}_evaluateLevel1(e,r,i,n,s,o,a,l){let u,f;if(!(u=o.value)){for(u in l)f=l[u],o.value=Number(u),this._evaluateLevel2(e,r,i,n,s,a,f);o.value=null}else(f=l[u])&&this._evaluateLevel2(e,r,i,n,s,a,f)}_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,f]=o,c=f.basePremise.subject.value;c||(f.basePremise.subject.value=a);let _=f.basePremise.predicate.value;_||(f.basePremise.predicate.value=l);let h=f.basePremise.object.value;h||(f.basePremise.object.value=u),f.premise.length===0?s(f.conclusion):this._evaluatePremise(f,r,n),c||(f.basePremise.subject.value=null),_||(f.basePremise.predicate.value=null),h||(f.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=dl(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(_n(o.subject,a.subject)&&_n(o.predicate,a.predicate)&&_n(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 f=0;f<n.premise.length;f++)f!==s&&u.push(cl(n.premise[f],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=>cl(s,n))}let r=this._store._getGraphs();try{for(let i in r)this._reasonGraphNaive(e,r[i])}finally{this._store._size=null}}};function cl({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 _n(t,e){return t.value===null&&(t.value=e.value),t.value===e.value}var hl=zt(Fr());var Ht=class extends hl.Transform{constructor(e){super({decodeStrings:!0}),this._readableState.objectMode=!0;let r=new he(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("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this.emit("error",r)}),this}};var pl=zt(Fr());var Qt=class extends pl.Transform{constructor(e){super({encoding:"utf8",writableObjectMode:!0});let r=this._writer=new Z({write:(i,n,s)=>{this.push(i),s&&s()},end:i=>{this.push(null),i&&i()}},e);this._transform=(i,n,s)=>{r.addQuad(i,s)},this._flush=i=>{r.end(i)}}import(e){return e.on("data",r=>{this.write(r)}),e.on("end",()=>{this.end()}),e.on("error",r=>{this.emit("error",r)}),e.on("prefix",(r,i)=>{this._writer.addPrefix(r,i)}),this}};var gb={Lexer:Ce,Parser:he,Writer:Z,Store:je,StoreFactory:Gt,EntityIndex:Wt,StreamParser:Ht,StreamWriter:Qt,Util:Kr,Reasoner:Vt,BaseIRI:Me,DataFactory:W,Term:U,NamedNode:rt,Literal:ce,BlankNode:It,Variable:Rt,DefaultGraph:Tt,Quad:Ie,Triple:Ie,termFromId:Se,termToId:de};export{Me as BaseIRI,It as BlankNode,W as DataFactory,Tt as DefaultGraph,Wt as EntityIndex,Ce as Lexer,ce as Literal,rt as NamedNode,he as Parser,Ie as Quad,Vt as Reasoner,je as Store,Gt as StoreFactory,Ht as StreamParser,Qt as StreamWriter,U as Term,Ie as Triple,Kr as Util,Rt as Variable,Z as Writer,gb as default,dl as getRulesFromDataset,Se as termFromId,de as termToId};
|
|
23
23
|
/*! Bundled license information:
|
|
24
24
|
|
|
25
25
|
ieee754/index.js:
|