Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 5fb5821

Browse files
sami-m-gjsvgoncalves
authored andcommitted
Refactor Enums to dds_glossary/enums.py
Signed-off-by: sami-m-g <sami.mg@outlook.com> Reviewed-by: João Gonçalves <jsvgoncalves@gmail.com>
1 parent 1319b10 commit 5fb5821

6 files changed

Lines changed: 43 additions & 44 deletions

File tree

dds_glossary/enums.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Enum classes for the dds_glossary package."""
2+
3+
from enum import Enum
4+
5+
6+
class MemberType(Enum):
7+
"""
8+
Enum class for the types of collection members.
9+
10+
Attributes:
11+
CONCEPT (str): The concept type.
12+
COLLECTION (str): The collection type.
13+
"""
14+
15+
COLLECTION_MEMBER: str = "collection_member"
16+
CONCEPT: str = "concept"
17+
COLLECTION: str = "collection"
18+
19+
20+
class SemanticRelationType(Enum):
21+
"""
22+
Enum class for the types of semantic relations.
23+
24+
Attributes:
25+
BROADER (str): The broader semantic relation.
26+
NARROWER (str): The narrower semantic relation.
27+
RELATED (str): The related semantic relation.
28+
BROADER_TRANSITIVE (str): The transitive broader semantic relation
29+
NARROWER_TRANSITIVE (str): The transitive narrower semantic relation.
30+
"""
31+
32+
BROADER: str = "broader"
33+
NARROWER: str = "narrower"
34+
RELATED: str = "related"
35+
BROADER_TRANSITIVE: str = "broaderTransitive"
36+
NARROWER_TRANSITIVE: str = "narrowerTransitive"

dds_glossary/model.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from abc import abstractmethod
44
from collections import defaultdict
5-
from enum import Enum
65
from typing import ClassVar
76

87
from pydantic import BaseModel
98
from sqlalchemy import Column, ForeignKey, String, Table
109
from sqlalchemy.dialects.postgresql import JSONB
1110
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
1211

12+
from .enums import MemberType, SemanticRelationType
13+
1314

1415
class Dataset(BaseModel):
1516
"""
@@ -35,39 +36,6 @@ class FailedDataset(Dataset):
3536
error: str
3637

3738

38-
class MemberType(Enum):
39-
"""
40-
Enum class for the types of collection members.
41-
42-
Attributes:
43-
CONCEPT (str): The concept type.
44-
COLLECTION (str): The collection type.
45-
"""
46-
47-
COLLECTION_MEMBER: str = "collection_member"
48-
CONCEPT: str = "concept"
49-
COLLECTION: str = "collection"
50-
51-
52-
class SemanticRelationType(Enum):
53-
"""
54-
Enum class for the types of semantic relations.
55-
56-
Attributes:
57-
BROADER (str): The broader semantic relation.
58-
NARROWER (str): The narrower semantic relation.
59-
RELATED (str): The related semantic relation.
60-
BROADER_TRANSITIVE (str): The transitive broader semantic relation
61-
NARROWER_TRANSITIVE (str): The transitive narrower semantic relation.
62-
"""
63-
64-
BROADER: str = "broader"
65-
NARROWER: str = "narrower"
66-
RELATED: str = "related"
67-
BROADER_TRANSITIVE: str = "broaderTransitive"
68-
NARROWER_TRANSITIVE: str = "narrowerTransitive"
69-
70-
7139
class Base(DeclarativeBase):
7240
"""Base class for all models."""
7341

dds_glossary/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
save_dataset,
2121
search_database,
2222
)
23+
from .enums import MemberType
2324
from .exceptions import (
2425
CollectionNotFoundException,
2526
ConceptNotFoundException,
@@ -32,7 +33,6 @@
3233
Dataset,
3334
FailedDataset,
3435
Member,
35-
MemberType,
3636
SemanticRelation,
3737
)
3838
from .schema import (

tests/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from sqlalchemy import Engine
44
from sqlalchemy.orm import Session
55

6+
from dds_glossary.enums import SemanticRelationType
67
from dds_glossary.model import (
78
Collection,
89
Concept,
910
ConceptScheme,
1011
Member,
1112
SemanticRelation,
12-
SemanticRelationType,
1313
)
1414

1515

tests/unit/test_database.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
save_dataset,
1616
search_database,
1717
)
18-
from dds_glossary.model import (
19-
Collection,
20-
Concept,
21-
ConceptScheme,
22-
SemanticRelation,
23-
SemanticRelationType,
24-
)
18+
from dds_glossary.enums import SemanticRelationType
19+
from dds_glossary.model import Collection, Concept, ConceptScheme, SemanticRelation
2520

2621
from ..common import add_collections, add_concept_schemes, add_concepts, add_relations
2722

tests/unit/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"""Tests for dds_glossary.model module."""
22

3+
from dds_glossary.enums import SemanticRelationType
34
from dds_glossary.model import (
45
Base,
56
Collection,
67
Concept,
78
ConceptScheme,
89
SemanticRelation,
9-
SemanticRelationType,
1010
)
1111

1212

0 commit comments

Comments
 (0)