@mapequation/infomap 2.1.0 → 2.4.0
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/CHANGELOG.md +48 -0
- package/arguments.d.ts +2 -0
- package/index.d.ts +6 -3
- package/index.js +1 -1
- package/network.d.ts +6 -7
- package/package.json +3 -5
- package/parser.d.ts +0 -20
- package/parser.js +0 -1
package/network.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
interface Node {
|
|
1
|
+
export interface Node {
|
|
2
2
|
id: number;
|
|
3
3
|
name?: string;
|
|
4
4
|
weight?: number;
|
|
5
5
|
}
|
|
6
|
-
interface StateNode extends Omit<Node, "weight"> {
|
|
6
|
+
export interface StateNode extends Omit<Node, "weight"> {
|
|
7
7
|
stateId: number;
|
|
8
8
|
}
|
|
9
|
-
interface Link {
|
|
9
|
+
export interface Link {
|
|
10
10
|
source: number;
|
|
11
11
|
target: number;
|
|
12
12
|
weight?: number;
|
|
@@ -22,14 +22,14 @@ export interface StateNetwork extends Required<Network> {
|
|
|
22
22
|
states: StateNode[];
|
|
23
23
|
}
|
|
24
24
|
export declare type BipartiteStateNetwork = Required<BipartiteNetwork> & StateNetwork;
|
|
25
|
-
interface MultilayerLink extends Link {
|
|
25
|
+
export interface MultilayerLink extends Link {
|
|
26
26
|
sourceLayer: number;
|
|
27
27
|
targetLayer: number;
|
|
28
28
|
}
|
|
29
|
-
interface IntraLink extends Link {
|
|
29
|
+
export interface IntraLink extends Link {
|
|
30
30
|
layerId: number;
|
|
31
31
|
}
|
|
32
|
-
interface InterLink extends Omit<MultilayerLink, "source" | "target"> {
|
|
32
|
+
export interface InterLink extends Omit<MultilayerLink, "source" | "target"> {
|
|
33
33
|
id: number;
|
|
34
34
|
}
|
|
35
35
|
export declare type MultilayerNetwork = Network<MultilayerLink>;
|
|
@@ -39,4 +39,3 @@ export interface MultilayerIntraInterNetwork extends Omit<Network, "links"> {
|
|
|
39
39
|
}
|
|
40
40
|
export declare type NetworkTypes = Network | BipartiteNetwork | StateNetwork | BipartiteStateNetwork | MultilayerNetwork | MultilayerIntraInterNetwork;
|
|
41
41
|
export default function toString(network: NetworkTypes): string | undefined;
|
|
42
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mapequation/infomap",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Infomap network clustering algorithm",
|
|
5
5
|
"browser": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
"index.d.ts",
|
|
12
12
|
"arguments.d.ts",
|
|
13
13
|
"filetypes.d.ts",
|
|
14
|
-
"parser.js",
|
|
15
|
-
"parser.d.ts",
|
|
16
14
|
"network.d.ts",
|
|
17
15
|
"LICENSE_AGPLv3.txt"
|
|
18
16
|
],
|
|
@@ -71,8 +69,8 @@
|
|
|
71
69
|
"package.json",
|
|
72
70
|
"package-lock.json",
|
|
73
71
|
{
|
|
74
|
-
"filename": "src/
|
|
75
|
-
"updater": "utils/update-version-
|
|
72
|
+
"filename": "src/version.h",
|
|
73
|
+
"updater": "utils/update-version-h.js"
|
|
76
74
|
},
|
|
77
75
|
{
|
|
78
76
|
"filename": "CITATION.cff",
|
package/parser.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { NodeBase, CluNode, TreeNode as JsonTreeNode } from "./filetypes";
|
|
2
|
-
import type { Header as JsonHeader, Module } from "./index";
|
|
3
|
-
declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
4
|
-
declare type Header = Optional<JsonHeader, "directed">;
|
|
5
|
-
declare type Path = {
|
|
6
|
-
path: string | number[];
|
|
7
|
-
};
|
|
8
|
-
declare type TreeNode = Omit<JsonTreeNode, "modules" | "mec" | "path"> & Path;
|
|
9
|
-
export declare type Result<NodeType extends NodeBase> = Header & {
|
|
10
|
-
nodes: NodeType[];
|
|
11
|
-
modules?: Module[];
|
|
12
|
-
};
|
|
13
|
-
export declare type Extension = "clu" | "tree";
|
|
14
|
-
export declare function extension(filename: string): string | null;
|
|
15
|
-
export declare function readFile(file: File): Promise<unknown>;
|
|
16
|
-
export declare function parse(file: string | string[], type?: Extension, parseLinks?: boolean): Result<CluNode<"moduleId">> | Result<TreeNode> | null;
|
|
17
|
-
export declare function parseClu<NodeType extends CluNode>(file: string | string[], nodeHeader?: string[]): Result<NodeType>;
|
|
18
|
-
export declare function parseTree<NodeType extends TreeNode>(file: string | string[], nodeHeader?: string[], parseLinks?: boolean): Result<NodeType>;
|
|
19
|
-
export declare function parseHeader(file: string | string[]): Header;
|
|
20
|
-
export {};
|
package/parser.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.infomap=t():e.infomap=t()}(self,(function(){return(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.parseHeader=t.parseTree=t.parseClu=t.parse=t.readFile=t.extension=void 0,t.extension=function(e){var t;return null!==(t=e.split(".").pop())&&void 0!==t?t:null},t.readFile=function(e){return new Promise(((t,n)=>{const o=new FileReader;o.onload=()=>t(o.result),o.onerror=n,o.readAsText(e)}))},t.parse=function(e,t,n=!1){"string"==typeof e&&(e=e.split("\n"));const r=s(e);if(t&&"clu"===t||r.includes("module")){if("node_id"===r[0])return o(e,r);if("state_id"===r[0])return o(e,r)}else if(t&&"tree"===t||r.includes("path")){if("name"===r[r.length-2])return i(e,r,n);if("state_id"===r[r.length-2]||"layer_id"===r[r.length-1])return i(e,r,n)}return null};const n={node_id:"id",module:"moduleId",flow:"flow",name:"name",state_id:"stateId",layer_id:"layerId",path:"path"};function o(e,t){"string"==typeof e&&(e=e.split("\n"));const o=l(e);t||(t=s(e));const i=[];for(const[o,s]of r(e)){const e=s.split(" ").map(Number);if(e.length<t.length)continue;const r={};for(let o=0;o<t.length;++o){const i=t[o];r[n[i]]=e[o]}if(void 0===r.id||void 0===r.moduleId||void 0===r.flow)throw new Error(`Invalid node at line ${o+1}: ${s}`);i.push(r)}return Object.assign(Object.assign({},o),{nodes:i})}function i(e,t,o=!1){var i;"string"==typeof e&&(e=e.split("\n"));const a=l(e);t||(t=s(e));const d=[];let c=0;for(const[o,i]of r(e)){c=o;const e=i.match(/[^\s"']+|"([^"]*)"/g);if(null===e||e.length<t.length)continue;const r={};for(let o=0;o<t.length;++o){const i=t[o],s=n[i];switch(i){case"path":r.path=e[o];break;case"name":r.name=e[o].slice(1,-1);break;case"node_id":r.id=Number(e[o]);break;case"state_id":case"layer_id":case"flow":r[s]=Number(e[o]);break;default:console.warn(`Unknown field ${i}`)}}if(void 0===r.path||void 0===r.flow||void 0===r.name||void 0===r.id)throw new Error(`Invalid node at line ${o+1}: ${i}`);d.push(r)}if(++c,e.length<=c+1)return Object.assign(Object.assign({},a),{nodes:d});const u=[];let f=null;const p=e[c];let h=!1;if(null==p?void 0:p.startsWith("*Links")){const e=p.trim().split(" ");h=e.length>1&&"directed"===e[1]}for(const[t,n]of function*(e,t=0){if(!(e.length<=t)&&e[t].startsWith("*Links"))for(let n=++t;n<e.length;++n){const t=e[n];0!==t.length&&(yield[n,t])}}(e,c)){if(n.startsWith("*Links")){const[e,t,...i]=n.split(" "),r="root"===t?[0]:t.split(":").map(Number),[s,l,a,d]=i.map(Number);f={path:r,enterFlow:s,exitFlow:l,numEdges:a,numChildren:d,links:o?[]:void 0},u.push(f);continue}if(!o||!f)continue;const[e,t,r]=n.split(" ").map(Number);null===(i=f.links)||void 0===i||i.push({source:e,target:t,flow:r})}return Object.assign(Object.assign({},a),{directed:h,nodes:d,modules:u})}function*r(e){for(let t=0;t<e.length;++t){const n=e[t];if(!n.startsWith("#")&&0!==n.length){if(n.startsWith("*"))break;yield[t,n]}}}function s(e){const t=["# path","# node_id","# state_id"];"string"==typeof e&&(e=e.split("\n"));for(const n of e){if(!n.startsWith("#"))break;if(t.some((e=>n.startsWith(e))))return n.slice(2).split(" ")}throw new Error("Could not parse node header")}function l(e){var t,n,o,i,r,s,l;const a={};if("string"==typeof e&&(e=e.split("\n")),e.length<8)throw new Error("Expected file header to have at least 8 lines");const d=null===(t=e[0].match(/^# (v\d+\.\d+\.\d+)/))||void 0===t?void 0:t[1];if(!d)throw new Error("Could not parse version");a.version=d;const c=null===(n=e[1].match(/^# (.+)/))||void 0===n?void 0:n[1];if(!c)throw new Error("Could not parse args");a.args=c;for(let t=2;t<e.length;++t){const n=e[t];if(!n.startsWith("#"))break;const d=null===(o=n.match(/^# started at (.+)/))||void 0===o?void 0:o[1];if(d){a.startedAt=d;continue}const c=null===(i=n.match(/^# completed in (.+) s/))||void 0===i?void 0:i[1];if(c){a.completedIn=Number(c);continue}const u=n.match(/^# partitioned into (\d+) levels with (\d+) top modules/);if(u){a.numLevels=Number(u[1]),a.numTopModules=Number(u[2]);continue}const f=null===(r=n.match(/^# codelength (.+) bits/))||void 0===r?void 0:r[1];if(f){a.codelength=Number(f);continue}const p=null===(s=n.match(/^# relative codelength savings (.+)%/))||void 0===s?void 0:s[1];if(p){a.relativeCodelengthSavings=Number(p)/100;continue}const h=null===(l=n.match(/^# bipartite start id (\d+)/))||void 0===l?void 0:l[1];h&&(a.bipartiteStartId=Number(h))}if(!(a.startedAt&&a.completedIn&&a.numLevels&&a.numTopModules&&a.codelength&&a.relativeCodelengthSavings))throw new Error("Could not parse file header");return a}t.parseClu=o,t.parseTree=i,t.parseHeader=l})(),e})()}));
|