Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
# ruff: noqa: RUF001
# Intentional Unicode in the source-qualified fixtures.
"""Synthetic outputs qualified against LightOnOCR's pinned published recipe.
Expected constants were produced with lightonai/LightOnOCR at
36755d461be079737860a5f03ae0c803501269e9: omit_margins, _join,
fix_escaped_dollars, then pp3. No document text or model inference is needed.
"""
import pytest
from sie_server.adapters.lighton_ocr._markdown import lightonocr3_markdown
@pytest.mark.parametrize(
("raw", "expected"),
[
pytest.param(
"discard this prefix\n\nheader\n"
"\nbody\nsecond line\n"
"\naside\n"
"\nretained footnote\n"
"\nfooter\n\n42",
"body\nsecond line\n\nretained footnote",
id="block-omission-and-retained-footnote",
),
pytest.param(r"We use \$x^2\$ here. Price \$5.", r"We use $x^2$ here. Price \$5.", id="math-and-currency"),
pytest.param(r"$x\$\$x\$", "$x$$x$", id="successive-dollar-repair-stages"),
pytest.param(
"```tex\n\\$x^2\\$\n```\n\nInline `\\$y^2\\$` stays.\n\nMath \\$z^2\\$.",
"```tex\n\\$x^2\\$\n```\n\nInline `\\$y^2\\$` stays.\n\nMath $z^2$.",
id="fenced-and-inline-code",
),
pytest.param(
"| $x$ | $x^2$ |\n| --- | --- |\n| \\$y\\$ | \\$5 |",
"| x | $x^2$ |\n| --- | --- |\n| y | \\$5 |",
id="table-math",
),
pytest.param(
"preamble\n\nRésumé — 東京\nδεύτερη γραμμή\n\n注釈 αβγ",
"Résumé — 東京\nδεύτερη γραμμή\n\n注釈 αβγ",
id="multiline-unicode",
),
pytest.param(" first line\n\nsecond line\n ", "first line\n\nsecond line", id="no-marker-fallback"),
pytest.param(
"Label .............\nName: _____________",
"Label .............\nName: _____________",
id="pp3-preserves-dots-and-form-blanks",
),
pytest.param(
r"We consider the variables \$x\$, \$y\$ and \$z\$ in this sentence.",
"We consider the variables $x, y and z$ in this sentence.",
id="pp3-linked-math",
),
pytest.param(" \n\t ", "", id="blank"),
pytest.param(
"header\nfooter",
"",
id="all-margin",
),
],
)
def test_published_markdown_recipe(raw: str, expected: str) -> None:
assert lightonocr3_markdown(raw) == expected
@pytest.mark.parametrize(
"label",
["header", "footer", "page_number", "page_header", "page_footer", "header_image", "footer_image", "aside_text"],
)
def test_all_published_margin_labels_are_omitted(label: str) -> None:
raw = f"omit\nbody"
assert lightonocr3_markdown(raw) == "body"
@pytest.mark.parametrize(
"raw",
["body", "body", "body"],
)
def test_marker_grammar_keeps_unrecognized_markers(raw: str) -> None:
assert lightonocr3_markdown(raw) == raw
def test_empty_retained_blocks_do_not_add_separators() -> None:
assert lightonocr3_markdown("\n \nnote") == "note"