-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_selection.js
More file actions
46 lines (38 loc) · 1.45 KB
/
test_selection.js
File metadata and controls
46 lines (38 loc) · 1.45 KB
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
const entities = new Map();
entities.set("Sherlock", {
name: "Sherlock",
aliases: ["Holmes"],
occurrences: []
});
const contextText = "Holmes looked at the evidence.";
const entitiesInContext = new Set();
// Current logic (simplified) - only looks for explicit @@ tags
const entityRegex = /@@(?:([\p{L}\p{N}_]+)|\(([\p{L}\p{N}_]+)\))/gu;
let match;
while ((match = entityRegex.exec(contextText)) !== null) {
const entityName = (match[1] || match[2]).replace(/_/g, " ");
entitiesInContext.add(entityName);
}
console.log("Entities found (current logic):", [...entitiesInContext]);
// New logic - looks for names and aliases
const newEntitiesInContext = new Set();
// 1. Add explicit annotations (keep existing logic)
// Reset regex
entityRegex.lastIndex = 0;
while ((match = entityRegex.exec(contextText)) !== null) {
const entityName = (match[1] || match[2]).replace(/_/g, " ");
newEntitiesInContext.add(entityName);
}
// 2. Add implicit references (names and aliases)
entities.forEach((entity, name) => {
const candidates = [name, ...(entity.aliases || [])];
candidates.forEach(candidate => {
// Escape special regex chars
const escaped = candidate.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const regex = new RegExp(`\\b${escaped}\\b`, 'u');
if (regex.test(contextText)) {
newEntitiesInContext.add(name);
}
});
});
console.log("Entities found (new logic):", [...newEntitiesInContext]);