Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

What am I doing wrong? #31

Open
manti-by opened this issue Jun 24, 2020 · 1 comment
Open

What am I doing wrong? #31

manti-by opened this issue Jun 24, 2020 · 1 comment

Comments

@manti-by
Copy link

manti-by commented Jun 24, 2020

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.

@rominf
Copy link
Owner

rominf commented Sep 21, 2020

Hi. Sorry for the late response. I don't actively maintain the library anymore. PRs are welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants