lynxteds 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lynxteds/__init__.py ADDED
@@ -0,0 +1,64 @@
1
+ """LynxTEDS: TEDS and TEDS-S, the same scores as the official code, compiled.
2
+
3
+ from lynxteds import teds, teds_s
4
+ teds(pred_html, true_html) # structure and cell text, 0..1
5
+ teds_s(pred_html, true_html) # structure only (TEDS-S)
6
+
7
+ from lynxteds import TEDS # the official class's interface (PubTabNet, src/metric.py)
8
+ TEDS(structure_only=True).evaluate(pred_html, true_html)
9
+ TEDS(n_jobs=8).batch_evaluate(pred_json, true_json)
10
+ """
11
+ from __future__ import annotations
12
+
13
+ from typing import Mapping, Sequence
14
+
15
+ from .fast_teds import score_s, score_w
16
+
17
+ __all__ = ["TEDS", "teds", "teds_s"]
18
+ __version__ = "0.1.0"
19
+
20
+
21
+ def teds(pred: str, true: str, ignore_nodes: Sequence[str] | None = None) -> float:
22
+ """TEDS of two HTML pages, structure and cell text (0..1), as the official TEDS(structure_only=False).evaluate."""
23
+ return score_w(pred, true, ignore_nodes)
24
+
25
+
26
+ def teds_s(pred: str, true: str, ignore_nodes: Sequence[str] | None = None) -> float:
27
+ """TEDS-S of two HTML pages, structure and spans only (0..1), as the official TEDS(structure_only=True).evaluate."""
28
+ return score_s(pred, true, ignore_nodes)
29
+
30
+
31
+ def _one(job) -> float:
32
+ pred, true, structure_only, ignore_nodes = job
33
+ return (score_s if structure_only else score_w)(pred, true, ignore_nodes)
34
+
35
+
36
+ class TEDS:
37
+ """The official class's interface.
38
+
39
+ structure_only True = TEDS-S (structure and spans), False = TEDS (with cell text)
40
+ n_jobs processes for batch_evaluate (1 = this process); on Windows and macOS call it under `if __name__ == "__main__":`
41
+ ignore_nodes tags removed before scoring (their content kept), as the official option
42
+ """
43
+
44
+ def __init__(self, structure_only: bool = False, n_jobs: int = 1, ignore_nodes: Sequence[str] | None = None):
45
+ if n_jobs < 1:
46
+ raise ValueError("n_jobs is 1 or more")
47
+ self.structure_only, self.n_jobs, self.ignore_nodes = structure_only, n_jobs, ignore_nodes
48
+
49
+ def evaluate(self, pred: str, true: str) -> float:
50
+ """One predicted page against its key: the score, 0..1."""
51
+ return _one((pred, true, self.structure_only, self.ignore_nodes))
52
+
53
+ def batch_evaluate(self, pred_json: Mapping[str, str], true_json: Mapping[str, Mapping[str, str]]) -> dict[str, float]:
54
+ """{name: predicted HTML} against {name: {"html": key HTML}} -> {name: score}, for every name of the key (a missing prediction scores 0)."""
55
+ names = list(true_json)
56
+ jobs = [(pred_json.get(k, ""), true_json[k]["html"], self.structure_only, self.ignore_nodes) for k in names]
57
+ if self.n_jobs == 1 or len(jobs) < 2:
58
+ scores = [_one(j) for j in jobs]
59
+ else:
60
+ import multiprocessing as mp
61
+
62
+ with mp.Pool(self.n_jobs) as pool:
63
+ scores = pool.map(_one, jobs, chunksize=max(1, min(64, len(jobs) // (4 * self.n_jobs))))
64
+ return dict(zip(names, scores))
lynxteds/cli.py ADDED
@@ -0,0 +1,33 @@
1
+ """lynxteds PRED.json TRUE.json: scores predicted tables against their key, in the official file format, and prints the mean."""
2
+ from __future__ import annotations
3
+
4
+ import argparse
5
+ import json
6
+ import os
7
+ from pathlib import Path
8
+
9
+ from . import TEDS, __version__
10
+
11
+
12
+ def main(argv: list[str] | None = None) -> int:
13
+ ap = argparse.ArgumentParser(prog="lynxteds", description="TEDS and TEDS-S of predicted HTML tables against their key (the official scores, compiled).")
14
+ ap.add_argument("pred", help='a JSON file {"name": "<html>...</html>"}')
15
+ ap.add_argument("true", help='a JSON file {"name": {"html": "<html>...</html>"}}, the official key format')
16
+ ap.add_argument("--structure", action="store_true", help="TEDS-S: structure and spans only")
17
+ ap.add_argument("--jobs", type=int, default=os.cpu_count() or 1, help="processes (default: all cores)")
18
+ ap.add_argument("--out", help="a JSON file for every table's score")
19
+ ap.add_argument("--version", action="version", version=__version__)
20
+ a = ap.parse_args(argv)
21
+ pred = json.loads(Path(a.pred).read_text(encoding="utf-8"))
22
+ true = json.loads(Path(a.true).read_text(encoding="utf-8"))
23
+ scores = TEDS(structure_only=a.structure, n_jobs=max(1, a.jobs)).batch_evaluate(pred, true)
24
+ if a.out:
25
+ Path(a.out).write_text(json.dumps(scores), encoding="utf-8")
26
+ name = "TEDS-S" if a.structure else "TEDS"
27
+ mean = 100.0 * sum(scores.values()) / max(1, len(scores))
28
+ print(f"{name} {mean:.2f} on {len(scores)} tables ({sum(k in pred for k in true)} predicted)")
29
+ return 0
30
+
31
+
32
+ if __name__ == "__main__":
33
+ raise SystemExit(main())
lynxteds/fast_teds.py ADDED
@@ -0,0 +1,225 @@
1
+ """The trees and the distance.
2
+
3
+ A page becomes the tree the official scorer builds (PubTabNet's src/metric.py): every element under the table, a `td` with its colspan and rowspan
4
+ (and, for TEDS with text, its tokens: tags as one token each, text as single characters). The tree edit distance is computed exactly by
5
+ Zhang-Shasha's dynamic program on post-order arrays, compiled by Numba: unit insert and delete; rename 1 when the tag or the spans differ, else 0
6
+ for TEDS-S and, for two cells, the Levenshtein distance of their tokens over the longer length (rapidfuzz, compiled). The score is the official
7
+ formula, 1 - distance / max(nodes of either table).
8
+ """
9
+ from __future__ import annotations
10
+
11
+ from typing import Sequence
12
+
13
+ import numpy as np
14
+ from lxml import etree, html
15
+ from numba import njit
16
+ from rapidfuzz.distance import Levenshtein
17
+ from rapidfuzz.process import cdist
18
+
19
+ _LABEL: dict = {}
20
+
21
+
22
+ def _label(tag, cs, rs) -> int:
23
+ k = (tag, cs, rs)
24
+ v = _LABEL.get(k)
25
+ if v is None:
26
+ v = _LABEL[k] = len(_LABEL)
27
+ return v
28
+
29
+
30
+ def _tokens(node, out: list) -> None:
31
+ """the official tokenize(): tags as one token, text as single characters"""
32
+ out.append("<%s>" % node.tag)
33
+ if node.text is not None:
34
+ out.extend(node.text)
35
+ for n in list(node):
36
+ _tokens(n, out)
37
+ if node.tag != "unk":
38
+ out.append("</%s>" % node.tag)
39
+ if node.tag != "td" and node.tail is not None:
40
+ out.extend(node.tail)
41
+
42
+
43
+ def _tree(root, words: bool):
44
+ """post-order arrays: labels, the leftmost leaf of each node, the keyroots; with words, each node's text id (-1 = not a cell) and the texts"""
45
+ lab, left, txt, seen, texts = [], [], [], {}, []
46
+ stack = [(root, iter([]) if root.tag == "td" else iter(list(root)), [-1])]
47
+ while stack:
48
+ node, it, first = stack[-1]
49
+ child = next(it, None)
50
+ if child is not None:
51
+ stack.append((child, iter([]) if child.tag == "td" else iter(list(child)), [-1]))
52
+ continue
53
+ stack.pop()
54
+ i = len(lab)
55
+ if node.tag == "td":
56
+ lab.append(_label("td", int(node.attrib.get("colspan", "1")), int(node.attrib.get("rowspan", "1"))))
57
+ if words:
58
+ t: list = []
59
+ _tokens(node, t)
60
+ t = tuple(t[1:-1])
61
+ k = seen.get(t)
62
+ if k is None:
63
+ k = seen[t] = len(texts)
64
+ texts.append(t)
65
+ txt.append(k)
66
+ else:
67
+ lab.append(_label(node.tag, None, None))
68
+ if words:
69
+ txt.append(-1)
70
+ left.append(i if first[0] < 0 else first[0])
71
+ if stack and stack[-1][2][0] < 0:
72
+ stack[-1][2][0] = left[i]
73
+ last = {}
74
+ for i, lf in enumerate(left):
75
+ last[lf] = i
76
+ arrays = (np.asarray(lab, np.int64), np.asarray(left, np.int64), np.asarray(sorted(last.values()), np.int64))
77
+ return arrays + ((np.asarray(txt, np.int64), texts) if words else ())
78
+
79
+
80
+ def parse(page: str, words: bool, ignore_nodes: Sequence[str] | None = None):
81
+ """-> (tree arrays, nodes as the official counts them), or None when the page has no table in its body"""
82
+ t = html.fromstring(page, parser=html.HTMLParser(remove_comments=True, encoding="utf-8")).xpath("body/table")
83
+ if not t:
84
+ return None
85
+ t = t[0]
86
+ if ignore_nodes:
87
+ etree.strip_tags(t, *ignore_nodes)
88
+ return _tree(t, words), len(t.xpath(".//*"))
89
+
90
+
91
+ @njit(cache=True)
92
+ def distance_s(lab1, l1, kr1, lab2, l2, kr2):
93
+ """the structure distance: rename 0 or 1"""
94
+ n1, n2 = len(lab1), len(lab2)
95
+ td = np.zeros((n1, n2), np.int32)
96
+ fd = np.zeros((n1 + 1, n2 + 1), np.int32)
97
+ for a in range(len(kr1)):
98
+ i = kr1[a]
99
+ il = l1[i]
100
+ m = i - il + 2
101
+ for b in range(len(kr2)):
102
+ j = kr2[b]
103
+ jl = l2[j]
104
+ n = j - jl + 2
105
+ fd[0, 0] = 0
106
+ for x in range(1, m):
107
+ fd[x, 0] = fd[x - 1, 0] + 1
108
+ for y in range(1, n):
109
+ fd[0, y] = fd[0, y - 1] + 1
110
+ for x in range(1, m):
111
+ px = x + il - 1
112
+ lx = l1[px]
113
+ for y in range(1, n):
114
+ py = y + jl - 1
115
+ d = fd[x - 1, y] + 1
116
+ e = fd[x, y - 1] + 1
117
+ if e < d:
118
+ d = e
119
+ if lx == il and l2[py] == jl:
120
+ e = fd[x - 1, y - 1] + (1 if lab1[px] != lab2[py] else 0)
121
+ if e < d:
122
+ d = e
123
+ fd[x, y] = d
124
+ td[px, py] = d
125
+ else:
126
+ e = fd[lx - il, l2[py] - jl] + td[px, py]
127
+ if e < d:
128
+ d = e
129
+ fd[x, y] = d
130
+ return td[n1 - 1, n2 - 1]
131
+
132
+
133
+ @njit(cache=True)
134
+ def distance_w(lab1, l1, kr1, t1, lab2, l2, kr2, t2, cost):
135
+ """the distance with text: two cells with the same spans cost their texts' normalised Levenshtein distance"""
136
+ n1, n2 = len(lab1), len(lab2)
137
+ td = np.zeros((n1, n2), np.float64)
138
+ fd = np.zeros((n1 + 1, n2 + 1), np.float64)
139
+ for a in range(len(kr1)):
140
+ i = kr1[a]
141
+ il = l1[i]
142
+ m = i - il + 2
143
+ for b in range(len(kr2)):
144
+ j = kr2[b]
145
+ jl = l2[j]
146
+ n = j - jl + 2
147
+ fd[0, 0] = 0.0
148
+ for x in range(1, m):
149
+ fd[x, 0] = fd[x - 1, 0] + 1.0
150
+ for y in range(1, n):
151
+ fd[0, y] = fd[0, y - 1] + 1.0
152
+ for x in range(1, m):
153
+ px = x + il - 1
154
+ lx = l1[px]
155
+ for y in range(1, n):
156
+ py = y + jl - 1
157
+ d = fd[x - 1, y] + 1.0
158
+ e = fd[x, y - 1] + 1.0
159
+ if e < d:
160
+ d = e
161
+ if lx == il and l2[py] == jl:
162
+ if lab1[px] != lab2[py]:
163
+ r = 1.0
164
+ elif t1[px] >= 0:
165
+ r = cost[t1[px], t2[py]]
166
+ else:
167
+ r = 0.0
168
+ e = fd[x - 1, y - 1] + r
169
+ if e < d:
170
+ d = e
171
+ fd[x, y] = d
172
+ td[px, py] = d
173
+ else:
174
+ e = fd[lx - il, l2[py] - jl] + td[px, py]
175
+ if e < d:
176
+ d = e
177
+ fd[x, y] = d
178
+ return td[n1 - 1, n2 - 1]
179
+
180
+
181
+ def text_costs(ta, tb) -> np.ndarray:
182
+ """the official normalized_distance of every pair of cell texts, as a matrix (two empty cells: 0)"""
183
+ ids: dict = {}
184
+ enc = []
185
+ for t in list(ta) + list(tb):
186
+ s = []
187
+ for tok in t:
188
+ c = ids.get(tok)
189
+ if c is None:
190
+ c = ids[tok] = chr(0xF0000 + len(ids)) # one private-use character per token
191
+ s.append(c)
192
+ enc.append("".join(s))
193
+ a, b = enc[:len(ta)], enc[len(ta):]
194
+ d = cdist(a, b, scorer=Levenshtein.distance, dtype=np.int32).astype(np.float64)
195
+ la = np.array([len(x) for x in a])[:, None]
196
+ lb = np.array([len(x) for x in b])[None, :]
197
+ m = np.maximum(la, lb)
198
+ return np.where(m > 0, d / np.where(m > 0, m, 1), 0.0)
199
+
200
+
201
+ def score_s(pred: str, true: str, ignore_nodes=None) -> float:
202
+ if (not pred) or (not true):
203
+ return 0.0
204
+ p, t = parse(pred, False, ignore_nodes), parse(true, False, ignore_nodes)
205
+ if p is None or t is None:
206
+ return 0.0
207
+ (a, la, ka), na = p
208
+ (b, lb, kb), nb = t
209
+ if len(a) == len(b) and np.array_equal(a, b) and np.array_equal(la, lb):
210
+ return 1.0 # the same tree: distance 0
211
+ return 1.0 - float(distance_s(a, la, ka, b, lb, kb)) / max(na, nb)
212
+
213
+
214
+ def score_w(pred: str, true: str, ignore_nodes=None) -> float:
215
+ if (not pred) or (not true):
216
+ return 0.0
217
+ if pred == true:
218
+ return 1.0 if parse(true, False, ignore_nodes) is not None else 0.0
219
+ p, t = parse(pred, True, ignore_nodes), parse(true, True, ignore_nodes)
220
+ if p is None or t is None:
221
+ return 0.0
222
+ (a, la, ka, xa, ta), na = p
223
+ (b, lb, kb, xb, tb), nb = t
224
+ cost = text_costs(ta, tb) if ta and tb else np.zeros((max(len(ta), 1), max(len(tb), 1)))
225
+ return 1.0 - float(distance_w(a, la, ka, xa, b, lb, kb, xb, cost)) / max(na, nb)
@@ -0,0 +1,116 @@
1
+ Metadata-Version: 2.4
2
+ Name: lynxteds
3
+ Version: 0.1.0
4
+ Summary: TEDS and TEDS-S for table recognition: the official scores to the last bit, 78 to 724 times faster
5
+ Author: Sibisrinivas B
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/torvexlabs/lynxtsr
8
+ Project-URL: Source, https://github.com/torvexlabs/lynxtsr/tree/main/lynxteds
9
+ Project-URL: Author, https://github.com/sibisrinivasb
10
+ Keywords: teds,table recognition,table structure recognition,tree edit distance,evaluation,metric
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ License-File: NOTICE
17
+ Requires-Dist: numpy>=1.24
18
+ Requires-Dist: numba>=0.59
19
+ Requires-Dist: rapidfuzz>=3.0
20
+ Requires-Dist: lxml>=4.9
21
+ Provides-Extra: test
22
+ Requires-Dist: pytest; extra == "test"
23
+ Requires-Dist: apted; extra == "test"
24
+ Requires-Dist: distance; extra == "test"
25
+ Dynamic: license-file
26
+
27
+ # LynxTEDS
28
+
29
+ **TEDS and TEDS-S for table recognition: the same scores as the official code, to the last bit, 78 to 724 times faster.**
30
+
31
+ TEDS (Zhong et al., 2020) scores a predicted table against its key as a tree edit distance, and nearly every table recognition paper
32
+ reports it. The official code (IBM's `src/metric.py` in PubTabNet) matches the trees in plain Python, so scoring a few benchmarks takes
33
+ minutes for the structure and close to an hour with the text. LynxTEDS builds the same trees and computes the same distance exactly,
34
+ compiled: one score per table in under a millisecond.
35
+
36
+ ```
37
+ pip install lynxteds
38
+ ```
39
+
40
+ ## Use
41
+
42
+ ```python
43
+ from lynxteds import teds, teds_s
44
+
45
+ teds(pred_html, true_html) # structure and cell text, 0..1
46
+ teds_s(pred_html, true_html) # structure and spans only (TEDS-S)
47
+ ```
48
+
49
+ The official class's interface, so existing evaluation code changes one import:
50
+
51
+ ```python
52
+ from lynxteds import TEDS # instead of: from metric import TEDS
53
+
54
+ scorer = TEDS(structure_only=False, n_jobs=8)
55
+ scorer.evaluate(pred_html, true_html)
56
+ scorer.batch_evaluate(pred_json, true_json) # {name: html} against {name: {"html": html}} -> {name: score}
57
+ ```
58
+
59
+ From the command line, in the same file format:
60
+
61
+ ```
62
+ lynxteds pred.json true.json # TEDS
63
+ lynxteds pred.json true.json --structure # TEDS-S
64
+ ```
65
+
66
+ ## How fast, and how exact
67
+
68
+ Seconds on one laptop (Ryzen 9 6900HS, 10 processes, nothing else running), the same tables on both sides; each benchmark's predictions
69
+ come from one table recogniser and its keys from the dataset. The times count the scoring only, on both sides: the pages already in
70
+ memory and the processes already started (starting 10 processes and the first compile take about 4 s more):
71
+
72
+ | score | benchmark | tables | official | LynxTEDS | faster | scores equal to the official |
73
+ |---|---|---|---|---|---|---|
74
+ | TEDS-S | FinTabNet.c test | 9,289 | 67.6 | 1.0 | ~68x | 9,289 of 9,289 |
75
+ | | OmniDocBench tables | 665 | 16.4 | 0.2 | ~82x | 665 of 665 |
76
+ | | PubTabNet val | 9,115 | 137.7 | 1.6 | ~86x | 9,115 of 9,115 |
77
+ | | MUSTARD | 1,429 | 4.8 | 0.1 | ~48x | 1,429 of 1,429 |
78
+ | | **all** | **20,498** | **226.5** | **2.9** | **78x** | **20,498 of 20,498, to the last bit** |
79
+ | TEDS | FinTabNet.c test | 9,289 | 1,966.5 | 2.3 | ~859x | 9,289 of 9,289 |
80
+ | | PubTabNet val | 6,942 | 1,249.9 | 2.2 | ~580x | 6,942 of 6,942 |
81
+ | | **all** | **16,231** | **3,216.4** | **4.4** | **724x** | **16,231 of 16,231** (largest difference 3e-14) |
82
+
83
+ One process, 1,000 random tables, TEDS-S: 70.8 ms per table official, 0.71 ms LynxTEDS. The per-benchmark times are rounded, so those
84
+ ratios are approximate. The table's times do all the work; LynxTEDS also gives a page identical to its key 1 straight away (the official
85
+ code computes it, to the same 1), and with that TEDS on all 16,231 pages takes 2.8 s. The tests compare LynxTEDS with IBM's code on random tables, with and without text and `ignore_nodes`.
86
+
87
+ ## How
88
+
89
+ The same trees as the official code: every element under the table; a cell carries its colspan and rowspan and, for TEDS, its tokens
90
+ (each tag one token, the text one character at a time). The same rename rule: 1 when the tag or the spans differ, otherwise 0 for TEDS-S
91
+ and, for two cells, the Levenshtein distance of their tokens over the longer length. The same score: 1 - distance / the larger number
92
+ of nodes. Only the computation changes: Zhang and Shasha's dynamic program on post-order arrays, compiled by Numba, with the cell texts
93
+ compared by rapidfuzz.
94
+
95
+ ## Good to know
96
+
97
+ - The first call compiles (about half a second); the result is cached for later runs.
98
+ - LynxTEDS scores the HTML it is given, as the official code does. Benchmarks that clean the HTML first (OmniDocBench, for one) do
99
+ that before calling TEDS; do the same cleaning before calling LynxTEDS.
100
+ - `n_jobs` above 1 starts processes: on Windows and macOS, call it under `if __name__ == "__main__":`.
101
+ - A pair of very large tables needs (nodes of one) x (nodes of the other) numbers in memory, twice.
102
+ - Needs Numba (with llvmlite, about 45 MB to download), rapidfuzz, lxml and NumPy.
103
+
104
+ ## Credits and licence
105
+
106
+ Apache License 2.0. The metric is TEDS by Xu Zhong, Elaheh ShafieiBavani and Antonio Jimeno Yepes, and the scores are those of IBM's
107
+ reference code (Apache License 2.0); see [NOTICE](NOTICE).
108
+
109
+ ```bibtex
110
+ @inproceedings{zhong2020image,
111
+ title = {Image-based table recognition: data, model, and evaluation},
112
+ author = {Zhong, Xu and ShafieiBavani, Elaheh and Jimeno Yepes, Antonio},
113
+ booktitle = {European Conference on Computer Vision},
114
+ year = {2020}
115
+ }
116
+ ```
@@ -0,0 +1,10 @@
1
+ lynxteds/__init__.py,sha256=WOK-BZVJGaQn1oyC2kNr7e2WUUa3rR0pn7hR0oG3Po8,2933
2
+ lynxteds/cli.py,sha256=cNgiwv8yBk7qWTrqG6aU0UqY2Yrvo-gijer5t9yGTmw,1621
3
+ lynxteds/fast_teds.py,sha256=mm9q5lKebqJCCRKlN3z3D-_Y7JlSBuTGpU3v8eZaA0w,8473
4
+ lynxteds-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
5
+ lynxteds-0.1.0.dist-info/licenses/NOTICE,sha256=9P2P7koLbm0j1ID0rGYRLPiNflwuzFt_lYoZ1UlHeH0,557
6
+ lynxteds-0.1.0.dist-info/METADATA,sha256=WbP2HIu3qECwFYxS8Em-aUWmS1IRRAa6qg2w0rgPJ9s,5729
7
+ lynxteds-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ lynxteds-0.1.0.dist-info/entry_points.txt,sha256=DNOvGjjW6vzOGT5eHhJiScRX5yeZdof1_7znLVad7K8,47
9
+ lynxteds-0.1.0.dist-info/top_level.txt,sha256=E_g1z_2H9NNYZIIaKLPalt_-8pWvcmRLY7qjGap3Xs4,9
10
+ lynxteds-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ lynxteds = lynxteds.cli:main
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ LynxTEDS
2
+ Copyright 2026 Sibisrinivas B
3
+
4
+ The scores are TEDS (Zhong, ShafieiBavani and Jimeno Yepes, "Image-based table recognition: data, model, and evaluation", ECCV 2020) as
5
+ computed by IBM's reference code, PubTabNet's src/metric.py (https://github.com/ibm-aur-nlp/PubTabNet, IBM, Apache License 2.0): the
6
+ same trees, tokens, rename rule and formula. LynxTEDS computes the same tree edit distance with a compiled Zhang-Shasha program.
7
+
8
+ tests/official_teds.py is IBM's src/metric.py, with IBM's header kept; the changes are listed at the top of the file.
@@ -0,0 +1 @@
1
+ lynxteds