From 0e7791394f503e7de6fd3fe7e08eec60d4d45c07 Mon Sep 17 00:00:00 2001 From: Matthias Bisping Date: Wed, 15 Feb 2023 18:52:57 +0100 Subject: [PATCH] Refactoring: Rename --- synthesis/content_generator.py | 2 +- synthesis/partitioner/page_partitioner.py | 2 +- synthesis/partitioner/random.py | 2 +- synthesis/partitioner/two_column.py | 2 +- synthesis/{random.py => randomization.py} | 3 +++ synthesis/segment/plot.py | 2 +- synthesis/segment/random_content_rectangle.py | 2 +- synthesis/segment/segments.py | 2 +- synthesis/segment/table/table.py | 4 ++-- synthesis/text/font.py | 2 +- synthesis/text/line_formatter/paragraph.py | 2 +- synthesis/text/text.py | 2 +- synthesis/text/text_block_generator/caption.py | 2 +- synthesis/text/text_block_generator/paragraph.py | 2 +- test/fixtures/page_generation/page.py | 2 +- 15 files changed, 18 insertions(+), 15 deletions(-) rename synthesis/{random.py => randomization.py} (91%) diff --git a/synthesis/content_generator.py b/synthesis/content_generator.py index 021f07e..4b1b071 100644 --- a/synthesis/content_generator.py +++ b/synthesis/content_generator.py @@ -10,7 +10,7 @@ from cv_analysis.utils.geometric import is_square_like from cv_analysis.utils.merging import merge_related_rectangles from cv_analysis.utils.postprocessing import remove_included, remove_overlapping from cv_analysis.utils.rectangle import Rectangle -from synthesis.random import rnd +from synthesis.randomization import rnd from synthesis.segment.content_rectangle import ContentRectangle from synthesis.segment.recursive_content_rectangle import RecursiveContentRectangle from synthesis.segment.segments import ( diff --git a/synthesis/partitioner/page_partitioner.py b/synthesis/partitioner/page_partitioner.py index aea30e6..f48d384 100644 --- a/synthesis/partitioner/page_partitioner.py +++ b/synthesis/partitioner/page_partitioner.py @@ -5,7 +5,7 @@ from PIL import Image from funcy import lflatten from cv_analysis.utils.rectangle import Rectangle -from synthesis.random import rnd +from synthesis.randomization import rnd class PagePartitioner(abc.ABC): diff --git a/synthesis/partitioner/random.py b/synthesis/partitioner/random.py index fe2ec9d..5c2dc30 100644 --- a/synthesis/partitioner/random.py +++ b/synthesis/partitioner/random.py @@ -1,6 +1,6 @@ from cv_analysis.utils.rectangle import Rectangle from synthesis.partitioner.page_partitioner import PagePartitioner -from synthesis.random import rnd +from synthesis.randomization import rnd class RandomPagePartitioner(PagePartitioner): diff --git a/synthesis/partitioner/two_column.py b/synthesis/partitioner/two_column.py index 02cde9c..1d464cf 100644 --- a/synthesis/partitioner/two_column.py +++ b/synthesis/partitioner/two_column.py @@ -1,6 +1,6 @@ from cv_analysis.utils.rectangle import Rectangle from synthesis.partitioner.page_partitioner import PagePartitioner -from synthesis.random import rnd +from synthesis.randomization import rnd class TwoColumnPagePartitioner(PagePartitioner): diff --git a/synthesis/random.py b/synthesis/randomization.py similarity index 91% rename from synthesis/random.py rename to synthesis/randomization.py index 110f970..af22da6 100644 --- a/synthesis/random.py +++ b/synthesis/randomization.py @@ -13,6 +13,9 @@ random_seed = random.randint(0, 2**32 - 1) # 2467967671 +# random_seed = 237553299 +# random_seed = 1021421466 + logger.info(f"Random seed: {random_seed}") rnd = random.Random(random_seed) diff --git a/synthesis/segment/plot.py b/synthesis/segment/plot.py index 3cb4570..f21c7f6 100644 --- a/synthesis/segment/plot.py +++ b/synthesis/segment/plot.py @@ -11,7 +11,7 @@ from matplotlib.colors import ListedColormap from cv_analysis.utils.geometric import is_square_like, is_wide, is_tall from cv_analysis.utils.image_operations import superimpose from cv_analysis.utils.rectangle import Rectangle -from synthesis.random import rnd, probably, maybe +from synthesis.randomization import rnd, probably, maybe from synthesis.segment.random_content_rectangle import RandomContentRectangle from synthesis.text.text import generate_random_words diff --git a/synthesis/segment/random_content_rectangle.py b/synthesis/segment/random_content_rectangle.py index 309b6bd..dca8a27 100644 --- a/synthesis/segment/random_content_rectangle.py +++ b/synthesis/segment/random_content_rectangle.py @@ -1,6 +1,6 @@ import random -from synthesis.random import get_random_seed +from synthesis.randomization import get_random_seed from synthesis.segment.content_rectangle import ContentRectangle diff --git a/synthesis/segment/segments.py b/synthesis/segment/segments.py index 02e9fc6..f644e6a 100644 --- a/synthesis/segment/segments.py +++ b/synthesis/segment/segments.py @@ -1,5 +1,5 @@ from cv_analysis.utils.rectangle import Rectangle -from synthesis.random import probably, rnd +from synthesis.randomization import probably, rnd from synthesis.segment.content_rectangle import ContentRectangle from synthesis.segment.plot import RandomPlot from synthesis.segment.text_block import TextBlock diff --git a/synthesis/segment/table/table.py b/synthesis/segment/table/table.py index ac47284..c1d2e18 100644 --- a/synthesis/segment/table/table.py +++ b/synthesis/segment/table/table.py @@ -13,7 +13,7 @@ from cv_analysis.utils.geometric import is_square_like from cv_analysis.utils.image_operations import superimpose from cv_analysis.utils.rectangle import Rectangle from cv_analysis.utils.spacial import area -from synthesis.random import rnd, possibly +from synthesis.randomization import rnd, possibly, maybe from synthesis.segment.content_rectangle import ContentRectangle from synthesis.segment.plot import pick_colormap from synthesis.segment.random_content_rectangle import RandomContentRectangle @@ -50,7 +50,7 @@ class RecursiveRandomTable(RandomContentRectangle, RecursiveContentRectangle): self.content = Image.new("RGBA", (self.width, self.height), (255, 255, 255, 0)) - self.background_color = get_random_background_color() + self.background_color = maybe() and get_random_background_color() or (255, 255, 255, 0) self.layout = layout or self.pick_random_layout() logger.debug(f"Layout: {self.layout}") diff --git a/synthesis/text/font.py b/synthesis/text/font.py index 01b5484..eaf75ce 100644 --- a/synthesis/text/font.py +++ b/synthesis/text/font.py @@ -7,7 +7,7 @@ from PIL import Image, ImageDraw, ImageFont from funcy import lmap, complement, keep, first, lzip, omit, project from loguru import logger -from synthesis.random import rnd +from synthesis.randomization import rnd class RandomFontPicker: diff --git a/synthesis/text/line_formatter/paragraph.py b/synthesis/text/line_formatter/paragraph.py index 88809c4..58e5b65 100644 --- a/synthesis/text/line_formatter/paragraph.py +++ b/synthesis/text/line_formatter/paragraph.py @@ -1,7 +1,7 @@ from funcy import identity, compose, first, juxt, rest, rcompose from cv_analysis.utils import star, rconj -from synthesis.random import rnd +from synthesis.randomization import rnd from synthesis.text.line_formatter.line_formatter import LineFormatter diff --git a/synthesis/text/text.py b/synthesis/text/text.py index deaedee..f604b99 100644 --- a/synthesis/text/text.py +++ b/synthesis/text/text.py @@ -2,7 +2,7 @@ import random from faker import Faker -from synthesis.random import rnd +from synthesis.randomization import rnd def generate_random_words(n_min, n_max): diff --git a/synthesis/text/text_block_generator/caption.py b/synthesis/text/text_block_generator/caption.py index bb8f2fa..78ff3bf 100644 --- a/synthesis/text/text_block_generator/caption.py +++ b/synthesis/text/text_block_generator/caption.py @@ -1,7 +1,7 @@ from funcy import first, rest from cv_analysis.utils import conj -from synthesis.random import rnd +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 diff --git a/synthesis/text/text_block_generator/paragraph.py b/synthesis/text/text_block_generator/paragraph.py index 9c3afd9..43dfc6f 100644 --- a/synthesis/text/text_block_generator/paragraph.py +++ b/synthesis/text/text_block_generator/paragraph.py @@ -7,7 +7,7 @@ from funcy import iterate, take, last from cv_analysis.logging import debug_log from cv_analysis.utils import star from cv_analysis.utils.rectangle import Rectangle -from synthesis.random import rnd +from synthesis.randomization import rnd from synthesis.text.line_formatter.identity import IdentityLineFormatter from synthesis.text.line_formatter.line_formatter import LineFormatter from synthesis.text.line_formatter.paragraph import ParagraphLineFormatter diff --git a/test/fixtures/page_generation/page.py b/test/fixtures/page_generation/page.py index 34fe6bc..b737a05 100644 --- a/test/fixtures/page_generation/page.py +++ b/test/fixtures/page_generation/page.py @@ -14,7 +14,7 @@ from cv_analysis.utils.image_operations import blur, sharpen, overlay, superimpo from cv_analysis.utils.rectangle import Rectangle from synthesis.content_generator import ContentGenerator from synthesis.partitioner.two_column import TwoColumnPagePartitioner -from synthesis.random import rnd +from synthesis.randomization import rnd from synthesis.segment.table.table import paste_contents