@soulcraft/brainy 1.5.0 → 2.0.1

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.
Files changed (141) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/LICENSE +2 -2
  3. package/README.md +200 -595
  4. package/bin/brainy-interactive.js +564 -0
  5. package/bin/brainy-ts.js +18 -0
  6. package/bin/brainy.js +672 -81
  7. package/dist/augmentationPipeline.d.ts +48 -220
  8. package/dist/augmentationPipeline.js +60 -508
  9. package/dist/augmentationRegistry.d.ts +22 -31
  10. package/dist/augmentationRegistry.js +28 -79
  11. package/dist/augmentations/apiServerAugmentation.d.ts +108 -0
  12. package/dist/augmentations/apiServerAugmentation.js +502 -0
  13. package/dist/augmentations/batchProcessingAugmentation.d.ts +95 -0
  14. package/dist/augmentations/batchProcessingAugmentation.js +567 -0
  15. package/dist/augmentations/brainyAugmentation.d.ts +153 -0
  16. package/dist/augmentations/brainyAugmentation.js +145 -0
  17. package/dist/augmentations/cacheAugmentation.d.ts +105 -0
  18. package/dist/augmentations/cacheAugmentation.js +238 -0
  19. package/dist/augmentations/conduitAugmentations.d.ts +54 -156
  20. package/dist/augmentations/conduitAugmentations.js +156 -1082
  21. package/dist/augmentations/connectionPoolAugmentation.d.ts +62 -0
  22. package/dist/augmentations/connectionPoolAugmentation.js +316 -0
  23. package/dist/augmentations/defaultAugmentations.d.ts +53 -0
  24. package/dist/augmentations/defaultAugmentations.js +88 -0
  25. package/dist/augmentations/entityRegistryAugmentation.d.ts +126 -0
  26. package/dist/augmentations/entityRegistryAugmentation.js +386 -0
  27. package/dist/augmentations/indexAugmentation.d.ts +117 -0
  28. package/dist/augmentations/indexAugmentation.js +284 -0
  29. package/dist/augmentations/intelligentVerbScoringAugmentation.d.ts +152 -0
  30. package/dist/augmentations/intelligentVerbScoringAugmentation.js +554 -0
  31. package/dist/augmentations/metricsAugmentation.d.ts +202 -0
  32. package/dist/augmentations/metricsAugmentation.js +291 -0
  33. package/dist/augmentations/monitoringAugmentation.d.ts +94 -0
  34. package/dist/augmentations/monitoringAugmentation.js +227 -0
  35. package/dist/augmentations/neuralImport.d.ts +50 -117
  36. package/dist/augmentations/neuralImport.js +255 -629
  37. package/dist/augmentations/requestDeduplicatorAugmentation.d.ts +52 -0
  38. package/dist/augmentations/requestDeduplicatorAugmentation.js +162 -0
  39. package/dist/augmentations/serverSearchAugmentations.d.ts +43 -22
  40. package/dist/augmentations/serverSearchAugmentations.js +125 -72
  41. package/dist/augmentations/storageAugmentation.d.ts +54 -0
  42. package/dist/augmentations/storageAugmentation.js +93 -0
  43. package/dist/augmentations/storageAugmentations.d.ts +96 -0
  44. package/dist/augmentations/storageAugmentations.js +182 -0
  45. package/dist/augmentations/synapseAugmentation.d.ts +156 -0
  46. package/dist/augmentations/synapseAugmentation.js +312 -0
  47. package/dist/augmentations/walAugmentation.d.ts +108 -0
  48. package/dist/augmentations/walAugmentation.js +515 -0
  49. package/dist/brainyData.d.ts +404 -130
  50. package/dist/brainyData.js +1331 -853
  51. package/dist/chat/BrainyChat.d.ts +16 -8
  52. package/dist/chat/BrainyChat.js +60 -32
  53. package/dist/chat/ChatCLI.d.ts +1 -1
  54. package/dist/chat/ChatCLI.js +6 -6
  55. package/dist/cli/catalog.d.ts +3 -3
  56. package/dist/cli/catalog.js +116 -70
  57. package/dist/cli/commands/core.d.ts +61 -0
  58. package/dist/cli/commands/core.js +348 -0
  59. package/dist/cli/commands/neural.d.ts +25 -0
  60. package/dist/cli/commands/neural.js +508 -0
  61. package/dist/cli/commands/utility.d.ts +37 -0
  62. package/dist/cli/commands/utility.js +276 -0
  63. package/dist/cli/index.d.ts +7 -0
  64. package/dist/cli/index.js +167 -0
  65. package/dist/cli/interactive.d.ts +164 -0
  66. package/dist/cli/interactive.js +542 -0
  67. package/dist/cortex/neuralImport.js +5 -5
  68. package/dist/critical/model-guardian.js +11 -4
  69. package/dist/embeddings/lightweight-embedder.d.ts +23 -0
  70. package/dist/embeddings/lightweight-embedder.js +136 -0
  71. package/dist/embeddings/universal-memory-manager.d.ts +38 -0
  72. package/dist/embeddings/universal-memory-manager.js +206 -0
  73. package/dist/embeddings/worker-embedding.d.ts +7 -0
  74. package/dist/embeddings/worker-embedding.js +77 -0
  75. package/dist/embeddings/worker-manager.d.ts +28 -0
  76. package/dist/embeddings/worker-manager.js +162 -0
  77. package/dist/examples/basicUsage.js +7 -7
  78. package/dist/graph/pathfinding.d.ts +78 -0
  79. package/dist/graph/pathfinding.js +393 -0
  80. package/dist/hnsw/hnswIndex.d.ts +13 -0
  81. package/dist/hnsw/hnswIndex.js +35 -0
  82. package/dist/hnsw/hnswIndexOptimized.d.ts +1 -0
  83. package/dist/hnsw/hnswIndexOptimized.js +3 -0
  84. package/dist/index.d.ts +9 -11
  85. package/dist/index.js +21 -11
  86. package/dist/indices/fieldIndex.d.ts +76 -0
  87. package/dist/indices/fieldIndex.js +357 -0
  88. package/dist/mcp/brainyMCPAdapter.js +3 -2
  89. package/dist/mcp/mcpAugmentationToolset.js +11 -17
  90. package/dist/neural/embeddedPatterns.d.ts +41 -0
  91. package/dist/neural/embeddedPatterns.js +4044 -0
  92. package/dist/neural/naturalLanguageProcessor.d.ts +94 -0
  93. package/dist/neural/naturalLanguageProcessor.js +317 -0
  94. package/dist/neural/naturalLanguageProcessorStatic.d.ts +64 -0
  95. package/dist/neural/naturalLanguageProcessorStatic.js +151 -0
  96. package/dist/neural/neuralAPI.d.ts +255 -0
  97. package/dist/neural/neuralAPI.js +612 -0
  98. package/dist/neural/patternLibrary.d.ts +101 -0
  99. package/dist/neural/patternLibrary.js +313 -0
  100. package/dist/neural/patterns.d.ts +27 -0
  101. package/dist/neural/patterns.js +68 -0
  102. package/dist/neural/staticPatternMatcher.d.ts +35 -0
  103. package/dist/neural/staticPatternMatcher.js +153 -0
  104. package/dist/scripts/precomputePatternEmbeddings.d.ts +19 -0
  105. package/dist/scripts/precomputePatternEmbeddings.js +100 -0
  106. package/dist/storage/adapters/fileSystemStorage.d.ts +5 -0
  107. package/dist/storage/adapters/fileSystemStorage.js +20 -0
  108. package/dist/storage/adapters/s3CompatibleStorage.d.ts +5 -0
  109. package/dist/storage/adapters/s3CompatibleStorage.js +16 -0
  110. package/dist/storage/enhancedClearOperations.d.ts +83 -0
  111. package/dist/storage/enhancedClearOperations.js +345 -0
  112. package/dist/storage/storageFactory.js +31 -27
  113. package/dist/triple/TripleIntelligence.d.ts +134 -0
  114. package/dist/triple/TripleIntelligence.js +548 -0
  115. package/dist/types/augmentations.d.ts +45 -344
  116. package/dist/types/augmentations.js +5 -2
  117. package/dist/types/brainyDataInterface.d.ts +20 -10
  118. package/dist/types/graphTypes.d.ts +46 -0
  119. package/dist/types/graphTypes.js +16 -2
  120. package/dist/utils/BoundedRegistry.d.ts +29 -0
  121. package/dist/utils/BoundedRegistry.js +54 -0
  122. package/dist/utils/embedding.js +20 -3
  123. package/dist/utils/hybridModelManager.js +10 -5
  124. package/dist/utils/metadataFilter.d.ts +33 -19
  125. package/dist/utils/metadataFilter.js +58 -23
  126. package/dist/utils/metadataIndex.d.ts +37 -6
  127. package/dist/utils/metadataIndex.js +427 -64
  128. package/dist/utils/requestDeduplicator.d.ts +10 -0
  129. package/dist/utils/requestDeduplicator.js +24 -0
  130. package/dist/utils/unifiedCache.d.ts +103 -0
  131. package/dist/utils/unifiedCache.js +311 -0
  132. package/package.json +40 -125
  133. package/scripts/ensure-models.js +108 -0
  134. package/scripts/prepare-models.js +387 -0
  135. package/OFFLINE_MODELS.md +0 -56
  136. package/dist/intelligence/neuralEngine.d.ts +0 -207
  137. package/dist/intelligence/neuralEngine.js +0 -706
  138. package/dist/utils/modelLoader.d.ts +0 -32
  139. package/dist/utils/modelLoader.js +0 -219
  140. package/dist/utils/modelManager.d.ts +0 -77
  141. package/dist/utils/modelManager.js +0 -219
@@ -4,260 +4,110 @@
4
4
  * 🧠 Built-in AI augmentation for intelligent data processing
5
5
  * ⚛️ Always free, always included, always enabled
6
6
  *
7
- * This is the default AI-powered augmentation that comes with every Brainy installation.
8
- * It provides intelligent data understanding, entity detection, and relationship analysis.
7
+ * Now using the unified BrainyAugmentation interface!
9
8
  */
10
- import { NounType, VerbType } from '../types/graphTypes.js';
11
- import * as fs from '../universal/fs.js';
9
+ import { BaseAugmentation } from './brainyAugmentation.js';
12
10
  import * as path from '../universal/path.js';
13
11
  /**
14
- * Neural Import SENSE Augmentation - The Brain's Perceptual System
12
+ * Neural Import Augmentation - Unified Implementation
13
+ * Processes data with AI before storage operations
15
14
  */
16
- export class NeuralImportAugmentation {
17
- constructor(brainy, config = {}) {
15
+ export class NeuralImportAugmentation extends BaseAugmentation {
16
+ constructor(config = {}) {
17
+ super();
18
18
  this.name = 'neural-import';
19
- this.description = 'Built-in AI-powered data understanding and entity detection';
20
- this.enabled = true;
21
- this.brainy = brainy;
19
+ this.timing = 'before'; // Process data before storage
20
+ this.operations = ['add', 'addNoun', 'addVerb', 'all']; // Use 'all' to catch batch operations
21
+ this.priority = 80; // High priority for data processing
22
+ this.analysisCache = new Map();
22
23
  this.config = {
23
24
  confidenceThreshold: 0.7,
24
25
  enableWeights: true,
25
26
  skipDuplicates: true,
27
+ dataType: 'json',
26
28
  ...config
27
29
  };
28
30
  }
29
- async initialize() {
30
- // Initialize the cortex analysis system
31
- console.log('🧠 Neural Import augmentation initialized');
31
+ async onInitialize() {
32
+ this.log('🧠 Neural Import augmentation initialized');
32
33
  }
33
- async shutDown() {
34
- console.log('🧠 Neural Import SENSE augmentation shut down');
35
- }
36
- async getStatus() {
37
- return this.enabled ? 'active' : 'inactive';
34
+ async onShutdown() {
35
+ this.analysisCache.clear();
36
+ this.log('🧠 Neural Import augmentation shut down');
38
37
  }
39
38
  /**
40
- * Process raw data into structured nouns and verbs using neural analysis
39
+ * Execute augmentation - process data with AI before storage
41
40
  */
42
- async processRawData(rawData, dataType, options) {
41
+ async execute(operation, params, next) {
42
+ // Only process on add operations
43
+ if (!this.operations.includes(operation)) {
44
+ return next();
45
+ }
43
46
  try {
44
- // Merge options with config
45
- const mergedConfig = { ...this.config, ...options };
46
- // Parse the raw data based on type
47
- const parsedData = await this.parseRawData(rawData, dataType);
47
+ // Extract data from params based on operation
48
+ const rawData = this.extractRawData(operation, params);
49
+ if (!rawData) {
50
+ return next();
51
+ }
48
52
  // Perform neural analysis
49
- const analysis = await this.performNeuralAnalysis(parsedData, mergedConfig);
50
- // Extract nouns and verbs for the ISenseAugmentation interface
51
- const nouns = analysis.detectedEntities.map(entity => entity.suggestedId);
52
- const verbs = analysis.detectedRelationships.map(rel => `${rel.sourceId}->${rel.verbType}->${rel.targetId}`);
53
- // Store the full analysis for later retrieval
53
+ const analysis = await this.performNeuralAnalysis(rawData, this.config);
54
+ // Enhance params with neural insights
55
+ if (params.metadata) {
56
+ params.metadata._neuralProcessed = true;
57
+ params.metadata._neuralConfidence = analysis.confidence;
58
+ params.metadata._detectedEntities = analysis.detectedEntities.length;
59
+ params.metadata._detectedRelationships = analysis.detectedRelationships.length;
60
+ params.metadata._neuralInsights = analysis.insights;
61
+ }
62
+ else if (typeof params === 'object') {
63
+ params.metadata = {
64
+ _neuralProcessed: true,
65
+ _neuralConfidence: analysis.confidence,
66
+ _detectedEntities: analysis.detectedEntities.length,
67
+ _detectedRelationships: analysis.detectedRelationships.length,
68
+ _neuralInsights: analysis.insights
69
+ };
70
+ }
71
+ // Store neural analysis for later retrieval
54
72
  await this.storeNeuralAnalysis(analysis);
55
- return {
56
- success: true,
57
- data: {
58
- nouns,
59
- verbs,
60
- confidence: analysis.confidence,
61
- insights: analysis.insights.map((insight) => ({
62
- type: insight.type,
63
- description: insight.description,
64
- confidence: insight.confidence
65
- })),
66
- metadata: {
67
- detectedEntities: analysis.detectedEntities.length,
68
- detectedRelationships: analysis.detectedRelationships.length,
69
- timestamp: new Date().toISOString(),
70
- augmentation: 'neural-import-sense'
71
- }
72
- }
73
- };
74
- }
75
- catch (error) {
76
- return {
77
- success: false,
78
- data: { nouns: [], verbs: [] },
79
- error: error instanceof Error ? error.message : 'Neural analysis failed'
80
- };
81
- }
82
- }
83
- /**
84
- * Listen to real-time data feeds and process them
85
- */
86
- async listenToFeed(feedUrl, callback) {
87
- // For file-based feeds, watch for changes
88
- if (feedUrl.startsWith('file://')) {
89
- const filePath = feedUrl.replace('file://', '');
90
- // Watch file for changes using Node.js fs.watch
91
- const fsWatch = require('fs');
92
- const watcher = fsWatch.watch(filePath, async (eventType) => {
93
- if (eventType === 'change') {
94
- try {
95
- const fileContent = await fs.readFile(filePath);
96
- const result = await this.processRawData(fileContent, this.getDataTypeFromPath(filePath));
97
- if (result.success) {
98
- callback({
99
- nouns: result.data.nouns,
100
- verbs: result.data.verbs,
101
- confidence: result.data.confidence
102
- });
103
- }
104
- }
105
- catch (error) {
106
- console.error('Neural Import feed error:', error);
107
- }
108
- }
109
- });
110
- return;
111
- }
112
- // For other feed types, implement appropriate listeners
113
- console.log(`🧠 Neural Import listening to feed: ${feedUrl}`);
114
- }
115
- /**
116
- * Analyze data structure without processing (preview mode)
117
- */
118
- async analyzeStructure(rawData, dataType, options) {
119
- try {
120
- // Parse the raw data
121
- const parsedData = await this.parseRawData(rawData, dataType);
122
- // Perform lightweight analysis for structure detection
123
- const analysis = await this.performNeuralAnalysis(parsedData, { ...this.config, ...options });
124
- // Summarize entity types
125
- const entityTypeCounts = new Map();
126
- analysis.detectedEntities.forEach(entity => {
127
- const existing = entityTypeCounts.get(entity.nounType) || { count: 0, totalConfidence: 0 };
128
- entityTypeCounts.set(entity.nounType, {
129
- count: existing.count + 1,
130
- totalConfidence: existing.totalConfidence + entity.confidence
131
- });
132
- });
133
- const entityTypes = Array.from(entityTypeCounts.entries()).map(([type, stats]) => ({
134
- type,
135
- count: stats.count,
136
- confidence: stats.totalConfidence / stats.count
137
- }));
138
- // Summarize relationship types
139
- const relationshipTypeCounts = new Map();
140
- analysis.detectedRelationships.forEach(rel => {
141
- const existing = relationshipTypeCounts.get(rel.verbType) || { count: 0, totalConfidence: 0 };
142
- relationshipTypeCounts.set(rel.verbType, {
143
- count: existing.count + 1,
144
- totalConfidence: existing.totalConfidence + rel.confidence
145
- });
146
- });
147
- const relationshipTypes = Array.from(relationshipTypeCounts.entries()).map(([type, stats]) => ({
148
- type,
149
- count: stats.count,
150
- confidence: stats.totalConfidence / stats.count
151
- }));
152
- // Assess data quality
153
- const dataQuality = this.assessDataQuality(parsedData, analysis);
154
- // Generate recommendations
155
- const recommendations = this.generateRecommendations(parsedData, analysis, entityTypes, relationshipTypes);
156
- return {
157
- success: true,
158
- data: {
159
- entityTypes,
160
- relationshipTypes,
161
- dataQuality,
162
- recommendations
163
- }
164
- };
73
+ // If we detected entities/relationships, potentially add them
74
+ if (this.context?.brain && analysis.detectedEntities.length > 0) {
75
+ // This could automatically create entities/relationships
76
+ // But for now, just enhance the metadata
77
+ this.log(`Detected ${analysis.detectedEntities.length} entities and ${analysis.detectedRelationships.length} relationships`);
78
+ }
79
+ // Continue with enhanced data
80
+ return next();
165
81
  }
166
82
  catch (error) {
167
- return {
168
- success: false,
169
- data: {
170
- entityTypes: [],
171
- relationshipTypes: [],
172
- dataQuality: { completeness: 0, consistency: 0, accuracy: 0 },
173
- recommendations: []
174
- },
175
- error: error instanceof Error ? error.message : 'Structure analysis failed'
176
- };
83
+ this.log(`Neural analysis failed: ${error}`, 'warn');
84
+ // Continue without neural processing
85
+ return next();
177
86
  }
178
87
  }
179
88
  /**
180
- * Validate data compatibility with current knowledge base
89
+ * Extract raw data from operation params
181
90
  */
182
- async validateCompatibility(rawData, dataType) {
183
- try {
184
- // Parse the raw data
185
- const parsedData = await this.parseRawData(rawData, dataType);
186
- // Perform neural analysis
187
- const analysis = await this.performNeuralAnalysis(parsedData);
188
- const issues = [];
189
- const suggestions = [];
190
- // Check for low confidence entities
191
- const lowConfidenceEntities = analysis.detectedEntities.filter((e) => e.confidence < 0.5);
192
- if (lowConfidenceEntities.length > 0) {
193
- issues.push({
194
- type: 'confidence',
195
- description: `${lowConfidenceEntities.length} entities have low confidence scores`,
196
- severity: 'medium'
197
- });
198
- suggestions.push('Consider reviewing field names and data structure for better entity detection');
199
- }
200
- // Check for missing relationships
201
- if (analysis.detectedRelationships.length === 0 && analysis.detectedEntities.length > 1) {
202
- issues.push({
203
- type: 'relationships',
204
- description: 'No relationships detected between entities',
205
- severity: 'low'
206
- });
207
- suggestions.push('Consider adding contextual fields that describe entity relationships');
208
- }
209
- // Check for data type compatibility
210
- const supportedTypes = ['json', 'csv', 'yaml', 'text'];
211
- if (!supportedTypes.includes(dataType.toLowerCase())) {
212
- issues.push({
213
- type: 'format',
214
- description: `Data type '${dataType}' may not be fully supported`,
215
- severity: 'high'
216
- });
217
- suggestions.push(`Convert data to one of: ${supportedTypes.join(', ')}`);
218
- }
219
- // Check for data completeness
220
- const incompleteEntities = analysis.detectedEntities.filter((e) => !e.originalData || Object.keys(e.originalData).length < 2);
221
- if (incompleteEntities.length > 0) {
222
- issues.push({
223
- type: 'completeness',
224
- description: `${incompleteEntities.length} entities have insufficient data`,
225
- severity: 'medium'
226
- });
227
- suggestions.push('Ensure each entity has multiple descriptive fields');
228
- }
229
- const compatible = issues.filter(i => i.severity === 'high').length === 0;
230
- return {
231
- success: true,
232
- data: {
233
- compatible,
234
- issues,
235
- suggestions
236
- }
237
- };
238
- }
239
- catch (error) {
240
- return {
241
- success: false,
242
- data: {
243
- compatible: false,
244
- issues: [{
245
- type: 'error',
246
- description: error instanceof Error ? error.message : 'Validation failed',
247
- severity: 'high'
248
- }],
249
- suggestions: []
250
- },
251
- error: error instanceof Error ? error.message : 'Compatibility validation failed'
252
- };
91
+ extractRawData(operation, params) {
92
+ switch (operation) {
93
+ case 'add':
94
+ return params.content || params.data || params;
95
+ case 'addNoun':
96
+ return params.noun || params.data || params;
97
+ case 'addVerb':
98
+ return params.verb || params;
99
+ case 'addBatch':
100
+ return params.items || params.batch || params;
101
+ default:
102
+ return null;
253
103
  }
254
104
  }
255
105
  /**
256
- * Get the full neural analysis result (custom method for Cortex integration)
106
+ * Get the full neural analysis result (for external use)
257
107
  */
258
108
  async getNeuralAnalysis(rawData, dataType) {
259
- const parsedData = await this.parseRawData(rawData, dataType);
260
- return await this.performNeuralAnalysis(parsedData);
109
+ const parsedData = await this.parseRawData(rawData, dataType || this.config.dataType || 'json');
110
+ return await this.performNeuralAnalysis(parsedData, this.config);
261
111
  }
262
112
  /**
263
113
  * Parse raw data based on type
@@ -266,33 +116,45 @@ export class NeuralImportAugmentation {
266
116
  const content = typeof rawData === 'string' ? rawData : rawData.toString('utf8');
267
117
  switch (dataType.toLowerCase()) {
268
118
  case 'json':
269
- const jsonData = JSON.parse(content);
270
- return Array.isArray(jsonData) ? jsonData : [jsonData];
119
+ try {
120
+ const jsonData = JSON.parse(content);
121
+ return Array.isArray(jsonData) ? jsonData : [jsonData];
122
+ }
123
+ catch {
124
+ // If JSON parse fails, treat as text
125
+ return [{ text: content }];
126
+ }
271
127
  case 'csv':
272
128
  return this.parseCSV(content);
273
129
  case 'yaml':
274
130
  case 'yml':
275
131
  // For now, basic YAML support - in full implementation would use yaml parser
276
- return JSON.parse(content); // Placeholder
132
+ try {
133
+ return JSON.parse(content); // Placeholder
134
+ }
135
+ catch {
136
+ return [{ text: content }];
137
+ }
277
138
  case 'txt':
278
139
  case 'text':
279
140
  // Split text into sentences/paragraphs for analysis
280
141
  return content.split(/\n+/).filter(line => line.trim()).map(line => ({ text: line }));
281
142
  default:
282
- throw new Error(`Unsupported data type: ${dataType}`);
143
+ // Unknown type, treat as text
144
+ return [{ text: content }];
283
145
  }
284
146
  }
285
147
  /**
286
- * Basic CSV parser
148
+ * Parse CSV data
287
149
  */
288
150
  parseCSV(content) {
289
151
  const lines = content.split('\n').filter(line => line.trim());
290
- if (lines.length < 2)
152
+ if (lines.length === 0)
291
153
  return [];
292
- const headers = lines[0].split(',').map(h => h.trim().replace(/"/g, ''));
154
+ const headers = lines[0].split(',').map(h => h.trim());
293
155
  const data = [];
294
156
  for (let i = 1; i < lines.length; i++) {
295
- const values = lines[i].split(',').map(v => v.trim().replace(/"/g, ''));
157
+ const values = lines[i].split(',').map(v => v.trim());
296
158
  const row = {};
297
159
  headers.forEach((header, index) => {
298
160
  row[header] = values[index] || '';
@@ -304,447 +166,211 @@ export class NeuralImportAugmentation {
304
166
  /**
305
167
  * Perform neural analysis on parsed data
306
168
  */
307
- async performNeuralAnalysis(parsedData, config = this.config) {
308
- // Phase 1: Neural Entity Detection
309
- const detectedEntities = await this.detectEntitiesWithNeuralAnalysis(parsedData, config);
310
- // Phase 2: Neural Relationship Detection
311
- const detectedRelationships = await this.detectRelationshipsWithNeuralAnalysis(detectedEntities, parsedData, config);
312
- // Phase 3: Neural Insights Generation
313
- const insights = await this.generateNeuralInsights(detectedEntities, detectedRelationships);
314
- // Phase 4: Confidence Scoring
315
- const overallConfidence = this.calculateOverallConfidence(detectedEntities, detectedRelationships);
169
+ async performNeuralAnalysis(data, config) {
170
+ const detectedEntities = [];
171
+ const detectedRelationships = [];
172
+ const insights = [];
173
+ // Simple entity detection (in real implementation, would use ML)
174
+ for (const item of data) {
175
+ if (typeof item === 'object') {
176
+ // Detect entities from object properties
177
+ const entityId = item.id || item.name || item.title || `entity_${Date.now()}_${Math.random()}`;
178
+ detectedEntities.push({
179
+ originalData: item,
180
+ nounType: this.inferNounType(item),
181
+ confidence: 0.85,
182
+ suggestedId: String(entityId),
183
+ reasoning: 'Detected from structured data',
184
+ alternativeTypes: []
185
+ });
186
+ // Detect relationships from references
187
+ this.detectRelationships(item, entityId, detectedRelationships);
188
+ }
189
+ }
190
+ // Generate insights
191
+ if (detectedEntities.length > 10) {
192
+ insights.push({
193
+ type: 'pattern',
194
+ description: `Large dataset with ${detectedEntities.length} entities detected`,
195
+ confidence: 0.9,
196
+ affectedEntities: detectedEntities.slice(0, 5).map(e => e.suggestedId),
197
+ recommendation: 'Consider batch processing for optimal performance'
198
+ });
199
+ }
200
+ // Look for clusters
201
+ const typeGroups = this.groupByType(detectedEntities);
202
+ if (Object.keys(typeGroups).length > 1) {
203
+ insights.push({
204
+ type: 'cluster',
205
+ description: `Multiple entity types detected: ${Object.keys(typeGroups).join(', ')}`,
206
+ confidence: 0.8,
207
+ affectedEntities: [],
208
+ recommendation: 'Data contains diverse entity types suitable for graph analysis'
209
+ });
210
+ }
316
211
  return {
317
212
  detectedEntities,
318
213
  detectedRelationships,
319
- confidence: overallConfidence,
214
+ confidence: detectedEntities.length > 0 ? 0.85 : 0.5,
320
215
  insights
321
216
  };
322
217
  }
323
218
  /**
324
- * Neural Entity Detection - The Core AI Engine
325
- */
326
- async detectEntitiesWithNeuralAnalysis(rawData, config = this.config) {
327
- const entities = [];
328
- const nounTypes = Object.values(NounType);
329
- for (const [index, dataItem] of rawData.entries()) {
330
- const mainText = this.extractMainText(dataItem);
331
- const detections = [];
332
- // Test against all noun types using semantic similarity
333
- for (const nounType of nounTypes) {
334
- const confidence = await this.calculateEntityTypeConfidence(mainText, dataItem, nounType);
335
- if (confidence >= config.confidenceThreshold - 0.2) { // Allow slightly lower for alternatives
336
- const reasoning = await this.generateEntityReasoning(mainText, dataItem, nounType);
337
- detections.push({ type: nounType, confidence, reasoning });
338
- }
339
- }
340
- if (detections.length > 0) {
341
- // Sort by confidence
342
- detections.sort((a, b) => b.confidence - a.confidence);
343
- const primaryType = detections[0];
344
- const alternatives = detections.slice(1, 3); // Top 2 alternatives
345
- entities.push({
346
- originalData: dataItem,
347
- nounType: primaryType.type,
348
- confidence: primaryType.confidence,
349
- suggestedId: this.generateSmartId(dataItem, primaryType.type, index),
350
- reasoning: primaryType.reasoning,
351
- alternativeTypes: alternatives
352
- });
353
- }
354
- }
355
- return entities;
356
- }
357
- /**
358
- * Calculate entity type confidence using AI
359
- */
360
- async calculateEntityTypeConfidence(text, data, nounType) {
361
- // Base semantic similarity using search
362
- const searchResults = await this.brainy.search(text + ' ' + nounType, 1);
363
- const textSimilarity = searchResults.length > 0 ? searchResults[0].score : 0.5;
364
- // Field-based confidence boost
365
- const fieldBoost = this.calculateFieldBasedConfidence(data, nounType);
366
- // Pattern-based confidence boost
367
- const patternBoost = this.calculatePatternBasedConfidence(text, data, nounType);
368
- // Combine confidences with weights
369
- const combined = (textSimilarity * 0.5) + (fieldBoost * 0.3) + (patternBoost * 0.2);
370
- return Math.min(combined, 1.0);
371
- }
372
- /**
373
- * Field-based confidence calculation
219
+ * Infer noun type from object structure
374
220
  */
375
- calculateFieldBasedConfidence(data, nounType) {
376
- const fields = Object.keys(data);
377
- let boost = 0;
378
- // Field patterns that boost confidence for specific noun types
379
- const fieldPatterns = {
380
- [NounType.Person]: ['name', 'email', 'phone', 'age', 'firstname', 'lastname', 'employee'],
381
- [NounType.Organization]: ['company', 'organization', 'corp', 'inc', 'ltd', 'department', 'team'],
382
- [NounType.Project]: ['project', 'task', 'deadline', 'status', 'milestone', 'deliverable'],
383
- [NounType.Location]: ['address', 'city', 'country', 'state', 'zip', 'location', 'coordinates'],
384
- [NounType.Product]: ['product', 'price', 'sku', 'inventory', 'category', 'brand'],
385
- [NounType.Event]: ['date', 'time', 'venue', 'event', 'meeting', 'conference', 'schedule']
386
- };
387
- const relevantPatterns = fieldPatterns[nounType] || [];
388
- for (const field of fields) {
389
- for (const pattern of relevantPatterns) {
390
- if (field.toLowerCase().includes(pattern)) {
391
- boost += 0.1;
392
- }
393
- }
394
- }
395
- return Math.min(boost, 0.5);
221
+ inferNounType(obj) {
222
+ // Simple heuristics for type detection
223
+ if (obj.email || obj.username)
224
+ return 'Person';
225
+ if (obj.title && obj.content)
226
+ return 'Document';
227
+ if (obj.price || obj.product)
228
+ return 'Product';
229
+ if (obj.date || obj.timestamp)
230
+ return 'Event';
231
+ if (obj.url || obj.link)
232
+ return 'Resource';
233
+ if (obj.lat || obj.longitude)
234
+ return 'Location';
235
+ // Default fallback
236
+ return 'Entity';
396
237
  }
397
238
  /**
398
- * Pattern-based confidence calculation
239
+ * Detect relationships from object references
399
240
  */
400
- calculatePatternBasedConfidence(text, data, nounType) {
401
- let boost = 0;
402
- // Content patterns that indicate entity types
403
- const patterns = {
404
- [NounType.Person]: [
405
- /@.*\.com/i, // Email pattern
406
- /\b[A-Z][a-z]+ [A-Z][a-z]+\b/, // Name pattern
407
- /Mr\.|Mrs\.|Dr\.|Prof\./i // Title pattern
408
- ],
409
- [NounType.Organization]: [
410
- /\bInc\.|Corp\.|LLC\.|Ltd\./i, // Corporate suffixes
411
- /Company|Corporation|Enterprise/i
412
- ],
413
- [NounType.Location]: [
414
- /\b\d{5}(-\d{4})?\b/, // ZIP code
415
- /Street|Ave|Road|Blvd/i
416
- ]
417
- };
418
- const relevantPatterns = patterns[nounType] || [];
419
- for (const pattern of relevantPatterns) {
420
- if (pattern.test(text)) {
421
- boost += 0.15;
241
+ detectRelationships(obj, sourceId, relationships) {
242
+ // Look for reference patterns
243
+ for (const [key, value] of Object.entries(obj)) {
244
+ if (key.endsWith('Id') || key.endsWith('_id') || key === 'parentId' || key === 'userId') {
245
+ relationships.push({
246
+ sourceId,
247
+ targetId: String(value),
248
+ verbType: this.inferVerbType(key),
249
+ confidence: 0.75,
250
+ weight: 1,
251
+ reasoning: `Reference detected in field: ${key}`,
252
+ context: key
253
+ });
422
254
  }
423
- }
424
- return Math.min(boost, 0.3);
425
- }
426
- /**
427
- * Generate reasoning for entity type selection
428
- */
429
- async generateEntityReasoning(text, data, nounType) {
430
- const reasons = [];
431
- // Semantic similarity reason
432
- const searchResults = await this.brainy.search(text + ' ' + nounType, 1);
433
- const similarity = searchResults.length > 0 ? searchResults[0].score : 0.5;
434
- if (similarity > 0.7) {
435
- reasons.push(`High semantic similarity (${(similarity * 100).toFixed(1)}%)`);
436
- }
437
- // Field-based reasons
438
- const relevantFields = this.getRelevantFields(data, nounType);
439
- if (relevantFields.length > 0) {
440
- reasons.push(`Contains ${nounType}-specific fields: ${relevantFields.join(', ')}`);
441
- }
442
- // Pattern-based reasons
443
- const matchedPatterns = this.getMatchedPatterns(text, data, nounType);
444
- if (matchedPatterns.length > 0) {
445
- reasons.push(`Matches ${nounType} patterns: ${matchedPatterns.join(', ')}`);
446
- }
447
- return reasons.length > 0 ? reasons.join('; ') : 'General semantic match';
448
- }
449
- /**
450
- * Neural Relationship Detection
451
- */
452
- async detectRelationshipsWithNeuralAnalysis(entities, rawData, config = this.config) {
453
- const relationships = [];
454
- const verbTypes = Object.values(VerbType);
455
- // For each pair of entities, test relationship possibilities
456
- for (let i = 0; i < entities.length; i++) {
457
- for (let j = i + 1; j < entities.length; j++) {
458
- const sourceEntity = entities[i];
459
- const targetEntity = entities[j];
460
- // Extract context for relationship detection
461
- const context = this.extractRelationshipContext(sourceEntity.originalData, targetEntity.originalData, rawData);
462
- // Test all verb types
463
- for (const verbType of verbTypes) {
464
- const confidence = await this.calculateRelationshipConfidence(sourceEntity, targetEntity, verbType, context);
465
- if (confidence >= config.confidenceThreshold - 0.1) { // Slightly lower threshold for relationships
466
- const weight = config.enableWeights ?
467
- this.calculateRelationshipWeight(sourceEntity, targetEntity, verbType, context) :
468
- 0.5;
469
- const reasoning = await this.generateRelationshipReasoning(sourceEntity, targetEntity, verbType, context);
255
+ // Array of IDs
256
+ if (Array.isArray(value) && value.length > 0 && typeof value[0] === 'string') {
257
+ if (key.endsWith('Ids') || key.endsWith('_ids')) {
258
+ for (const targetId of value) {
470
259
  relationships.push({
471
- sourceId: sourceEntity.suggestedId,
472
- targetId: targetEntity.suggestedId,
473
- verbType,
474
- confidence,
475
- weight,
476
- reasoning,
477
- context,
478
- metadata: this.extractRelationshipMetadata(sourceEntity.originalData, targetEntity.originalData, verbType)
260
+ sourceId,
261
+ targetId: String(targetId),
262
+ verbType: this.inferVerbType(key),
263
+ confidence: 0.7,
264
+ weight: 1,
265
+ reasoning: `Array reference in field: ${key}`,
266
+ context: key
479
267
  });
480
268
  }
481
269
  }
482
270
  }
483
271
  }
484
- // Sort by confidence and remove duplicates/conflicts
485
- return this.pruneRelationships(relationships);
486
- }
487
- /**
488
- * Calculate relationship confidence
489
- */
490
- async calculateRelationshipConfidence(source, target, verbType, context) {
491
- // Semantic similarity between entities and verb type
492
- const relationshipText = `${this.extractMainText(source.originalData)} ${verbType} ${this.extractMainText(target.originalData)}`;
493
- const directResults = await this.brainy.search(relationshipText, 1);
494
- const directSimilarity = directResults.length > 0 ? directResults[0].score : 0.5;
495
- // Context-based similarity
496
- const contextResults = await this.brainy.search(context + ' ' + verbType, 1);
497
- const contextSimilarity = contextResults.length > 0 ? contextResults[0].score : 0.5;
498
- // Entity type compatibility
499
- const typeCompatibility = this.calculateTypeCompatibility(source.nounType, target.nounType, verbType);
500
- // Combine with weights
501
- return (directSimilarity * 0.4) + (contextSimilarity * 0.4) + (typeCompatibility * 0.2);
502
- }
503
- /**
504
- * Calculate relationship weight/strength
505
- */
506
- calculateRelationshipWeight(source, target, verbType, context) {
507
- let weight = 0.5; // Base weight
508
- // Context richness (more descriptive = stronger)
509
- const contextWords = context.split(' ').length;
510
- weight += Math.min(contextWords / 20, 0.2);
511
- // Entity importance (higher confidence entities = stronger relationships)
512
- const avgEntityConfidence = (source.confidence + target.confidence) / 2;
513
- weight += avgEntityConfidence * 0.2;
514
- // Verb type specificity (more specific verbs = stronger)
515
- const verbSpecificity = this.getVerbSpecificity(verbType);
516
- weight += verbSpecificity * 0.1;
517
- return Math.min(weight, 1.0);
518
272
  }
519
273
  /**
520
- * Generate Neural Insights - The Intelligence Layer
274
+ * Infer verb type from field name
521
275
  */
522
- async generateNeuralInsights(entities, relationships) {
523
- const insights = [];
524
- // Detect hierarchies
525
- const hierarchies = this.detectHierarchies(relationships);
526
- hierarchies.forEach(hierarchy => {
527
- insights.push({
528
- type: 'hierarchy',
529
- description: `Detected ${hierarchy.type} hierarchy with ${hierarchy.levels} levels`,
530
- confidence: hierarchy.confidence,
531
- affectedEntities: hierarchy.entities,
532
- recommendation: `Consider visualizing the ${hierarchy.type} structure`
533
- });
534
- });
535
- // Detect clusters
536
- const clusters = this.detectClusters(entities, relationships);
537
- clusters.forEach(cluster => {
538
- insights.push({
539
- type: 'cluster',
540
- description: `Found cluster of ${cluster.size} ${cluster.primaryType} entities`,
541
- confidence: cluster.confidence,
542
- affectedEntities: cluster.entities,
543
- recommendation: `These ${cluster.primaryType}s might form a natural grouping`
544
- });
545
- });
546
- // Detect patterns
547
- const patterns = this.detectPatterns(relationships);
548
- patterns.forEach(pattern => {
549
- insights.push({
550
- type: 'pattern',
551
- description: `Common relationship pattern: ${pattern.description}`,
552
- confidence: pattern.confidence,
553
- affectedEntities: pattern.entities,
554
- recommendation: pattern.recommendation
555
- });
556
- });
557
- return insights;
276
+ inferVerbType(fieldName) {
277
+ const normalized = fieldName.toLowerCase();
278
+ if (normalized.includes('parent'))
279
+ return 'childOf';
280
+ if (normalized.includes('user'))
281
+ return 'belongsTo';
282
+ if (normalized.includes('author'))
283
+ return 'authoredBy';
284
+ if (normalized.includes('owner'))
285
+ return 'ownedBy';
286
+ if (normalized.includes('creator'))
287
+ return 'createdBy';
288
+ if (normalized.includes('member'))
289
+ return 'memberOf';
290
+ if (normalized.includes('tag'))
291
+ return 'taggedWith';
292
+ if (normalized.includes('category'))
293
+ return 'categorizedAs';
294
+ return 'relatedTo';
558
295
  }
559
296
  /**
560
- * Helper methods for the neural system
297
+ * Group entities by type
561
298
  */
562
- extractMainText(data) {
563
- // Extract the most relevant text from a data object
564
- const textFields = ['name', 'title', 'description', 'content', 'text', 'label'];
565
- for (const field of textFields) {
566
- if (data[field] && typeof data[field] === 'string') {
567
- return data[field];
299
+ groupByType(entities) {
300
+ const groups = {};
301
+ for (const entity of entities) {
302
+ if (!groups[entity.nounType]) {
303
+ groups[entity.nounType] = [];
568
304
  }
305
+ groups[entity.nounType].push(entity);
569
306
  }
570
- // Fallback: concatenate all string values
571
- return Object.values(data)
572
- .filter(v => typeof v === 'string')
573
- .join(' ')
574
- .substring(0, 200); // Limit length
575
- }
576
- generateSmartId(data, nounType, index) {
577
- const mainText = this.extractMainText(data);
578
- const cleanText = mainText.toLowerCase().replace(/[^a-z0-9]/g, '_').substring(0, 20);
579
- return `${nounType}_${cleanText}_${index}`;
307
+ return groups;
580
308
  }
581
- extractRelationshipContext(source, target, allData) {
582
- // Extract context for relationship detection
583
- return [
584
- this.extractMainText(source),
585
- this.extractMainText(target),
586
- // Add more contextual information
587
- ].join(' ');
588
- }
589
- calculateTypeCompatibility(sourceType, targetType, verbType) {
590
- // Define type compatibility matrix for relationships
591
- const compatibilityMatrix = {
592
- [NounType.Person]: {
593
- [NounType.Organization]: [VerbType.MemberOf, VerbType.WorksWith],
594
- [NounType.Project]: [VerbType.WorksWith, VerbType.Creates],
595
- [NounType.Person]: [VerbType.WorksWith, VerbType.Mentors, VerbType.ReportsTo]
309
+ /**
310
+ * Store neural analysis results
311
+ */
312
+ async storeNeuralAnalysis(analysis) {
313
+ // Cache the analysis for potential later use
314
+ const key = `analysis_${Date.now()}`;
315
+ this.analysisCache.set(key, analysis);
316
+ // Limit cache size
317
+ if (this.analysisCache.size > 100) {
318
+ const firstKey = this.analysisCache.keys().next().value;
319
+ if (firstKey) {
320
+ this.analysisCache.delete(firstKey);
596
321
  }
597
- // Add more compatibility rules
598
- };
599
- const sourceCompatibility = compatibilityMatrix[sourceType];
600
- if (sourceCompatibility && sourceCompatibility[targetType]) {
601
- return sourceCompatibility[targetType].includes(verbType) ? 1.0 : 0.3;
602
322
  }
603
- return 0.5; // Default compatibility
604
- }
605
- getVerbSpecificity(verbType) {
606
- // More specific verbs get higher scores
607
- const specificityScores = {
608
- [VerbType.RelatedTo]: 0.1, // Very generic
609
- [VerbType.WorksWith]: 0.7, // Specific
610
- [VerbType.Mentors]: 0.9, // Very specific
611
- [VerbType.ReportsTo]: 0.9, // Very specific
612
- [VerbType.Supervises]: 0.9 // Very specific
613
- };
614
- return specificityScores[verbType] || 0.5;
615
- }
616
- getRelevantFields(data, nounType) {
617
- // Implementation for finding relevant fields
618
- return [];
619
- }
620
- getMatchedPatterns(text, data, nounType) {
621
- // Implementation for finding matched patterns
622
- return [];
623
- }
624
- pruneRelationships(relationships) {
625
- // Remove duplicates and low-confidence relationships
626
- return relationships
627
- .sort((a, b) => b.confidence - a.confidence)
628
- .slice(0, 1000); // Limit to top 1000 relationships
629
- }
630
- detectHierarchies(relationships) {
631
- // Detect hierarchical structures
632
- return [];
633
- }
634
- detectClusters(entities, relationships) {
635
- // Detect entity clusters
636
- return [];
637
- }
638
- detectPatterns(relationships) {
639
- // Detect relationship patterns
640
- return [];
641
- }
642
- calculateOverallConfidence(entities, relationships) {
643
- if (entities.length === 0)
644
- return 0;
645
- const entityConfidence = entities.reduce((sum, e) => sum + e.confidence, 0) / entities.length;
646
- if (relationships.length === 0)
647
- return entityConfidence;
648
- const relationshipConfidence = relationships.reduce((sum, r) => sum + r.confidence, 0) / relationships.length;
649
- return (entityConfidence + relationshipConfidence) / 2;
650
- }
651
- async storeNeuralAnalysis(analysis) {
652
- // Store the full analysis result for later retrieval by Neural Import or other systems
653
- // This could be stored in the brainy instance metadata or a separate analysis store
654
323
  }
324
+ /**
325
+ * Helper to get data type from file path
326
+ */
655
327
  getDataTypeFromPath(filePath) {
656
328
  const ext = path.extname(filePath).toLowerCase();
657
329
  switch (ext) {
658
330
  case '.json': return 'json';
659
331
  case '.csv': return 'csv';
332
+ case '.txt': return 'text';
660
333
  case '.yaml':
661
334
  case '.yml': return 'yaml';
662
- case '.txt': return 'text';
663
335
  default: return 'text';
664
336
  }
665
337
  }
666
- async generateRelationshipReasoning(source, target, verbType, context) {
667
- return `Neural analysis detected ${verbType} relationship based on semantic context`;
668
- }
669
- extractRelationshipMetadata(sourceData, targetData, verbType) {
670
- return {
671
- sourceType: typeof sourceData,
672
- targetType: typeof targetData,
673
- detectedBy: 'neural-import-sense',
674
- timestamp: new Date().toISOString()
675
- };
676
- }
677
- /**
678
- * Assess data quality metrics
679
- */
680
- assessDataQuality(parsedData, analysis) {
681
- // Completeness: ratio of fields with data
682
- let totalFields = 0;
683
- let filledFields = 0;
684
- parsedData.forEach(item => {
685
- const fields = Object.keys(item);
686
- totalFields += fields.length;
687
- filledFields += fields.filter(field => item[field] !== null &&
688
- item[field] !== undefined &&
689
- item[field] !== '').length;
690
- });
691
- const completeness = totalFields > 0 ? filledFields / totalFields : 0;
692
- // Consistency: variance in field structure
693
- const fieldSets = parsedData.map(item => new Set(Object.keys(item)));
694
- const allFields = new Set(fieldSets.flatMap(set => Array.from(set)));
695
- let consistencyScore = 0;
696
- if (fieldSets.length > 0) {
697
- consistencyScore = Array.from(allFields).reduce((score, field) => {
698
- const hasField = fieldSets.filter(set => set.has(field)).length;
699
- return score + (hasField / fieldSets.length);
700
- }, 0) / allFields.size;
701
- }
702
- // Accuracy: average confidence of detected entities
703
- const accuracy = analysis.detectedEntities.length > 0 ?
704
- analysis.detectedEntities.reduce((sum, e) => sum + e.confidence, 0) / analysis.detectedEntities.length :
705
- 0;
706
- return {
707
- completeness,
708
- consistency: consistencyScore,
709
- accuracy
710
- };
711
- }
712
338
  /**
713
- * Generate recommendations based on analysis
339
+ * PUBLIC API: Process raw data (for external use, like Synapses)
340
+ * This maintains compatibility with code that wants to use Neural Import directly
714
341
  */
715
- generateRecommendations(parsedData, analysis, entityTypes, relationshipTypes) {
716
- const recommendations = [];
717
- // Low entity confidence recommendations
718
- const lowConfidenceEntities = entityTypes.filter(et => et.confidence < 0.7);
719
- if (lowConfidenceEntities.length > 0) {
720
- recommendations.push(`Consider improving field names for ${lowConfidenceEntities.map(e => e.type).join(', ')} entities`);
721
- }
722
- // Missing relationships recommendations
723
- if (relationshipTypes.length === 0 && entityTypes.length > 1) {
724
- recommendations.push('Add fields that describe how entities relate to each other');
725
- }
726
- // Data structure recommendations
727
- if (parsedData.length > 0) {
728
- const firstItem = parsedData[0];
729
- const fieldCount = Object.keys(firstItem).length;
730
- if (fieldCount < 3) {
731
- recommendations.push('Consider adding more descriptive fields to each entity');
732
- }
733
- if (fieldCount > 20) {
734
- recommendations.push('Consider grouping related fields or splitting complex entities');
735
- }
736
- }
737
- // Entity distribution recommendations
738
- const dominantEntityType = entityTypes.reduce((max, current) => current.count > max.count ? current : max, entityTypes[0] || { count: 0 });
739
- if (dominantEntityType && dominantEntityType.count > parsedData.length * 0.8) {
740
- recommendations.push(`Consider diversifying entity types - ${dominantEntityType.type} dominates the dataset`);
342
+ async processRawData(rawData, dataType, options) {
343
+ try {
344
+ const analysis = await this.getNeuralAnalysis(rawData, dataType);
345
+ // Convert to legacy format for compatibility
346
+ const nouns = analysis.detectedEntities.map(e => e.suggestedId);
347
+ const verbs = analysis.detectedRelationships.map(r => `${r.sourceId}->${r.verbType}->${r.targetId}`);
348
+ return {
349
+ success: true,
350
+ data: {
351
+ nouns,
352
+ verbs,
353
+ confidence: analysis.confidence,
354
+ insights: analysis.insights.map(i => ({
355
+ type: i.type,
356
+ description: i.description,
357
+ confidence: i.confidence
358
+ })),
359
+ metadata: {
360
+ detectedEntities: analysis.detectedEntities.length,
361
+ detectedRelationships: analysis.detectedRelationships.length,
362
+ timestamp: new Date().toISOString()
363
+ }
364
+ }
365
+ };
741
366
  }
742
- // Relationship quality recommendations
743
- const lowWeightRelationships = relationshipTypes.filter(rt => rt.confidence < 0.6);
744
- if (lowWeightRelationships.length > 0) {
745
- recommendations.push('Consider adding more contextual information to strengthen relationship detection');
367
+ catch (error) {
368
+ return {
369
+ success: false,
370
+ data: { nouns: [], verbs: [] },
371
+ error: error instanceof Error ? error.message : 'Neural analysis failed'
372
+ };
746
373
  }
747
- return recommendations;
748
374
  }
749
375
  }
750
376
  //# sourceMappingURL=neuralImport.js.map