Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: make extractEntities' name-detection regex script-agnostic

masashiono06117e3cda8b74b6
diff --git a/src/core/enrichment-service.ts b/src/core/enrichment-service.ts
index 0aa869edc7..49cf23936c 100644
--- a/src/core/enrichment-service.ts
+++ b/src/core/enrichment-service.ts
@@ -362,7 +362,7 @@ export function extractEntities(text: string): Array<{ name: string; type: 'pers
// and the Unicode line/paragraph separators (U+2028/U+2029) -- while
// retaining horizontal whitespace (spaces, tabs, NBSP, other Unicode
// space separators), unlike a plain `[ \t]+`.
- const namePattern = /\b([A-Z][a-z]+(?:[^\S\r\n\v\f\u2028\u2029]+[A-Z][a-z]+){1,3})\b/g;
+ const namePattern = /(?<!\p{L})(\p{Lu}[\p{Ll}\p{M}]+(?:[^\S\r\n\v\f\u2028\u2029]+\p{Lu}[\p{Ll}\p{M}]+){1,3})(?!\p{L})/gu;
let match;
while ((match = namePattern.exec(text)) !== null) {
const name = match[1];
diff --git a/test/enrichment-service.test.ts b/test/enrichment-service.test.ts
index a39dcd8dda..d3d7fcd5a3 100644
--- a/test/enrichment-service.test.ts
+++ b/test/enrichment-service.test.ts
@@ -51,6 +51,16 @@ describe('enrichment-service', () => {
expect(names).toContain('Sarah Connor');
});
+ test('extracts capitalized multi-word names in other scripts', () => {
+ // Was ASCII-only ([A-Z][a-z]+): every non-Latin name-shaped token was
+ // invisible to the extractor, so extract_entities found zero entities
+ // in non-Latin text regardless of how well-formed the names were.
+ const entities = extractEntities('Вчера встретился с Иван Петров и Анна Смирнова.');
+ const names = entities.map(e => e.name);
+ expect(names).toContain('Иван Петров');
+ expect(names).toContain('Анна Смирнова');
+ });
+
test('classifies company names with Corp/Inc/Labs', () => {
const entities = extractEntities('We visited Acme Corp and Beta Labs.');
const acme = entities.find(e => e.name.includes('Acme'));