From 799128667f6df5d500d31b287c7a306c53520f46 Mon Sep 17 00:00:00 2001 From: Basique Evangelist Date: Fri, 20 Dec 2019 18:14:19 +0000 Subject: [PATCH] Make learn and unlearn commands simpler --- .../Commands/UnlearnCommand.cs | 16 ++------ AntiAntiSwearingBot/Config.cs | 5 --- AntiAntiSwearingBot/SearchDictionary.cs | 40 +++---------------- AntiAntiSwearingBot/aasb.cfg.json | 8 +--- 4 files changed, 11 insertions(+), 58 deletions(-) diff --git a/AntiAntiSwearingBot/Commands/UnlearnCommand.cs b/AntiAntiSwearingBot/Commands/UnlearnCommand.cs index ea76503..1754208 100644 --- a/AntiAntiSwearingBot/Commands/UnlearnCommand.cs +++ b/AntiAntiSwearingBot/Commands/UnlearnCommand.cs @@ -21,18 +21,10 @@ namespace AntiAntiSwearingBot.Commands if (!Regex.IsMatch(word, @"[а-яА-Я]+")) return null; - var res = Dict.Unlearn(word); - - switch (res) - { - case SearchDictionary.UnlearnResult.Demoted: - return $"Понизил слово \"{word}\""; - case SearchDictionary.UnlearnResult.Removed: - return $"Удалил слово \"{word}\""; - case SearchDictionary.UnlearnResult.NotFound: - default: - return $"Не нашел слово \"{word}\""; - } + if (Dict.Unlearn(word)) + return $"Удалил слово \"{word}\""; + else + return $"Не нашел слово \"{word}\""; } } } diff --git a/AntiAntiSwearingBot/Config.cs b/AntiAntiSwearingBot/Config.cs index b8ce4c1..0a164d4 100644 --- a/AntiAntiSwearingBot/Config.cs +++ b/AntiAntiSwearingBot/Config.cs @@ -18,11 +18,6 @@ public struct SearchDictionarySettings { public string DictionaryPath { get; private set; } - - public double LearnNudgeFactor { get; private set; } - public double LearnInitialRating { get; private set; } - public int MinUnlearnNudge { get; private set; } - public double UnlearnNudgeFactor { get; private set; } } public struct ProxySettings diff --git a/AntiAntiSwearingBot/SearchDictionary.cs b/AntiAntiSwearingBot/SearchDictionary.cs index 553c595..f6ff071 100644 --- a/AntiAntiSwearingBot/SearchDictionary.cs +++ b/AntiAntiSwearingBot/SearchDictionary.cs @@ -13,11 +13,6 @@ namespace AntiAntiSwearingBot path = s.DictionaryPath; tmppath = path + ".tmp"; - learnInitialRating = Math.Clamp(s.LearnInitialRating, 0,1); - learnNudgeFactor = Math.Clamp(s.LearnNudgeFactor, 0, 1); - unlearnNudgeFactor = Math.Clamp(s.UnlearnNudgeFactor, 0, 1); - minUnlearnNudge = Math.Max(s.MinUnlearnNudge, 0); - words = File.ReadAllLines(path).ToList(); } @@ -62,55 +57,30 @@ namespace AntiAntiSwearingBot int index = words.IndexOf(word); if (index > 0) { - int newIndex = (int)(index * learnNudgeFactor); - words.Move(index, newIndex); + words.Move(index, 0); return false; } else { - words.Insert((int)(words.Count * learnInitialRating), word); + words.Insert(0, word); return true; } } } - public enum UnlearnResult { NotFound, Demoted, Removed } - public UnlearnResult Unlearn(string word) + public bool Unlearn(string word) { lock (SyncRoot) - { - int index = words.IndexOf(word); - if (index < 0) - return UnlearnResult.NotFound; - - int indexFromEnd = words.Count - 1 - index; - int change = Math.Max(minUnlearnNudge, (int)(indexFromEnd * unlearnNudgeFactor )); - int newIndex = index + change; - if (newIndex > words.Count) - { - words.RemoveAt(index); - return UnlearnResult.Removed; - } - else - { - words.Move(index, newIndex); - return UnlearnResult.Demoted; - } - } + return words.Remove(word); } #region service readonly string path, tmppath; - double learnInitialRating = 0.75; - double learnNudgeFactor = 0.5; - double unlearnNudgeFactor = 0.66; - int minUnlearnNudge = 5; - object SyncRoot = new object(); List words; - + #endregion } } diff --git a/AntiAntiSwearingBot/aasb.cfg.json b/AntiAntiSwearingBot/aasb.cfg.json index 5060a9b..8ce2aeb 100644 --- a/AntiAntiSwearingBot/aasb.cfg.json +++ b/AntiAntiSwearingBot/aasb.cfg.json @@ -2,13 +2,9 @@ "Unbleeper": { "BleepedSwearsRegex": "[а-яА-Я@\\*#]+", "MinWordLength": 3, - "MinAmbiguousWordLength": 5 + "MinAmbiguousWordLength": 5 }, "SearchDictionary": { - "DictionaryPath": "dict/ObsceneDictionaryRu.txt", - "LearnNudgeFactor": 0.5, - "LearnInitialRating": 0.75, - "MinUnlearnNudge": 5, - "UnlearnNudgeFactor": 0.66 + "DictionaryPath": "dict/ObsceneDictionaryRu.txt" } } \ No newline at end of file