Python: captionbob.transcript
captionbob.transcript.caption_groups
Caption groups: the few words that show together as one caption.
A caption never holds a whole sentence. Each effect sets the most words and the fewest words of a group. A group ends at the end of a sentence, so the words of two sentences never show together. Each word keeps its own times.
Source file: captionbob/transcript/caption_groups.py
CaptionGroup
@dataclass(frozen=True)
class CaptionGroup
The words that show together as one caption.
Args:
words: The words of the group in time order. At least one word.
Raises:
TypeError: When words is not a tuple of Word.ValueError: When the group has no word.
CaptionGroup.start_seconds
@property
def start_seconds(self) -> float
Time at which the first word of the group starts.
CaptionGroup.end_seconds
@property
def end_seconds(self) -> float
Time at which the last word of the group ends.
CaptionGroup.text
@property
def text(self) -> str
The words of the group with one space between them.
ends_a_sentence
def ends_a_sentence(text: str) -> bool
Say if a word is the last word of a sentence.
Args:
text: The text of one word, with its punctuation.
Returns:
True when the text ends with a sentence end mark. A closing quote or bracket after the mark does not change the answer.
build_caption_groups
def build_caption_groups(
words: Sequence[Word], most_words: int,
fewest_words: int) -> tuple[CaptionGroup, ...]
Build the caption groups of a word list.
No group holds more than the most words. A group ends at the end of a sentence, so a group never holds words of two sentences. Each group holds the fewest words or more when its sentence is long enough for that. A sentence that is shorter than the fewest words is one group.
Args:
words: The words of the transcript in time order.most_words: The most words that one caption shows, 1 or above.fewest_words: The fewest words that one caption shows, from 1 to most_words.
Returns:
The caption groups in time order. Together they hold every word one time, in the order of the word list. It is empty for no words.
Raises:
TypeError: When a word count is not a whole number.ValueError: When a word count is below 1, or when fewest_words is above most_words.