feat: improve Velum hit review and session creation
This commit is contained in:
@@ -91,12 +91,14 @@ it("merkt abgelehnte Sitzungstreffer und schlägt sie im nächsten Lauf nicht er
|
||||
spans: [{ start: 0, end: 11, type: "PERSON", score: 0.8,
|
||||
placeholder: "PERSON_01", original: "Fachbegriff" }],
|
||||
});
|
||||
const prepared = await prepareTextInContext({ sessionId: "__new_session__" },
|
||||
const prepared = await prepareTextInContext({ sessionId: "__new_session__", newSessionName: " Kundenmail " },
|
||||
"Fachbegriff", ["PERSON"], request);
|
||||
expect(await sessions.listSessions()).toHaveLength(0);
|
||||
const { result, session } = await commitPreparedText(prepared, new Set());
|
||||
expect(result.pseudonymized_text).toBe("Fachbegriff");
|
||||
expect(session.name).toBe("Kundenmail");
|
||||
expect(session.mapping).toEqual({});
|
||||
expect(await sessions.getActiveSessionId()).toBe(session.id);
|
||||
expect((await sessions.getSession(session.id))?.excludedTerms).toEqual([
|
||||
{ type: "PERSON", original: "Fachbegriff" },
|
||||
]);
|
||||
@@ -104,6 +106,59 @@ it("merkt abgelehnte Sitzungstreffer und schlägt sie im nächsten Lauf nicht er
|
||||
expect(next.raw.spans).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(["session", "project"])("fasst geprüfte Namensvarianten zusammen und speichert sie für Folgeläufe (%s)", async (context) => {
|
||||
let values = { sessionId: "__new_session__", newProjectPath: [] as string[] };
|
||||
if (context === "project") {
|
||||
const root = await fs.mkdtemp(join(tmpdir(), "velum-text-merge-"));
|
||||
roots.push(root);
|
||||
const folder = join(root, "Projekt");
|
||||
await fs.mkdir(folder);
|
||||
values = { sessionId: "__new_project__", newProjectPath: [folder] };
|
||||
}
|
||||
const source = "😀 Max Muster\nMax und Mia";
|
||||
const prepared = await prepareTextInContext(values, source, ["PERSON"], async () => ({
|
||||
pseudonymized_text: "😀 PERSON_01\nPERSON_02 und PERSON_03",
|
||||
selected_entity_types: ["PERSON"], entity_count: 3,
|
||||
mapping: {
|
||||
PERSON_01: { type: "PERSON", original: "Max Muster" },
|
||||
PERSON_02: { type: "PERSON", original: "Max" },
|
||||
PERSON_03: { type: "PERSON", original: "Mia" },
|
||||
},
|
||||
spans: [
|
||||
{ start: 2, end: 12, type: "PERSON", score: 1, placeholder: "PERSON_01", original: "Max Muster" },
|
||||
{ start: 13, end: 16, type: "PERSON", score: 1, placeholder: "PERSON_02", original: "Max" },
|
||||
{ start: 21, end: 24, type: "PERSON", score: 1, placeholder: "PERSON_03", original: "Mia" },
|
||||
],
|
||||
}));
|
||||
await expect(commitPreparedText(prepared, new Set([0, 1]), true, { PERSON_02: "PERSON_03" }))
|
||||
.rejects.toThrow("ausgewählte Personen");
|
||||
const { result, session } = await commitPreparedText(prepared, new Set([0, 1]), true, { PERSON_02: "PERSON_01" });
|
||||
expect(result.pseudonymized_text).toBe("😀 <PERSON_01>\n<PERSON_01> und Mia");
|
||||
expect(result.entity_count).toBe(1);
|
||||
expect(result.spans.map((span) => span.placeholder)).toEqual(["PERSON_01", "PERSON_01"]);
|
||||
expect(result.mapping["<PERSON_02>"]).toEqual({ type: "PERSON", original: "Max", merged_into: "<PERSON_01>" });
|
||||
expect(result.mapping["<PERSON_03>"]).toBeUndefined();
|
||||
expect(session.mapping["<PERSON_02>"].original).toBe("Max Muster");
|
||||
|
||||
const followup = await prepareTextInContext({ sessionId: session.id }, "Max und Maximilian", ["PERSON"],
|
||||
async (_text, mapping) => {
|
||||
expect(mapping.PERSON_02.merged_into).toBe("PERSON_01");
|
||||
expect(mapping["<PERSON_02>"]).toBeUndefined();
|
||||
return {
|
||||
pseudonymized_text: "PERSON_01 und PERSON_03", selected_entity_types: ["PERSON"], entity_count: 2,
|
||||
mapping: { ...mapping, PERSON_03: { type: "PERSON", original: "Maximilian" } },
|
||||
spans: [
|
||||
{ start: 0, end: 3, type: "PERSON", score: 1, placeholder: "PERSON_01", original: "Max" },
|
||||
{ start: 8, end: 18, type: "PERSON", score: 1, placeholder: "PERSON_03", original: "Maximilian" },
|
||||
],
|
||||
};
|
||||
});
|
||||
const updated = await commitPreparedText(followup, new Set([0, 1]), false, { PERSON_01: "PERSON_03" });
|
||||
expect(updated.result.pseudonymized_text).toBe("PERSON_03 und PERSON_03");
|
||||
expect(updated.result.mapping.PERSON_02.merged_into).toBe("PERSON_03");
|
||||
expect(updated.session.mapping.PERSON_02.original).toBe("Maximilian");
|
||||
});
|
||||
|
||||
it("entfernt eine False-Positive-Gruppe aus der Sitzung und merkt alle Varianten", async () => {
|
||||
const session = await sessions.createSession("Test");
|
||||
await sessions.updateSessionMapping(session.id, {
|
||||
|
||||
Reference in New Issue
Block a user