pyrit.prompt_converter.EmojiConverter#

class EmojiConverter(*, indices: List[int] | None = None, keywords: List[str] | None = None, proportion: float | None = None, regex: str | Pattern | None = None)[source]#

Bases: WordLevelConverter

Converts English text to randomly chosen circle or square character emojis.

Inspired by BASI-LABS/parseltongue

__init__(*, indices: List[int] | None = None, keywords: List[str] | None = None, proportion: float | None = None, regex: str | Pattern | None = None)#

Initializes the converter with the specified selection parameters.

This class allows for selection of words to convert based on various criteria. Only one selection parameter may be provided at a time (indices, keywords, proportion, or regex). If no selection parameter is provided, all words will be converted.

Parameters:
  • indices (Optional[List[int]]) – Specific indices of words to convert.

  • keywords (Optional[List[str]]) – Keywords to select words for conversion.

  • proportion (Optional[float]) – Proportion of randomly selected words to convert [0.0-1.0].

  • regex (Optional[Union[str, re.Pattern]]) – Regex pattern to match words for conversion.

Methods

__init__(*[, indices, keywords, proportion, ...])

Initializes the converter with the specified selection parameters.

convert_async(*, prompt[, input_type])

Converts the given prompt into the target format supported by the converter.

convert_tokens_async(*, prompt[, ...])

Converts substrings within a prompt that are enclosed by specified start and end tokens.

convert_word_async(word)

Converts a single word into the target format supported by the converter.

get_identifier()

Returns an identifier dictionary for the converter.

input_supported(input_type)

Checks if the input type is supported by the converter.

join_words(words)

Provides a way for subclasses to override the default behavior of joining words.

output_supported(output_type)

Checks if the output type is supported by the converter.

validate_input(prompt)

Validates the input before processing (can be overridden by subclasses).

Attributes

emoji_dict

Dictionary mapping letters to their corresponding emojis.

supported_input_types

Returns a list of supported input types for the converter.

supported_output_types

Returns a list of supported output types for the converter.

async convert_word_async(word: str) str[source]#

Converts a single word into the target format supported by the converter.

Parameters:

word (str) – The word to be converted.

Returns:

The converted word.

Return type:

str

emoji_dict = {'a': ['🅐', '🅰️', '🄰'], 'b': ['🅑', '🅱️', '🄱'], 'c': ['🅒', '🅲', '🄲'], 'd': ['🅓', '🅳', '🄳'], 'e': ['🅔', '🅴', '🄴'], 'f': ['🅕', '🅵', '🄵'], 'g': ['🅖', '🅶', '🄶'], 'h': ['🅗', '🅷', '🄷'], 'i': ['🅘', '🅸', '🄸'], 'j': ['🅙', '🅹', '🄹'], 'k': ['🅚', '🅺', '🄺'], 'l': ['🅛', '🅻', '🄻'], 'm': ['🅜', '🅼', '🄼'], 'n': ['🅝', '🅽', '🄽'], 'o': ['🅞', '🅾️', '🄾'], 'p': ['🅟', '🅿️', '🄿'], 'q': ['🅠', '🆀', '🅀'], 'r': ['🅡', '🆁', '🅁'], 's': ['🅢', '🆂', '🅂'], 't': ['🅣', '🆃', '🅃'], 'u': ['🅤', '🆄', '🅄'], 'v': ['🅥', '🆅', '🅅'], 'w': ['🅦', '🆆', '🅆'], 'x': ['🅧', '🆇', '🅇'], 'y': ['🅨', '🆈', '🅈'], 'z': ['🅩', '🆉', '🅉']}#

Dictionary mapping letters to their corresponding emojis.