imgutils.tagging.blacklist

Overview:

Detect and drop some blacklisted tags, which are listed here.

is_blacklisted

imgutils.tagging.blacklist.is_blacklisted(tag: str) bool[source]

Check if any of the given tags are blacklisted.

Parameters:

tag (str) – Tags to be checked.

Returns:

True if any tag is blacklisted, False otherwise.

Return type:

bool

Examples::
>>> from imgutils.tagging import is_blacklisted
>>>
>>> is_blacklisted('cosplay')
True
>>> is_blacklisted('no_eyewear')
True
>>> is_blacklisted('no eyewear')  # span does not matter
True
>>> is_blacklisted('red_hair')
False

drop_blacklisted_tags

imgutils.tagging.blacklist.drop_blacklisted_tags(tags: List[str] | Mapping[str, float], use_presets: bool = True, custom_blacklist: List[str] | None = None) List[str] | Mapping[str, float][source]

Drop blacklisted tags from the given list or mapping of tags.

Parameters:
  • tags (Union[List[str], Mapping[str, float]]) – List or mapping of tags to be filtered.

  • use_presets (bool, optional) – Whether to use the online blacklist presets, defaults to True.

  • custom_blacklist (Optional[List[str]], optional) – Custom blacklist to be used, defaults to None.

Returns:

Filtered list or mapping of tags without the blacklisted ones.

Return type:

Union[List[str], Mapping[str, float]]

Raises:

TypeError – If the input tags are neither a list nor a dictionary.

Examples::
>>> from imgutils.tagging import drop_blacklisted_tags
>>>
>>> drop_blacklisted_tags({
...     'solo': 1.0, '1girl': 0.95,
...     'cosplay': 0.7, 'no_eyewear': 0.6,
... })
{'solo': 1.0, '1girl': 0.95}
>>> drop_blacklisted_tags(['solo', '1girl', 'cosplay', 'no_eyewear'])
['solo', '1girl']