profanity-filter
profanity-filter copied to clipboard
What am I doing wrong?
I created a simple service using instructions from your readme but nothing works.
My service:
import spacy
from django.conf import settings
from functools import cached_property
from profanity_filter import ProfanityFilter
class ProfanityService:
def __init__(self):
en_nlp = spacy.load("en_core_web_sm")
pl_nlp = spacy.load("pl_core_news_sm")
self.filter = ProfanityFilter(nlps={"en": en_nlp, "pl": pl_nlp})
self.filter.custom_profane_word_dictionaries = self.dictionaries
self.filter.censor_char = "*"
@cached_property
def dictionaries(self):
dicts = {}
with open(settings.EN_PROFANITY_DICT, "r") as f:
dicts["en"] = f.read().splitlines()
with open(settings.PL_PROFANITY_DICT, "r") as f:
dicts["pl"] = f.read().splitlines()
return dicts
def censor(self, text):
return self.filter.censor(text)
And I got errors when I call censor method.
common/services/profanity.py:28: in censor
return self.filter.censor(text)
../venv/lib/python3.8/site-packages/profanity_filter/profanity_filter.py:201: in censor
return self._censor(text=text, return_bool=False)
../venv/lib/python3.8/site-packages/profanity_filter/profanity_filter.py:798: in _censor
if token._.is_profane:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <spacy.tokens.underscore.Underscore object at 0x7f85da213ee0>, name = 'is_profane'
def __getattr__(self, name):
if name not in self._extensions:
> raise AttributeError(Errors.E046.format(name=name))
E AttributeError: [E046] Can't retrieve unregistered extension attribute 'is_profane'. Did you forget to call the `set_extension` method?
../venv/lib/python3.8/site-packages/spacy/tokens/underscore.py:35: AttributeError
P.S. I tried different ways but have no luck.
Hi. Sorry for the late response. I don't actively maintain the library anymore. PRs are welcome.