Skip to content

feat: empaia parser#48

Merged
matejpekar merged 3 commits into
mainfrom
feature/empaia-parser
Mar 31, 2026
Merged

feat: empaia parser#48
matejpekar merged 3 commits into
mainfrom
feature/empaia-parser

Conversation

@Adames4
Copy link
Copy Markdown
Member

@Adames4 Adames4 commented Mar 25, 2026

Parser for annotations downloaded from EMPAIA.

Summary by CodeRabbit

  • New Features

    • EMPAIAParser added to process EMPAIA annotation files, extracting polygons and points with name-based filtering.
  • Documentation

    • Added a reference page documenting the EMPAIA parser.
  • Tests

    • New tests covering EMPAIA parser parsing of points, polygons, and name-filtering behavior.
  • Chores

    • Package version bumped to 1.3.1.
    • Project authors list updated with an additional contributor.

@Adames4 Adames4 self-assigned this Mar 25, 2026
@Adames4 Adames4 requested review from a team March 25, 2026 15:57
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f39a4bba-8fb7-4df7-8bbb-7f5c52d18bfd

📥 Commits

Reviewing files that changed from the base of the PR and between 90eb060 and 1d60406.

📒 Files selected for processing (3)
  • pyproject.toml
  • ratiopath/parsers/empaia_parser.py
  • tests/test_parsers.py
✅ Files skipped from review due to trivial changes (2)
  • pyproject.toml
  • tests/test_parsers.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • ratiopath/parsers/empaia_parser.py

📝 Walkthrough

Walkthrough

Adds a new EMPAIAParser for reading and filtering EMPAIA JSON annotations, exposes it via the parsers package, includes docs and tests, and bumps package version to 1.3.1 while updating authors and modernizing a Shapely import.

Changes

Cohort / File(s) Summary
Documentation & Metadata
docs/reference/parsers/empaia.md, pyproject.toml
Added API reference stub for EMPAIAParser; bumped package version to 1.3.1 and added author Vít Musil.
Parser Exports
ratiopath/parsers/__init__.py
Imported and exported EMPAIAParser via __all__.
New Parser Implementation
ratiopath/parsers/empaia_parser.py
New EMPAIAParser class: loads EMPAIA JSON from path or file-like object, filters annotations by regex name and type, provides get_polygons() and get_points() returning Shapely geometries.
Existing Parser Modernization
ratiopath/parsers/asap_parser.py
Updated Shapely import style and added explicit -> None return annotation to ASAPParser.__init__.
Tests
tests/test_parsers.py
Added TestEMPAIAParser tests verifying polygon/point parsing, coordinate conversion, and name-based filtering.

Sequence Diagram(s)

sequenceDiagram
  participant File as EMPAIA JSON (file)
  participant Parser as EMPAIAParser
  participant Shapely as Shapely Geometry
  File->>Parser: provide JSON stream or path
  Parser->>Parser: load JSON into self.annotations
  Parser->>Parser: compile name regex, filter items by name & type
  Parser->>Shapely: convert coords -> Polygon / Point
  Shapely-->>Parser: geometry object
  Parser-->>Client: yield geometry
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

Suggested reviewers

  • vejtek
  • JakubPekar

Poem

🐰 I hopped through JSON, sniffed each name,
Matched points and polygons — what a game!
I stitched coordinates, neat and bright,
Bumped the version and tested right. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: empaia parser' directly and clearly describes the main change: introducing a new EMPAIA parser to the codebase, which is the primary purpose of this pull request.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/empaia-parser

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the library's annotation parsing capabilities by integrating a new parser for EMPAIA-formatted JSON files, allowing for the extraction of both polygon and point annotations. Alongside this new feature, the project's version has been updated, and new contributors have been acknowledged. Minor code improvements were also applied to an existing parser for better consistency and type hinting.

Highlights

  • New Feature: EMPAIA Parser: Introduced a new EMPAIAParser to handle annotations from EMPAIA-formatted JSON files, supporting both polygon and point geometries.
  • Project Metadata Update: The project version has been incremented to 1.3.1, and the list of authors in pyproject.toml has been expanded to include new contributors.
  • Code Refinement and Consistency: Updated the ASAPParser to use a more direct shapely import and added a return type hint to its constructor for improved code clarity.
  • Comprehensive Test Coverage: Added a dedicated test suite for the new EMPAIAParser, ensuring its functionality for extracting polygons and points, including filtering capabilities.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
ratiopath/parsers/empaia_parser.py (2)

31-49: Note: re.match() only matches at the start of the string.

This means name="1" won't match "Annotation 1". If you intend for the pattern to match anywhere in the name, use re.search() instead. However, if matching from the start is intentional (consistent with how other parsers work), this is fine.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ratiopath/parsers/empaia_parser.py` around lines 31 - 49, The current
_get_filtered_annotations function uses name_regex.match(...) which only checks
the start of annotation["name"]; if you want the provided pattern to match
anywhere in the string, replace the use of re.match with re.search (i.e.,
compile the pattern into name_regex and call
name_regex.search(annotation["name"]) when testing annotations in
self.annotations["items"]) so names like "Annotation 1" will match a pattern
"1"; if start-anchored matching is desired, leave as-is but add a comment
clarifying the intentional behavior.

60-66: Avoid creating intermediate Point objects when constructing Polygon.

Shapely's Polygon constructor accepts coordinate tuples directly. Creating Point objects adds unnecessary overhead.

♻️ Suggested simplification
 for annotation in self._get_filtered_annotations(name, "polygon"):
-    yield Polygon(
-        [
-            Point(float(coordinate[0]), float(coordinate[1]))
-            for coordinate in annotation["coordinates"]
-        ]
-    )
+    yield Polygon(
+        [
+            (float(coord[0]), float(coord[1]))
+            for coord in annotation["coordinates"]
+        ]
+    )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ratiopath/parsers/empaia_parser.py` around lines 60 - 66, The code is
creating intermediate Point objects when building a Polygon; update the polygon
construction in the loop over self._get_filtered_annotations(name, "polygon") to
pass coordinate tuples directly to shapely.geometry.Polygon instead of creating
Point instances: transform annotation["coordinates"] into an iterable of
(float(x), float(y)) tuples and pass that to Polygon (no Point instantiation),
keeping the surrounding loop and yield as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ratiopath/parsers/empaia_parser.py`:
- Around line 31-49: The current _get_filtered_annotations function uses
name_regex.match(...) which only checks the start of annotation["name"]; if you
want the provided pattern to match anywhere in the string, replace the use of
re.match with re.search (i.e., compile the pattern into name_regex and call
name_regex.search(annotation["name"]) when testing annotations in
self.annotations["items"]) so names like "Annotation 1" will match a pattern
"1"; if start-anchored matching is desired, leave as-is but add a comment
clarifying the intentional behavior.
- Around line 60-66: The code is creating intermediate Point objects when
building a Polygon; update the polygon construction in the loop over
self._get_filtered_annotations(name, "polygon") to pass coordinate tuples
directly to shapely.geometry.Polygon instead of creating Point instances:
transform annotation["coordinates"] into an iterable of (float(x), float(y))
tuples and pass that to Polygon (no Point instantiation), keeping the
surrounding loop and yield as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7e7888e3-652f-47f6-89b0-b8ba4679d90a

📥 Commits

Reviewing files that changed from the base of the PR and between 4f8c69b and 90eb060.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • docs/reference/parsers/empaia.md
  • pyproject.toml
  • ratiopath/parsers/__init__.py
  • ratiopath/parsers/asap_parser.py
  • ratiopath/parsers/empaia_parser.py
  • tests/test_parsers.py

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new EMPAIAParser for handling EMPAIA format annotation files, supporting both polygon and point features. The changes include the parser implementation, integration into the package's __init__.py, and comprehensive unit tests. The project version has been updated to 1.3.1, and new authors have been added. Feedback includes suggestions to improve efficiency in EMPAIAParser.get_polygons by directly using coordinate tuples for shapely.Polygon construction and to enhance the robustness of polygon assertions in tests by verifying the full closed coordinate sequence.

Comment thread ratiopath/parsers/empaia_parser.py
Comment thread tests/test_parsers.py Outdated
Comment thread ratiopath/parsers/empaia_parser.py Outdated
Comment thread pyproject.toml Outdated
@matejpekar matejpekar merged commit 8eb007e into main Mar 31, 2026
6 checks passed
@matejpekar matejpekar deleted the feature/empaia-parser branch March 31, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants