sxng-cli 1.0.9 → 1.1.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/dist/commands/graph-add.d.ts.map +1 -1
- package/dist/commands/graph-add.js +9 -1
- package/dist/commands/graph-add.js.map +1 -1
- package/dist/commands/graph-drill.d.ts +11 -0
- package/dist/commands/graph-drill.d.ts.map +1 -0
- package/dist/commands/graph-drill.js +26 -0
- package/dist/commands/graph-drill.js.map +1 -0
- package/dist/commands/graph-explore.d.ts +10 -0
- package/dist/commands/graph-explore.d.ts.map +1 -0
- package/dist/commands/graph-explore.js +32 -0
- package/dist/commands/graph-explore.js.map +1 -0
- package/dist/commands/graph-obfuscate.d.ts +17 -0
- package/dist/commands/graph-obfuscate.d.ts.map +1 -0
- package/dist/commands/graph-obfuscate.js +110 -0
- package/dist/commands/graph-obfuscate.js.map +1 -0
- package/dist/commands/graph-search.d.ts +11 -0
- package/dist/commands/graph-search.d.ts.map +1 -0
- package/dist/commands/graph-search.js +19 -0
- package/dist/commands/graph-search.js.map +1 -0
- package/dist/commands/graph-traverse.d.ts +10 -0
- package/dist/commands/graph-traverse.d.ts.map +1 -0
- package/dist/commands/graph-traverse.js +39 -0
- package/dist/commands/graph-traverse.js.map +1 -0
- package/dist/commands/query-graph.d.ts +2 -0
- package/dist/commands/query-graph.d.ts.map +1 -1
- package/dist/commands/query-graph.js +66 -0
- package/dist/commands/query-graph.js.map +1 -1
- package/dist/deep/co-occurrence.d.ts +50 -0
- package/dist/deep/co-occurrence.d.ts.map +1 -0
- package/dist/deep/co-occurrence.js +95 -0
- package/dist/deep/co-occurrence.js.map +1 -0
- package/dist/deep/degree-utils.d.ts +39 -0
- package/dist/deep/degree-utils.d.ts.map +1 -0
- package/dist/deep/degree-utils.js +42 -0
- package/dist/deep/degree-utils.js.map +1 -0
- package/dist/deep/extractor.d.ts +7 -2
- package/dist/deep/extractor.d.ts.map +1 -1
- package/dist/deep/extractor.js +143 -78
- package/dist/deep/extractor.js.map +1 -1
- package/dist/deep/graph-explore.d.ts +115 -0
- package/dist/deep/graph-explore.d.ts.map +1 -0
- package/dist/deep/graph-explore.js +586 -0
- package/dist/deep/graph-explore.js.map +1 -0
- package/dist/deep/graph-obfuscate.d.ts +51 -0
- package/dist/deep/graph-obfuscate.d.ts.map +1 -0
- package/dist/deep/graph-obfuscate.js +226 -0
- package/dist/deep/graph-obfuscate.js.map +1 -0
- package/dist/deep/graph-preprocess.d.ts +41 -0
- package/dist/deep/graph-preprocess.d.ts.map +1 -0
- package/dist/deep/graph-preprocess.js +32 -0
- package/dist/deep/graph-preprocess.js.map +1 -0
- package/dist/deep/graph-sampling.d.ts +51 -0
- package/dist/deep/graph-sampling.d.ts.map +1 -0
- package/dist/deep/graph-sampling.js +409 -0
- package/dist/deep/graph-sampling.js.map +1 -0
- package/dist/deep/graph.d.ts +24 -1
- package/dist/deep/graph.d.ts.map +1 -1
- package/dist/deep/graph.js +42 -1
- package/dist/deep/graph.js.map +1 -1
- package/dist/deep/iteration-data.d.ts +38 -0
- package/dist/deep/iteration-data.d.ts.map +1 -0
- package/dist/deep/iteration-data.js +48 -0
- package/dist/deep/iteration-data.js.map +1 -0
- package/dist/deep/path-extraction.d.ts +53 -0
- package/dist/deep/path-extraction.d.ts.map +1 -0
- package/dist/deep/path-extraction.js +229 -0
- package/dist/deep/path-extraction.js.map +1 -0
- package/dist/deep/quality-assess.d.ts +45 -0
- package/dist/deep/quality-assess.d.ts.map +1 -0
- package/dist/deep/quality-assess.js +125 -0
- package/dist/deep/quality-assess.js.map +1 -0
- package/dist/deep/query-redundancy.d.ts +39 -0
- package/dist/deep/query-redundancy.d.ts.map +1 -0
- package/dist/deep/query-redundancy.js +109 -0
- package/dist/deep/query-redundancy.js.map +1 -0
- package/dist/deep/query-suggest.d.ts +35 -0
- package/dist/deep/query-suggest.d.ts.map +1 -0
- package/dist/deep/query-suggest.js +98 -0
- package/dist/deep/query-suggest.js.map +1 -0
- package/dist/deep/recovery-analysis.d.ts +61 -0
- package/dist/deep/recovery-analysis.d.ts.map +1 -0
- package/dist/deep/recovery-analysis.js +188 -0
- package/dist/deep/recovery-analysis.js.map +1 -0
- package/dist/deep/search-strategy.d.ts +37 -0
- package/dist/deep/search-strategy.d.ts.map +1 -0
- package/dist/deep/search-strategy.js +99 -0
- package/dist/deep/search-strategy.js.map +1 -0
- package/dist/deep/session.d.ts +2 -0
- package/dist/deep/session.d.ts.map +1 -1
- package/dist/deep/session.js +1 -1
- package/dist/deep/session.js.map +1 -1
- package/dist/deep/simhash.d.ts +5 -0
- package/dist/deep/simhash.d.ts.map +1 -1
- package/dist/deep/simhash.js +16 -0
- package/dist/deep/simhash.js.map +1 -1
- package/dist/deep/tfidf.d.ts +38 -0
- package/dist/deep/tfidf.d.ts.map +1 -0
- package/dist/deep/tfidf.js +103 -0
- package/dist/deep/tfidf.js.map +1 -0
- package/dist/runCli.d.ts +3 -1
- package/dist/runCli.d.ts.map +1 -1
- package/dist/runCli.js +762 -307
- package/dist/runCli.js.map +1 -1
- package/package.json +17 -4
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity obfuscation (MTG-inspired) for knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Primary flow: Agent (LLM) generates obfuscated labels.
|
|
5
|
+
* Fallback flow: simple rule-based obfuscation (experimental).
|
|
6
|
+
*
|
|
7
|
+
* The `graph-obfuscate` command outputs candidate entities for obfuscation,
|
|
8
|
+
* then the Agent uses LLM to produce obfuscated labels and writes them
|
|
9
|
+
* back via `graph-add`.
|
|
10
|
+
*
|
|
11
|
+
* Fallback rules are intentionally weak — they preserve too many
|
|
12
|
+
* identifying cues. Marked as experimental, not for production use.
|
|
13
|
+
*/
|
|
14
|
+
import { DirectedGraph } from 'graphology';
|
|
15
|
+
import { GraphNodeAttrs, GraphEdgeAttrs } from './graph.js';
|
|
16
|
+
export interface ObfuscationCandidate {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
entityType?: string;
|
|
20
|
+
score?: number;
|
|
21
|
+
hasObfuscatedLabel: boolean;
|
|
22
|
+
obfuscatedLabel?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface FallbackRuleResult {
|
|
25
|
+
original: string;
|
|
26
|
+
obfuscated: string;
|
|
27
|
+
rule: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ObfuscationResult {
|
|
30
|
+
mode: 'list' | 'fallback_rules';
|
|
31
|
+
candidates: ObfuscationCandidate[];
|
|
32
|
+
fallbackResults?: FallbackRuleResult[];
|
|
33
|
+
stats: {
|
|
34
|
+
totalEntities: number;
|
|
35
|
+
alreadyObfuscated: number;
|
|
36
|
+
needObfuscation: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface ObfuscationConfig {
|
|
40
|
+
mode: 'list' | 'fallback_rules';
|
|
41
|
+
/** Entity types to skip during obfuscation (e.g. "concept" may be too vague) */
|
|
42
|
+
skipEntityTypes?: string[];
|
|
43
|
+
}
|
|
44
|
+
/** List entities that are candidates for obfuscation (those without obfuscatedLabel). */
|
|
45
|
+
export declare function listObfuscationCandidates(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, config?: ObfuscationConfig): ObfuscationResult;
|
|
46
|
+
/** Apply fallback rules to all entities without obfuscatedLabel and write results to graph.
|
|
47
|
+
* Returns the list of applied rules. */
|
|
48
|
+
export declare function applyFallbackRules(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, config?: ObfuscationConfig): ObfuscationResult;
|
|
49
|
+
/** Run entity obfuscation on a graph. */
|
|
50
|
+
export declare function runGraphObfuscate(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, config: ObfuscationConfig): ObfuscationResult;
|
|
51
|
+
//# sourceMappingURL=graph-obfuscate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-obfuscate.d.ts","sourceRoot":"","sources":["../../src/deep/graph-obfu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CAAyC;AACzC,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,MAAM,EAAE,iBAAiB,GAC1B,iBAAiB,CAanB"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity obfuscation (MTG-inspired) for knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Primary flow: Agent (LLM) generates obfuscated labels.
|
|
5
|
+
* Fallback flow: simple rule-based obfuscation (experimental).
|
|
6
|
+
*
|
|
7
|
+
* The `graph-obfuscate` command outputs candidate entities for obfuscation,
|
|
8
|
+
* then the Agent uses LLM to produce obfuscated labels and writes them
|
|
9
|
+
* back via `graph-add`.
|
|
10
|
+
*
|
|
11
|
+
* Fallback rules are intentionally weak — they preserve too many
|
|
12
|
+
* identifying cues. Marked as experimental, not for production use.
|
|
13
|
+
*/
|
|
14
|
+
// ── List candidates ───────────────────────────────────────────────
|
|
15
|
+
/** List entities that are candidates for obfuscation (those without obfuscatedLabel). */
|
|
16
|
+
export function listObfuscationCandidates(graph, config) {
|
|
17
|
+
const candidates = [];
|
|
18
|
+
let totalEntities = 0;
|
|
19
|
+
let alreadyObfuscated = 0;
|
|
20
|
+
const skipTypes = new Set(config?.skipEntityTypes ?? []);
|
|
21
|
+
graph.forEachNode((node, attrs) => {
|
|
22
|
+
if (attrs.type !== 'entity')
|
|
23
|
+
return;
|
|
24
|
+
totalEntities++;
|
|
25
|
+
if (skipTypes.has(attrs.entityType ?? ''))
|
|
26
|
+
return;
|
|
27
|
+
const hasObfuscated = !!attrs.obfuscatedLabel;
|
|
28
|
+
if (hasObfuscated) {
|
|
29
|
+
alreadyObfuscated++;
|
|
30
|
+
}
|
|
31
|
+
candidates.push({
|
|
32
|
+
id: node,
|
|
33
|
+
label: attrs.label,
|
|
34
|
+
entityType: attrs.entityType,
|
|
35
|
+
score: attrs.score,
|
|
36
|
+
hasObfuscatedLabel: hasObfuscated,
|
|
37
|
+
obfuscatedLabel: attrs.obfuscatedLabel,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
const needObfuscation = totalEntities - alreadyObfuscated;
|
|
41
|
+
return {
|
|
42
|
+
mode: 'list',
|
|
43
|
+
candidates,
|
|
44
|
+
stats: { totalEntities, alreadyObfuscated, needObfuscation },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// ── Fallback rules (experimental) ────────────────────────────────
|
|
48
|
+
/** Version number removal: "TypeScript 5.8" → "TypeScript latest"
|
|
49
|
+
* Matches trailing version patterns like "5.8", "19", "v3.2.1"
|
|
50
|
+
* Excludes 4-digit years (dates) which are handled by generalizeDate. */
|
|
51
|
+
function removeVersion(label) {
|
|
52
|
+
// Match labels ending with version-like suffixes, but NOT bare 4-digit years
|
|
53
|
+
const versionPattern = /^(.+?)\s+v?(\d+\.\d+(?:\.\d+)*|\d{1,3})$/;
|
|
54
|
+
const match = label.match(versionPattern);
|
|
55
|
+
if (match) {
|
|
56
|
+
return {
|
|
57
|
+
original: label,
|
|
58
|
+
obfuscated: `${match[1].trim()} latest`,
|
|
59
|
+
rule: 'remove_version',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/** Category replacement: known software/framework names → generic category.
|
|
65
|
+
* Uses entityType if available, otherwise heuristics. */
|
|
66
|
+
function replaceWithCategory(label, entityType) {
|
|
67
|
+
const CATEGORY_MAP = {
|
|
68
|
+
runtime: 'a runtime',
|
|
69
|
+
library: 'a library',
|
|
70
|
+
framework: 'a framework',
|
|
71
|
+
language: 'a programming language',
|
|
72
|
+
tool: 'a development tool',
|
|
73
|
+
database: 'a database',
|
|
74
|
+
protocol: 'a protocol',
|
|
75
|
+
platform: 'a platform',
|
|
76
|
+
service: 'a service',
|
|
77
|
+
organization: 'an organization',
|
|
78
|
+
person: 'a person',
|
|
79
|
+
};
|
|
80
|
+
if (entityType && CATEGORY_MAP[entityType]) {
|
|
81
|
+
return {
|
|
82
|
+
original: label,
|
|
83
|
+
obfuscated: CATEGORY_MAP[entityType],
|
|
84
|
+
rule: 'category_replacement',
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
/** Date generalization: "February 2026" → "early 2026", "Q3 2025" → "mid 2025"
|
|
90
|
+
* Matches month names, quarters, and specific date patterns. */
|
|
91
|
+
function generalizeDate(label) {
|
|
92
|
+
const MONTH_QUARTER_MAP = {
|
|
93
|
+
'january': 'early', 'february': 'early', 'march': 'early',
|
|
94
|
+
'april': 'mid', 'may': 'mid', 'june': 'mid',
|
|
95
|
+
'july': 'late', 'august': 'late', 'september': 'late',
|
|
96
|
+
'october': 'late', 'november': 'late', 'december': 'late',
|
|
97
|
+
'q1': 'early', 'q2': 'mid', 'q3': 'late', 'q4': 'late',
|
|
98
|
+
};
|
|
99
|
+
// "February 2026" or "Feb 2026"
|
|
100
|
+
const monthYearPattern = /^(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec)\s+(\d{4})$/i;
|
|
101
|
+
const match = label.match(monthYearPattern);
|
|
102
|
+
if (match) {
|
|
103
|
+
const month = match[1].toLowerCase().slice(0, 3);
|
|
104
|
+
const year = match[2];
|
|
105
|
+
// Normalize abbreviated months
|
|
106
|
+
const fullMonth = {
|
|
107
|
+
jan: 'january', feb: 'february', mar: 'march', apr: 'april',
|
|
108
|
+
jun: 'june', jul: 'july', aug: 'august', sep: 'september',
|
|
109
|
+
oct: 'october', nov: 'november', dec: 'december',
|
|
110
|
+
};
|
|
111
|
+
const normalized = fullMonth[month] || month;
|
|
112
|
+
const period = MONTH_QUARTER_MAP[normalized];
|
|
113
|
+
if (period) {
|
|
114
|
+
return {
|
|
115
|
+
original: label,
|
|
116
|
+
obfuscated: `${period} ${year}`,
|
|
117
|
+
rule: 'date_generalization',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// "Q3 2025" pattern
|
|
122
|
+
const quarterPattern = /^(q[1-4])\s+(\d{4})$/i;
|
|
123
|
+
const qMatch = label.match(quarterPattern);
|
|
124
|
+
if (qMatch) {
|
|
125
|
+
const quarter = qMatch[1].toLowerCase();
|
|
126
|
+
const year = qMatch[2];
|
|
127
|
+
const period = MONTH_QUARTER_MAP[quarter];
|
|
128
|
+
if (period) {
|
|
129
|
+
return {
|
|
130
|
+
original: label,
|
|
131
|
+
obfuscated: `${period} ${year}`,
|
|
132
|
+
rule: 'date_generalization',
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
/** Apply fallback obfuscation rules in priority order:
|
|
139
|
+
* 1. Date generalization (before version removal to avoid "February 2026" → "February latest")
|
|
140
|
+
* 2. Version removal
|
|
141
|
+
* 3. Category replacement
|
|
142
|
+
*
|
|
143
|
+
* ⚠️ Fallback rules are experimental — they preserve too many
|
|
144
|
+
* identifying cues for true MTG-style obfuscation. */
|
|
145
|
+
function applyFallbackRule(label, entityType) {
|
|
146
|
+
return generalizeDate(label) || removeVersion(label) || replaceWithCategory(label, entityType);
|
|
147
|
+
}
|
|
148
|
+
/** Apply fallback rules to all entities without obfuscatedLabel and write results to graph.
|
|
149
|
+
* Returns the list of applied rules. */
|
|
150
|
+
export function applyFallbackRules(graph, config) {
|
|
151
|
+
const skipTypes = new Set(config?.skipEntityTypes ?? []);
|
|
152
|
+
const fallbackResults = [];
|
|
153
|
+
let totalEntities = 0;
|
|
154
|
+
let alreadyObfuscated = 0;
|
|
155
|
+
let needObfuscation = 0;
|
|
156
|
+
const candidates = [];
|
|
157
|
+
graph.forEachNode((node, attrs) => {
|
|
158
|
+
if (attrs.type !== 'entity')
|
|
159
|
+
return;
|
|
160
|
+
totalEntities++;
|
|
161
|
+
if (skipTypes.has(attrs.entityType ?? ''))
|
|
162
|
+
return;
|
|
163
|
+
if (attrs.obfuscatedLabel) {
|
|
164
|
+
alreadyObfuscated++;
|
|
165
|
+
candidates.push({
|
|
166
|
+
id: node,
|
|
167
|
+
label: attrs.label,
|
|
168
|
+
entityType: attrs.entityType,
|
|
169
|
+
score: attrs.score,
|
|
170
|
+
hasObfuscatedLabel: true,
|
|
171
|
+
obfuscatedLabel: attrs.obfuscatedLabel,
|
|
172
|
+
});
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
needObfuscation++;
|
|
176
|
+
const result = applyFallbackRule(attrs.label, attrs.entityType);
|
|
177
|
+
if (result) {
|
|
178
|
+
// Write obfuscatedLabel back to graph node
|
|
179
|
+
graph.mergeNode(node, {
|
|
180
|
+
...attrs,
|
|
181
|
+
obfuscatedLabel: result.obfuscated,
|
|
182
|
+
});
|
|
183
|
+
fallbackResults.push(result);
|
|
184
|
+
candidates.push({
|
|
185
|
+
id: node,
|
|
186
|
+
label: attrs.label,
|
|
187
|
+
entityType: attrs.entityType,
|
|
188
|
+
score: attrs.score,
|
|
189
|
+
hasObfuscatedLabel: true,
|
|
190
|
+
obfuscatedLabel: result.obfuscated,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
candidates.push({
|
|
195
|
+
id: node,
|
|
196
|
+
label: attrs.label,
|
|
197
|
+
entityType: attrs.entityType,
|
|
198
|
+
score: attrs.score,
|
|
199
|
+
hasObfuscatedLabel: false,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
mode: 'fallback_rules',
|
|
205
|
+
candidates,
|
|
206
|
+
fallbackResults,
|
|
207
|
+
stats: { totalEntities, alreadyObfuscated, needObfuscation },
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
// ── Main dispatch ─────────────────────────────────────────────────
|
|
211
|
+
/** Run entity obfuscation on a graph. */
|
|
212
|
+
export function runGraphObfuscate(graph, config) {
|
|
213
|
+
switch (config.mode) {
|
|
214
|
+
case 'list':
|
|
215
|
+
return listObfuscationCandidates(graph, config);
|
|
216
|
+
case 'fallback_rules':
|
|
217
|
+
return applyFallbackRules(graph, config);
|
|
218
|
+
default:
|
|
219
|
+
return {
|
|
220
|
+
mode: config.mode,
|
|
221
|
+
candidates: [],
|
|
222
|
+
stats: { totalEntities: 0, alreadyObfuscated: 0, needObfuscation: 0 },
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=graph-obfuscate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-obfuscate.js","sourceRoot":"","sources":["../../src/deep/graph-obfuscate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAuCH,qEAAqE;AAErE,yFAAyF;AACzF,MAAM,UAAU,yBAAyB,CACrC,KAAoD,EACpD,MAA0B;IAE1B,MAAM,UAAU,GAA2B,EAAE,CAAC;IAC9C,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,iBAAiB,GAAG,CAAC,CAAC;IAC1B,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,eAAe,IAAI,EAAE,CAAC,CAAC;IAEzD,KAAK,CAAC,WAAW,CAAC,CAAC,IAAY,EAAE,KAAqB,EAAE,EAAE;QACtD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO;QACpC,aAAa,EAAE,CAAC;QAEhB,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC;YAAE,OAAO;QAElD,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC;QAC9C,IAAI,aAAa,EAAE,CAAC;YAChB,iBAAiB,EAAE,CAAC;QACxB,CAAC;QAED,UAAU,CAAC,IAAI,CAAC;YACZ,EAAE,EAAE,IAAI;YACR,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,kBAAk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CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,IAAI,CAAC;gBACZ,EAAE,EAAE,IAAI;gBACR,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,kBAAkB,EAAE,KAAK;aAC5B,CAAC,CAAC;QACP,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACH,IAAI,EAAE,gBAAgB;QACtB,UAAU;QACV,eAAe;QACf,KAAK,EAAE,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE;KAC/D,CAAC;AACN,CAAC;AAED,qEAAqE;AAErE,yCAAyC;AACzC,MAAM,UAAU,iBAAiB,CAC7B,KAAoD,EACpD,MAAyB;IAEzB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,MAAM;YACP,OAAO,yBAAyB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACpD,KAAK,gBAAgB;YACjB,OAAO,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7C;YACI,OAAO;gBACH,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,UAAU,EAAE,EAAE;gBACd,KAAK,EAAE,EAAE,aAAa,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC,EAAE;aACxE,CAAC;IACV,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graph-preprocess: Preprocess session data to produce TF-IDF terms,
|
|
3
|
+
* co-occurrence pairs, and existing entity context for Agent consumption.
|
|
4
|
+
*/
|
|
5
|
+
export interface PreprocessResult {
|
|
6
|
+
tfidfTerms: Array<{
|
|
7
|
+
term: string;
|
|
8
|
+
tf: number;
|
|
9
|
+
idf: number;
|
|
10
|
+
tfidf: number;
|
|
11
|
+
docFreq: number;
|
|
12
|
+
}>;
|
|
13
|
+
coOccurrences: Array<{
|
|
14
|
+
term1: string;
|
|
15
|
+
term2: string;
|
|
16
|
+
count: number;
|
|
17
|
+
}>;
|
|
18
|
+
existingEntities: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
label: string;
|
|
21
|
+
degree: number;
|
|
22
|
+
entityType?: string;
|
|
23
|
+
}>;
|
|
24
|
+
termFrequencies: Array<{
|
|
25
|
+
term: string;
|
|
26
|
+
count: number;
|
|
27
|
+
}>;
|
|
28
|
+
roundsCovered: number;
|
|
29
|
+
totalResults: number;
|
|
30
|
+
resultsWithContent: number;
|
|
31
|
+
tokenizationStrategy: string;
|
|
32
|
+
coOccurrenceTruncated: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface PreprocessOptions {
|
|
35
|
+
top?: number;
|
|
36
|
+
coOccurrenceThreshold?: number;
|
|
37
|
+
maxTermsForCoOccurrence?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Run full preprocessing pipeline on a session directory. */
|
|
40
|
+
export declare function graphPreprocess(sessionDir: string, opts?: PreprocessOptions): PreprocessResult;
|
|
41
|
+
//# sourceMappingURL=graph-preprocess.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-preprocess.d.ts","sourceRoot":"","sources":["../../src/deep/graph-preprocess.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,MAAM,WAAW,gBAAgB;IAC7B,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7F,aAAa,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtE,gBAAgB,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5F,eAAe,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,OAAO,CAAC;CAClC;AAED,MAAM,WAAW,iBAAiB;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAC3B,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,iBAAiB,GACzB,gBAAgB,CAwBlB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graph-preprocess: Preprocess session data to produce TF-IDF terms,
|
|
3
|
+
* co-occurrence pairs, and existing entity context for Agent consumption.
|
|
4
|
+
*/
|
|
5
|
+
import { computeTfIdf } from './tfidf.js';
|
|
6
|
+
import { buildCoOccurrence, computeCrossResultFrequency, getExistingEntityContext } from './co-occurrence.js';
|
|
7
|
+
import { loadSessionResults, loadSessionGraph, loadSessionRounds } from './session.js';
|
|
8
|
+
/** Run full preprocessing pipeline on a session directory. */
|
|
9
|
+
export function graphPreprocess(sessionDir, opts) {
|
|
10
|
+
const results = loadSessionResults(sessionDir);
|
|
11
|
+
const graph = loadSessionGraph(sessionDir);
|
|
12
|
+
const rounds = loadSessionRounds(sessionDir);
|
|
13
|
+
const tfidf = computeTfIdf(results, { top: opts?.top });
|
|
14
|
+
const coOcc = buildCoOccurrence(results, {
|
|
15
|
+
threshold: opts?.coOccurrenceThreshold,
|
|
16
|
+
maxTerms: opts?.maxTermsForCoOccurrence,
|
|
17
|
+
});
|
|
18
|
+
const termFreqs = computeCrossResultFrequency(results, { top: opts?.top ?? 50 });
|
|
19
|
+
const entities = getExistingEntityContext(graph);
|
|
20
|
+
return {
|
|
21
|
+
tfidfTerms: tfidf.terms,
|
|
22
|
+
coOccurrences: coOcc.pairs,
|
|
23
|
+
existingEntities: entities,
|
|
24
|
+
termFrequencies: termFreqs,
|
|
25
|
+
roundsCovered: rounds,
|
|
26
|
+
totalResults: results.length,
|
|
27
|
+
resultsWithContent: tfidf.resultsWithContent,
|
|
28
|
+
tokenizationStrategy: tfidf.tokenizationStrategy,
|
|
29
|
+
coOccurrenceTruncated: coOcc.truncated,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=graph-preprocess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-preprocess.js","sourceRoot":"","sources":["../../src/deep/graph-preprocess.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAqBvF,8DAA8D;AAC9D,MAAM,UAAU,eAAe,CAC3B,UAAkB,EAClB,IAAwB;IAExB,MAAM,OAAO,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAkD,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC1F,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAE7C,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;IACxD,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,EAAE;QACrC,SAAS,EAAE,IAAI,EAAE,qBAAqB;QACtC,QAAQ,EAAE,IAAI,EAAE,uBAAuB;KAC1C,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,2BAA2B,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,CAAC;IACjF,MAAM,QAAQ,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IAEjD,OAAO;QACH,UAAU,EAAE,KAAK,CAAC,KAAK;QACvB,aAAa,EAAE,KAAK,CAAC,KAAK;QAC1B,gBAAgB,EAAE,QAAQ;QAC1B,eAAe,EAAE,SAAS;QAC1B,aAAa,EAAE,MAAM;QACrB,YAAY,EAAE,OAAO,CAAC,MAAM;QAC5B,kBAAkB,EAAE,KAAK,CAAC,kBAAkB;QAC5C,oBAAoB,EAAE,KAAK,CAAC,oBAAoB;QAChD,qBAAqB,EAAE,KAAK,CAAC,SAAS;KACzC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph sampling strategies for knowledge graph exploration.
|
|
3
|
+
*
|
|
4
|
+
* Given a graph, seed entities, and a strategy, produces a sampled subgraph
|
|
5
|
+
* focused on the most relevant structures for reasoning.
|
|
6
|
+
*
|
|
7
|
+
* Strategies:
|
|
8
|
+
* - augmented_chain: sequential entity chain with attribute enrichment
|
|
9
|
+
* - dual_core_bridge: two seed entities converging on a shared target
|
|
10
|
+
* - community_core_path: high-degree hub → peripheral entities
|
|
11
|
+
* - deep_chain: depth-limited DFS (max 5-8 hops)
|
|
12
|
+
* - mixed: randomly pick one of the above
|
|
13
|
+
*/
|
|
14
|
+
import { DirectedGraph } from 'graphology';
|
|
15
|
+
import { GraphNodeAttrs, GraphEdgeAttrs } from './graph.js';
|
|
16
|
+
export type SamplingStrategy = 'augmented_chain' | 'dual_core_bridge' | 'community_core_path' | 'deep_chain' | 'mixed';
|
|
17
|
+
export interface SamplingConfig {
|
|
18
|
+
strategy: SamplingStrategy;
|
|
19
|
+
seedEntities: string[];
|
|
20
|
+
maxHops: number;
|
|
21
|
+
degreeRange?: {
|
|
22
|
+
min?: number;
|
|
23
|
+
max?: number;
|
|
24
|
+
maxDegreeCap?: number;
|
|
25
|
+
};
|
|
26
|
+
/** Random seed for deterministic output. Used by mixed strategy. */
|
|
27
|
+
rngSeed?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface SampledEntity {
|
|
30
|
+
id: string;
|
|
31
|
+
label: string;
|
|
32
|
+
entityType?: string;
|
|
33
|
+
score?: number;
|
|
34
|
+
degree: number;
|
|
35
|
+
}
|
|
36
|
+
export interface SampledEdge {
|
|
37
|
+
source: string;
|
|
38
|
+
target: string;
|
|
39
|
+
relation: string;
|
|
40
|
+
weight: number;
|
|
41
|
+
}
|
|
42
|
+
export interface SamplingResult {
|
|
43
|
+
strategy: SamplingStrategy;
|
|
44
|
+
entities: SampledEntity[];
|
|
45
|
+
edges: SampledEdge[];
|
|
46
|
+
hopsCovered: number;
|
|
47
|
+
metadata: Record<string, unknown>;
|
|
48
|
+
}
|
|
49
|
+
/** Sample a knowledge graph using the specified strategy. */
|
|
50
|
+
export declare function sampleGraph(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, config: SamplingConfig): SamplingResult;
|
|
51
|
+
//# sourceMappingURL=graph-sampling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-sampling.d.ts","sourceRoot":"","sources":["../../src/deep/graph-sampling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAY,MAAM,YAAY,CAAC;AAKtE,MAAM,MAAM,gBAAgB,GACtB,iBAAiB,GACjB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