@zuvia-software-solutions/code-mapper 1.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/README.md +215 -0
- package/dist/cli/ai-context.d.ts +19 -0
- package/dist/cli/ai-context.js +168 -0
- package/dist/cli/analyze.d.ts +7 -0
- package/dist/cli/analyze.js +325 -0
- package/dist/cli/augment.d.ts +7 -0
- package/dist/cli/augment.js +27 -0
- package/dist/cli/clean.d.ts +5 -0
- package/dist/cli/clean.js +56 -0
- package/dist/cli/eval-server.d.ts +25 -0
- package/dist/cli/eval-server.js +365 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +102 -0
- package/dist/cli/lazy-action.d.ts +6 -0
- package/dist/cli/lazy-action.js +19 -0
- package/dist/cli/list.d.ts +2 -0
- package/dist/cli/list.js +27 -0
- package/dist/cli/mcp.d.ts +8 -0
- package/dist/cli/mcp.js +35 -0
- package/dist/cli/refresh.d.ts +12 -0
- package/dist/cli/refresh.js +165 -0
- package/dist/cli/serve.d.ts +5 -0
- package/dist/cli/serve.js +8 -0
- package/dist/cli/setup.d.ts +6 -0
- package/dist/cli/setup.js +218 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.js +33 -0
- package/dist/cli/tool.d.ts +28 -0
- package/dist/cli/tool.js +87 -0
- package/dist/config/ignore-service.d.ts +32 -0
- package/dist/config/ignore-service.js +282 -0
- package/dist/config/supported-languages.d.ts +23 -0
- package/dist/config/supported-languages.js +52 -0
- package/dist/core/augmentation/engine.d.ts +22 -0
- package/dist/core/augmentation/engine.js +232 -0
- package/dist/core/embeddings/embedder.d.ts +35 -0
- package/dist/core/embeddings/embedder.js +171 -0
- package/dist/core/embeddings/embedding-pipeline.d.ts +41 -0
- package/dist/core/embeddings/embedding-pipeline.js +402 -0
- package/dist/core/embeddings/index.d.ts +5 -0
- package/dist/core/embeddings/index.js +6 -0
- package/dist/core/embeddings/text-generator.d.ts +20 -0
- package/dist/core/embeddings/text-generator.js +159 -0
- package/dist/core/embeddings/types.d.ts +60 -0
- package/dist/core/embeddings/types.js +23 -0
- package/dist/core/graph/graph.d.ts +4 -0
- package/dist/core/graph/graph.js +65 -0
- package/dist/core/graph/types.d.ts +69 -0
- package/dist/core/graph/types.js +3 -0
- package/dist/core/incremental/child-process.d.ts +8 -0
- package/dist/core/incremental/child-process.js +649 -0
- package/dist/core/incremental/refresh-coordinator.d.ts +32 -0
- package/dist/core/incremental/refresh-coordinator.js +147 -0
- package/dist/core/incremental/types.d.ts +78 -0
- package/dist/core/incremental/types.js +153 -0
- package/dist/core/incremental/watcher.d.ts +63 -0
- package/dist/core/incremental/watcher.js +338 -0
- package/dist/core/ingestion/ast-cache.d.ts +12 -0
- package/dist/core/ingestion/ast-cache.js +34 -0
- package/dist/core/ingestion/call-processor.d.ts +34 -0
- package/dist/core/ingestion/call-processor.js +937 -0
- package/dist/core/ingestion/call-routing.d.ts +40 -0
- package/dist/core/ingestion/call-routing.js +97 -0
- package/dist/core/ingestion/cluster-enricher.d.ts +30 -0
- package/dist/core/ingestion/cluster-enricher.js +151 -0
- package/dist/core/ingestion/community-processor.d.ts +26 -0
- package/dist/core/ingestion/community-processor.js +272 -0
- package/dist/core/ingestion/constants.d.ts +5 -0
- package/dist/core/ingestion/constants.js +8 -0
- package/dist/core/ingestion/entry-point-scoring.d.ts +23 -0
- package/dist/core/ingestion/entry-point-scoring.js +317 -0
- package/dist/core/ingestion/export-detection.d.ts +11 -0
- package/dist/core/ingestion/export-detection.js +203 -0
- package/dist/core/ingestion/filesystem-walker.d.ts +18 -0
- package/dist/core/ingestion/filesystem-walker.js +64 -0
- package/dist/core/ingestion/framework-detection.d.ts +42 -0
- package/dist/core/ingestion/framework-detection.js +405 -0
- package/dist/core/ingestion/heritage-processor.d.ts +15 -0
- package/dist/core/ingestion/heritage-processor.js +237 -0
- package/dist/core/ingestion/import-processor.d.ts +31 -0
- package/dist/core/ingestion/import-processor.js +416 -0
- package/dist/core/ingestion/language-config.d.ts +32 -0
- package/dist/core/ingestion/language-config.js +161 -0
- package/dist/core/ingestion/mro-processor.d.ts +32 -0
- package/dist/core/ingestion/mro-processor.js +343 -0
- package/dist/core/ingestion/named-binding-extraction.d.ts +51 -0
- package/dist/core/ingestion/named-binding-extraction.js +343 -0
- package/dist/core/ingestion/parsing-processor.d.ts +20 -0
- package/dist/core/ingestion/parsing-processor.js +282 -0
- package/dist/core/ingestion/pipeline.d.ts +3 -0
- package/dist/core/ingestion/pipeline.js +416 -0
- package/dist/core/ingestion/process-processor.d.ts +42 -0
- package/dist/core/ingestion/process-processor.js +357 -0
- package/dist/core/ingestion/resolution-context.d.ts +40 -0
- package/dist/core/ingestion/resolution-context.js +171 -0
- package/dist/core/ingestion/resolvers/csharp.d.ts +10 -0
- package/dist/core/ingestion/resolvers/csharp.js +101 -0
- package/dist/core/ingestion/resolvers/go.d.ts +8 -0
- package/dist/core/ingestion/resolvers/go.js +33 -0
- package/dist/core/ingestion/resolvers/index.d.ts +14 -0
- package/dist/core/ingestion/resolvers/index.js +10 -0
- package/dist/core/ingestion/resolvers/jvm.d.ts +9 -0
- package/dist/core/ingestion/resolvers/jvm.js +74 -0
- package/dist/core/ingestion/resolvers/php.d.ts +7 -0
- package/dist/core/ingestion/resolvers/php.js +30 -0
- package/dist/core/ingestion/resolvers/ruby.d.ts +9 -0
- package/dist/core/ingestion/resolvers/ruby.js +13 -0
- package/dist/core/ingestion/resolvers/rust.d.ts +5 -0
- package/dist/core/ingestion/resolvers/rust.js +62 -0
- package/dist/core/ingestion/resolvers/standard.d.ts +16 -0
- package/dist/core/ingestion/resolvers/standard.js +144 -0
- package/dist/core/ingestion/resolvers/utils.d.ts +18 -0
- package/dist/core/ingestion/resolvers/utils.js +113 -0
- package/dist/core/ingestion/structure-processor.d.ts +4 -0
- package/dist/core/ingestion/structure-processor.js +39 -0
- package/dist/core/ingestion/symbol-table.d.ts +34 -0
- package/dist/core/ingestion/symbol-table.js +48 -0
- package/dist/core/ingestion/tree-sitter-queries.d.ts +20 -0
- package/dist/core/ingestion/tree-sitter-queries.js +691 -0
- package/dist/core/ingestion/type-env.d.ts +52 -0
- package/dist/core/ingestion/type-env.js +349 -0
- package/dist/core/ingestion/type-extractors/c-cpp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/c-cpp.js +214 -0
- package/dist/core/ingestion/type-extractors/csharp.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/csharp.js +224 -0
- package/dist/core/ingestion/type-extractors/go.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/go.js +261 -0
- package/dist/core/ingestion/type-extractors/index.d.ts +20 -0
- package/dist/core/ingestion/type-extractors/index.js +30 -0
- package/dist/core/ingestion/type-extractors/jvm.d.ts +5 -0
- package/dist/core/ingestion/type-extractors/jvm.js +386 -0
- package/dist/core/ingestion/type-extractors/php.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/php.js +280 -0
- package/dist/core/ingestion/type-extractors/python.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/python.js +175 -0
- package/dist/core/ingestion/type-extractors/ruby.d.ts +12 -0
- package/dist/core/ingestion/type-extractors/ruby.js +218 -0
- package/dist/core/ingestion/type-extractors/rust.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/rust.js +290 -0
- package/dist/core/ingestion/type-extractors/shared.d.ts +81 -0
- package/dist/core/ingestion/type-extractors/shared.js +322 -0
- package/dist/core/ingestion/type-extractors/swift.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/swift.js +140 -0
- package/dist/core/ingestion/type-extractors/types.d.ts +111 -0
- package/dist/core/ingestion/type-extractors/types.js +4 -0
- package/dist/core/ingestion/type-extractors/typescript.d.ts +4 -0
- package/dist/core/ingestion/type-extractors/typescript.js +227 -0
- package/dist/core/ingestion/utils.d.ts +73 -0
- package/dist/core/ingestion/utils.js +992 -0
- package/dist/core/ingestion/workers/parse-worker.d.ts +99 -0
- package/dist/core/ingestion/workers/parse-worker.js +1055 -0
- package/dist/core/ingestion/workers/worker-pool.d.ts +15 -0
- package/dist/core/ingestion/workers/worker-pool.js +123 -0
- package/dist/core/lbug/csv-generator.d.ts +28 -0
- package/dist/core/lbug/csv-generator.js +355 -0
- package/dist/core/lbug/lbug-adapter.d.ts +96 -0
- package/dist/core/lbug/lbug-adapter.js +753 -0
- package/dist/core/lbug/schema.d.ts +46 -0
- package/dist/core/lbug/schema.js +402 -0
- package/dist/core/search/bm25-index.d.ts +20 -0
- package/dist/core/search/bm25-index.js +123 -0
- package/dist/core/search/hybrid-search.d.ts +32 -0
- package/dist/core/search/hybrid-search.js +131 -0
- package/dist/core/search/query-cache.d.ts +18 -0
- package/dist/core/search/query-cache.js +47 -0
- package/dist/core/search/query-expansion.d.ts +19 -0
- package/dist/core/search/query-expansion.js +75 -0
- package/dist/core/search/reranker.d.ts +29 -0
- package/dist/core/search/reranker.js +122 -0
- package/dist/core/search/types.d.ts +154 -0
- package/dist/core/search/types.js +51 -0
- package/dist/core/semantic/tsgo-service.d.ts +67 -0
- package/dist/core/semantic/tsgo-service.js +355 -0
- package/dist/core/tree-sitter/parser-loader.d.ts +12 -0
- package/dist/core/tree-sitter/parser-loader.js +71 -0
- package/dist/lib/memory-guard.d.ts +35 -0
- package/dist/lib/memory-guard.js +70 -0
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.js +6 -0
- package/dist/mcp/compatible-stdio-transport.d.ts +32 -0
- package/dist/mcp/compatible-stdio-transport.js +209 -0
- package/dist/mcp/core/embedder.d.ts +24 -0
- package/dist/mcp/core/embedder.js +168 -0
- package/dist/mcp/core/lbug-adapter.d.ts +29 -0
- package/dist/mcp/core/lbug-adapter.js +330 -0
- package/dist/mcp/local/local-backend.d.ts +188 -0
- package/dist/mcp/local/local-backend.js +2759 -0
- package/dist/mcp/resources.d.ts +22 -0
- package/dist/mcp/resources.js +379 -0
- package/dist/mcp/server.d.ts +10 -0
- package/dist/mcp/server.js +217 -0
- package/dist/mcp/staleness.d.ts +10 -0
- package/dist/mcp/staleness.js +25 -0
- package/dist/mcp/tools.d.ts +21 -0
- package/dist/mcp/tools.js +202 -0
- package/dist/server/api.d.ts +5 -0
- package/dist/server/api.js +340 -0
- package/dist/server/mcp-http.d.ts +7 -0
- package/dist/server/mcp-http.js +95 -0
- package/dist/storage/git.d.ts +6 -0
- package/dist/storage/git.js +35 -0
- package/dist/storage/repo-manager.d.ts +87 -0
- package/dist/storage/repo-manager.js +249 -0
- package/dist/types/pipeline.d.ts +35 -0
- package/dist/types/pipeline.js +20 -0
- package/hooks/claude/code-mapper-hook.cjs +238 -0
- package/hooks/claude/pre-tool-use.sh +79 -0
- package/hooks/claude/session-start.sh +42 -0
- package/models/mlx-embedder.py +185 -0
- package/package.json +100 -0
- package/scripts/patch-tree-sitter-swift.cjs +74 -0
- package/vendor/leiden/index.cjs +355 -0
- package/vendor/leiden/utils.cjs +392 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graphology Leiden Algorithm
|
|
3
|
+
* ============================
|
|
4
|
+
*
|
|
5
|
+
* JavaScript implementation of the Leiden community detection
|
|
6
|
+
* algorithm for graphology.
|
|
7
|
+
*
|
|
8
|
+
* Vendored from: https://github.com/graphology/graphology/tree/master/src/communities-leiden
|
|
9
|
+
* License: MIT
|
|
10
|
+
*
|
|
11
|
+
* [Reference]
|
|
12
|
+
* Traag, V. A., et al. "From Louvain to Leiden: Guaranteeing Well-Connected
|
|
13
|
+
* Communities". Scientific Reports, vol. 9, no 1, 2019, p. 5233.
|
|
14
|
+
* https://arxiv.org/abs/1810.08473
|
|
15
|
+
*/
|
|
16
|
+
var resolveDefaults = require('graphology-utils/defaults');
|
|
17
|
+
var isGraph = require('graphology-utils/is-graph');
|
|
18
|
+
var inferType = require('graphology-utils/infer-type');
|
|
19
|
+
var SparseMap = require('mnemonist/sparse-map');
|
|
20
|
+
var SparseQueueSet = require('mnemonist/sparse-queue-set');
|
|
21
|
+
var createRandomIndex = require('pandemonium/random-index').createRandomIndex;
|
|
22
|
+
var utils = require('./utils.cjs');
|
|
23
|
+
|
|
24
|
+
var indices = require('graphology-indices/louvain');
|
|
25
|
+
var addWeightToCommunity = utils.addWeightToCommunity;
|
|
26
|
+
|
|
27
|
+
var UndirectedLouvainIndex = indices.UndirectedLouvainIndex;
|
|
28
|
+
|
|
29
|
+
var UndirectedLeidenAddenda = utils.UndirectedLeidenAddenda;
|
|
30
|
+
|
|
31
|
+
var DEFAULTS = {
|
|
32
|
+
attributes: {
|
|
33
|
+
community: 'community',
|
|
34
|
+
weight: 'weight'
|
|
35
|
+
},
|
|
36
|
+
randomness: 0.01,
|
|
37
|
+
randomWalk: true,
|
|
38
|
+
resolution: 1,
|
|
39
|
+
rng: Math.random,
|
|
40
|
+
weighted: false
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var EPSILON = 1e-10;
|
|
44
|
+
|
|
45
|
+
function tieBreaker(
|
|
46
|
+
bestCommunity,
|
|
47
|
+
currentCommunity,
|
|
48
|
+
targetCommunity,
|
|
49
|
+
delta,
|
|
50
|
+
bestDelta
|
|
51
|
+
) {
|
|
52
|
+
if (Math.abs(delta - bestDelta) < EPSILON) {
|
|
53
|
+
if (bestCommunity === currentCommunity) {
|
|
54
|
+
return false;
|
|
55
|
+
} else {
|
|
56
|
+
return targetCommunity > bestCommunity;
|
|
57
|
+
}
|
|
58
|
+
} else if (delta > bestDelta) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function undirectedLeiden(detailed, graph, options) {
|
|
66
|
+
var index = new UndirectedLouvainIndex(graph, {
|
|
67
|
+
attributes: {
|
|
68
|
+
weight: options.attributes.weight
|
|
69
|
+
},
|
|
70
|
+
keepDendrogram: detailed,
|
|
71
|
+
resolution: options.resolution,
|
|
72
|
+
weighted: options.weighted
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
var addenda = new UndirectedLeidenAddenda(index, {
|
|
76
|
+
randomness: options.randomness,
|
|
77
|
+
rng: options.rng
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
var randomIndex = createRandomIndex(options.rng);
|
|
81
|
+
|
|
82
|
+
// Communities
|
|
83
|
+
var currentCommunity, targetCommunity;
|
|
84
|
+
var communities = new SparseMap(Float64Array, index.C);
|
|
85
|
+
|
|
86
|
+
// Traversal
|
|
87
|
+
var queue = new SparseQueueSet(index.C),
|
|
88
|
+
start,
|
|
89
|
+
end,
|
|
90
|
+
weight,
|
|
91
|
+
ci,
|
|
92
|
+
ri,
|
|
93
|
+
s,
|
|
94
|
+
i,
|
|
95
|
+
j,
|
|
96
|
+
l;
|
|
97
|
+
|
|
98
|
+
// Metrics
|
|
99
|
+
var degree, targetCommunityDegree;
|
|
100
|
+
|
|
101
|
+
// Moves
|
|
102
|
+
var bestCommunity, bestDelta, deltaIsBetter, delta;
|
|
103
|
+
|
|
104
|
+
// Details
|
|
105
|
+
var deltaComputations = 0,
|
|
106
|
+
nodesVisited = 0,
|
|
107
|
+
moves = [],
|
|
108
|
+
currentMoves;
|
|
109
|
+
|
|
110
|
+
while (true) {
|
|
111
|
+
l = index.C;
|
|
112
|
+
|
|
113
|
+
currentMoves = 0;
|
|
114
|
+
|
|
115
|
+
// Traversal of the graph
|
|
116
|
+
ri = options.randomWalk ? randomIndex(l) : 0;
|
|
117
|
+
|
|
118
|
+
for (s = 0; s < l; s++, ri++) {
|
|
119
|
+
i = ri % l;
|
|
120
|
+
queue.enqueue(i);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
while (queue.size !== 0) {
|
|
124
|
+
i = queue.dequeue();
|
|
125
|
+
nodesVisited++;
|
|
126
|
+
|
|
127
|
+
degree = 0;
|
|
128
|
+
communities.clear();
|
|
129
|
+
|
|
130
|
+
currentCommunity = index.belongings[i];
|
|
131
|
+
|
|
132
|
+
start = index.starts[i];
|
|
133
|
+
end = index.starts[i + 1];
|
|
134
|
+
|
|
135
|
+
// Traversing neighbors
|
|
136
|
+
for (; start < end; start++) {
|
|
137
|
+
j = index.neighborhood[start];
|
|
138
|
+
weight = index.weights[start];
|
|
139
|
+
|
|
140
|
+
targetCommunity = index.belongings[j];
|
|
141
|
+
|
|
142
|
+
// Incrementing metrics
|
|
143
|
+
degree += weight;
|
|
144
|
+
addWeightToCommunity(communities, targetCommunity, weight);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Finding best community to move to
|
|
148
|
+
bestDelta = index.fastDeltaWithOwnCommunity(
|
|
149
|
+
i,
|
|
150
|
+
degree,
|
|
151
|
+
communities.get(currentCommunity) || 0,
|
|
152
|
+
currentCommunity
|
|
153
|
+
);
|
|
154
|
+
bestCommunity = currentCommunity;
|
|
155
|
+
|
|
156
|
+
for (ci = 0; ci < communities.size; ci++) {
|
|
157
|
+
targetCommunity = communities.dense[ci];
|
|
158
|
+
|
|
159
|
+
if (targetCommunity === currentCommunity) continue;
|
|
160
|
+
|
|
161
|
+
targetCommunityDegree = communities.vals[ci];
|
|
162
|
+
|
|
163
|
+
deltaComputations++;
|
|
164
|
+
|
|
165
|
+
delta = index.fastDelta(
|
|
166
|
+
i,
|
|
167
|
+
degree,
|
|
168
|
+
targetCommunityDegree,
|
|
169
|
+
targetCommunity
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
deltaIsBetter = tieBreaker(
|
|
173
|
+
bestCommunity,
|
|
174
|
+
currentCommunity,
|
|
175
|
+
targetCommunity,
|
|
176
|
+
delta,
|
|
177
|
+
bestDelta
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
if (deltaIsBetter) {
|
|
181
|
+
bestDelta = delta;
|
|
182
|
+
bestCommunity = targetCommunity;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (bestDelta < 0) {
|
|
187
|
+
bestCommunity = index.isolate(i, degree);
|
|
188
|
+
|
|
189
|
+
if (bestCommunity === currentCommunity) continue;
|
|
190
|
+
} else {
|
|
191
|
+
if (bestCommunity === currentCommunity) {
|
|
192
|
+
continue;
|
|
193
|
+
} else {
|
|
194
|
+
index.move(i, degree, bestCommunity);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
currentMoves++;
|
|
199
|
+
|
|
200
|
+
// Adding neighbors from other communities to the queue
|
|
201
|
+
start = index.starts[i];
|
|
202
|
+
end = index.starts[i + 1];
|
|
203
|
+
|
|
204
|
+
for (; start < end; start++) {
|
|
205
|
+
j = index.neighborhood[start];
|
|
206
|
+
targetCommunity = index.belongings[j];
|
|
207
|
+
|
|
208
|
+
if (targetCommunity !== bestCommunity) queue.enqueue(j);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
moves.push(currentMoves);
|
|
213
|
+
|
|
214
|
+
if (currentMoves === 0) {
|
|
215
|
+
index.zoomOut();
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (!addenda.onlySingletons()) {
|
|
220
|
+
// We continue working on the induced graph
|
|
221
|
+
addenda.zoomOut();
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var results = {
|
|
229
|
+
index: index,
|
|
230
|
+
deltaComputations: deltaComputations,
|
|
231
|
+
nodesVisited: nodesVisited,
|
|
232
|
+
moves: moves
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return results;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Function returning the communities mapping of the graph.
|
|
240
|
+
*
|
|
241
|
+
* @param {boolean} assign - Assign communities to nodes attributes?
|
|
242
|
+
* @param {boolean} detailed - Whether to return detailed information.
|
|
243
|
+
* @param {Graph} graph - Target graph.
|
|
244
|
+
* @param {object} options - Options:
|
|
245
|
+
* @param {object} attributes - Attribute names:
|
|
246
|
+
* @param {string} community - Community node attribute name.
|
|
247
|
+
* @param {string} weight - Weight edge attribute name.
|
|
248
|
+
* @param {number} randomness - Randomness parameter.
|
|
249
|
+
* @param {boolean} randomWalk - Whether to traverse the graph in random order.
|
|
250
|
+
* @param {number} resolution - Resolution parameter.
|
|
251
|
+
* @param {function} rng - RNG function to use.
|
|
252
|
+
* @param {boolean} weighted - Whether to compute the weighted version.
|
|
253
|
+
* @return {object}
|
|
254
|
+
*/
|
|
255
|
+
function leiden(assign, detailed, graph, options) {
|
|
256
|
+
if (!isGraph(graph))
|
|
257
|
+
throw new Error(
|
|
258
|
+
'graphology-communities-leiden: the given graph is not a valid graphology instance.'
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
var type = inferType(graph);
|
|
262
|
+
|
|
263
|
+
if (type === 'mixed')
|
|
264
|
+
throw new Error(
|
|
265
|
+
'graphology-communities-leiden: cannot run the algorithm on a true mixed graph.'
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
if (type === 'directed')
|
|
269
|
+
throw new Error(
|
|
270
|
+
'graphology-communities-leiden: not yet implemented for directed graphs.'
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
// Attributes name
|
|
274
|
+
options = resolveDefaults(options, DEFAULTS);
|
|
275
|
+
|
|
276
|
+
// Empty graph case
|
|
277
|
+
var c = 0;
|
|
278
|
+
|
|
279
|
+
if (graph.size === 0) {
|
|
280
|
+
if (assign) {
|
|
281
|
+
graph.forEachNode(function (node) {
|
|
282
|
+
graph.setNodeAttribute(node, options.attributes.communities, c++);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
var communities = {};
|
|
289
|
+
|
|
290
|
+
graph.forEachNode(function (node) {
|
|
291
|
+
communities[node] = c++;
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
if (!detailed) return communities;
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
communities: communities,
|
|
298
|
+
count: graph.order,
|
|
299
|
+
deltaComputations: 0,
|
|
300
|
+
dendrogram: null,
|
|
301
|
+
level: 0,
|
|
302
|
+
modularity: NaN,
|
|
303
|
+
moves: null,
|
|
304
|
+
nodesVisited: 0,
|
|
305
|
+
resolution: options.resolution
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
var fn = undirectedLeiden;
|
|
310
|
+
|
|
311
|
+
var results = fn(detailed, graph, options);
|
|
312
|
+
|
|
313
|
+
var index = results.index;
|
|
314
|
+
|
|
315
|
+
// Standard output
|
|
316
|
+
if (!detailed) {
|
|
317
|
+
if (assign) {
|
|
318
|
+
index.assign(options.attributes.community);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return index.collect();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Detailed output
|
|
326
|
+
var output = {
|
|
327
|
+
count: index.C,
|
|
328
|
+
deltaComputations: results.deltaComputations,
|
|
329
|
+
dendrogram: index.dendrogram,
|
|
330
|
+
level: index.level,
|
|
331
|
+
modularity: index.modularity(),
|
|
332
|
+
moves: results.moves,
|
|
333
|
+
nodesVisited: results.nodesVisited,
|
|
334
|
+
resolution: options.resolution
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
if (assign) {
|
|
338
|
+
index.assign(options.attributes.community);
|
|
339
|
+
return output;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
output.communities = index.collect();
|
|
343
|
+
|
|
344
|
+
return output;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Exporting.
|
|
349
|
+
*/
|
|
350
|
+
var fn = leiden.bind(null, false, false);
|
|
351
|
+
fn.assign = leiden.bind(null, true, false);
|
|
352
|
+
fn.detailed = leiden.bind(null, false, true);
|
|
353
|
+
fn.defaults = DEFAULTS;
|
|
354
|
+
|
|
355
|
+
module.exports = fn;
|