Structure: no-heading fallback also works for short books (body threshold relative to the median page)
This commit is contained in:
@@ -92,8 +92,11 @@ def find_headings(units):
|
||||
found.append(h)
|
||||
break
|
||||
if not found:
|
||||
for ui, u in enumerate(units):
|
||||
if len(re.sub(r"\s", "", u["text"])) >= 500:
|
||||
sizes = [len(re.sub(r"\s", "", u["text"])) for u in units]
|
||||
filled = sorted(n for n in sizes if n >= 20)
|
||||
floor = max(40, 0.4 * filled[len(filled) // 2]) if filled else 0 # a page with 40% of the median text or more is body
|
||||
for ui, n in enumerate(sizes):
|
||||
if filled and n >= floor:
|
||||
return [{"unit": ui, "line": -1, "title_end": 0, "number": 1, "title": "The Complete Text", "synthetic": True}]
|
||||
return found
|
||||
|
||||
|
||||
Reference in New Issue
Block a user