interface interactive
This commit is contained in:
32
app/utils/generateAnonymizedText.ts
Normal file
32
app/utils/generateAnonymizedText.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user