Python: captionbob.transcript
captionbob.transcript.keywords
Keywords of a caption group.
A keyword picker takes one caption group and gives the places of its keywords. This file holds the type of a picker and four pickers: the longest word of the caption, the longest word when it is long enough, which need no model, the words that have a close emoji, which uses the emoji matcher of captionbob/emoji, and the longest word of a set of keyword words, such as the nouns and the adjectives that the word kind tagger of captionbob/transcript/word_kinds.py names. An effect takes the picker as a value, so another picker can take its place.
The letters of a word are its Unicode letters, its joining marks and its numbers. A joining mark is a character that sits on a letter, such as a vowel sign of Hindi, Bengali or Thai, or an accent that is typed after its letter. So a word of these scripts counts every character that it shows. The emoji matcher reads the text of a word by the same rule.
Source file: captionbob/transcript/keywords.py
WordMatcher
class WordMatcher(Protocol)
Finds the closest emoji of words, as EmojiMatcher of captionbob/emoji/emoji_matcher.py does.
WordMatcher.match_words
def match_words(self, word_texts: Sequence[str]) -> Sequence[object]
Give for each word its closest emoji, or None when the word is not a keyword.
is_word_mark
def is_word_mark(mark: str) -> bool
Say if a character is a letter, a joining mark or a number.
Args:
mark: One character.
Returns:
True when the character is part of a word.
trimmed_word_text
def trimmed_word_text(word_text: str) -> str
Give the text of a word without the characters at its two ends that are not part of the word, such as a comma, a full stop or a quote.
Args:
word_text: The text of one word of the transcript.
Returns:
The text from the first to the last letter, joining mark or number. It is empty when the word has none.
longest_word_keywords
def longest_word_keywords(group: CaptionGroup) -> tuple[int, ...]
Pick the longest word of a caption as its one keyword.
The length of a word is the count of its letters, its joining marks and its digits, so a comma or a full stop at a word does not make the word longer. When two words have the same length, the first one is the keyword.
Args:
group: The words of the caption.
Returns:
A tuple with the place of the keyword in the words of the group. An empty tuple when no word of the group has a letter, a joining mark or a digit.
long_word_keywords
def long_word_keywords(fewest_letters: int) -> KeywordPicker
Make a picker whose keyword is the longest word of a caption when that word is long enough.
The length of a word is the count of its letters, its joining marks and its digits, as in longest_word_keywords. A caption whose longest word is shorter has no keyword, so only some captions have one.
Args:
fewest_letters: The fewest letters, joining marks and digits of a keyword, 1 or above.
Returns:
The picker. It gives the place of the longest word, the first one of two of one length, or no place.
Raises:
TypeError: When the fewest letters is not a whole number.ValueError: When the fewest letters is below 1.
emoji_keywords
def emoji_keywords(matcher: WordMatcher) -> KeywordPicker
Make a picker whose keywords are the words that have a close emoji.
A word is a keyword when the score of its closest emoji reaches the minimum score of the matcher. There is no list of stop words, so the picker works in every language of the model of the matcher.
Args:
matcher: The emoji matcher.
Returns:
The picker. It gives the places of the keywords in the order of the words, and no place when no word of the caption is a keyword.
word_kind_keywords
def word_kind_keywords(keyword_words: frozenset[Word]) -> KeywordPicker
Make a picker whose keyword is the longest word of a caption that is one of a set of keyword words.
The set holds words of the transcript, such as its nouns and its adjectives. The length of a word is the count of its letters, its joining marks and its digits, as in longest_word_keywords. A caption with no word of the set has no keyword.
Args:
keyword_words: The keyword words of the transcript.
Returns:
The picker. It gives the place of the longest keyword word, the first one of two of one length, or no place.
Raises:
TypeError: When the keyword words are not a frozenset.