Matthias Bisping f9019d6625 Misc fixes
2023-02-15 19:50:14 +01:00

23 lines
975 B
Python

from funcy import first, rest
from cv_analysis.utils import conj
from synthesis.randomization import rnd
from synthesis.text.text_block_generator.paragraph import generate_random_text_lines
from synthesis.text.text_block_generator.text_block_generator import TextBlockGenerator
from synthesis.text.line_formatter.identity import IdentityLineFormatter
class CaptionGenerator(TextBlockGenerator):
def __init__(self, caption_start=None):
self.line_formatter = IdentityLineFormatter()
self.caption_start = caption_start or f"Fig {rnd.randint(1, 20)}"
def __call__(self, rectangle, n_sentences):
return self.generate_paragraph(rectangle, n_sentences)
def generate_paragraph(self, rectangle, n_sentences):
lines = generate_random_text_lines(rectangle, self.line_formatter, n_sentences)
first_line_modified = f"{self.caption_start}: {first(lines)}"
lines = conj(first_line_modified, rest(lines))
return lines