@soulcraft/brainy 4.3.0 → 4.3.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.
|
@@ -129,6 +129,24 @@ export declare class SmartExcelImporter {
|
|
|
129
129
|
* Map type string to NounType
|
|
130
130
|
*/
|
|
131
131
|
private mapTypeString;
|
|
132
|
+
/**
|
|
133
|
+
* Infer entity type from Excel sheet name
|
|
134
|
+
*
|
|
135
|
+
* Uses common naming patterns to suggest appropriate entity types:
|
|
136
|
+
* - "Characters", "People", "Humans" → Person
|
|
137
|
+
* - "Places", "Locations" → Location
|
|
138
|
+
* - "Terms", "Concepts", "Glossary" → Concept
|
|
139
|
+
* - etc.
|
|
140
|
+
*
|
|
141
|
+
* @param sheetName - Excel sheet name
|
|
142
|
+
* @returns Inferred NounType or null if no match
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* inferTypeFromSheetName("Characters") // → NounType.Person
|
|
146
|
+
* inferTypeFromSheetName("Places") // → NounType.Location
|
|
147
|
+
* inferTypeFromSheetName("Animals") // → null (no semantic hint)
|
|
148
|
+
*/
|
|
149
|
+
private inferTypeFromSheetName;
|
|
132
150
|
/**
|
|
133
151
|
* Infer relationship type from context using SmartRelationshipExtractor
|
|
134
152
|
*/
|
|
@@ -107,10 +107,16 @@ export class SmartExcelImporter {
|
|
|
107
107
|
? this.brain.extractConcepts(definition, { limit: 10 }).catch(() => [])
|
|
108
108
|
: Promise.resolve([])
|
|
109
109
|
]);
|
|
110
|
-
// Determine main entity type
|
|
110
|
+
// Determine main entity type with priority order:
|
|
111
|
+
// 1. Explicit "Type" column (highest priority - user specified)
|
|
112
|
+
// 2. Sheet name inference (NEW - semantic hint from Excel structure)
|
|
113
|
+
// 3. AI extraction from related entities
|
|
114
|
+
// 4. Default to Thing (fallback)
|
|
115
|
+
const sheetTypeHint = this.inferTypeFromSheetName(row._sheet || '');
|
|
111
116
|
const mainEntityType = type ?
|
|
112
117
|
this.mapTypeString(type) :
|
|
113
|
-
|
|
118
|
+
sheetTypeHint ||
|
|
119
|
+
(relatedEntities.length > 0 ? relatedEntities[0].type : NounType.Thing);
|
|
114
120
|
// Generate entity ID
|
|
115
121
|
const entityId = this.generateEntityId(term);
|
|
116
122
|
// Create main entity
|
|
@@ -297,6 +303,58 @@ export class SmartExcelImporter {
|
|
|
297
303
|
};
|
|
298
304
|
return mapping[normalized] || NounType.Thing;
|
|
299
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Infer entity type from Excel sheet name
|
|
308
|
+
*
|
|
309
|
+
* Uses common naming patterns to suggest appropriate entity types:
|
|
310
|
+
* - "Characters", "People", "Humans" → Person
|
|
311
|
+
* - "Places", "Locations" → Location
|
|
312
|
+
* - "Terms", "Concepts", "Glossary" → Concept
|
|
313
|
+
* - etc.
|
|
314
|
+
*
|
|
315
|
+
* @param sheetName - Excel sheet name
|
|
316
|
+
* @returns Inferred NounType or null if no match
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* inferTypeFromSheetName("Characters") // → NounType.Person
|
|
320
|
+
* inferTypeFromSheetName("Places") // → NounType.Location
|
|
321
|
+
* inferTypeFromSheetName("Animals") // → null (no semantic hint)
|
|
322
|
+
*/
|
|
323
|
+
inferTypeFromSheetName(sheetName) {
|
|
324
|
+
if (!sheetName)
|
|
325
|
+
return null;
|
|
326
|
+
const normalized = sheetName.toLowerCase();
|
|
327
|
+
// Person types: characters, people, humans, individuals
|
|
328
|
+
if (normalized.match(/character|people|person|human|individual|npc|cast/)) {
|
|
329
|
+
return NounType.Person;
|
|
330
|
+
}
|
|
331
|
+
// Location types: places, locations, areas, regions
|
|
332
|
+
if (normalized.match(/place|location|area|region|zone|geography|map|world/)) {
|
|
333
|
+
return NounType.Location;
|
|
334
|
+
}
|
|
335
|
+
// Concept types: terms, concepts, ideas, glossary
|
|
336
|
+
if (normalized.match(/term|concept|idea|definition|glossary|vocabulary|lexicon/)) {
|
|
337
|
+
return NounType.Concept;
|
|
338
|
+
}
|
|
339
|
+
// Organization types: groups, factions, companies
|
|
340
|
+
if (normalized.match(/organization|company|group|faction|tribe|guild|clan|corp/)) {
|
|
341
|
+
return NounType.Organization;
|
|
342
|
+
}
|
|
343
|
+
// Event types: events, occurrences, happenings
|
|
344
|
+
if (normalized.match(/event|occurrence|happening|battle|encounter|scene/)) {
|
|
345
|
+
return NounType.Event;
|
|
346
|
+
}
|
|
347
|
+
// Product types: items, equipment, gear
|
|
348
|
+
if (normalized.match(/item|product|equipment|gear|weapon|armor|artifact|treasure/)) {
|
|
349
|
+
return NounType.Product;
|
|
350
|
+
}
|
|
351
|
+
// Project types: quests, missions, campaigns
|
|
352
|
+
if (normalized.match(/project|quest|mission|campaign|task/)) {
|
|
353
|
+
return NounType.Project;
|
|
354
|
+
}
|
|
355
|
+
// No semantic match found - return null to continue to next type determination method
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
300
358
|
/**
|
|
301
359
|
* Infer relationship type from context using SmartRelationshipExtractor
|
|
302
360
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soulcraft/brainy",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "Universal Knowledge Protocol™ - World's first Triple Intelligence database unifying vector, graph, and document search in one API. 31 nouns × 40 verbs for infinite expressiveness.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|