node-relation
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -120,2 +120,11 @@ export declare type Relation<T> = T[]; | ||
/** | ||
* 인스턴스에 있는 관계의 깊이를 계산합니다. 현재 노드에서 목표 노드까지의 가장 짧은 깊이를 반환해야 합니다. | ||
* 시작 노드는 재귀하여 호출될 때 마다 변경됩니다. | ||
* @param current 현재 노드입니다. | ||
* @param target 목표 노드입니다. | ||
* @param depth 재귀호출되며 누적된 깊이입니다. | ||
* @param tests 탐색된 노드를 담고있는 배열입니다. 이미 한 번 탐색된 노드는 이 배열에 담깁니다. 상호참조하는 관계로 인해 무한히 탐색되는 것을 방지하는 용도로 사용됩니다. | ||
*/ | ||
protected getSearchedDepth(current: T, target: T, depth?: number, tests?: T[]): number; | ||
/** | ||
* Only the nodes that are related to the node received by the parameter are filtered and returned in a new Relationship instance. | ||
@@ -208,4 +217,14 @@ * You can control calculation depth relationship with depth parameter. | ||
weights(log?: boolean, normalize?: boolean): Map<T, number>; | ||
/** | ||
* Returns the found minimum distance to between source to target. | ||
* @param source Node to start | ||
* @param target Node to target | ||
* @param log If this parameter is set to true, it returns the value to which the log function is applied. This is useful when the value is too high. | ||
* @example | ||
* const A = state.to('user-a', 'user-b').to('user-b', 'user-c') | ||
* A.distance('user-a', 'user-c') // 2 | ||
*/ | ||
distance(source: T, target: T, log?: boolean): number; | ||
/** Destroy the data in the instance. It is used for garbage collector. */ | ||
clear(): void; | ||
} |
@@ -1,1 +0,1 @@ | ||
var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{W:()=>s});class r{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const s of e)r.has(t,s)||t.push(s);return t}static drop(t,...e){for(const s of e)if(r.has(t,s)){const e=t.indexOf(s);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,s]of this.__relations)r.add(t,e),r.add(t,...s);return t}get nodeset(){const t=new Set;for(const[e,r]of this.__relations){t.add(e);for(const e of r)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((r,s)=>{const o=new Array(e.length).fill(0);o[s]=1,t.set(r,o)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,r)=>{t.set(e,r)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const s=this.__relations.get(t);for(const t of e)r.add(s,t);return s}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const r of e)this.ensureRelation(r,t);return this}all(...t){for(const e of t){const s=this.ensureRelation(e,...t);r.drop(s,e)}return this}getCombinedDataset(t,e){const s=new Map,o=new Map(t),n=new Map(e);for(const[t,e]of o){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}for(const[t,e]of n){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}return Array.from(s)}getSearchedRelationDataset(t,e,s=[[t,[]]],o=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],a=[[t,n]];if(!e)return a;if(!n)return a;if(r.has(o,t))return a;r.add(o,t),e--,s=this.getCombinedDataset(s,a);for(const t of n){const r=this.getSearchedRelationDataset(t,e,s,o);s=this.getCombinedDataset(s,r)}return s}from(t,e=-1){const r=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(r)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const r=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,r)})),new this.constructor(e)}without(...t){return r.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const s=this.__relations.get(t);s&&r.drop(s,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const r of e)this.unlinkRefersFromSource(r,t);return this}drop(...t){for(const e of this.__relations.values())r.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[s,o]of this.__relations)if(s===t||r.has(o,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let s=0;for(const e of this.__relations.values())r.has(e,t)&&s++;return e&&(s=Math.log(s+1)),s}weights(t=!1,e=!1){const r=new Map;let s=0;for(const e of this.nodes){const o=this.weight(e,t);o>s&&(s=o),r.set(e,o)}if(e){const t=Array.from(r);for(const[e,o]of t)r.set(e,o/s)}return r}clear(){this.__relations.clear()}}class s extends r{constructor(t=[]){super(t)}to(t,...e){return super.to.call(this.copy,t,...e)}both(t,...e){return super.both.call(this.copy,t,...e)}all(...t){return super.all.call(this.copy,...t)}unlinkTo(t,...e){return super.unlinkTo.call(this.copy,t,...e)}unlinkBoth(t,...e){return super.unlinkBoth.call(this.copy,t,...e)}drop(...t){return super.drop.call(this.copy,...t)}}var o=e.W;export{o as Relationship}; | ||
var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{W:()=>s});class r{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const s of e)r.has(t,s)||t.push(s);return t}static drop(t,...e){for(const s of e)if(r.has(t,s)){const e=t.indexOf(s);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,s]of this.__relations)r.add(t,e,...s);return t}get nodeset(){const t=new Set;for(const[e,r]of this.__relations){t.add(e);for(const e of r)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((r,s)=>{const o=new Array(e.length).fill(0);o[s]=1,t.set(r,o)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,r)=>{t.set(e,r)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const s=this.__relations.get(t);for(const t of e)r.add(s,t);return s}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const r of e)this.ensureRelation(r,t);return this}all(...t){for(const e of t){const s=this.ensureRelation(e,...t);r.drop(s,e)}return this}getCombinedDataset(t,e){const s=new Map,o=new Map(t),n=new Map(e);for(const[t,e]of o){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}for(const[t,e]of n){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}return Array.from(s)}getSearchedRelationDataset(t,e,s=[[t,[]]],o=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],a=[[t,n]];if(!e)return a;if(!n)return a;if(r.has(o,t))return a;r.add(o,t),e--,s=this.getCombinedDataset(s,a);for(const t of n){const r=this.getSearchedRelationDataset(t,e,s,o);s=this.getCombinedDataset(s,r)}return s}getSearchedDepth(t,e,s=0,o=[]){if(t===e)return s;if(r.has(o,t))return 1/0;r.add(o,t),s++;let n=1/0;const a=this.__relations.has(t)?this.__relations.get(t):[];for(const t of a){const r=this.getSearchedDepth(t,e,s,o);n=Math.min(n,r)}return n}from(t,e=-1){const r=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(r)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const r=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,r)})),new this.constructor(e)}without(...t){return r.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const s=this.__relations.get(t);s&&r.drop(s,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const r of e)this.unlinkRefersFromSource(r,t);return this}drop(...t){for(const e of this.__relations.values())r.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[s,o]of this.__relations)if(s===t||r.has(o,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let s=0;for(const e of this.__relations.values())r.has(e,t)&&s++;return e&&(s=Math.log(s+1)),s}weights(t=!1,e=!1){const r=new Map;let s=0;for(const e of this.nodes){const o=this.weight(e,t);o>s&&(s=o),r.set(e,o)}if(e){const t=Array.from(r);for(const[e,o]of t)r.set(e,o/s)}return r}distance(t,e,r=!1){let s=this.getSearchedDepth(t,e);return r&&(s=Math.log(s+1)),s}clear(){this.__relations.clear()}}class s extends r{constructor(t=[]){super(t)}to(t,...e){return super.to.call(this.copy,t,...e)}both(t,...e){return super.both.call(this.copy,t,...e)}all(...t){return super.all.call(this.copy,...t)}unlinkTo(t,...e){return super.unlinkTo.call(this.copy,t,...e)}unlinkBoth(t,...e){return super.unlinkBoth.call(this.copy,t,...e)}drop(...t){return super.drop.call(this.copy,...t)}}var o=e.W;export{o as Relationship}; |
@@ -1,1 +0,1 @@ | ||
var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{W:()=>s});class r{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const s of e)r.has(t,s)||t.push(s);return t}static drop(t,...e){for(const s of e)if(r.has(t,s)){const e=t.indexOf(s);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,s]of this.__relations)r.add(t,e),r.add(t,...s);return t}get nodeset(){const t=new Set;for(const[e,r]of this.__relations){t.add(e);for(const e of r)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((r,s)=>{const o=new Array(e.length).fill(0);o[s]=1,t.set(r,o)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,r)=>{t.set(e,r)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const s=this.__relations.get(t);for(const t of e)r.add(s,t);return s}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const r of e)this.ensureRelation(r,t);return this}all(...t){for(const e of t){const s=this.ensureRelation(e,...t);r.drop(s,e)}return this}getCombinedDataset(t,e){const s=new Map,o=new Map(t),n=new Map(e);for(const[t,e]of o){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}for(const[t,e]of n){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}return Array.from(s)}getSearchedRelationDataset(t,e,s=[[t,[]]],o=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],a=[[t,n]];if(!e)return a;if(!n)return a;if(r.has(o,t))return a;r.add(o,t),e--,s=this.getCombinedDataset(s,a);for(const t of n){const r=this.getSearchedRelationDataset(t,e,s,o);s=this.getCombinedDataset(s,r)}return s}from(t,e=-1){const r=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(r)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const r=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,r)})),new this.constructor(e)}without(...t){return r.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const s=this.__relations.get(t);s&&r.drop(s,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const r of e)this.unlinkRefersFromSource(r,t);return this}drop(...t){for(const e of this.__relations.values())r.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[s,o]of this.__relations)if(s===t||r.has(o,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let s=0;for(const e of this.__relations.values())r.has(e,t)&&s++;return e&&(s=Math.log(s+1)),s}weights(t=!1,e=!1){const r=new Map;let s=0;for(const e of this.nodes){const o=this.weight(e,t);o>s&&(s=o),r.set(e,o)}if(e){const t=Array.from(r);for(const[e,o]of t)r.set(e,o/s)}return r}clear(){this.__relations.clear()}}class s extends r{constructor(t=[]){super(t)}to(t,...e){return super.to.call(this.copy,t,...e)}both(t,...e){return super.both.call(this.copy,t,...e)}all(...t){return super.all.call(this.copy,...t)}unlinkTo(t,...e){return super.unlinkTo.call(this.copy,t,...e)}unlinkBoth(t,...e){return super.unlinkBoth.call(this.copy,t,...e)}drop(...t){return super.drop.call(this.copy,...t)}}var o=e.W;export{o as Relationship}; | ||
var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{W:()=>s});class r{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const s of e)r.has(t,s)||t.push(s);return t}static drop(t,...e){for(const s of e)if(r.has(t,s)){const e=t.indexOf(s);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,s]of this.__relations)r.add(t,e,...s);return t}get nodeset(){const t=new Set;for(const[e,r]of this.__relations){t.add(e);for(const e of r)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((r,s)=>{const o=new Array(e.length).fill(0);o[s]=1,t.set(r,o)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,r)=>{t.set(e,r)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const s=this.__relations.get(t);for(const t of e)r.add(s,t);return s}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const r of e)this.ensureRelation(r,t);return this}all(...t){for(const e of t){const s=this.ensureRelation(e,...t);r.drop(s,e)}return this}getCombinedDataset(t,e){const s=new Map,o=new Map(t),n=new Map(e);for(const[t,e]of o){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}for(const[t,e]of n){s.has(t)||s.set(t,e);const o=s.get(t);r.add(o,...e)}return Array.from(s)}getSearchedRelationDataset(t,e,s=[[t,[]]],o=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],a=[[t,n]];if(!e)return a;if(!n)return a;if(r.has(o,t))return a;r.add(o,t),e--,s=this.getCombinedDataset(s,a);for(const t of n){const r=this.getSearchedRelationDataset(t,e,s,o);s=this.getCombinedDataset(s,r)}return s}getSearchedDepth(t,e,s=0,o=[]){if(t===e)return s;if(r.has(o,t))return 1/0;r.add(o,t),s++;let n=1/0;const a=this.__relations.has(t)?this.__relations.get(t):[];for(const t of a){const r=this.getSearchedDepth(t,e,s,o);n=Math.min(n,r)}return n}from(t,e=-1){const r=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(r)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const r=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,r)})),new this.constructor(e)}without(...t){return r.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const s=this.__relations.get(t);s&&r.drop(s,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const r of e)this.unlinkRefersFromSource(r,t);return this}drop(...t){for(const e of this.__relations.values())r.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[s,o]of this.__relations)if(s===t||r.has(o,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let s=0;for(const e of this.__relations.values())r.has(e,t)&&s++;return e&&(s=Math.log(s+1)),s}weights(t=!1,e=!1){const r=new Map;let s=0;for(const e of this.nodes){const o=this.weight(e,t);o>s&&(s=o),r.set(e,o)}if(e){const t=Array.from(r);for(const[e,o]of t)r.set(e,o/s)}return r}distance(t,e,r=!1){let s=this.getSearchedDepth(t,e);return r&&(s=Math.log(s+1)),s}clear(){this.__relations.clear()}}class s extends r{constructor(t=[]){super(t)}to(t,...e){return super.to.call(this.copy,t,...e)}both(t,...e){return super.both.call(this.copy,t,...e)}all(...t){return super.all.call(this.copy,...t)}unlinkTo(t,...e){return super.unlinkTo.call(this.copy,t,...e)}unlinkBoth(t,...e){return super.unlinkBoth.call(this.copy,t,...e)}drop(...t){return super.drop.call(this.copy,...t)}}var o=e.W;export{o as Relationship}; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NodeRelation=e():t.NodeRelation=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Relationship:()=>r});class o{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const r of e)o.has(t,r)||t.push(r);return t}static drop(t,...e){for(const r of e)if(o.has(t,r)){const e=t.indexOf(r);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,r]of this.__relations)o.add(t,e),o.add(t,...r);return t}get nodeset(){const t=new Set;for(const[e,o]of this.__relations){t.add(e);for(const e of o)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((o,r)=>{const s=new Array(e.length).fill(0);s[r]=1,t.set(o,s)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,o)=>{t.set(e,o)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const r=this.__relations.get(t);for(const t of e)o.add(r,t);return r}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const o of e)this.ensureRelation(o,t);return this}all(...t){for(const e of t){const r=this.ensureRelation(e,...t);o.drop(r,e)}return this}getCombinedDataset(t,e){const r=new Map,s=new Map(t),n=new Map(e);for(const[t,e]of s){r.has(t)||r.set(t,e);const s=r.get(t);o.add(s,...e)}for(const[t,e]of n){r.has(t)||r.set(t,e);const s=r.get(t);o.add(s,...e)}return Array.from(r)}getSearchedRelationDataset(t,e,r=[[t,[]]],s=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],i=[[t,n]];if(!e)return i;if(!n)return i;if(o.has(s,t))return i;o.add(s,t),e--,r=this.getCombinedDataset(r,i);for(const t of n){const o=this.getSearchedRelationDataset(t,e,r,s);r=this.getCombinedDataset(r,o)}return r}from(t,e=-1){const o=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(o)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const o=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,o)})),new this.constructor(e)}without(...t){return o.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const r=this.__relations.get(t);r&&o.drop(r,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const o of e)this.unlinkRefersFromSource(o,t);return this}drop(...t){for(const e of this.__relations.values())o.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[r,s]of this.__relations)if(r===t||o.has(s,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let r=0;for(const e of this.__relations.values())o.has(e,t)&&r++;return e&&(r=Math.log(r+1)),r}weights(t=!1,e=!1){const o=new Map;let r=0;for(const e of this.nodes){const s=this.weight(e,t);s>r&&(r=s),o.set(e,s)}if(e){const t=Array.from(o);for(const[e,s]of t)o.set(e,s/r)}return o}clear(){this.__relations.clear()}}class r extends o{constructor(t=[]){super(t)}to(t,...e){return super.to.call(this.copy,t,...e)}both(t,...e){return super.both.call(this.copy,t,...e)}all(...t){return super.all.call(this.copy,...t)}unlinkTo(t,...e){return super.unlinkTo.call(this.copy,t,...e)}unlinkBoth(t,...e){return super.unlinkBoth.call(this.copy,t,...e)}drop(...t){return super.drop.call(this.copy,...t)}}return e})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NodeRelation=e():t.NodeRelation=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,r)=>{for(var o in r)t.o(r,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Relationship:()=>o});class r{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const o of e)r.has(t,o)||t.push(o);return t}static drop(t,...e){for(const o of e)if(r.has(t,o)){const e=t.indexOf(o);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,o]of this.__relations)r.add(t,e,...o);return t}get nodeset(){const t=new Set;for(const[e,r]of this.__relations){t.add(e);for(const e of r)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((r,o)=>{const s=new Array(e.length).fill(0);s[o]=1,t.set(r,s)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,r)=>{t.set(e,r)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const o=this.__relations.get(t);for(const t of e)r.add(o,t);return o}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const r of e)this.ensureRelation(r,t);return this}all(...t){for(const e of t){const o=this.ensureRelation(e,...t);r.drop(o,e)}return this}getCombinedDataset(t,e){const o=new Map,s=new Map(t),n=new Map(e);for(const[t,e]of s){o.has(t)||o.set(t,e);const s=o.get(t);r.add(s,...e)}for(const[t,e]of n){o.has(t)||o.set(t,e);const s=o.get(t);r.add(s,...e)}return Array.from(o)}getSearchedRelationDataset(t,e,o=[[t,[]]],s=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],i=[[t,n]];if(!e)return i;if(!n)return i;if(r.has(s,t))return i;r.add(s,t),e--,o=this.getCombinedDataset(o,i);for(const t of n){const r=this.getSearchedRelationDataset(t,e,o,s);o=this.getCombinedDataset(o,r)}return o}getSearchedDepth(t,e,o=0,s=[]){if(t===e)return o;if(r.has(s,t))return 1/0;r.add(s,t),o++;let n=1/0;const i=this.__relations.has(t)?this.__relations.get(t):[];for(const t of i){const r=this.getSearchedDepth(t,e,o,s);n=Math.min(n,r)}return n}from(t,e=-1){const r=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(r)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const r=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,r)})),new this.constructor(e)}without(...t){return r.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const o=this.__relations.get(t);o&&r.drop(o,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const r of e)this.unlinkRefersFromSource(r,t);return this}drop(...t){for(const e of this.__relations.values())r.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[o,s]of this.__relations)if(o===t||r.has(s,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let o=0;for(const e of this.__relations.values())r.has(e,t)&&o++;return e&&(o=Math.log(o+1)),o}weights(t=!1,e=!1){const r=new Map;let o=0;for(const e of this.nodes){const s=this.weight(e,t);s>o&&(o=s),r.set(e,s)}if(e){const t=Array.from(r);for(const[e,s]of t)r.set(e,s/o)}return r}distance(t,e,r=!1){let o=this.getSearchedDepth(t,e);return r&&(o=Math.log(o+1)),o}clear(){this.__relations.clear()}}class o extends r{constructor(t=[]){super(t)}to(t,...e){return super.to.call(this.copy,t,...e)}both(t,...e){return super.both.call(this.copy,t,...e)}all(...t){return super.all.call(this.copy,...t)}unlinkTo(t,...e){return super.unlinkTo.call(this.copy,t,...e)}unlinkBoth(t,...e){return super.unlinkBoth.call(this.copy,t,...e)}drop(...t){return super.drop.call(this.copy,...t)}}return e})()})); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NodeRelation=e():t.NodeRelation=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Relationship:()=>o});class o{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const r of e)o.has(t,r)||t.push(r);return t}static drop(t,...e){for(const r of e)if(o.has(t,r)){const e=t.indexOf(r);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,r]of this.__relations)o.add(t,e),o.add(t,...r);return t}get nodeset(){const t=new Set;for(const[e,o]of this.__relations){t.add(e);for(const e of o)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((o,r)=>{const s=new Array(e.length).fill(0);s[r]=1,t.set(o,s)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,o)=>{t.set(e,o)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const r=this.__relations.get(t);for(const t of e)o.add(r,t);return r}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const o of e)this.ensureRelation(o,t);return this}all(...t){for(const e of t){const r=this.ensureRelation(e,...t);o.drop(r,e)}return this}getCombinedDataset(t,e){const r=new Map,s=new Map(t),n=new Map(e);for(const[t,e]of s){r.has(t)||r.set(t,e);const s=r.get(t);o.add(s,...e)}for(const[t,e]of n){r.has(t)||r.set(t,e);const s=r.get(t);o.add(s,...e)}return Array.from(r)}getSearchedRelationDataset(t,e,r=[[t,[]]],s=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],i=[[t,n]];if(!e)return i;if(!n)return i;if(o.has(s,t))return i;o.add(s,t),e--,r=this.getCombinedDataset(r,i);for(const t of n){const o=this.getSearchedRelationDataset(t,e,r,s);r=this.getCombinedDataset(r,o)}return r}from(t,e=-1){const o=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(o)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const o=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,o)})),new this.constructor(e)}without(...t){return o.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const r=this.__relations.get(t);r&&o.drop(r,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const o of e)this.unlinkRefersFromSource(o,t);return this}drop(...t){for(const e of this.__relations.values())o.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[r,s]of this.__relations)if(r===t||o.has(s,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let r=0;for(const e of this.__relations.values())o.has(e,t)&&r++;return e&&(r=Math.log(r+1)),r}weights(t=!1,e=!1){const o=new Map;let r=0;for(const e of this.nodes){const s=this.weight(e,t);s>r&&(r=s),o.set(e,s)}if(e){const t=Array.from(o);for(const[e,s]of t)o.set(e,s/r)}return o}clear(){this.__relations.clear()}}return e})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NodeRelation=e():t.NodeRelation=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{Relationship:()=>o});class o{constructor(t=[]){this.__relations=new Map(t)}static has(t,e){return t.includes(e)}static add(t,...e){for(const r of e)o.has(t,r)||t.push(r);return t}static drop(t,...e){for(const r of e)if(o.has(t,r)){const e=t.indexOf(r);-1!==e&&t.splice(e,1)}return t}static clear(t){return t.length=0,t}get dataset(){return Array.from(this.__relations)}get nodes(){const t=[];for(const[e,r]of this.__relations)o.add(t,e,...r);return t}get nodeset(){const t=new Set;for(const[e,o]of this.__relations){t.add(e);for(const e of o)t.add(e)}return t}get oneHot(){const t=new Map,e=this.nodes;return e.forEach(((o,r)=>{const s=new Array(e.length).fill(0);s[r]=1,t.set(o,s)})),t}get zeroVector(){return new Array(this.nodes.length).fill(0)}get label(){const t=new Map;return this.nodes.forEach(((e,o)=>{t.set(e,o)})),t}get clone(){return this.copy}get copy(){return new this.constructor(this.dataset)}ensureRelation(t,...e){this.__relations.has(t)||this.__relations.set(t,[]);const r=this.__relations.get(t);for(const t of e)o.add(r,t);return r}to(t,...e){return this.ensureRelation(t,...e),this}both(t,...e){this.ensureRelation(t,...e);for(const o of e)this.ensureRelation(o,t);return this}all(...t){for(const e of t){const r=this.ensureRelation(e,...t);o.drop(r,e)}return this}getCombinedDataset(t,e){const r=new Map,s=new Map(t),n=new Map(e);for(const[t,e]of s){r.has(t)||r.set(t,e);const s=r.get(t);o.add(s,...e)}for(const[t,e]of n){r.has(t)||r.set(t,e);const s=r.get(t);o.add(s,...e)}return Array.from(r)}getSearchedRelationDataset(t,e,r=[[t,[]]],s=[]){const n=this.__relations.has(t)?this.__relations.get(t):[],i=[[t,n]];if(!e)return i;if(!n)return i;if(o.has(s,t))return i;o.add(s,t),e--,r=this.getCombinedDataset(r,i);for(const t of n){const o=this.getSearchedRelationDataset(t,e,r,s);r=this.getCombinedDataset(r,o)}return r}getSearchedDepth(t,e,r=0,s=[]){if(t===e)return r;if(o.has(s,t))return 1/0;o.add(s,t),r++;let n=1/0;const i=this.__relations.has(t)?this.__relations.get(t):[];for(const t of i){const o=this.getSearchedDepth(t,e,r,s);n=Math.min(n,o)}return n}from(t,e=-1){const o=this.copy.getSearchedRelationDataset(t,--e);return new this.constructor(o)}where(t){let e=[];return this.nodes.filter(t).forEach((t=>{const o=this.getSearchedRelationDataset(t,-1);e=this.getCombinedDataset(e,o)})),new this.constructor(e)}without(...t){return o.drop(this.nodes,...t)}unlinkRefersFromSource(t,...e){const r=this.__relations.get(t);r&&o.drop(r,...e)}unlinkTo(t,...e){return this.unlinkRefersFromSource(t,...e),this}unlinkBoth(t,...e){this.unlinkRefersFromSource(t,...e);for(const o of e)this.unlinkRefersFromSource(o,t);return this}drop(...t){for(const e of this.__relations.values())o.drop(e,...t);for(const e of t)this.__relations.delete(e);return this}has(t){let e=this.__relations.has(t);for(const[r,s]of this.__relations)if(r===t||o.has(s,t)){e=!0;break}return e}hasAll(...t){for(const e of t)if(!this.has(e))return!1;return!0}weight(t,e=!1){let r=0;for(const e of this.__relations.values())o.has(e,t)&&r++;return e&&(r=Math.log(r+1)),r}weights(t=!1,e=!1){const o=new Map;let r=0;for(const e of this.nodes){const s=this.weight(e,t);s>r&&(r=s),o.set(e,s)}if(e){const t=Array.from(o);for(const[e,s]of t)o.set(e,s/r)}return o}distance(t,e,o=!1){let r=this.getSearchedDepth(t,e);return o&&(r=Math.log(r+1)),r}clear(){this.__relations.clear()}}return e})()})); |
{ | ||
"name": "node-relation", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "Manage strings, number, object that are related to each other.", | ||
@@ -5,0 +5,0 @@ "main": "dist/umd/index.js", |
@@ -115,3 +115,3 @@ # node-relation | ||
### `(getter)` zeroVector: `number[]` | ||
#### `(getter)` zeroVector: `number[]` | ||
@@ -280,2 +280,10 @@ Get a 1-dimensional vector that was filled 0. The vector's size are same as nodes length of instance. This is useful for representing data that does not belong to anything. It could be used as dataset for machine learning. | ||
#### distance(source: `RelationNode`, target: `RelationNode`, log?: `boolean` = `false`): `number` | ||
Returns the found minimum distance to between source to target. | ||
```javascript | ||
const distance = B.distance('language', 'Korean') // 2 | ||
``` | ||
#### clear(): `void` | ||
@@ -282,0 +290,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41553
278
375