fixed code
This commit is contained in:
@@ -3,11 +3,8 @@ import re
|
||||
from app.moderation.profanity.dictionary import ProfanityDictionary
|
||||
from app.moderation.profanity.lemmatizer import Lemmatizer
|
||||
|
||||
|
||||
|
||||
class ProfanityDetector:
|
||||
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
dictionary: ProfanityDictionary,
|
||||
@@ -17,23 +14,18 @@ class ProfanityDetector:
|
||||
self.dictionary = dictionary
|
||||
self.lemmatizer = lemmatizer
|
||||
|
||||
|
||||
|
||||
def detect(
|
||||
self,
|
||||
text: str
|
||||
) -> list[str]:
|
||||
|
||||
|
||||
words = re.findall(
|
||||
r"[а-яА-ЯёЁ]+",
|
||||
text.lower()
|
||||
)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
|
||||
for word in words:
|
||||
|
||||
lemma = self.lemmatizer.normalize(word)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class ProfanityDictionary:
|
||||
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
file_path: str
|
||||
@@ -20,7 +18,6 @@ class ProfanityDictionary:
|
||||
|
||||
path = Path(file_path)
|
||||
|
||||
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(
|
||||
f"Profanity dictionary not found: {file_path}"
|
||||
@@ -39,8 +36,6 @@ class ProfanityDictionary:
|
||||
if line.strip()
|
||||
}
|
||||
|
||||
|
||||
|
||||
def contains(
|
||||
self,
|
||||
word: str
|
||||
|
||||
@@ -3,18 +3,13 @@ import pymorphy3
|
||||
|
||||
class Lemmatizer:
|
||||
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.morph = pymorphy3.MorphAnalyzer()
|
||||
|
||||
|
||||
|
||||
def normalize(
|
||||
self,
|
||||
word: str
|
||||
) -> str:
|
||||
|
||||
result = self.morph.parse(word)
|
||||
|
||||
return result[0].normal_form
|
||||
return result[0].normal_form
|
||||
|
||||
Reference in New Issue
Block a user