@soulcraft/brainy 4.1.3 → 4.2.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 +100 -7
- package/dist/brainy.d.ts +74 -16
- package/dist/brainy.js +74 -16
- package/dist/import/FormatDetector.d.ts +6 -1
- package/dist/import/FormatDetector.js +40 -1
- package/dist/import/ImportCoordinator.d.ts +155 -5
- package/dist/import/ImportCoordinator.js +346 -6
- package/dist/import/InstancePool.d.ts +136 -0
- package/dist/import/InstancePool.js +231 -0
- package/dist/importers/SmartCSVImporter.d.ts +2 -1
- package/dist/importers/SmartCSVImporter.js +11 -22
- package/dist/importers/SmartDOCXImporter.d.ts +125 -0
- package/dist/importers/SmartDOCXImporter.js +227 -0
- package/dist/importers/SmartExcelImporter.d.ts +12 -1
- package/dist/importers/SmartExcelImporter.js +40 -25
- package/dist/importers/SmartJSONImporter.d.ts +1 -0
- package/dist/importers/SmartJSONImporter.js +25 -6
- package/dist/importers/SmartMarkdownImporter.d.ts +2 -1
- package/dist/importers/SmartMarkdownImporter.js +11 -16
- package/dist/importers/SmartPDFImporter.d.ts +2 -1
- package/dist/importers/SmartPDFImporter.js +11 -22
- package/dist/importers/SmartYAMLImporter.d.ts +121 -0
- package/dist/importers/SmartYAMLImporter.js +275 -0
- package/dist/importers/VFSStructureGenerator.js +12 -0
- package/dist/neural/SmartExtractor.d.ts +279 -0
- package/dist/neural/SmartExtractor.js +592 -0
- package/dist/neural/SmartRelationshipExtractor.d.ts +217 -0
- package/dist/neural/SmartRelationshipExtractor.js +396 -0
- package/dist/neural/embeddedTypeEmbeddings.d.ts +1 -1
- package/dist/neural/embeddedTypeEmbeddings.js +2 -2
- package/dist/neural/entityExtractor.d.ts +3 -0
- package/dist/neural/entityExtractor.js +34 -36
- package/dist/neural/presets.d.ts +189 -0
- package/dist/neural/presets.js +365 -0
- package/dist/neural/signals/ContextSignal.d.ts +166 -0
- package/dist/neural/signals/ContextSignal.js +646 -0
- package/dist/neural/signals/EmbeddingSignal.d.ts +175 -0
- package/dist/neural/signals/EmbeddingSignal.js +435 -0
- package/dist/neural/signals/ExactMatchSignal.d.ts +220 -0
- package/dist/neural/signals/ExactMatchSignal.js +542 -0
- package/dist/neural/signals/PatternSignal.d.ts +159 -0
- package/dist/neural/signals/PatternSignal.js +478 -0
- package/dist/neural/signals/VerbContextSignal.d.ts +102 -0
- package/dist/neural/signals/VerbContextSignal.js +390 -0
- package/dist/neural/signals/VerbEmbeddingSignal.d.ts +131 -0
- package/dist/neural/signals/VerbEmbeddingSignal.js +304 -0
- package/dist/neural/signals/VerbExactMatchSignal.d.ts +115 -0
- package/dist/neural/signals/VerbExactMatchSignal.js +335 -0
- package/dist/neural/signals/VerbPatternSignal.d.ts +104 -0
- package/dist/neural/signals/VerbPatternSignal.js +457 -0
- package/dist/types/graphTypes.d.ts +2 -0
- package/package.json +4 -1
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { NeuralEntityExtractor } from '../neural/entityExtractor.js';
|
|
12
12
|
import { NaturalLanguageProcessor } from '../neural/naturalLanguageProcessor.js';
|
|
13
|
+
import { SmartRelationshipExtractor } from '../neural/SmartRelationshipExtractor.js';
|
|
13
14
|
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
14
15
|
import { ExcelHandler } from '../augmentations/intelligentImport/handlers/excelHandler.js';
|
|
15
16
|
/**
|
|
@@ -20,6 +21,7 @@ export class SmartExcelImporter {
|
|
|
20
21
|
this.brain = brain;
|
|
21
22
|
this.extractor = new NeuralEntityExtractor(brain);
|
|
22
23
|
this.nlp = new NaturalLanguageProcessor(brain);
|
|
24
|
+
this.relationshipExtractor = new SmartRelationshipExtractor(brain);
|
|
23
25
|
this.excelHandler = new ExcelHandler();
|
|
24
26
|
}
|
|
25
27
|
/**
|
|
@@ -131,7 +133,9 @@ export class SmartExcelImporter {
|
|
|
131
133
|
if (opts.enableRelationshipInference) {
|
|
132
134
|
// Extract relationships from definition text
|
|
133
135
|
for (const relEntity of relatedEntities) {
|
|
134
|
-
const verbType = await this.inferRelationship(term, relEntity.text, definition
|
|
136
|
+
const verbType = await this.inferRelationship(term, relEntity.text, definition, mainEntityType, // Pass subject type hint
|
|
137
|
+
relEntity.type // Pass object type hint
|
|
138
|
+
);
|
|
135
139
|
relationships.push({
|
|
136
140
|
from: entityId,
|
|
137
141
|
to: relEntity.text,
|
|
@@ -145,10 +149,13 @@ export class SmartExcelImporter {
|
|
|
145
149
|
const terms = relatedTerms.split(/[,;]/).map(t => t.trim()).filter(Boolean);
|
|
146
150
|
for (const relTerm of terms) {
|
|
147
151
|
if (relTerm.toLowerCase() !== term.toLowerCase()) {
|
|
152
|
+
// Use SmartRelationshipExtractor even for explicit relationships
|
|
153
|
+
const verbType = await this.inferRelationship(term, relTerm, `${term} related to ${relTerm}. ${definition}`, // Combine for better context
|
|
154
|
+
mainEntityType);
|
|
148
155
|
relationships.push({
|
|
149
156
|
from: entityId,
|
|
150
157
|
to: relTerm,
|
|
151
|
-
type:
|
|
158
|
+
type: verbType,
|
|
152
159
|
confidence: 0.9,
|
|
153
160
|
evidence: `Explicitly listed in "Related" column`
|
|
154
161
|
});
|
|
@@ -203,6 +210,26 @@ export class SmartExcelImporter {
|
|
|
203
210
|
phase: 'extracting'
|
|
204
211
|
});
|
|
205
212
|
}
|
|
213
|
+
// Group rows by sheet for VFS extraction (v4.2.0)
|
|
214
|
+
const sheetGroups = new Map();
|
|
215
|
+
extractedRows.forEach((extractedRow, index) => {
|
|
216
|
+
const originalRow = rows[index];
|
|
217
|
+
const sheetName = originalRow._sheet || 'Sheet1';
|
|
218
|
+
if (!sheetGroups.has(sheetName)) {
|
|
219
|
+
sheetGroups.set(sheetName, []);
|
|
220
|
+
}
|
|
221
|
+
sheetGroups.get(sheetName).push(extractedRow);
|
|
222
|
+
});
|
|
223
|
+
// Build sheet-specific statistics
|
|
224
|
+
const sheets = Array.from(sheetGroups.entries()).map(([name, sheetRows]) => ({
|
|
225
|
+
name,
|
|
226
|
+
rows: sheetRows,
|
|
227
|
+
stats: {
|
|
228
|
+
rowCount: sheetRows.length,
|
|
229
|
+
entityCount: sheetRows.reduce((sum, row) => sum + 1 + row.relatedEntities.length, 0),
|
|
230
|
+
relationshipCount: sheetRows.reduce((sum, row) => sum + row.relationships.length, 0)
|
|
231
|
+
}
|
|
232
|
+
}));
|
|
206
233
|
return {
|
|
207
234
|
rowsProcessed: rows.length,
|
|
208
235
|
entitiesExtracted: extractedRows.reduce((sum, row) => sum + 1 + row.relatedEntities.length, 0),
|
|
@@ -210,7 +237,8 @@ export class SmartExcelImporter {
|
|
|
210
237
|
rows: extractedRows,
|
|
211
238
|
entityMap,
|
|
212
239
|
processingTime: Date.now() - startTime,
|
|
213
|
-
stats
|
|
240
|
+
stats,
|
|
241
|
+
sheets
|
|
214
242
|
};
|
|
215
243
|
}
|
|
216
244
|
/**
|
|
@@ -270,29 +298,16 @@ export class SmartExcelImporter {
|
|
|
270
298
|
return mapping[normalized] || NounType.Thing;
|
|
271
299
|
}
|
|
272
300
|
/**
|
|
273
|
-
* Infer relationship type from context
|
|
301
|
+
* Infer relationship type from context using SmartRelationshipExtractor
|
|
274
302
|
*/
|
|
275
|
-
async inferRelationship(fromTerm, toTerm, context) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
[new RegExp(`capital.*${toTerm}`, 'i'), VerbType.Contains],
|
|
284
|
-
[new RegExp(`created by.*${toTerm}`, 'i'), VerbType.CreatedBy],
|
|
285
|
-
[new RegExp(`authored by.*${toTerm}`, 'i'), VerbType.CreatedBy],
|
|
286
|
-
[new RegExp(`part of.*${toTerm}`, 'i'), VerbType.PartOf],
|
|
287
|
-
[new RegExp(`related to.*${toTerm}`, 'i'), VerbType.RelatedTo]
|
|
288
|
-
];
|
|
289
|
-
for (const [pattern, verbType] of patterns) {
|
|
290
|
-
if (pattern.test(lowerContext)) {
|
|
291
|
-
return verbType;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
// Default to RelatedTo
|
|
295
|
-
return VerbType.RelatedTo;
|
|
303
|
+
async inferRelationship(fromTerm, toTerm, context, fromType, toType) {
|
|
304
|
+
// Use SmartRelationshipExtractor for robust relationship classification
|
|
305
|
+
const result = await this.relationshipExtractor.infer(fromTerm, toTerm, context, {
|
|
306
|
+
subjectType: fromType,
|
|
307
|
+
objectType: toType
|
|
308
|
+
});
|
|
309
|
+
// Return inferred type or fallback to RelatedTo
|
|
310
|
+
return result?.type || VerbType.RelatedTo;
|
|
296
311
|
}
|
|
297
312
|
/**
|
|
298
313
|
* Generate consistent entity ID from name
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { NeuralEntityExtractor } from '../neural/entityExtractor.js';
|
|
13
13
|
import { NaturalLanguageProcessor } from '../neural/naturalLanguageProcessor.js';
|
|
14
|
+
import { SmartRelationshipExtractor } from '../neural/SmartRelationshipExtractor.js';
|
|
14
15
|
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
15
16
|
/**
|
|
16
17
|
* SmartJSONImporter - Extracts structured knowledge from JSON files
|
|
@@ -20,6 +21,7 @@ export class SmartJSONImporter {
|
|
|
20
21
|
this.brain = brain;
|
|
21
22
|
this.extractor = new NeuralEntityExtractor(brain);
|
|
22
23
|
this.nlp = new NaturalLanguageProcessor(brain);
|
|
24
|
+
this.relationshipExtractor = new SmartRelationshipExtractor(brain);
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Initialize the importer
|
|
@@ -120,12 +122,20 @@ export class SmartJSONImporter {
|
|
|
120
122
|
// Create hierarchical relationship if parent exists
|
|
121
123
|
if (options.enableHierarchicalRelationships && parentPath && entityMap.has(parentPath)) {
|
|
122
124
|
const parentId = entityMap.get(parentPath);
|
|
125
|
+
// Extract parent and child names from paths
|
|
126
|
+
const parentName = parentPath.split('.').pop()?.replace(/\[(\d+)\]/, 'item $1') || 'parent';
|
|
127
|
+
const childName = entity.name;
|
|
128
|
+
// Infer relationship type using SmartRelationshipExtractor
|
|
129
|
+
const context = `Hierarchical JSON structure: ${parentName} contains ${childName}. Parent path: ${parentPath}, Child path: ${path}`;
|
|
130
|
+
const inferredRelationship = await this.relationshipExtractor.infer(parentName, childName, context, {
|
|
131
|
+
objectType: entity.type // Pass child entity type as hint
|
|
132
|
+
});
|
|
123
133
|
relationships.push({
|
|
124
134
|
from: parentId,
|
|
125
135
|
to: entity.id,
|
|
126
|
-
type: VerbType.Contains,
|
|
127
|
-
confidence: 0.95,
|
|
128
|
-
evidence: `Hierarchical relationship: ${parentPath} contains ${path}`
|
|
136
|
+
type: inferredRelationship?.type || VerbType.Contains, // Fallback to Contains for hierarchical relationships
|
|
137
|
+
confidence: inferredRelationship?.confidence || 0.95,
|
|
138
|
+
evidence: inferredRelationship?.evidence || `Hierarchical relationship: ${parentPath} contains ${path}`
|
|
129
139
|
});
|
|
130
140
|
}
|
|
131
141
|
}
|
|
@@ -165,12 +175,21 @@ export class SmartJSONImporter {
|
|
|
165
175
|
// Link to parent if exists
|
|
166
176
|
if (options.enableHierarchicalRelationships && parentPath && entityMap.has(parentPath)) {
|
|
167
177
|
const parentId = entityMap.get(parentPath);
|
|
178
|
+
// Extract parent name from path
|
|
179
|
+
const parentName = parentPath.split('.').pop()?.replace(/\[(\d+)\]/, 'item $1') || 'parent';
|
|
180
|
+
const childName = entity.name;
|
|
181
|
+
// Infer relationship type using SmartRelationshipExtractor
|
|
182
|
+
// Context: entity was extracted from string value within parent container
|
|
183
|
+
const context = `Entity "${childName}" found in text value at path ${path} within parent "${parentName}". Full text: "${node.substring(0, 200)}..."`;
|
|
184
|
+
const inferredRelationship = await this.relationshipExtractor.infer(parentName, childName, context, {
|
|
185
|
+
objectType: entity.type // Pass extracted entity type as hint
|
|
186
|
+
});
|
|
168
187
|
relationships.push({
|
|
169
188
|
from: parentId,
|
|
170
189
|
to: entity.id,
|
|
171
|
-
type: VerbType.RelatedTo,
|
|
172
|
-
confidence: extracted.confidence * 0.9,
|
|
173
|
-
evidence: `Found in: ${path}`
|
|
190
|
+
type: inferredRelationship?.type || VerbType.RelatedTo, // Fallback to RelatedTo for text extraction
|
|
191
|
+
confidence: inferredRelationship?.confidence || (extracted.confidence * 0.9),
|
|
192
|
+
evidence: inferredRelationship?.evidence || `Found in: ${path}`
|
|
174
193
|
});
|
|
175
194
|
}
|
|
176
195
|
}
|
|
@@ -107,6 +107,7 @@ export declare class SmartMarkdownImporter {
|
|
|
107
107
|
private brain;
|
|
108
108
|
private extractor;
|
|
109
109
|
private nlp;
|
|
110
|
+
private relationshipExtractor;
|
|
110
111
|
constructor(brain: Brainy);
|
|
111
112
|
/**
|
|
112
113
|
* Initialize the importer
|
|
@@ -145,7 +146,7 @@ export declare class SmartMarkdownImporter {
|
|
|
145
146
|
*/
|
|
146
147
|
private entitiesAreRelated;
|
|
147
148
|
/**
|
|
148
|
-
* Infer relationship type from context
|
|
149
|
+
* Infer relationship type from context using SmartRelationshipExtractor
|
|
149
150
|
*/
|
|
150
151
|
private inferRelationship;
|
|
151
152
|
/**
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { NeuralEntityExtractor } from '../neural/entityExtractor.js';
|
|
13
13
|
import { NaturalLanguageProcessor } from '../neural/naturalLanguageProcessor.js';
|
|
14
|
+
import { SmartRelationshipExtractor } from '../neural/SmartRelationshipExtractor.js';
|
|
14
15
|
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
15
16
|
/**
|
|
16
17
|
* SmartMarkdownImporter - Extracts structured knowledge from Markdown files
|
|
@@ -20,6 +21,7 @@ export class SmartMarkdownImporter {
|
|
|
20
21
|
this.brain = brain;
|
|
21
22
|
this.extractor = new NeuralEntityExtractor(brain);
|
|
22
23
|
this.nlp = new NaturalLanguageProcessor(brain);
|
|
24
|
+
this.relationshipExtractor = new SmartRelationshipExtractor(brain);
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Initialize the importer
|
|
@@ -321,23 +323,16 @@ export class SmartMarkdownImporter {
|
|
|
321
323
|
return Math.abs(index1 - index2) < 300;
|
|
322
324
|
}
|
|
323
325
|
/**
|
|
324
|
-
* Infer relationship type from context
|
|
326
|
+
* Infer relationship type from context using SmartRelationshipExtractor
|
|
325
327
|
*/
|
|
326
|
-
async inferRelationship(fromEntity, toEntity, context) {
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
];
|
|
335
|
-
for (const [pattern, verbType] of patterns) {
|
|
336
|
-
if (pattern.test(lowerContext)) {
|
|
337
|
-
return verbType;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return VerbType.RelatedTo;
|
|
328
|
+
async inferRelationship(fromEntity, toEntity, context, fromType, toType) {
|
|
329
|
+
// Use SmartRelationshipExtractor for robust relationship classification
|
|
330
|
+
const result = await this.relationshipExtractor.infer(fromEntity, toEntity, context, {
|
|
331
|
+
subjectType: fromType,
|
|
332
|
+
objectType: toType
|
|
333
|
+
});
|
|
334
|
+
// Return inferred type or fallback to RelatedTo
|
|
335
|
+
return result?.type || VerbType.RelatedTo;
|
|
341
336
|
}
|
|
342
337
|
/**
|
|
343
338
|
* Generate consistent entity ID
|
|
@@ -111,6 +111,7 @@ export declare class SmartPDFImporter {
|
|
|
111
111
|
private brain;
|
|
112
112
|
private extractor;
|
|
113
113
|
private nlp;
|
|
114
|
+
private relationshipExtractor;
|
|
114
115
|
private pdfHandler;
|
|
115
116
|
constructor(brain: Brainy);
|
|
116
117
|
/**
|
|
@@ -142,7 +143,7 @@ export declare class SmartPDFImporter {
|
|
|
142
143
|
*/
|
|
143
144
|
private extractRelationshipContext;
|
|
144
145
|
/**
|
|
145
|
-
* Infer relationship type from context
|
|
146
|
+
* Infer relationship type from context using SmartRelationshipExtractor
|
|
146
147
|
*/
|
|
147
148
|
private inferRelationship;
|
|
148
149
|
/**
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { NeuralEntityExtractor } from '../neural/entityExtractor.js';
|
|
13
13
|
import { NaturalLanguageProcessor } from '../neural/naturalLanguageProcessor.js';
|
|
14
|
+
import { SmartRelationshipExtractor } from '../neural/SmartRelationshipExtractor.js';
|
|
14
15
|
import { VerbType } from '../types/graphTypes.js';
|
|
15
16
|
import { PDFHandler } from '../augmentations/intelligentImport/handlers/pdfHandler.js';
|
|
16
17
|
/**
|
|
@@ -21,6 +22,7 @@ export class SmartPDFImporter {
|
|
|
21
22
|
this.brain = brain;
|
|
22
23
|
this.extractor = new NeuralEntityExtractor(brain);
|
|
23
24
|
this.nlp = new NaturalLanguageProcessor(brain);
|
|
25
|
+
this.relationshipExtractor = new SmartRelationshipExtractor(brain);
|
|
24
26
|
this.pdfHandler = new PDFHandler();
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
@@ -272,29 +274,16 @@ export class SmartPDFImporter {
|
|
|
272
274
|
return text.substring(start, end + 100).trim();
|
|
273
275
|
}
|
|
274
276
|
/**
|
|
275
|
-
* Infer relationship type from context
|
|
277
|
+
* Infer relationship type from context using SmartRelationshipExtractor
|
|
276
278
|
*/
|
|
277
|
-
async inferRelationship(fromEntity, toEntity, context) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
[new RegExp(`${fromEntity}.*created.*${toEntity}`, 'i'), VerbType.Creates],
|
|
286
|
-
[new RegExp(`${fromEntity}.*authored.*${toEntity}`, 'i'), VerbType.CreatedBy],
|
|
287
|
-
[new RegExp(`${fromEntity}.*part of.*${toEntity}`, 'i'), VerbType.PartOf],
|
|
288
|
-
[new RegExp(`${fromEntity}.*related to.*${toEntity}`, 'i'), VerbType.RelatedTo],
|
|
289
|
-
[new RegExp(`${fromEntity}.*and.*${toEntity}`, 'i'), VerbType.RelatedTo]
|
|
290
|
-
];
|
|
291
|
-
for (const [pattern, verbType] of patterns) {
|
|
292
|
-
if (pattern.test(lowerContext)) {
|
|
293
|
-
return verbType;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
// Default to RelatedTo
|
|
297
|
-
return VerbType.RelatedTo;
|
|
279
|
+
async inferRelationship(fromEntity, toEntity, context, fromType, toType) {
|
|
280
|
+
// Use SmartRelationshipExtractor for robust relationship classification
|
|
281
|
+
const result = await this.relationshipExtractor.infer(fromEntity, toEntity, context, {
|
|
282
|
+
subjectType: fromType,
|
|
283
|
+
objectType: toType
|
|
284
|
+
});
|
|
285
|
+
// Return inferred type or fallback to RelatedTo
|
|
286
|
+
return result?.type || VerbType.RelatedTo;
|
|
298
287
|
}
|
|
299
288
|
/**
|
|
300
289
|
* Generate consistent entity ID
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Smart YAML Importer
|
|
3
|
+
*
|
|
4
|
+
* Extracts entities and relationships from YAML files using:
|
|
5
|
+
* - YAML parsing to JSON-like structure
|
|
6
|
+
* - Recursive traversal of nested structures
|
|
7
|
+
* - NeuralEntityExtractor for entity extraction from text values
|
|
8
|
+
* - NaturalLanguageProcessor for relationship inference
|
|
9
|
+
* - Hierarchical relationship creation (parent-child, contains, etc.)
|
|
10
|
+
*
|
|
11
|
+
* v4.2.0: New format handler
|
|
12
|
+
* NO MOCKS - Production-ready implementation
|
|
13
|
+
*/
|
|
14
|
+
import { Brainy } from '../brainy.js';
|
|
15
|
+
import { NounType, VerbType } from '../types/graphTypes.js';
|
|
16
|
+
export interface SmartYAMLOptions {
|
|
17
|
+
/** Enable neural entity extraction from string values */
|
|
18
|
+
enableNeuralExtraction?: boolean;
|
|
19
|
+
/** Enable hierarchical relationship creation */
|
|
20
|
+
enableHierarchicalRelationships?: boolean;
|
|
21
|
+
/** Enable concept extraction for tagging */
|
|
22
|
+
enableConceptExtraction?: boolean;
|
|
23
|
+
/** Confidence threshold for entities (0-1) */
|
|
24
|
+
confidenceThreshold?: number;
|
|
25
|
+
/** Maximum depth to traverse */
|
|
26
|
+
maxDepth?: number;
|
|
27
|
+
/** Minimum string length to process for entity extraction */
|
|
28
|
+
minStringLength?: number;
|
|
29
|
+
/** Keys that indicate entity names */
|
|
30
|
+
nameKeys?: string[];
|
|
31
|
+
/** Keys that indicate entity descriptions */
|
|
32
|
+
descriptionKeys?: string[];
|
|
33
|
+
/** Keys that indicate entity types */
|
|
34
|
+
typeKeys?: string[];
|
|
35
|
+
/** Progress callback */
|
|
36
|
+
onProgress?: (stats: {
|
|
37
|
+
processed: number;
|
|
38
|
+
entities: number;
|
|
39
|
+
relationships: number;
|
|
40
|
+
}) => void;
|
|
41
|
+
}
|
|
42
|
+
export interface ExtractedYAMLEntity {
|
|
43
|
+
/** Entity ID */
|
|
44
|
+
id: string;
|
|
45
|
+
/** Entity name */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Entity type */
|
|
48
|
+
type: NounType;
|
|
49
|
+
/** Entity description/value */
|
|
50
|
+
description: string;
|
|
51
|
+
/** Confidence score */
|
|
52
|
+
confidence: number;
|
|
53
|
+
/** Weight/importance score */
|
|
54
|
+
weight?: number;
|
|
55
|
+
/** YAML path to this entity */
|
|
56
|
+
path: string;
|
|
57
|
+
/** Parent path in YAML hierarchy */
|
|
58
|
+
parentPath: string | null;
|
|
59
|
+
/** Metadata */
|
|
60
|
+
metadata: Record<string, any>;
|
|
61
|
+
}
|
|
62
|
+
export interface ExtractedYAMLRelationship {
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
type: VerbType;
|
|
66
|
+
confidence: number;
|
|
67
|
+
weight?: number;
|
|
68
|
+
evidence: string;
|
|
69
|
+
}
|
|
70
|
+
export interface SmartYAMLResult {
|
|
71
|
+
/** Total nodes processed */
|
|
72
|
+
nodesProcessed: number;
|
|
73
|
+
/** Entities extracted */
|
|
74
|
+
entitiesExtracted: number;
|
|
75
|
+
/** Relationships inferred */
|
|
76
|
+
relationshipsInferred: number;
|
|
77
|
+
/** All extracted entities */
|
|
78
|
+
entities: ExtractedYAMLEntity[];
|
|
79
|
+
/** All relationships */
|
|
80
|
+
relationships: ExtractedYAMLRelationship[];
|
|
81
|
+
/** Entity ID mapping (path -> ID) */
|
|
82
|
+
entityMap: Map<string, string>;
|
|
83
|
+
/** Processing time in ms */
|
|
84
|
+
processingTime: number;
|
|
85
|
+
/** Extraction statistics */
|
|
86
|
+
stats: {
|
|
87
|
+
byType: Record<string, number>;
|
|
88
|
+
byDepth: Record<number, number>;
|
|
89
|
+
byConfidence: {
|
|
90
|
+
high: number;
|
|
91
|
+
medium: number;
|
|
92
|
+
low: number;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* SmartYAMLImporter - Extracts structured knowledge from YAML files
|
|
98
|
+
*/
|
|
99
|
+
export declare class SmartYAMLImporter {
|
|
100
|
+
private brain;
|
|
101
|
+
private extractor;
|
|
102
|
+
private nlp;
|
|
103
|
+
private relationshipExtractor;
|
|
104
|
+
constructor(brain: Brainy);
|
|
105
|
+
/**
|
|
106
|
+
* Initialize the importer
|
|
107
|
+
*/
|
|
108
|
+
init(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Extract entities and relationships from YAML string or buffer
|
|
111
|
+
*/
|
|
112
|
+
extract(yamlContent: string | Buffer, options?: SmartYAMLOptions): Promise<SmartYAMLResult>;
|
|
113
|
+
/**
|
|
114
|
+
* Extract entities and relationships from parsed YAML data
|
|
115
|
+
*/
|
|
116
|
+
private extractFromData;
|
|
117
|
+
/**
|
|
118
|
+
* Extract an entity from a YAML object node
|
|
119
|
+
*/
|
|
120
|
+
private extractEntityFromObject;
|
|
121
|
+
}
|