Skip to content

属性の制約に関するモジュールattribute_restrictionsを追加しました。 #707

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

Merged
merged 13 commits into from
Mar 20, 2025

Conversation

yuji38kwmt
Copy link
Collaborator

@yuji38kwmt yuji38kwmt commented Mar 20, 2025

属性間の制約を設定するには、ユーザー自身でJSONを作成する必要があります。

自分でJSONを書く場合、以下の問題があります。

  • 属性名でなく属性IDで表現するため(ラベルや選択肢も同様)、JSONだけではどのような制約なのかが分からない
  • 利用できない制約(たとえばトラッキングID属性に対して「正規表現に一致する」など)を表現できてしまう。
  • 「AかつBならばC」という制約を、「A -> (B -> C)」でなく「(A -> B) -> C」という表現にしてしまい、期待通りの制約が設定できない

上記の問題を解決するため、属性の制約を定義できるモジュールを作成しました。
このモジュールの特徴は以下の通りです。

  • IDだけでなく英語名で表現できる

  • 利用できない制約に対応するメソッドは定義されていない

  • 属性のUIに対応したメソッドが定義されている。たとえば「チェックボックスがON」という制約は、checked()というメソッドで表現できる

@yuji38kwmt yuji38kwmt changed the title Add restrictions 属性の制約に関するモジュールattribute_restrictionsを追加しました。 Mar 20, 2025
@yuji38kwmt yuji38kwmt requested a review from Copilot March 20, 2025 08:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new module for attribute restrictions, which allows outputting constraint information based on attribute names. The changes include:

  • Adding the attribute_restrictions module with various restriction classes (e.g., Checkbox, StringTextBox, IntegerTextBox, AnnotationLink, TrackingId, and Selection) and their corresponding behaviors.
  • Implementing tests in tests/util/test_local_attribute_restrictions.py to validate the new attribute constraints.
  • Minor updates in annotation_specs.py and pyproject.toml (e.g., enabling column number display) to support and document the new functionality.

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

File Description
tests/util/test_local_attribute_restrictions.py New tests validating the behavior of attribute restriction methods.
annofabapi/util/attribute_restrictions.py New module defining attribute restriction classes and their methods.
annofabapi/util/annotation_specs.py Updated helper functions to support the new attribute restrictions.
pyproject.toml Minor configuration change to show column numbers in diagnostics.
Files not reviewed (2)
  • docs/api_reference/index.rst: Language not supported
  • docs/api_reference/util.rst: Language not supported
Comments suppressed due to low confidence (1)

annofabapi/util/annotation_specs.py:1

  • [nitpick] The docstring refers to 'InternalizationMessage' whereas the parameter is named 'internationalization_message'. Consider updating the term to 'InternationalizationMessage' for consistency.
def get_english_message(internationalization_message: dict[str, Any]) -> str:

@yuji38kwmt yuji38kwmt requested a review from Copilot March 20, 2025 08:24
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds a new module for defining attribute restrictions, enabling constraints to be specified using both attribute IDs and English names. It also introduces comprehensive tests for these new restrictions and updates utility functions in the annotation specs module to support the new behavior.

  • Added the module annofabapi/util/attribute_restrictions.py with various attribute restriction classes (e.g., Checkbox, StringTextBox, IntegerTextBox, etc.) and their corresponding methods.
  • Introduced tests in tests/util/test_local_attribute_restrictions.py covering the functionality of each restriction class, including implications between restrictions.
  • Updated the annotation specs utilities to enhance clarity and consistency when retrieving attribute and label information.

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

File Description
tests/util/test_local_attribute_restrictions.py New tests for the attribute restrictions module
annofabapi/util/attribute_restrictions.py New module providing classes and methods for attribute constraints
annofabapi/util/annotation_specs.py Updated functions to support English message retrieval and choice lookup
pyproject.toml Enabled column number display for improved lint output
Files not reviewed (2)
  • docs/api_reference/index.rst: Language not supported
  • docs/api_reference/util.rst: Language not supported
Comments suppressed due to low confidence (1)

tests/util/test_local_attribute_restrictions.py:66

  • The test method name 'test__not_matches' is misleading because it validates the 'not_equals' functionality; consider renaming it to 'test__not_equals' for clarity.
def test__not_matches(self):

@yuji38kwmt yuji38kwmt requested a review from Copilot March 20, 2025 08:27
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new module, attribute_restrictions, to provide a structured way to define constraints on attributes by supporting both ID- and English name–based representations. Key changes include:

  • Adding various attribute classes (e.g., Checkbox, StringTextBox, IntegerTextBox, Selection, TrackingId) with methods that output constraint definitions.
  • Implementing and testing an imply method for chaining restrictions, along with error handling for unsupported chaining.
  • Updating annotation_specs helper functions and pyproject.toml configuration.

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

File Description
tests/util/test_local_attribute_restrictions.py New tests covering attribute restriction methods and error handling for type checks.
annofabapi/util/attribute_restrictions.py New module providing restrictions implementations and chaining via imply method.
annofabapi/util/annotation_specs.py Updates to support internationalized messages and retrieval of attribute/choice info.
pyproject.toml Minor configuration update to show column numbers in linting output.
Files not reviewed (2)
  • docs/api_reference/index.rst: Language not supported
  • docs/api_reference/util.rst: Language not supported

@yuji38kwmt yuji38kwmt merged commit 9a03c97 into main Mar 20, 2025
8 checks passed
@yuji38kwmt yuji38kwmt deleted the add-restrictions branch March 20, 2025 08:30
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.

1 participant