Files
post-moderation/ai-moderation/app/moderation/profanity/dictionary.py
2026-07-28 01:10:11 +03:00

49 lines
664 B
Python

from pathlib import Path
class ProfanityDictionary:
def __init__(
self,
file_path: str
):
self.words = self.load(file_path)
def load(
self,
file_path: str
) -> set[str]:
path = Path(file_path)
if not path.exists():
raise FileNotFoundError(
f"Profanity dictionary not found: {file_path}"
)
with open(
path,
"r",
encoding="utf-8"
) as file:
return {
line.strip().lower().replace("\ufeff", "")
for line in file
if line.strip()
}
def contains(
self,
word: str
) -> bool:
return word in self.words