Skip to content

Fix list content duplication #396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions prettyprinter/textractprettyprinter/t_pretty_print_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ def _get_layout_blocks(self) -> tuple:
self.figures = [{"page": block.get('Page', 1), "geometry": block['Geometry']['BoundingBox']} \
for block in self.j['Blocks'] \
if block['BlockType'] == 'LAYOUT_FIGURE']

"""Avoid duplicating list contents: exclude LAYOUT* elements that are children of LAYOUT_LIST elements."""
list_layout_child_ids = set()
for layout in layouts:
layout_block = id2block[layout["Id"]]
if layout_block["BlockType"] != "LAYOUT_LIST":
continue
for relationship in [
r for r in layout_block.get("Relationships", []) if r["Type"] == "CHILD"
]:
for rel_id in relationship["Ids"]:
if id2block[rel_id]["BlockType"].startswith('LAYOUT'):
list_layout_child_ids.add(rel_id)
layouts = [
layout for layout in layouts if layout["Id"] not in list_layout_child_ids
]

if not layouts:
logger.warning("No LAYOUT information found in Textract response. \
Please use LAYOUT feature for AnalyzeDocument API call \
Expand Down