Ontology rendering#113
Merged
Merged
Conversation
| scaled_points = [ | ||
| (p[0] * page_width, p[1] * page_height) for p in region.points | ||
| ] | ||
| shape.draw_rect(pymupdf.Quad(*scaled_points).rect) |
There was a problem hiding this comment.
Bug: pymupdf.Quad(*scaled_points) crashes if region.points has anything other than exactly 4 points.
Severity: MEDIUM
Suggested Fix
Clamp scaled_points to exactly 4 points (e.g., use scaled_points[:4]) or construct the rect directly via pymupdf.Rect(min_x, min_y, max_x, max_y) computed from all points, avoiding the Quad constraint entirely.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: bc2/core/common/ontopainter.py#L127
Potential issue: In `_paint_rect` (line 127), `pymupdf.Quad(*scaled_points)` unpacks all
points from `region.points` as positional arguments. `pymupdf.Quad` accepts exactly 4
corner points (ul, ur, ll, lr). The polygon from Azure DI is converted in `openai.py` by
iterating `range(0, len(polygon), 2)`, which typically yields 4 points (8-float
polygon). However, `SourceChunkBoundingRegion.points` is typed as an unconstrained
`list[tuple[float, float]]`, so if Azure DI returns a polygon with more or fewer than 4
points (e.g., for irregular regions or future API changes),
`pymupdf.Quad(*scaled_points)` will raise a `TypeError` about incorrect number of
arguments, crashing the painting pipeline for that document.
Comment on lines
+113
to
+120
| OntoPainterFieldConfig( | ||
| accessor=lambda report: [subject.dob for subject in report.subjects], | ||
| label="Subject DOB", | ||
| mark=OntoPainterMark.RECT, | ||
| fill=None, | ||
| stroke=Palette.Cyan1, | ||
| stroke_width=2, | ||
| ), |
There was a problem hiding this comment.
Bug: Subject DOB field is registered twice in painter, causing it to be painted twice on every document.
Severity: LOW
Suggested Fix
Remove the duplicate entry (lines 113-120) or replace it with the intended field configuration (e.g., subject.seq).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: bc2/core/paint/ontology.py#L113-L120
Potential issue: In `bc2/core/paint/ontology.py`, lines 105-120, the
`OntoPainterFieldConfig` for `Subject DOB` is defined twice with identical configuration
(`accessor=lambda report: [subject.dob for subject in report.subjects]`, label `"Subject
DOB"`, same stroke color). This causes the painter to iterate over DOB fields twice per
document: once at lines 105-112 and again at lines 113-120. Each DOB annotation will be
drawn twice on top of itself, wasting rendering time and potentially confusing
downstream users who try to match labels to fields. This is clearly a copy-paste
mistake—one entry should likely be for a different field (e.g., subject `seq`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new
paintmodule (differentiated from the generalrendermodule that operates onRedactedText) to annotate the input pdf with the results of the ontology extraction.Refactors some existing modules to pass through the appropriate data in the pipeline context.