From 178e137fbb6c07ee6dfa97c664cf5a2da7a4ef90 Mon Sep 17 00:00:00 2001 From: Stefan Plociennik <stefan.plociennik@mni.thm.de> Date: Sat, 15 May 2021 12:11:04 +0200 Subject: [PATCH] implemented profanity filter for german, english and french --- .../util/topic-cloud-admin.service.ts | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/app/services/util/topic-cloud-admin.service.ts b/src/app/services/util/topic-cloud-admin.service.ts index 1dc8e0aed..2a391cca8 100644 --- a/src/app/services/util/topic-cloud-admin.service.ts +++ b/src/app/services/util/topic-cloud-admin.service.ts @@ -1,29 +1,47 @@ import { Injectable } from '@angular/core'; -import * as BadWordsList from 'badwords-list/lib/index.js'; +import * as BadWords from 'naughty-words'; + @Injectable({ providedIn: 'root' }) export class TopicCloudAdminService { - private badWords: string[] = []; + private badWords = []; get getBadWordList(): string[]{ return this.badWords; } constructor() { - this.badWords = BadWordsList.array; + this.badWords = BadWords; } filterProfanityWords(str: string): string{ let questionWithProfinity = str; - this.badWords.map(word =>{ - questionWithProfinity = questionWithProfinity.toLowerCase().includes(word) ? - this.replaceString(questionWithProfinity.toLowerCase(), word, this.generateXWord(word.length)) - : questionWithProfinity; - }); - return questionWithProfinity; + + // German Profanity + this.badWords['de'].map(word =>{ + questionWithProfinity = questionWithProfinity.toLowerCase().includes(word) ? + this.replaceString(questionWithProfinity.toLowerCase(), word, this.generateXWord(word.length)) + : questionWithProfinity; + }); + + // English Profanity + this.badWords['en'].map(word =>{ + questionWithProfinity = questionWithProfinity.toLowerCase().includes(word) ? + this.replaceString(questionWithProfinity.toLowerCase(), word, this.generateXWord(word.length)) + : questionWithProfinity; + }); + + // French Profanity + this.badWords['fr'].map(word =>{ + questionWithProfinity = questionWithProfinity.toLowerCase().includes(word) ? + this.replaceString(questionWithProfinity.toLowerCase(), word, this.generateXWord(word.length)) + : questionWithProfinity; + }); + + return questionWithProfinity; } addToBadwordList(word: string){ -- GitLab