Skip to content
Snippets Groups Projects
Commit 446eea0f authored by Ruben Bimberg's avatar Ruben Bimberg :computer:
Browse files

Merge branch '669-put-some-notorious-keywords-on-the-blacklist-for-all-rooms' into 'staging'

Resolve "Put some notorious keywords on the blacklist for all rooms"

Closes #659, #669, and #670

See merge request arsnova/frag.jetzt!685
parents 4cd88119 3f76feb0
Branches
Tags
No related merge requests found
...@@ -8,6 +8,7 @@ import { ExplanationDialogComponent } from '../explanation-dialog/explanation-di ...@@ -8,6 +8,7 @@ import { ExplanationDialogComponent } from '../explanation-dialog/explanation-di
import { DeepLService, FormalityType, TargetLang } from '../../../../services/http/deep-l.service'; import { DeepLService, FormalityType, TargetLang } from '../../../../services/http/deep-l.service';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { CreateCommentKeywords } from '../../../../utils/create-comment-keywords';
interface ResultValue { interface ResultValue {
body: string; body: string;
...@@ -48,7 +49,7 @@ export class DeepLDialogComponent implements OnInit, AfterViewInit { ...@@ -48,7 +49,7 @@ export class DeepLDialogComponent implements OnInit, AfterViewInit {
const delta = ViewCommentDataComponent.getDeltaFromData(body); const delta = ViewCommentDataComponent.getDeltaFromData(body);
const xml = delta.ops.reduce((acc, e, i) => { const xml = delta.ops.reduce((acc, e, i) => {
if (typeof e['insert'] === 'string' && e['insert'].trim().length) { if (typeof e['insert'] === 'string' && e['insert'].trim().length) {
acc += '<x i="' + i + '">' + this.encodeHTML(e['insert']) + '</x>'; acc += '<x i="' + i + '">' + this.encodeHTML(CreateCommentKeywords.removeMarkdown(e['insert'])) + '</x>';
e['insert'] = ''; e['insert'] = '';
} }
return acc; return acc;
......
...@@ -69,7 +69,9 @@ class TagComment implements CloudData { ...@@ -69,7 +69,9 @@ class TagComment implements CloudData {
const transformationScaleKiller = /scale\([^)]*\)/; const transformationScaleKiller = /scale\([^)]*\)/;
const transformationRotationKiller = /rotate\(([^)]*)\)/; const transformationRotationKiller = /rotate\(([^)]*)\)/;
const maskedCharsRegex = /[“”‘’„‚«»‹›『』﹃﹄「」﹁﹂",《》〈〉'`#&]|(\s(lu|li’u)(?=\s))|(^lu\s)|(\sli’u$)/gm; const maskedCharRegex = /[“”‘’„‚«»‹›『』﹃﹄「」﹁﹂",《》〈〉'`#&]|(\s(lu|li’u)(?=\s))|(^lu\s)|(\sli’u$)/;
const httpRegex = /(https?:[^\s](\s|$))/;
const hidelist = new RegExp(maskedCharRegex.source + '|' + httpRegex.source, 'gmi');
const CONDITION_ROOM = 0; const CONDITION_ROOM = 0;
const CONDITION_BUILT = 1; const CONDITION_BUILT = 1;
...@@ -318,7 +320,7 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit { ...@@ -318,7 +320,7 @@ export class TagCloudComponent implements OnInit, OnDestroy, AfterContentInit {
if (rotation === null || this._currentSettings.randomAngles) { if (rotation === null || this._currentSettings.randomAngles) {
rotation = Math.floor(Math.random() * 30 - 15); rotation = Math.floor(Math.random() * 30 - 15);
} }
const filteredTag = tag.replace(maskedCharsRegex, '') const filteredTag = tag.replace(hidelist, '')
.replace(regexMaskKeyword, '').replace(/ +/, ' ').trim(); .replace(regexMaskKeyword, '').replace(/ +/, ' ').trim();
newElements.push(new TagComment(filteredTag, tag, rotation, tagData.weight, tagData, newElements.length)); newElements.push(new TagComment(filteredTag, tag, rotation, tagData.weight, tagData, newElements.length));
} }
......
...@@ -17,7 +17,11 @@ import { UserRole } from '../../models/user-roles.enum'; ...@@ -17,7 +17,11 @@ import { UserRole } from '../../models/user-roles.enum';
import { CloudParameters } from '../../utils/cloud-parameters'; import { CloudParameters } from '../../utils/cloud-parameters';
import { RoomDataService } from './room-data.service'; import { RoomDataService } from './room-data.service';
export const regexMaskKeyword = /\b(frage|antwort|aufgabe|hallo|test|bzw|muss|more to come)\b/gmi; const words = [
'frage', 'antwort', 'aufgabe', 'hallo', 'test', 'bzw', 'bzw.', 'muss', 'more to come', 'mal', 'zb', 'zb\\.',
'z\\.\\s*b\\.', 'zum beispiel', 'beispiel', 'jeder?', 'jede/r', 'bisschen', 'bißchen', 'okay', 'ok', 'o.k.'
];
export const regexMaskKeyword = new RegExp('\\b(' + words.join('|') + ')\\b|…|\\\\|\\/', 'gmi');
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
......
...@@ -3,11 +3,17 @@ import { map } from 'rxjs/operators'; ...@@ -3,11 +3,17 @@ import { map } from 'rxjs/operators';
export class CreateCommentKeywords { export class CreateCommentKeywords {
static isKeywordAcceptable(keyword: string) { static isKeywordAcceptable(keyword: string): boolean {
const regex = /(^[ -@\[-`{-~]+$)/g; const regex = /(^[ -@\[-`{-~]+$)/g;
return keyword.match(regex) === null && keyword.length > 2; return keyword.match(regex) === null && keyword.length > 2;
} }
static removeMarkdown(text: string): string {
return text.replace(/([*_~]+(?=[^*_~\s]))|(^[ \t]*#+ )|(^[ \t]*>[> ]*)|(`+)/gm, '')
.replace(/([^*_~\s])[*_~]+/gm, '$1')
.replace(/\[([^\n\[\]]*)\]\(([^()\n]*)\)/gm, '$1 $2');
}
static isSpellingAcceptable(languagetoolService: LanguagetoolService, text: string, language: Language = 'auto') { static isSpellingAcceptable(languagetoolService: LanguagetoolService, text: string, language: Language = 'auto') {
return languagetoolService.checkSpellings(text, language).pipe( return languagetoolService.checkSpellings(text, language).pipe(
map(result => { map(result => {
...@@ -16,10 +22,37 @@ export class CreateCommentKeywords { ...@@ -16,10 +22,37 @@ export class CreateCommentKeywords {
const hasLessMistakes = (result.matches.length * 100) / wordCount <= 20; const hasLessMistakes = (result.matches.length * 100) / wordCount <= 20;
return { return {
isAcceptable: hasConfidence && hasLessMistakes, isAcceptable: hasConfidence && hasLessMistakes,
text, text: this.escapeForSpacy(text),
result result
}; };
}) })
); );
} }
private static escapeForSpacy(text: string): string {
text = this.makeCapslockLowercase(text);
return text.replace(/\(([^-\s)]+-)\)([^\s]+)/gmi, '$1$2');
}
private static makeCapslockLowercase(text: string): string {
const upperText = text.toUpperCase();
const regex = /\s+|$/gmi;
let m: RegExpExecArray;
let result = '';
let lastAddedIndex = 0;
while ((m = regex.exec(upperText)) !== null) {
const str = text.substring(lastAddedIndex, m.index);
if (m.index - lastAddedIndex >= 2 && str === upperText.substring(lastAddedIndex, m.index)) {
result += str.toLowerCase();
} else {
result += str;
}
result += text.substring(m.index, regex.lastIndex);
lastAddedIndex = regex.lastIndex;
if (regex.lastIndex === m.index) {
regex.lastIndex++;
}
}
return result;
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment