File size: 2,095 Bytes
fa9c65f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { EntityEntry } from './entity-registry.js';

export interface AliasMatcher {
  alias: string;
  entityId: string;
  regex: RegExp;
}

export interface EntityIndex {
  byId: Map<string, EntityEntry>;
  byAlias: Map<string, string>;
  byKeyword: Map<string, Set<string>>;
  bySector: Map<string, Set<string>>;
  byType: Map<string, Set<string>>;
  aliasMatchers: AliasMatcher[];
}

export interface EntityMatch {
  entityId: string;
  matchedText: string;
  matchType: 'alias' | 'keyword' | 'name';
  confidence: number;
  position: number;
}

export interface ExtractedEntity {
  entityId: string;
  name: string;
  matchedText: string;
  matchType: 'alias' | 'keyword' | 'name';
  confidence: number;
}

export interface EntityClusterInput {
  id: string;
  primaryTitle: string;
  allItems?: Array<{ title: string }>;
}

export interface NewsEntityContext {
  clusterId: string;
  title: string;
  entities: ExtractedEntity[];
  primaryEntity?: string;
  relatedEntityIds: string[];
}

export declare function buildEntityIndex(entities: EntityEntry[]): EntityIndex;
export declare function getEntityIndex(): EntityIndex;
export declare function lookupEntityByAlias(alias: string, index?: EntityIndex): EntityEntry | undefined;
export declare function lookupEntitiesByKeyword(keyword: string, index?: EntityIndex): EntityEntry[];
export declare function lookupEntitiesBySector(sector: string, index?: EntityIndex): EntityEntry[];
export declare function findRelatedEntities(entityId: string, index?: EntityIndex): EntityEntry[];
export declare function findEntitiesInText(text: string, index?: EntityIndex): EntityMatch[];
export declare function getEntityDisplayName(entityId: string, index?: EntityIndex): string;
export declare function extractEntitiesFromTitle(title: string, index?: EntityIndex): ExtractedEntity[];
export declare function extractEntityContext(
  cluster: EntityClusterInput,
  index?: EntityIndex,
): NewsEntityContext;
export declare function extractEntityContexts(
  clusters: EntityClusterInput[],
  index?: EntityIndex,
): Map<string, NewsEntityContext>;