imgutils.tagging.character

Overview:

Detect and drop character-related basic tags.

CHAR_WHITELIST_SUFFIX

imgutils.tagging.character.CHAR_WHITELIST_SUFFIX = ['anal_hair', 'anal_tail', 'arm_behind_head', 'arm_hair', 'arm_under_breasts', 'arms_behind_head', 'bird_on_head', 'blood_in_hair', 'breasts_on_glass', 'breasts_on_head', 'cat_on_head', 'closed_eyes', 'clothed_female_nude_female', 'clothed_female_nude_male', 'clothed_male_nude_female', 'clothes_between_breasts', 'cream_on_face', 'drying_hair', 'empty_eyes', 'face_to_breasts', 'facial', 'food_on_face', 'food_on_head', 'game_boy', "grabbing_another's_hair", 'grabbing_own_breast', 'gun_to_head', 'half-closed_eyes', 'head_between_breasts', 'heart_in_eye', 'multiple_boys', 'multiple_girls', 'object_on_breast', 'object_on_head', 'paint_splatter_on_face', 'parted_lips', 'penis_on_face', 'person_on_head', 'pokemon_on_head', 'pubic_hair', 'rabbit_on_head', 'rice_on_face', 'severed_head', 'star_in_eye', 'sticker_on_face', 'tentacles_on_male', 'tying_hair']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

CHAR_WHITELIST_PREFIX

imgutils.tagging.character.CHAR_WHITELIST_PREFIX = ['holding', 'hand on', 'hands on', 'hand to', 'hands to', 'hand in', 'hands in', 'hand over', 'hands over', 'futa with', 'futa on', 'cum on', 'covering', 'adjusting', 'rubbing', 'sitting', 'shading', 'playing', 'cutting']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

CHAR_WHITELIST_WORD

imgutils.tagging.character.CHAR_WHITELIST_WORD = ['drill']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

CHAR_SUFFIXES

imgutils.tagging.character.CHAR_SUFFIXES = ['eyes', 'skin', 'hair', 'bun', 'bangs', 'cut', 'sidelocks', 'twintails', 'braid', 'braids', 'afro', 'ahoge', 'drill', 'drills', 'bald', 'dreadlocks', 'side up', 'ponytail', 'updo', 'beard', 'mustache', 'pointy ears', 'ear', 'horn', 'tail', 'wing', 'ornament', 'hairband', 'pupil', 'bow', 'eyewear', 'headwear', 'ribbon', 'crown', 'cap', 'hat', 'hairclip', 'breast', 'mole', 'halo', 'earrings', 'animal ear fluff', 'hair flower', 'glasses', 'fang', 'female', 'girl', 'boy', 'male', 'beret', 'heterochromia', 'headdress', 'headgear', 'eyepatch', 'headphones', 'eyebrows', 'eyelashes', 'sunglasses', 'hair intakes', 'scrunchie', 'ear_piercing', 'head', 'on face', 'on head', 'on hair', 'headband', 'hair rings', 'under_mouth', 'freckles', 'lip', 'eyeliner', 'eyeshadow', 'tassel', 'over one eye', 'drill', 'drill hair']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

CHAR_PREFIXES

imgutils.tagging.character.CHAR_PREFIXES = ['hair over', 'hair between', 'facial']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

CharacterTagPool

class imgutils.tagging.character.CharacterTagPool(whitelist_suffixes: List[str] | None = None, whitelist_prefixes: List[str] | None = None, whitelist_words: List[str] | None = None, suffixes: List[str] | None = None, prefixes: List[str] | None = None)[source]

A pool of character-related tags for detection and removal of basic character tags.

__init__(whitelist_suffixes: List[str] | None = None, whitelist_prefixes: List[str] | None = None, whitelist_words: List[str] | None = None, suffixes: List[str] | None = None, prefixes: List[str] | None = None)[source]

Initialize a CharacterTagPool instance.

Parameters:
  • whitelist_suffixes (Optional[List[str]], optional) – A list of whitelisted suffixes, defaults to None

  • suffixes (Optional[List[str]], optional) – A list of suffixes to consider, defaults to None

  • prefixes (Optional[List[str]], optional) – A list of prefixes to consider, defaults to None

drop_basic_character_tags(tags: List[str] | Mapping[str, float]) List[str] | Mapping[str, float][source]

Drop basic character tags from a list or mapping of tags.

Parameters:

tags (Union[List[str], Mapping[str, float]]) – The tags to process

Returns:

Processed tags with basic character tags removed

Return type:

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

is_basic_character_tag(tag: str) bool[source]

Check if a given tag is a basic character tag.

Parameters:

tag (str) – The tag to check

Returns:

True if the tag is a basic character tag, False otherwise

Return type:

bool

is_basic_character_tag

imgutils.tagging.character.is_basic_character_tag(tag: str) bool[source]

Check if a tag is a basic character tag by matching with predefined whitelisted and blacklisted patterns.

Parameters:

tag (str) – The tag to check.

Returns:

True if the tag is a basic character tag, False otherwise.

Return type:

bool

Examples::
>>> from imgutils.tagging import is_basic_character_tag
>>>
>>> is_basic_character_tag('red hair')
True
>>> is_basic_character_tag('red_hair')  # span doesn't matter
True
>>> is_basic_character_tag('cat ears')  # singular
True
>>> is_basic_character_tag('cat ear')  # plural
True
>>> is_basic_character_tag('chair')  # only whole word will be matched
False
>>> is_basic_character_tag('hear')  # only whole word will be matched
False
>>> is_basic_character_tag('dress')
False

drop_basic_character_tags

imgutils.tagging.character.drop_basic_character_tags(tags: List[str] | Mapping[str, float]) List[str] | Mapping[str, float][source]

Drop basic character 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.

Returns:

Filtered list or mapping of tags without the basic character tags.

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_basic_character_tags
>>>
>>> drop_basic_character_tags({
...     '1girl': 1.0, 'solo': 0.95,
...     'red_hair': 0.7, 'cat ears': 0.6,
...     'chair': 0.86, 'hear': 0.72,
... })
{'1girl': 1.0, 'solo': 0.95, 'chair': 0.86, 'hear': 0.72}
>>> drop_basic_character_tags([
...     '1girl', 'solo', 'red_hair', 'cat ears', 'chair', 'hear'
... ])
['1girl', 'solo', 'chair', 'hear']