From f77ce857b233df3705d264435fe4f5bd2f07cdf0 Mon Sep 17 00:00:00 2001 From: "Gerber, Mike" Date: Tue, 14 Dec 2021 18:37:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20dinglehopper:=20Sahre=20json=5Ff?= =?UTF-8?q?loat=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qurator/dinglehopper/cli.py | 25 +++++++++++++------------ qurator/dinglehopper/cli_line_dirs.py | 16 +--------------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/qurator/dinglehopper/cli.py b/qurator/dinglehopper/cli.py index 32e159f..72d428d 100644 --- a/qurator/dinglehopper/cli.py +++ b/qurator/dinglehopper/cli.py @@ -84,6 +84,19 @@ def gen_diff_report(gt_in, ocr_in, css_prefix, joiner, none): ) +def json_float(value): + """Convert a float value to an JSON float. + + This is here so that float('inf') yields "Infinity", not "inf". + """ + if value == float("inf"): + return "Infinity" + elif value == float("-inf"): + return "-Infinity" + else: + return str(value) + + def process(gt, ocr, report_prefix, *, metrics=True, textequiv_level="region"): """Check OCR result against GT. @@ -107,18 +120,6 @@ def process(gt, ocr, report_prefix, *, metrics=True, textequiv_level="region"): gt_words, ocr_words, css_prefix="w", joiner=" ", none="⋯" ) - def json_float(value): - """Convert a float value to an JSON float. - - This is here so that float('inf') yields "Infinity", not "inf". - """ - if value == float("inf"): - return "Infinity" - elif value == float("-inf"): - return "-Infinity" - else: - return str(value) - env = Environment( loader=FileSystemLoader( os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates") diff --git a/qurator/dinglehopper/cli_line_dirs.py b/qurator/dinglehopper/cli_line_dirs.py index 48b86d2..4c07ce5 100644 --- a/qurator/dinglehopper/cli_line_dirs.py +++ b/qurator/dinglehopper/cli_line_dirs.py @@ -14,7 +14,7 @@ from .align import seq_align from .extracted_text import ExtractedText from .ocr_files import plain_extract from .config import Config -from .cli import gen_diff_report +from .cli import gen_diff_report, json_float def all_equal(iterable): @@ -82,20 +82,6 @@ def process(gt_dir, ocr_dir, report_prefix, *, metrics=True): gt_words, ocr_words, css_prefix="l{0}-w".format(k), joiner=" ", none="⋯" ) - - # XXX this is a copy from cli.py - def json_float(value): - """Convert a float value to an JSON float. - - This is here so that float('inf') yields "Infinity", not "inf". - """ - if value == float("inf"): - return "Infinity" - elif value == float("-inf"): - return "-Infinity" - else: - return str(value) - env = Environment( loader=FileSystemLoader( os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates")