Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
docrecJSON-utilities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc-Philipp Knechtle
docrecJSON-utilities
Commits
23badcc7
Commit
23badcc7
authored
2 years ago
by
Marc-Philipp Knechtle
Browse files
Options
Downloads
Patches
Plain Diff
add match_tables function
parent
79f04784
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/docrecjson-utilities/utilities.py
+37
-0
37 additions, 0 deletions
python/docrecjson-utilities/utilities.py
python/requirements.txt
+3
-0
3 additions, 0 deletions
python/requirements.txt
with
40 additions
and
0 deletions
python/docrecjson-utilities/utilities.py
0 → 100644
+
37
−
0
View file @
23badcc7
from
typing
import
List
,
Dict
,
Optional
from
docrecjson.elements
import
Table
import
shapely.geometry
as
shapely
from
shapely.validation
import
make_valid
def
match_tables
(
tables_to_find_candidates
:
List
[
Table
],
matching_tables
:
List
[
Table
])
->
Dict
[
Table
,
Table
]:
"""
:param: tables_to_find_candidates: these are the tables where the candidates are found from.
:param: matching_tables: These are the tables which are tried to match to the tables_to_find_candidates.
:return: a dictionary with each table in tables_to_find_candidates, with one corresponding entry if matched table
was found, else none.
"""
table
:
Table
matched_tables
:
Dict
[
Table
,
Table
]
=
{}
for
table
in
tables_to_find_candidates
:
table_gt_area
:
shapely
.
Polygon
=
shapely
.
Polygon
(
table
.
get_table_coordinates
())
matching_table_with_highest_intersection
:
Optional
[
Table
]
=
None
highest_intersection
:
float
=
0
table_to_match
:
Table
for
table_to_match
in
matching_tables
:
table_prediction_area
:
shapely
.
Polygon
=
shapely
.
Polygon
(
table_to_match
.
get_table_coordinates
())
if
not
table_prediction_area
.
is_valid
:
table_prediction_area
=
make_valid
(
table_prediction_area
)
if
table_gt_area
.
intersects
(
table_prediction_area
):
intersection
=
table_gt_area
.
intersection
(
table_prediction_area
)
if
intersection
.
area
>
highest_intersection
:
highest_intersection
=
intersection
.
area
matching_table_with_highest_intersection
=
table_to_match
matching_tables
.
remove
(
matching_table_with_highest_intersection
)
matched_tables
[
table
]
=
matching_table_with_highest_intersection
return
matched_tables
This diff is collapsed.
Click to expand it.
python/requirements.txt
+
3
−
0
View file @
23badcc7
-e .
-e shared-file-format/python
shapely
loguru
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment