pyrit.prompt_converter.WordPositionSelectionStrategy#

class WordPositionSelectionStrategy(*, start_proportion: float, end_proportion: float)[source]#

Bases: WordSelectionStrategy

Selects words based on proportional start and end positions.

__init__(*, start_proportion: float, end_proportion: float) None[source]#

Initializes the word position selection strategy.

Parameters:
  • start_proportion (float) – The starting position as a proportion (0.0 to 1.0).

  • end_proportion (float) – The ending position as a proportion (0.0 to 1.0).

Raises:

ValueError – If proportions are not between 0.0 and 1.0, or start >= end.

Methods

__init__(*, start_proportion, end_proportion)

Initializes the word position selection strategy.

select_range(*, text[, word_separator])

Selects a character range by first selecting words, then converting to character positions.

select_words(*, words)

Selects words based on the relative position.

select_words(*, words: List[str]) List[int][source]#

Selects words based on the relative position.

Parameters:

words (List[str]) – The list of words to select from.

Returns:

The list of indices in the specified position range.

Return type:

List[int]