@soulcraft/brainy 4.1.4 → 4.2.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 (52) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/import/FormatDetector.d.ts +6 -1
  3. package/dist/import/FormatDetector.js +40 -1
  4. package/dist/import/ImportCoordinator.d.ts +102 -4
  5. package/dist/import/ImportCoordinator.js +248 -6
  6. package/dist/import/InstancePool.d.ts +136 -0
  7. package/dist/import/InstancePool.js +231 -0
  8. package/dist/importers/SmartCSVImporter.d.ts +2 -1
  9. package/dist/importers/SmartCSVImporter.js +11 -22
  10. package/dist/importers/SmartDOCXImporter.d.ts +125 -0
  11. package/dist/importers/SmartDOCXImporter.js +227 -0
  12. package/dist/importers/SmartExcelImporter.d.ts +12 -1
  13. package/dist/importers/SmartExcelImporter.js +40 -25
  14. package/dist/importers/SmartJSONImporter.d.ts +1 -0
  15. package/dist/importers/SmartJSONImporter.js +25 -6
  16. package/dist/importers/SmartMarkdownImporter.d.ts +2 -1
  17. package/dist/importers/SmartMarkdownImporter.js +11 -16
  18. package/dist/importers/SmartPDFImporter.d.ts +2 -1
  19. package/dist/importers/SmartPDFImporter.js +11 -22
  20. package/dist/importers/SmartYAMLImporter.d.ts +121 -0
  21. package/dist/importers/SmartYAMLImporter.js +275 -0
  22. package/dist/importers/VFSStructureGenerator.js +12 -0
  23. package/dist/neural/SmartExtractor.d.ts +279 -0
  24. package/dist/neural/SmartExtractor.js +592 -0
  25. package/dist/neural/SmartRelationshipExtractor.d.ts +217 -0
  26. package/dist/neural/SmartRelationshipExtractor.js +396 -0
  27. package/dist/neural/embeddedTypeEmbeddings.d.ts +1 -1
  28. package/dist/neural/embeddedTypeEmbeddings.js +2 -2
  29. package/dist/neural/entityExtractor.d.ts +3 -0
  30. package/dist/neural/entityExtractor.js +34 -36
  31. package/dist/neural/presets.d.ts +189 -0
  32. package/dist/neural/presets.js +365 -0
  33. package/dist/neural/signals/ContextSignal.d.ts +166 -0
  34. package/dist/neural/signals/ContextSignal.js +646 -0
  35. package/dist/neural/signals/EmbeddingSignal.d.ts +175 -0
  36. package/dist/neural/signals/EmbeddingSignal.js +435 -0
  37. package/dist/neural/signals/ExactMatchSignal.d.ts +220 -0
  38. package/dist/neural/signals/ExactMatchSignal.js +542 -0
  39. package/dist/neural/signals/PatternSignal.d.ts +159 -0
  40. package/dist/neural/signals/PatternSignal.js +478 -0
  41. package/dist/neural/signals/VerbContextSignal.d.ts +102 -0
  42. package/dist/neural/signals/VerbContextSignal.js +390 -0
  43. package/dist/neural/signals/VerbEmbeddingSignal.d.ts +131 -0
  44. package/dist/neural/signals/VerbEmbeddingSignal.js +304 -0
  45. package/dist/neural/signals/VerbExactMatchSignal.d.ts +115 -0
  46. package/dist/neural/signals/VerbExactMatchSignal.js +335 -0
  47. package/dist/neural/signals/VerbPatternSignal.d.ts +104 -0
  48. package/dist/neural/signals/VerbPatternSignal.js +457 -0
  49. package/dist/types/graphTypes.d.ts +2 -0
  50. package/dist/utils/metadataIndex.d.ts +22 -0
  51. package/dist/utils/metadataIndex.js +76 -0
  52. package/package.json +4 -1
@@ -0,0 +1,166 @@
1
+ /**
2
+ * ContextSignal - Relationship-based entity type classification
3
+ *
4
+ * PRODUCTION-READY: Infers types from relationship patterns in context
5
+ *
6
+ * Weight: 5% (lowest, but critical for ambiguous cases)
7
+ * Speed: Very fast (~1ms) - pure pattern matching on context
8
+ *
9
+ * Key insight: Context reveals type even when entity itself is ambiguous
10
+ * Examples:
11
+ * - "CEO of X" → X is Organization
12
+ * - "lives in Y" → Y is Location
13
+ * - "uses Z" → Z is Technology
14
+ * - "attended W" → W is Event
15
+ *
16
+ * This signal fills the gap when:
17
+ * - Entity is too ambiguous for other signals
18
+ * - Multiple signals conflict
19
+ * - Need relationship-aware classification
20
+ */
21
+ import type { Brainy } from '../../brainy.js';
22
+ import type { NounType } from '../../types/graphTypes.js';
23
+ /**
24
+ * Signal result with classification details
25
+ */
26
+ export interface TypeSignal {
27
+ source: 'context-relationship' | 'context-attribute' | 'context-combined';
28
+ type: NounType;
29
+ confidence: number;
30
+ evidence: string;
31
+ metadata?: {
32
+ relationshipPattern?: string;
33
+ contextMatch?: string;
34
+ relatedEntities?: string[];
35
+ };
36
+ }
37
+ /**
38
+ * Options for context signal
39
+ */
40
+ export interface ContextSignalOptions {
41
+ minConfidence?: number;
42
+ timeout?: number;
43
+ cacheSize?: number;
44
+ }
45
+ /**
46
+ * ContextSignal - Infer entity types from relationship context
47
+ *
48
+ * Production features:
49
+ * - 50+ relationship patterns organized by type
50
+ * - Attribute patterns (e.g., "fast X" → X is Object/Technology)
51
+ * - Multi-pattern matching with confidence boosting
52
+ * - LRU cache for hot entities
53
+ * - Graceful degradation on errors
54
+ */
55
+ export declare class ContextSignal {
56
+ private brain;
57
+ private options;
58
+ private relationshipPatterns;
59
+ private cache;
60
+ private cacheOrder;
61
+ private stats;
62
+ constructor(brain: Brainy, options?: ContextSignalOptions);
63
+ /**
64
+ * Initialize relationship patterns
65
+ *
66
+ * Patterns organized by target type:
67
+ * - Person: roles, actions, possessives
68
+ * - Organization: membership, leadership, employment
69
+ * - Location: spatial relationships, residence
70
+ * - Technology: usage, implementation, integration
71
+ * - Event: attendance, occurrence, scheduling
72
+ * - Concept: understanding, application, theory
73
+ * - Object: ownership, interaction, description
74
+ */
75
+ private initializePatterns;
76
+ /**
77
+ * Add relationship patterns in bulk
78
+ */
79
+ private addPatterns;
80
+ /**
81
+ * Classify entity type using context-based signals
82
+ *
83
+ * Main entry point - checks relationship patterns in definition/context
84
+ *
85
+ * @param candidate Entity text to classify
86
+ * @param context Context with definition and related entities
87
+ * @returns TypeSignal with classification result
88
+ */
89
+ classify(candidate: string, context?: {
90
+ definition?: string;
91
+ allTerms?: string[];
92
+ metadata?: any;
93
+ }): Promise<TypeSignal | null>;
94
+ /**
95
+ * Build search text from candidate and context
96
+ *
97
+ * Extracts text around candidate to find relationship patterns
98
+ */
99
+ private buildSearchText;
100
+ /**
101
+ * Match relationship patterns in context
102
+ *
103
+ * Looks for patterns like "CEO of X" where X is the candidate
104
+ */
105
+ private matchRelationshipPatterns;
106
+ /**
107
+ * Match attribute patterns in context
108
+ *
109
+ * Looks for descriptive patterns like "fast X" where X is the candidate
110
+ */
111
+ private matchAttributePatterns;
112
+ /**
113
+ * Combine results from relationship and attribute matching
114
+ *
115
+ * Prefers relationship matches over attribute matches
116
+ */
117
+ private combineResults;
118
+ /**
119
+ * Get statistics about signal performance
120
+ */
121
+ getStats(): {
122
+ cacheSize: number;
123
+ cacheHitRate: number;
124
+ relationshipMatchRate: number;
125
+ attributeMatchRate: number;
126
+ calls: number;
127
+ cacheHits: number;
128
+ relationshipMatches: number;
129
+ attributeMatches: number;
130
+ combinedMatches: number;
131
+ };
132
+ /**
133
+ * Reset statistics (useful for testing)
134
+ */
135
+ resetStats(): void;
136
+ /**
137
+ * Clear cache
138
+ */
139
+ clearCache(): void;
140
+ /**
141
+ * Get pattern count (for testing)
142
+ */
143
+ getPatternCount(): number;
144
+ /**
145
+ * Generate cache key from candidate and context
146
+ */
147
+ private getCacheKey;
148
+ /**
149
+ * Get from LRU cache (returns undefined if not found, null if cached as null)
150
+ */
151
+ private getFromCache;
152
+ /**
153
+ * Add to LRU cache with eviction
154
+ */
155
+ private addToCache;
156
+ /**
157
+ * Escape special regex characters
158
+ */
159
+ private escapeRegex;
160
+ }
161
+ /**
162
+ * Create a new ContextSignal instance
163
+ *
164
+ * Convenience factory function
165
+ */
166
+ export declare function createContextSignal(brain: Brainy, options?: ContextSignalOptions): ContextSignal;