Recheck project filenames and Word commenters

This commit is contained in:
muena
2026-09-25 10:49:21 +02:00
parent d0d6a29ef6
commit c3ef1a6aed
7 changed files with 51 additions and 10 deletions

View File

@@ -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[] = [];

View File

@@ -112,6 +112,7 @@ export async function reviseProjectRun(args: {
const { directory, run } = created;
run.origin = previous.origin;
run.revisedFrom = previous.id;
run.commentAuthorCoverage = previous.commentAuthorCoverage;
run.mapping = plan.mapping;
run.matchModes = Object.fromEntries(Object.entries(previous.matchModes ?? {})
.filter(([key]) => key in plan.mapping));

View File

@@ -28,6 +28,8 @@ export type ProjectRun = {
sourceInPlace?: boolean;
/** Previous immutable snapshot when a project run was revised after creation. */
revisedFrom?: string;
/** Word comment authors were reviewed with the explicit author recognizer. */
commentAuthorCoverage?: boolean;
};
const DOCUMENTS = new Set([".docx", ".xlsx", ".pptx", ".pdf"]);