33 lines
824 B
TypeScript
33 lines
824 B
TypeScript
import { EntityMapping } from "@/app/config/entityLabels";
|
|
|
|
export const generateAnonymizedText = (
|
|
originalText: string,
|
|
mappings: EntityMapping[]
|
|
): string => {
|
|
if (!originalText || !mappings || mappings.length === 0) {
|
|
return originalText;
|
|
}
|
|
|
|
// Trier les mappings par position de début
|
|
const sortedMappings = [...mappings].sort((a, b) => a.start - b.start);
|
|
|
|
let result = "";
|
|
let lastIndex = 0;
|
|
|
|
for (const mapping of sortedMappings) {
|
|
// Ajouter le texte avant l'entité
|
|
result += originalText.slice(lastIndex, mapping.start);
|
|
|
|
// Utiliser displayName comme dans le tableau de mapping
|
|
result += mapping.displayName;
|
|
|
|
// Mettre à jour la position
|
|
lastIndex = mapping.end;
|
|
}
|
|
|
|
// Ajouter le reste du texte
|
|
result += originalText.slice(lastIndex);
|
|
|
|
return result;
|
|
};
|