Skip to content

[ENUM][CONFIG] Replaces all hard coded constant names in Enum#92

Merged
ChanukaUOJ merged 4 commits intoLDFLK:mainfrom
ChanukaUOJ:task-enum-migration
Mar 5, 2026
Merged

[ENUM][CONFIG] Replaces all hard coded constant names in Enum#92
ChanukaUOJ merged 4 commits intoLDFLK:mainfrom
ChanukaUOJ:task-enum-migration

Conversation

@ChanukaUOJ
Copy link
Member

Description

This PR addresses and completes Issue #56.

All previously hardcoded values related to Entity Major/Minor Kinds and Relation Names have been refactored to use Enum types. This improves code readability, enhances maintainability, and allows safer and easier future modifications.

Fixes #56

Changes

  • Replaced hardcoded constant values with Enum references
  • Introduced new Enum definitions for:
    • Relation Names
    • Relation Directions
    • Entity Major Kinds
    • Entity Minor Kinds
  • Removed unused imports and performed minor code cleanup

Testing

  • No new tests were added
  • All existing tests are passing successfully

@gemini-code-assist
Copy link
Contributor

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 refactors hardcoded constant names in the project to use Enum types, specifically for Entity Major/Minor Kinds and Relation Names. This change improves code quality by making it more readable, maintainable, and less prone to errors. The introduction of new Enum definitions standardizes the representation of these constants across the application.

Highlights

  • Refactoring: Replaced hardcoded constant values with Enum references for Entity Major/Minor Kinds and Relation Names, enhancing code readability and maintainability.
  • New Enums: Introduced new Enum definitions for Relation Names, Relation Directions, Entity Major Kinds, and Entity Minor Kinds.
  • Code Cleanup: Removed unused imports and performed minor code cleanup.
Changelog
  • src/enums/init.py
    • Exports the newly created enums.
  • src/enums/kindEnum.py
    • Defines enums for Entity Major and Minor Kinds.
  • src/enums/relationEnum.py
    • Defines enums for Relation Names and Relation Directions.
  • src/models/organisation_schemas.py
    • Added Optional import from typing.
  • src/routers/person_router.py
    • Removed unused imports.
  • src/services/data_service.py
    • Replaced hardcoded strings with enum values for category kinds and relation names/directions.
  • src/services/opengin_service.py
    • Updated model_dump calls to include mode='json'.
  • src/services/organisation_service.py
    • Replaced hardcoded relation names and directions with enum values.
  • src/services/person_service.py
    • Replaced hardcoded relation names and directions with enum values.
  • src/services/search_service.py
    • Replaced hardcoded entity types with enum values.
  • src/utils/util_functions.py
    • Replaced hardcoded tabular string with enum value.
  • test/test_data_service.py
    • Replaced hardcoded strings with enum values in tests.
  • test/test_opengin_service.py
    • Replaced hardcoded strings with enum values in tests.
  • test/test_organisation_service.py
    • Replaced hardcoded strings with enum values in tests.
  • test/test_person_service.py
    • Replaced hardcoded strings with enum values in tests.
  • test/test_retry_opengin_service.py
    • Replaced hardcoded strings with enum values in tests.
  • test/test_search_service.py
    • Replaced hardcoded strings with enum values in tests.
Activity
  • The pull request completes Issue [ENUM][CONFIG] Replaces all hard coded constant names with Enum #56, addressing the replacement of hardcoded values with Enum types.
  • The changes include refactoring entity kinds and relation names to use enums, enhancing code readability and maintainability.
  • Existing tests are passing successfully, ensuring no regressions were introduced.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
Contributor

@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 effectively replaces hardcoded strings with enums, which is a great improvement for code clarity and maintainability. My review includes suggestions to further improve consistency in this new enum usage, particularly within the search service, and fixes a minor bug in the test data. Overall, this is a solid step towards a more robust codebase.


# Check if we've reached a department, state minister or cabinet minister (root)
if current_category.kind and current_category.kind.minor in ["department", "stateMinister", "cabinetMinister"]:
if current_category.kind and current_category.kind.minor in [KindMinorEnum.DEPARTMENT.value, KindMinorEnum.STATE_MINISTER.value, KindMinorEnum.CABINET_MINISTER.value]:
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For membership testing, using a set is more idiomatic and slightly more performant than a list. Since this list of minor kinds is also used on line 529, consider defining it as a constant set at the module level to improve readability and avoid repetition.

Suggested change
if current_category.kind and current_category.kind.minor in [KindMinorEnum.DEPARTMENT.value, KindMinorEnum.STATE_MINISTER.value, KindMinorEnum.CABINET_MINISTER.value]:
if current_category.kind and current_category.kind.minor in {KindMinorEnum.DEPARTMENT.value, KindMinorEnum.STATE_MINISTER.value, KindMinorEnum.CABINET_MINISTER.value}:

Comment on lines 210 to 216
type_mapping = {
("Organisation".lower(), "department".lower()): "department",
("Organisation".lower(), "stateMinister".lower()): "stateMinister",
("Organisation".lower(), "cabinetMinister".lower()): "cabinetMinister",
("Dataset".lower(), "tabular".lower()): "dataset",
("Person".lower(), "citizen".lower()): "person",
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.DEPARTMENT.value.lower()): KindMinorEnum.DEPARTMENT.value,
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.STATE_MINISTER.value.lower()): KindMinorEnum.STATE_MINISTER.value,
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.CABINET_MINISTER.value.lower()): KindMinorEnum.CABINET_MINISTER.value,
(KindMajorEnum.DATASET.value.lower(), KindMinorEnum.TABULAR.value.lower()): "dataset",
(KindMajorEnum.PERSON.value.lower(), KindMinorEnum.CITIZEN.value.lower()): "person",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The type_mapping dictionary has inconsistent value types. It returns Enum members for Organisation kinds but hardcoded strings ('dataset', 'person') for others. This inconsistency propagates to VALID_ENTITY_TYPES (line 13) and entity_config (lines 54-60), undermining the goal of removing hardcoded strings.

To make this consistent, I suggest using Enum members for all types. This would involve:

  1. Updating this type_mapping to return KindMinorEnum.TABULAR.value and KindMinorEnum.CITIZEN.value.
  2. Updating VALID_ENTITY_TYPES to use these enum values instead of hardcoded strings.
  3. Updating the keys in entity_config to also use these enum values.
Suggested change
type_mapping = {
("Organisation".lower(), "department".lower()): "department",
("Organisation".lower(), "stateMinister".lower()): "stateMinister",
("Organisation".lower(), "cabinetMinister".lower()): "cabinetMinister",
("Dataset".lower(), "tabular".lower()): "dataset",
("Person".lower(), "citizen".lower()): "person",
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.DEPARTMENT.value.lower()): KindMinorEnum.DEPARTMENT.value,
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.STATE_MINISTER.value.lower()): KindMinorEnum.STATE_MINISTER.value,
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.CABINET_MINISTER.value.lower()): KindMinorEnum.CABINET_MINISTER.value,
(KindMajorEnum.DATASET.value.lower(), KindMinorEnum.TABULAR.value.lower()): "dataset",
(KindMajorEnum.PERSON.value.lower(), KindMinorEnum.CITIZEN.value.lower()): "person",
}
type_mapping = {
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.DEPARTMENT.value.lower()): KindMinorEnum.DEPARTMENT.value,
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.STATE_MINISTER.value.lower()): KindMinorEnum.STATE_MINISTER.value,
(KindMajorEnum.ORGANISATION.value.lower(), KindMinorEnum.CABINET_MINISTER.value.lower()): KindMinorEnum.CABINET_MINISTER.value,
(KindMajorEnum.DATASET.value.lower(), KindMinorEnum.TABULAR.value.lower()): KindMinorEnum.TABULAR.value,
(KindMajorEnum.PERSON.value.lower(), KindMinorEnum.CITIZEN.value.lower()): KindMinorEnum.CITIZEN.value,
}

@ChanukaUOJ ChanukaUOJ requested a review from zaeema-n March 3, 2026 07:33
@@ -1,3 +1,4 @@
from typing import Optional
Copy link
Member

@zaeema-n zaeema-n Mar 4, 2026

Choose a reason for hiding this comment

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

This import is not being used

Copy link
Member

@zaeema-n zaeema-n left a comment

Choose a reason for hiding this comment

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

LGTM

@ChanukaUOJ ChanukaUOJ merged commit cf7bb3b into LDFLK:main Mar 5, 2026
2 checks passed
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.

[ENUM][CONFIG] Replaces all hard coded constant names with Enum

2 participants