Skip to content

Latest commit

 

History

History

README.md

Docling metrics for document tables

Docling metrics for document tables.

Overview

The following metrics are used:

  • Tree Edit Distance.
  • GriTS (coming).
**Directory structure:** Before building the C++ code, we have only the source code directories:
.
├── devtools              # Various bash scripts, useful with C++ development
├── cmake                 # Cmake files required to compile the C++ code.
├── cpp_src               # C++ source code
├── cpp_tests             # C++ source code for the test
├── docling_metrics_table   # Python wrapper for the C++ bindings that implements the docling-metrics-core API
└── test                  # Python tests

After building the C++ code we have the following directories:

.
├── build                  # C++ build directory required during the build process
├── cmake
├── cpp_src
├── cpp_test
├── docling_metrics_table
├── externals              # C++ code of external libraries. Required during the compilation.
└── tests

Installation

All C++ and Python code is managed by uv. The following command starts the workflow that:

  1. Installs all Python dependencies.
  2. Builds the C++ code including the C++ external dependencies.
  3. Installs the *.so file with the python bindings inside the uv venv.
uv sync --all-packages

In case a manual compilation of the C++ code is needed, you can use the bash scripts from devtools/:

Build the C++ code:

devtools/build_cpp.sh

Run the native C++ tests:

devtools/test_cpp.sh

Usage

from docling_metrics_table import (
    TableMetric,
    TableMetricBracketInputSample,
    TableMetricHTMLInputSample,
    TableMetricSampleEvaluation,
)

# Input sample in bracket notation
bracket_sample = TableMetricBracketInputSample(
    id="s1",
    bracket_a="{x{a}{b}}",
    bracket_b="{x{a}{c}}",
)

table_metric = TableMetric()
bracket_sample_evaluation: TableMetricSampleEvaluation = table_metric.evaluate_sample(
    bracket_sample
)
print(f"TEDS with bracket input: {bracket_sample_evaluation}")


# Input sample in HTML notation
html_a = r"""
<table>
    <tr>
        <td colspan="2">This cell spans two columns with some dummy text</td>
    </tr>
    <tr>
        <td>Cell 2-1: More dummy text here</td>
        <td>Cell 2-2: Additional content</td>
    </tr>
</table>
"""

html_b = r"""
<table>
    <tr>
        <td>Dummy text</td>
        <td>Cell 1-2: Regular cell content</td>
    </tr>
    <tr>
        <td>Cell 2-1: More dummy text here</td>
        <td>Cell 2-2: Additional content</td>
    </tr>
</table>
"""

html_sample = TableMetricHTMLInputSample(
    id="s1",
    html_a=html_a,
    html_b=html_b,
    structure_only=False,
)
html_evaluation: TableMetricSampleEvaluation = table_metric.evaluate_sample(html_sample)
print(f"TEDS with HTML input: {html_evaluation}")

Links

tree-similarity

License

MIT