separate words from punctuation

This commit is contained in:
jetsparrow 2019-08-19 21:37:34 +03:00
parent 5db1aefcbb
commit ed5be399da
4 changed files with 67 additions and 14 deletions

View 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);
}
}
}

View File

@ -6,27 +6,35 @@ namespace AntiAntiSwearingBot.Tests
public class FilterTests public class FilterTests
{ {
Unbleeper ubl { get; } Unbleeper ubl { get; }
Config cfg { get; }
SearchDictionary dict { get; }
public FilterTests() public FilterTests()
{ {
var cfg = Config.Load<Config>("aasb.cfg.json", "aasb.cfg.secret.json"); cfg = Config.Load<Config>("aasb.cfg.json", "aasb.cfg.secret.json");
var dict = new SearchDictionary(cfg); dict = new SearchDictionary(cfg);
ubl = new Unbleeper(dict, cfg.Unbleeper); 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] [Theory]
[InlineData("*")] [InlineData("*")]
[InlineData("**#")] [InlineData("**#")]
[InlineData("@**#")] [InlineData("@*#")]
public void IgnoreShortGrawlixes(string text) => Assert.Null(ubl.UnbleepSwears(text)); 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] [Theory]
[InlineData("@pvkuznetsov https://github.com/jacksondunstan/UnityNativeScripting")] [InlineData("@pvkuznetsov https://github.com/jacksondunstan/UnityNativeScripting")]

View File

@ -20,6 +20,8 @@ namespace AntiAntiSwearingBot
Regex BleepedSwearsRegex { get; } Regex BleepedSwearsRegex { get; }
static readonly char[] WORD_SEPARATORS = { ' ', '\t', '\r', '\n', '.', ',', '!', '?', ';' };
public string UnbleepSwears(string text) public string UnbleepSwears(string text)
{ {
if (string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(text))
@ -30,7 +32,7 @@ namespace AntiAntiSwearingBot
if (text.StartsWith('/')) // is chat command if (text.StartsWith('/')) // is chat command
return null; return null;
var words = text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); var words = text.Split(WORD_SEPARATORS, StringSplitOptions.RemoveEmptyEntries);
var candidates = words var candidates = words
.Where(w => .Where(w =>
!Language.IsTelegramMention(w) !Language.IsTelegramMention(w)

View File

@ -84,6 +84,7 @@
выебанный выебанный
выебат выебат
выебаться выебаться
выебнулся
высрать высрать
высраться высраться
выссать выссать
@ -217,6 +218,7 @@
ебат ебат
ебаться ебаться
ебатьс ебатьс
ебашил
ебитесь ебитесь
ебло ебло
еблом еблом
@ -457,6 +459,7 @@
натрахаться натрахаться
натрахивать натрахивать
натрахиваться натрахиваться
нахуй
нахуякать нахуякать
нахуякаться нахуякаться
нахуякивать нахуякивать