Recheck project filenames and Word commenters
This commit is contained in:
@@ -9,6 +9,20 @@ export type BatchItem = { key: string; text: string };
|
||||
export type BatchSegment = BatchItem & { start: number; end: number };
|
||||
export type TextBatch = { text: string; segments: BatchSegment[] };
|
||||
|
||||
/** Filename separators look like spaces to NER, except inside known literal terms. */
|
||||
export function filenameScanText(stem: string, knownTerms: Iterable<string>): string {
|
||||
const protectedOffsets = new Set<number>();
|
||||
for (const term of knownTerms) {
|
||||
if (!term.includes("_")) continue;
|
||||
const escaped = term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
const pattern = new RegExp(`(?<![\\p{L}\\p{N}])${escaped}(?![\\p{L}\\p{N}])`, "giu");
|
||||
for (const match of stem.matchAll(pattern)) {
|
||||
for (let offset = match.index; offset < match.index + match[0].length; offset++) protectedOffsets.add(offset);
|
||||
}
|
||||
}
|
||||
return stem.replace(/_/g, (_character, offset: number) => protectedOffsets.has(offset) ? "_" : " ");
|
||||
}
|
||||
|
||||
/** Keep file boundaries while reducing many small text/path API calls to a few batches. */
|
||||
export function makeTextBatches(items: BatchItem[], limit = MAX_BATCH_CODEPOINTS): TextBatch[] {
|
||||
const batches: TextBatch[] = [];
|
||||
|
||||
Reference in New Issue
Block a user