reftable 1.0.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.
- reftable/__init__.py +19 -0
- reftable/__main__.py +13 -0
- reftable/abbrev/__init__.py +41 -0
- reftable/abbrev/geometry.py +69 -0
- reftable/abbrev/parser.py +36 -0
- reftable/abbrev/simple.py +66 -0
- reftable/cli.py +76 -0
- reftable/feature/__init__.py +8 -0
- reftable/feature/abbrev.py +67 -0
- reftable/feature/figure.py +51 -0
- reftable/feature/table.py +89 -0
- reftable/feature/toc.py +103 -0
- reftable/figure/__init__.py +19 -0
- reftable/figure/column.py +75 -0
- reftable/figure/normal.py +75 -0
- reftable/figure/strategy.py +44 -0
- reftable/horizontals.py +101 -0
- reftable/likelihood.py +128 -0
- reftable/pageselector.py +101 -0
- reftable/path.py +26 -0
- reftable/toc/__init__.py +58 -0
- reftable/toc/basic/__init__.py +8 -0
- reftable/toc/basic/group.py +62 -0
- reftable/toc/basic/layout.py +77 -0
- reftable/toc/basic/lineregex.py +240 -0
- reftable/toc/create.py +302 -0
- reftable/toc/decider.py +101 -0
- reftable/toc/run.py +54 -0
- reftable/toc/strategy/__init__.py +134 -0
- reftable/toc/strategy/balance.py +116 -0
- reftable/toc/strategy/geometry.py +136 -0
- reftable/toc/strategy/georegex.py +73 -0
- reftable/toc/strategy/pagetop.py +81 -0
- reftable/toc/strategy/regex.py +156 -0
- reftable-1.0.0.dist-info/METADATA +33 -0
- reftable-1.0.0.dist-info/RECORD +40 -0
- reftable-1.0.0.dist-info/WHEEL +5 -0
- reftable-1.0.0.dist-info/entry_points.txt +2 -0
- reftable-1.0.0.dist-info/licenses/LICENSE +21 -0
- reftable-1.0.0.dist-info/top_level.txt +1 -0
reftable/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
#==============================================================================
|
|
9
|
+
|
|
10
|
+
import importlib.metadata
|
|
11
|
+
import os
|
|
12
|
+
|
|
13
|
+
import reftable.path
|
|
14
|
+
|
|
15
|
+
PROCESS = 'reftable'
|
|
16
|
+
|
|
17
|
+
__version__ = importlib.metadata.version(PROCESS)
|
|
18
|
+
|
|
19
|
+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
reftable/__main__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
from reftable.cli import main
|
|
11
|
+
|
|
12
|
+
if __name__ == "__main__":
|
|
13
|
+
main()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
"""Abbreviation
|
|
10
|
+
============
|
|
11
|
+
|
|
12
|
+
Examples:
|
|
13
|
+
|
|
14
|
+
* homework/page_50_math.pdf:page6
|
|
15
|
+
* master/page_116_images_toc_formular.pdf:95
|
|
16
|
+
|
|
17
|
+
TODO: Abbreviation creation tool
|
|
18
|
+
TODO: Symbol collector
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import abc
|
|
22
|
+
import dataclasses
|
|
23
|
+
|
|
24
|
+
import iamraw
|
|
25
|
+
import texmex
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclasses.dataclass
|
|
29
|
+
class AbbreviationData:
|
|
30
|
+
normal: texmex.PTNs = None
|
|
31
|
+
oneline: texmex.PTNs = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AbbreviationExtractorStrategy(abc.ABC):
|
|
35
|
+
|
|
36
|
+
def __init__(self, loaded: AbbreviationData):
|
|
37
|
+
self.loaded = loaded
|
|
38
|
+
|
|
39
|
+
@abc.abstractmethod
|
|
40
|
+
def result(self) -> iamraw.AbbreviationResult:
|
|
41
|
+
pass
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
"""Abbreviation Parser: Geometry Strategy
|
|
10
|
+
======================================
|
|
11
|
+
|
|
12
|
+
This approach splits the page in two columns and detect a left shortcut
|
|
13
|
+
and a right description column. It is required that the distance between
|
|
14
|
+
left and right column is not ?too? tight.
|
|
15
|
+
|
|
16
|
+
Working Examples
|
|
17
|
+
----------------
|
|
18
|
+
|
|
19
|
+
* bachelor37: page 2
|
|
20
|
+
|
|
21
|
+
Not working
|
|
22
|
+
-----------
|
|
23
|
+
|
|
24
|
+
* homework50: columns are to tight together
|
|
25
|
+
|
|
26
|
+
Nearly working
|
|
27
|
+
--------------
|
|
28
|
+
|
|
29
|
+
* master116: improve layout parser
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
import geostrat
|
|
33
|
+
import iamraw
|
|
34
|
+
import texmex
|
|
35
|
+
import utilo
|
|
36
|
+
|
|
37
|
+
import reftable.abbrev
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class GeometryAbbreviationParser(reftable.abbrev.AbbreviationExtractorStrategy):
|
|
41
|
+
|
|
42
|
+
def result(self) -> iamraw.AbbreviationResult:
|
|
43
|
+
ready = iamraw.AbbreviationResult()
|
|
44
|
+
for page in self.loaded.normal:
|
|
45
|
+
parsed = parse_page(page)
|
|
46
|
+
if parsed is None:
|
|
47
|
+
utilo.info(f'could not parse page: {page.page}')
|
|
48
|
+
continue
|
|
49
|
+
for item in parsed:
|
|
50
|
+
ready.append(item)
|
|
51
|
+
ready.pdfpages.append(page.page)
|
|
52
|
+
return ready
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def parse_page(page: texmex.PTN) -> iamraw.Abbreviations:
|
|
56
|
+
parsed = geostrat.dc_parse_page(page)
|
|
57
|
+
if not parsed:
|
|
58
|
+
return None
|
|
59
|
+
result = []
|
|
60
|
+
for short, description in parsed:
|
|
61
|
+
short, description = short.strip(), description.strip()
|
|
62
|
+
description = description.lstrip('-')
|
|
63
|
+
result.append(
|
|
64
|
+
iamraw.Abbreviation(
|
|
65
|
+
short=short,
|
|
66
|
+
description=description,
|
|
67
|
+
position=iamraw.AbbreviationPosition(page=page.page),
|
|
68
|
+
))
|
|
69
|
+
return result
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import iamraw
|
|
11
|
+
|
|
12
|
+
import reftable.abbrev
|
|
13
|
+
import reftable.abbrev.geometry
|
|
14
|
+
import reftable.abbrev.simple
|
|
15
|
+
|
|
16
|
+
STRATEGIES = [
|
|
17
|
+
reftable.abbrev.simple.SimpleAbbreviationParser,
|
|
18
|
+
reftable.abbrev.geometry.GeometryAbbreviationParser,
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def parse(data: reftable.abbrev.AbbreviationData) -> iamraw.AbbreviationResult:
|
|
23
|
+
assert isinstance(data.normal, list), type(data)
|
|
24
|
+
assert isinstance(data.oneline, list), type(data)
|
|
25
|
+
parsed = [strategy(data).result() for strategy in STRATEGIES]
|
|
26
|
+
judged = judge(parsed)
|
|
27
|
+
return judged
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def judge(results) -> iamraw.AbbreviationResult:
|
|
31
|
+
simple = results[0]
|
|
32
|
+
geometry = results[1]
|
|
33
|
+
more_than_double_parsed = (len(geometry) * 2) < len(simple)
|
|
34
|
+
if more_than_double_parsed:
|
|
35
|
+
return simple
|
|
36
|
+
return geometry
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import elementae.headline.lookup
|
|
11
|
+
import iamraw
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
import reftable.abbrev
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SimpleAbbreviationParser(reftable.abbrev.AbbreviationExtractorStrategy):
|
|
18
|
+
|
|
19
|
+
def result(self) -> iamraw.AbbreviationResult:
|
|
20
|
+
ready = iamraw.AbbreviationResult()
|
|
21
|
+
for page in self.loaded.oneline:
|
|
22
|
+
parsed = parse_page(page)
|
|
23
|
+
for item in parsed:
|
|
24
|
+
ready.append(item)
|
|
25
|
+
if parsed:
|
|
26
|
+
ready.pdfpages.append(page.page)
|
|
27
|
+
return ready
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def parse_page(content):
|
|
31
|
+
result = []
|
|
32
|
+
for line in content:
|
|
33
|
+
raw = line.text
|
|
34
|
+
utilo.debug(f'parse: {raw}')
|
|
35
|
+
try:
|
|
36
|
+
short, description = raw.split(maxsplit=1)
|
|
37
|
+
except ValueError:
|
|
38
|
+
if not isexcluded(raw):
|
|
39
|
+
utilo.debug(f'could not parse abbreviation: {raw}')
|
|
40
|
+
continue
|
|
41
|
+
if isexcluded(short) or isexcluded(description):
|
|
42
|
+
utilo.info(f'skip: {short}, {description}')
|
|
43
|
+
continue
|
|
44
|
+
short, description = short.strip(), description.strip()
|
|
45
|
+
parsed = iamraw.Abbreviation(
|
|
46
|
+
short=short,
|
|
47
|
+
description=description,
|
|
48
|
+
)
|
|
49
|
+
utilo.debug(f'parsed: {parsed}')
|
|
50
|
+
result.append(parsed)
|
|
51
|
+
return result
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def isexcluded(item: str) -> bool:
|
|
55
|
+
# TODO: ADD MORE SOPHISTICATED DOUBLE COLUMN CHECKER
|
|
56
|
+
item = item.strip().lower()
|
|
57
|
+
if item in elementae.headline.lookup.HEADLINES:
|
|
58
|
+
return True
|
|
59
|
+
if item in NO_ABBREVIATION:
|
|
60
|
+
return True
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
NO_ABBREVIATION = utilo.splitlines("""\
|
|
65
|
+
BESCHREIBUNG
|
|
66
|
+
""")
|
reftable/cli.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#==============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
#------------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2019-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
#==============================================================================
|
|
9
|
+
|
|
10
|
+
import utilo
|
|
11
|
+
|
|
12
|
+
import reftable
|
|
13
|
+
|
|
14
|
+
DESCRIPTION = ''
|
|
15
|
+
|
|
16
|
+
WORKPLAN = [
|
|
17
|
+
utilo.create_step(
|
|
18
|
+
'abbrev',
|
|
19
|
+
inputs=[
|
|
20
|
+
utilo.ResultFile(producer='rawmaker', name='text_text'),
|
|
21
|
+
utilo.ResultFile(producer='rawmaker', name='text_positions'),
|
|
22
|
+
utilo.ResultFile(producer='rawmaker', name='oneline_text_text'),
|
|
23
|
+
utilo.ResultFile('rawmaker', name='oneline_text_positions'),
|
|
24
|
+
utilo.ResultFile(producer='groupme', name='footer_footerheader'),
|
|
25
|
+
utilo.ResultFile(producer='rawmaker', name='border_pages'),
|
|
26
|
+
],
|
|
27
|
+
output=('abbrev',),
|
|
28
|
+
),
|
|
29
|
+
utilo.create_step(
|
|
30
|
+
'toc',
|
|
31
|
+
inputs=[
|
|
32
|
+
utilo.ResultFile(producer='rawmaker', name='oneline_text_text'),
|
|
33
|
+
utilo.ResultFile('rawmaker', name='oneline_text_positions'),
|
|
34
|
+
utilo.ResultFile(producer='groupme', name='footer_footerheader'),
|
|
35
|
+
utilo.ResultFile(producer='rawmaker', name='border_pages'),
|
|
36
|
+
],
|
|
37
|
+
output=('toc',),
|
|
38
|
+
),
|
|
39
|
+
utilo.create_step(
|
|
40
|
+
'figure',
|
|
41
|
+
inputs=[
|
|
42
|
+
utilo.ResultFile(producer='rawmaker', name='text_text'),
|
|
43
|
+
utilo.ResultFile(producer='rawmaker', name='text_positions'),
|
|
44
|
+
utilo.ResultFile(producer='rawmaker', name='oneline_text_text'),
|
|
45
|
+
utilo.ResultFile('rawmaker', name='oneline_text_positions'),
|
|
46
|
+
utilo.ResultFile(producer='groupme', name='footer_footerheader'),
|
|
47
|
+
utilo.ResultFile(producer='rawmaker', name='border_pages'),
|
|
48
|
+
],
|
|
49
|
+
output=('figure',),
|
|
50
|
+
),
|
|
51
|
+
utilo.create_step(
|
|
52
|
+
'table',
|
|
53
|
+
inputs=[
|
|
54
|
+
utilo.ResultFile(producer='rawmaker', name='oneline_text_text'),
|
|
55
|
+
utilo.ResultFile('rawmaker', name='oneline_text_positions'),
|
|
56
|
+
utilo.ResultFile(producer='groupme', name='footer_footerheader'),
|
|
57
|
+
utilo.ResultFile(producer='rawmaker', name='border_pages'),
|
|
58
|
+
],
|
|
59
|
+
output=('table',),
|
|
60
|
+
),
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def main():
|
|
65
|
+
utilo.featurepack(
|
|
66
|
+
workplan=WORKPLAN,
|
|
67
|
+
root=reftable.ROOT,
|
|
68
|
+
featurepackage='reftable.feature',
|
|
69
|
+
config=utilo.FeaturePackConfig(
|
|
70
|
+
description=DESCRIPTION,
|
|
71
|
+
multiprocessed=True,
|
|
72
|
+
name=reftable.PROCESS,
|
|
73
|
+
pages=True,
|
|
74
|
+
version=reftable.__version__,
|
|
75
|
+
),
|
|
76
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2020-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import serializeraw
|
|
11
|
+
|
|
12
|
+
import reftable.abbrev
|
|
13
|
+
import reftable.abbrev.parser
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def work(
|
|
17
|
+
text: str,
|
|
18
|
+
textposition: str,
|
|
19
|
+
text_oneline: str,
|
|
20
|
+
textposition_oneline: str,
|
|
21
|
+
headerfooter: str,
|
|
22
|
+
sizeandborder: str,
|
|
23
|
+
pages: tuple = None,
|
|
24
|
+
) -> str:
|
|
25
|
+
data = load_data(
|
|
26
|
+
text,
|
|
27
|
+
textposition,
|
|
28
|
+
text_oneline,
|
|
29
|
+
textposition_oneline,
|
|
30
|
+
headerfooter,
|
|
31
|
+
sizeandborder,
|
|
32
|
+
pages,
|
|
33
|
+
)
|
|
34
|
+
parsed = reftable.abbrev.parser.parse(data)
|
|
35
|
+
# dump result
|
|
36
|
+
dumped = serializeraw.dump_abbreviation_table(parsed)
|
|
37
|
+
return dumped
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def load_data(
|
|
41
|
+
text: str,
|
|
42
|
+
textposition: str,
|
|
43
|
+
text_oneline: str,
|
|
44
|
+
textposition_oneline: str,
|
|
45
|
+
headerfooter: str,
|
|
46
|
+
sizeandborder: str,
|
|
47
|
+
pages: tuple = None,
|
|
48
|
+
) -> reftable.abbrev.AbbreviationData:
|
|
49
|
+
normal = serializeraw.ptcn_fromfile(
|
|
50
|
+
text=text,
|
|
51
|
+
textpositions=textposition,
|
|
52
|
+
sizeandborder=sizeandborder,
|
|
53
|
+
headerfooter=headerfooter,
|
|
54
|
+
pages=pages,
|
|
55
|
+
)
|
|
56
|
+
oneline = serializeraw.ptcn_fromfile(
|
|
57
|
+
text=text_oneline,
|
|
58
|
+
textpositions=textposition_oneline,
|
|
59
|
+
sizeandborder=sizeandborder,
|
|
60
|
+
headerfooter=headerfooter,
|
|
61
|
+
pages=pages,
|
|
62
|
+
)
|
|
63
|
+
data = reftable.abbrev.AbbreviationData(
|
|
64
|
+
normal=normal,
|
|
65
|
+
oneline=oneline,
|
|
66
|
+
)
|
|
67
|
+
return data
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2019-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
"""Table of figures extractor
|
|
10
|
+
==========================
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import serializeraw
|
|
14
|
+
|
|
15
|
+
import reftable.figure.strategy
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def work(
|
|
19
|
+
text: str,
|
|
20
|
+
textpositions: str,
|
|
21
|
+
oneline_text: str,
|
|
22
|
+
oneline_textpositions: str,
|
|
23
|
+
headerfooter: str,
|
|
24
|
+
sizeandborder: str,
|
|
25
|
+
pages: tuple = None,
|
|
26
|
+
) -> str:
|
|
27
|
+
"""Extract table of figures out of `document`.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
text(str): path to load document
|
|
31
|
+
textpositions(str): path to load document textpositions
|
|
32
|
+
oneline_text(str): oneline document
|
|
33
|
+
oneline_textpositions(str): oneline document positions
|
|
34
|
+
headerfooter(str): path with header and footer to determine
|
|
35
|
+
content border.
|
|
36
|
+
sizeandborder(str): path with page sizes and content border
|
|
37
|
+
pages(tuple): tuple of selected pages
|
|
38
|
+
Returns:
|
|
39
|
+
dump of extracted table of content
|
|
40
|
+
"""
|
|
41
|
+
result = reftable.figure.strategy.run(
|
|
42
|
+
text=text,
|
|
43
|
+
textpositions=textpositions,
|
|
44
|
+
oneline_text=oneline_text,
|
|
45
|
+
oneline_textpositions=oneline_textpositions,
|
|
46
|
+
headerfooter=headerfooter,
|
|
47
|
+
sizeandborder=sizeandborder,
|
|
48
|
+
pages=pages,
|
|
49
|
+
)
|
|
50
|
+
dumped = serializeraw.dump_toc(result)
|
|
51
|
+
return dumped
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2019-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
"""Table of figures extractor
|
|
10
|
+
==========================
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import configos
|
|
14
|
+
import elementae
|
|
15
|
+
import iamraw
|
|
16
|
+
import serializeraw
|
|
17
|
+
import utilo
|
|
18
|
+
|
|
19
|
+
import reftable.pageselector
|
|
20
|
+
import reftable.toc.create
|
|
21
|
+
import reftable.toc.run
|
|
22
|
+
|
|
23
|
+
# minimal percentage of tabletable lines per page
|
|
24
|
+
TOFS_PER_PAGE_MIN = configos.HV_PERCENT_PLUS(default=20, limit=100)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def work(
|
|
28
|
+
text: str,
|
|
29
|
+
textpositions: str,
|
|
30
|
+
headerfooter: str,
|
|
31
|
+
sizeandborder: str,
|
|
32
|
+
pages: tuple = None,
|
|
33
|
+
) -> str:
|
|
34
|
+
"""Extract table of figures out of `document`.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
text(str): path to load document
|
|
38
|
+
textpositions(str): path to load document textpositions
|
|
39
|
+
headerfooter(str): path with header and footer to determine
|
|
40
|
+
content border.
|
|
41
|
+
sizeandborder(str): path with page sizes and content border
|
|
42
|
+
pages(tuple): tuple of selected pages
|
|
43
|
+
Returns:
|
|
44
|
+
dump of extracted table of content
|
|
45
|
+
"""
|
|
46
|
+
navigators = serializeraw.ptcn_fromfile(
|
|
47
|
+
text,
|
|
48
|
+
textpositions,
|
|
49
|
+
sizeandborder=sizeandborder,
|
|
50
|
+
headerfooter=headerfooter,
|
|
51
|
+
pages=pages,
|
|
52
|
+
)
|
|
53
|
+
selected = reftable.pageselector.select_contentpages(
|
|
54
|
+
navigators,
|
|
55
|
+
wrong_table=NO_TABLES,
|
|
56
|
+
valid_lines_perpage_min=TOFS_PER_PAGE_MIN,
|
|
57
|
+
)
|
|
58
|
+
if not selected:
|
|
59
|
+
return EMPTY
|
|
60
|
+
# select toc pages only
|
|
61
|
+
navigators = utilo.select_pages(navigators, pages=selected)
|
|
62
|
+
if not headline_start(navigators[0]):
|
|
63
|
+
utilo.error(f'no valid table headline start: {selected}')
|
|
64
|
+
return EMPTY
|
|
65
|
+
# run
|
|
66
|
+
extracted = reftable.toc.run.extract(navigators)
|
|
67
|
+
# prepare
|
|
68
|
+
flat = utilo.flat(extracted.content)
|
|
69
|
+
leveled = reftable.toc.create.groupby_level(flat)
|
|
70
|
+
# dump
|
|
71
|
+
dumped = serializeraw.dump_toc(leveled)
|
|
72
|
+
return dumped
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
EMPTY = serializeraw.dump_toc(iamraw.Toc())
|
|
76
|
+
NO_TABLES = utilo.unique(elementae.ABBREVIATION + elementae.TOC +
|
|
77
|
+
elementae.FIGURETABLE + elementae.SYMBOLTABLE)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def headline_start(ptn) -> bool:
|
|
81
|
+
"""Verify that the first ptn starts with a valid figure table headline."""
|
|
82
|
+
# TODO: INTEGRATE INTO SELECT_CONTENTPAGES
|
|
83
|
+
for line in ptn[0:8]:
|
|
84
|
+
parsed = elementae.headline.parser.parse_headline(line.text)
|
|
85
|
+
if not parsed:
|
|
86
|
+
continue
|
|
87
|
+
if utilo.verysimilar(parsed[0], expected=elementae.TABLETABLE):
|
|
88
|
+
return True
|
|
89
|
+
return False
|
reftable/feature/toc.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2019-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
"""Table of content extractor
|
|
10
|
+
==========================
|
|
11
|
+
|
|
12
|
+
Outdated approaches
|
|
13
|
+
-------------------
|
|
14
|
+
|
|
15
|
+
- collect title and check if sequence exists again in the document
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import configos
|
|
20
|
+
import elementae
|
|
21
|
+
import elementae.headline.lookup
|
|
22
|
+
import serializeraw
|
|
23
|
+
import utilo
|
|
24
|
+
|
|
25
|
+
import reftable.feature
|
|
26
|
+
import reftable.pageselector
|
|
27
|
+
import reftable.toc
|
|
28
|
+
import reftable.toc.create
|
|
29
|
+
import reftable.toc.run
|
|
30
|
+
import reftable.toc.strategy
|
|
31
|
+
|
|
32
|
+
# minimal percentage of toc lines per page
|
|
33
|
+
TOCS_PER_PAGE_MIN = configos.HV_PERCENT_PLUS(default=30, limit=100)
|
|
34
|
+
|
|
35
|
+
# limit possible toc to the first 15 pages
|
|
36
|
+
POSSIBLE_PAGES = utilo.make_tuple(15)
|
|
37
|
+
|
|
38
|
+
TOC_COUNT_MIN = configos.HV_INT_PLUS(default=4)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def work(
|
|
42
|
+
text: str,
|
|
43
|
+
textpositions: str,
|
|
44
|
+
headerfooter: str,
|
|
45
|
+
sizeandborder: str,
|
|
46
|
+
pages: tuple = None,
|
|
47
|
+
) -> str:
|
|
48
|
+
"""Extract table of content out of `document`.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
text(str): path to load document
|
|
52
|
+
textpositions(str): path to load document textpositions
|
|
53
|
+
headerfooter(str): path with header and footer to determine
|
|
54
|
+
content border.
|
|
55
|
+
sizeandborder(str): path with page sizes and content border
|
|
56
|
+
pages(tuple): tuple of selected pages
|
|
57
|
+
Returns:
|
|
58
|
+
dump of extracted table of content
|
|
59
|
+
"""
|
|
60
|
+
pages = POSSIBLE_PAGES if pages is None else pages
|
|
61
|
+
navigators = serializeraw.ptcn_fromfile(
|
|
62
|
+
text,
|
|
63
|
+
textpositions,
|
|
64
|
+
sizeandborder=sizeandborder,
|
|
65
|
+
headerfooter=headerfooter,
|
|
66
|
+
pages=pages,
|
|
67
|
+
)
|
|
68
|
+
extracted = run(navigators)
|
|
69
|
+
dumped = dump(extracted)
|
|
70
|
+
return dumped
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def run(navigators):
|
|
74
|
+
selected = reftable.pageselector.select_contentpages(
|
|
75
|
+
textnavigators=navigators,
|
|
76
|
+
wrong_table=NO_TOC,
|
|
77
|
+
skip_higherqual_level_three=False,
|
|
78
|
+
valid_lines_perpage_min=TOCS_PER_PAGE_MIN,
|
|
79
|
+
)
|
|
80
|
+
navigators = utilo.select_pages(
|
|
81
|
+
navigators,
|
|
82
|
+
pages=selected,
|
|
83
|
+
)
|
|
84
|
+
extracted = reftable.toc.run.extract(
|
|
85
|
+
navigators,
|
|
86
|
+
min_detection_count=TOC_COUNT_MIN,
|
|
87
|
+
)
|
|
88
|
+
return extracted
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def dump(extracted):
|
|
92
|
+
flat = utilo.flat(extracted.content)
|
|
93
|
+
leveled = reftable.toc.create.groupby_level(flat)
|
|
94
|
+
leveled.__strategy__ = extracted.strategy
|
|
95
|
+
dumped = serializeraw.dump_toc(leveled)
|
|
96
|
+
return dumped
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# NO_TOC = elementae.headline.lookup.HEADLINES - elementae.headline.lookup.TOC
|
|
100
|
+
NO_TOC = [
|
|
101
|
+
item for item in elementae.headline.lookup.HEADLINES
|
|
102
|
+
if item not in elementae.headline.lookup.TOC
|
|
103
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# C O P Y R I G H T
|
|
3
|
+
# -----------------------------------------------------------------------------
|
|
4
|
+
# Copyright (c) 2022-2023 by Helmut Konrad Schewe. All rights reserved.
|
|
5
|
+
# This file is property of Helmut Konrad Schewe. Any unauthorized copy,
|
|
6
|
+
# use or distribution is an offensive act against international law and may
|
|
7
|
+
# be prosecuted under federal law. Its content is company confidential.
|
|
8
|
+
# =============================================================================
|
|
9
|
+
|
|
10
|
+
import configos
|
|
11
|
+
import elementae
|
|
12
|
+
import utilo
|
|
13
|
+
|
|
14
|
+
# minimal percentage of figure lines per page
|
|
15
|
+
TOFS_PER_PAGE_MIN = configos.HV_PERCENT_PLUS(default=20, limit=100.0)
|
|
16
|
+
|
|
17
|
+
NO_FIGURES = utilo.unique(elementae.ABBREVIATION + elementae.BIBLIOGRAPHY +
|
|
18
|
+
elementae.GLOSSARY + elementae.SYMBOLTABLE +
|
|
19
|
+
elementae.TABLETABLE + elementae.TOC)
|