mirror of
https://github.com/Jetsparrow/antiantiswearingbot.git
synced 2026-01-20 23:16:08 +03:00
separate words from punctuation
This commit is contained in:
parent
5db1aefcbb
commit
ed5be399da
40
AntiAntiSwearingBot.Tests/DetectTests.cs
Normal file
40
AntiAntiSwearingBot.Tests/DetectTests.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace AntiAntiSwearingBot.Tests
|
||||
{
|
||||
public class DetectTests
|
||||
{
|
||||
Unbleeper ubl { get; }
|
||||
Config cfg { get; }
|
||||
SearchDictionary dict { get; }
|
||||
|
||||
public DetectTests()
|
||||
{
|
||||
cfg = Config.Load<Config>("aasb.cfg.json");
|
||||
dict = new SearchDictionary(cfg);
|
||||
ubl = new Unbleeper(dict, cfg.Unbleeper);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("бл**ь", "*блядь")]
|
||||
[InlineData("ж**а", "*жопа")]
|
||||
public void UnbleepSimpleSwears(string word, string expected)
|
||||
{
|
||||
var unbleep = ubl.UnbleepSwears(word).TrimEnd(Environment.NewLine.ToCharArray());
|
||||
Assert.Equal(expected, unbleep);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Просто пи**ец, как хочется кушать.", "*пиздец")]
|
||||
[InlineData("Ужас на*уй!", "*нахуй")]
|
||||
[InlineData("Сергей опять вы**нулся своим знанием тонкостей русского языка; в окно еб*шил стылый ноябрьский ветер. ", "*выебнулся\n**ебашил")]
|
||||
public void DetectWordsWithPunctuation(string text, string expected)
|
||||
{
|
||||
var unbleep = ubl.UnbleepSwears(text).Replace("\r\n", "\n").Trim();
|
||||
Assert.Equal(expected, unbleep);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,27 +6,35 @@ namespace AntiAntiSwearingBot.Tests
|
||||
public class FilterTests
|
||||
{
|
||||
Unbleeper ubl { get; }
|
||||
Config cfg { get; }
|
||||
SearchDictionary dict { get; }
|
||||
|
||||
public FilterTests()
|
||||
{
|
||||
var cfg = Config.Load<Config>("aasb.cfg.json", "aasb.cfg.secret.json");
|
||||
var dict = new SearchDictionary(cfg);
|
||||
cfg = Config.Load<Config>("aasb.cfg.json", "aasb.cfg.secret.json");
|
||||
dict = new SearchDictionary(cfg);
|
||||
ubl = new Unbleeper(dict, cfg.Unbleeper);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("бл**ь", "*блядь")]
|
||||
[InlineData("ж**а", "*жопа")]
|
||||
public void UnbleepSimpleSwears(string word, string expected)
|
||||
{
|
||||
var unbleep = ubl.UnbleepSwears(word).TrimEnd(Environment.NewLine.ToCharArray());
|
||||
Assert.Equal(expected, unbleep);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("*")]
|
||||
[InlineData("**#")]
|
||||
[InlineData("@**#")]
|
||||
public void IgnoreShortGrawlixes(string text) => Assert.Null(ubl.UnbleepSwears(text));
|
||||
[InlineData("@*#")]
|
||||
public void IgnoreShortGrawlixesWithoutLetters(string text)
|
||||
{
|
||||
if (text.Length < cfg.Unbleeper.MinAmbiguousWordLength)
|
||||
Assert.Null(ubl.UnbleepSwears(text));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("*")]
|
||||
[InlineData("*б")]
|
||||
[InlineData("х#")]
|
||||
public void IgnoreShortWords(string text)
|
||||
{
|
||||
if (text.Length < cfg.Unbleeper.MinWordLength)
|
||||
Assert.Null(ubl.UnbleepSwears(text));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("@pvkuznetsov https://github.com/jacksondunstan/UnityNativeScripting")]
|
||||
|
||||
@ -20,6 +20,8 @@ namespace AntiAntiSwearingBot
|
||||
|
||||
Regex BleepedSwearsRegex { get; }
|
||||
|
||||
static readonly char[] WORD_SEPARATORS = { ' ', '\t', '\r', '\n', '.', ',', '!', '?', ';' };
|
||||
|
||||
public string UnbleepSwears(string text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
@ -30,7 +32,7 @@ namespace AntiAntiSwearingBot
|
||||
if (text.StartsWith('/')) // is chat command
|
||||
return null;
|
||||
|
||||
var words = text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
|
||||
var words = text.Split(WORD_SEPARATORS, StringSplitOptions.RemoveEmptyEntries);
|
||||
var candidates = words
|
||||
.Where(w =>
|
||||
!Language.IsTelegramMention(w)
|
||||
|
||||
@ -84,6 +84,7 @@
|
||||
выебанный
|
||||
выебат
|
||||
выебаться
|
||||
выебнулся
|
||||
высрать
|
||||
высраться
|
||||
выссать
|
||||
@ -217,6 +218,7 @@
|
||||
ебат
|
||||
ебаться
|
||||
ебатьс
|
||||
ебашил
|
||||
ебитесь
|
||||
ебло
|
||||
еблом
|
||||
@ -457,6 +459,7 @@
|
||||
натрахаться
|
||||
натрахивать
|
||||
натрахиваться
|
||||
нахуй
|
||||
нахуякать
|
||||
нахуякаться
|
||||
нахуякивать
|
||||
|
||||
Loading…
Reference in New Issue
Block a user