diff --git a/qurator/dinglehopper/templates/report.html.j2 b/qurator/dinglehopper/templates/report.html.j2 index a194a5a..be764db 100644 --- a/qurator/dinglehopper/templates/report.html.j2 +++ b/qurator/dinglehopper/templates/report.html.j2 @@ -40,13 +40,13 @@ {% if metrics %}

Metrics

- {% if cer %} + {% if cer is not none %}

CER: {{ cer|round(4) }}

{% endif %} - {% if wer %} + {% if wer is not none %}

WER: {{ wer|round(4) }}

{% endif %} - {% if fca %} + {% if fca is not none %}

FCA: {{ fca|round(4) }}

{% endif %} {% endif %} diff --git a/qurator/dinglehopper/templates/report.json.j2 b/qurator/dinglehopper/templates/report.json.j2 index b59fbba..161d342 100644 --- a/qurator/dinglehopper/templates/report.json.j2 +++ b/qurator/dinglehopper/templates/report.json.j2 @@ -1,10 +1,10 @@ { {% if metrics %} - {% if cer %}"cer": {{ cer|json_float }},{% endif %} - {% if wer %}"wer": {{ wer|json_float }},{% endif %} - {% if fca %}"fca": {{ fca|json_float }},{% endif %} - {% if n_characters %}"n_characters": {{ n_characters }},{% endif %} - {% if n_words %}"n_words": {{ n_words }},{% endif %} + {% if cer is not none %}"cer": {{ cer|json_float }},{% endif %} + {% if wer is not none %}"wer": {{ wer|json_float }},{% endif %} + {% if fca is not none %}"fca": {{ fca|json_float }},{% endif %} + {% if n_characters is not none %}"n_characters": {{ n_characters }},{% endif %} + {% if n_words is not none %}"n_words": {{ n_words }},{% endif %} {% endif %} "gt": "{{ gt }}", "ocr": "{{ ocr }}" diff --git a/qurator/dinglehopper/tests/test_integ_cli_valid_json.py b/qurator/dinglehopper/tests/test_integ_cli_valid_json.py index bcd30b3..1092a92 100644 --- a/qurator/dinglehopper/tests/test_integ_cli_valid_json.py +++ b/qurator/dinglehopper/tests/test_integ_cli_valid_json.py @@ -58,3 +58,18 @@ def test_cli_json_cer_is_infinity(tmp_path): j = json.load(jsonf) assert j["cer"] == pytest.approx(float("inf")) assert j["fca"] == pytest.approx(-13) + + +def test_cli_json_cer_0_in_report(tmp_path): + """Test that the cli/process() yields a loadable JSON report when CER == 0""" + + with working_directory(str(tmp_path)): + with open("gt.txt", "w") as gtf: + gtf.write("Lorem Ipsum") + + process("gt.txt", "gt.txt", "report", metrics="cer,wer,fca") + with open("report.json", "r") as jsonf: + j = json.load(jsonf) + assert j["cer"] == pytest.approx(0) + assert j["wer"] == pytest.approx(0) + assert j["fca"] == pytest.approx(1)