feat: remember project exclusions and merge selected people
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { expect, it } from "bun:test";
|
||||
import { groupReviewHits, makeTextBatches, spansBySegment } from "../src/lib/project-review";
|
||||
import {
|
||||
canonicalPerson, groupReviewHits, makeTextBatches, mappingForSelection, mergePeople,
|
||||
spansBySegment, withoutWhitelistedHits, withoutWhitelistedRules,
|
||||
} from "../src/lib/project-review";
|
||||
|
||||
it("ordnet gebündelte API-Treffer nach Unicode-Positionen den richtigen Dateien zu", () => {
|
||||
const [batch] = makeTextBatches([
|
||||
@@ -30,3 +33,38 @@ it("zeigt gleiche Zuordnungen einmal mit der Anzahl ihrer Vorkommen", () => {
|
||||
expect(groups.find((group) => group.placeholder === "PERSON_01")?.hits).toHaveLength(2);
|
||||
expect(groups.find((group) => group.placeholder === "PERSON_01")?.hits.map((hit) => hit.id)).toEqual(["a", "b"]);
|
||||
});
|
||||
|
||||
it("unterdrückt projektweit nur exakt abgewählte Begriffe samt erzwungener Regel", () => {
|
||||
const whitelist = [{ type: "PERSON", original: " Max Muster " }];
|
||||
const hits = [
|
||||
{ id: "1", type: "PERSON", original: "max muster", placeholder: "PERSON_01" },
|
||||
{ id: "2", type: "ORG", original: "Max Muster", placeholder: "ORG_01" },
|
||||
{ id: "3", type: "PERSON", original: "Max Mustermann", placeholder: "PERSON_02" },
|
||||
];
|
||||
expect(withoutWhitelistedHits(hits, whitelist).map((hit) => hit.id)).toEqual(["2", "3"]);
|
||||
expect(withoutWhitelistedRules([
|
||||
{ type: "PERSON", value: "Max Muster" }, { type: "ORG", value: "Max Muster" },
|
||||
], whitelist)).toEqual([{ type: "ORG", value: "Max Muster" }]);
|
||||
});
|
||||
|
||||
it("fasst ausgewählte Personen zu einem kanonischen Platzhalter zusammen und bewahrt alte Zuordnungen", () => {
|
||||
let merges = mergePeople({}, "PERSON_02", "PERSON_01");
|
||||
merges = mergePeople(merges, "PERSON_03", "PERSON_02");
|
||||
expect(canonicalPerson("PERSON_03", merges)).toBe("PERSON_01");
|
||||
const previous = { PERSON_09: { original: "Alt", type: "PERSON" } };
|
||||
const preview = {
|
||||
...previous,
|
||||
PERSON_01: { original: "Franz Fuchs", type: "PERSON" },
|
||||
PERSON_02: { original: "Franz", type: "PERSON" },
|
||||
PERSON_03: { original: "Hr. Fuchs", type: "PERSON" },
|
||||
PERSON_04: { original: "Fehlalarm", type: "PERSON" },
|
||||
};
|
||||
const accepted = ["PERSON_01", "PERSON_02", "PERSON_03"].map((placeholder) => ({
|
||||
id: placeholder, type: "PERSON", original: preview[placeholder as keyof typeof preview].original, placeholder,
|
||||
}));
|
||||
const mapping = mappingForSelection(preview, previous, accepted, merges);
|
||||
expect(mapping.PERSON_02.merged_into).toBe("PERSON_01");
|
||||
expect(mapping.PERSON_03.merged_into).toBe("PERSON_01");
|
||||
expect(mapping.PERSON_09.original).toBe("Alt");
|
||||
expect(mapping.PERSON_04).toBeUndefined();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user