mirror of
https://github.com/Jetsparrow/antiantiswearingbot.git
synced 2026-01-20 23:16:08 +03:00
Make learn and unlearn commands simpler
This commit is contained in:
parent
6021c7d7dc
commit
799128667f
@ -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}\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,52 +57,27 @@ 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<string> words;
|
||||
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user