-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: impl data descriptor classification and sync them with json…
… files
- Loading branch information
1 parent
866accb
commit 72fda26
Showing
27 changed files
with
264 additions
and
1,204 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,14 @@ | ||
from esgvoc.api.data_descriptors.data_descriptor import DrsPlainTermDataDescriptor | ||
|
||
from __future__ import annotations | ||
from typing import ( | ||
Optional | ||
) | ||
from pydantic.version import VERSION as PYDANTIC_VERSION | ||
if int(PYDANTIC_VERSION[0])>=2: | ||
from pydantic import ( | ||
BaseModel, | ||
ConfigDict, | ||
Field | ||
) | ||
else: | ||
from pydantic import ( | ||
BaseModel, | ||
Field | ||
) | ||
|
||
metamodel_version = "None" | ||
version = "None" | ||
|
||
|
||
class ConfiguredBaseModel(BaseModel): | ||
model_config = ConfigDict( | ||
validate_assignment = True, | ||
validate_default = True, | ||
extra = "allow", | ||
arbitrary_types_allowed = True, | ||
use_enum_values = True, | ||
strict = False, | ||
) | ||
pass | ||
|
||
|
||
|
||
class Activity(ConfiguredBaseModel): | ||
class Activity(DrsPlainTermDataDescriptor): | ||
""" | ||
an 'activity' refers to a coordinated set of modeling experiments designed to address specific scientific questions or objectives. Each activity is focused on different aspects of climate science and utilizes various models to study a wide range of climate phenomena. Activities are often organized around key research themes and may involve multiple experiments, scenarios, and model configurations. | ||
An 'activity' refers to a coordinated set of modeling experiments designed to address specific \ | ||
scientific questions or objectives. Each activity is focused on different aspects of climate \ | ||
science and utilizes various models to study a wide range of climate phenomena. \ | ||
Activities are often organized around key research themes and may involve multiple experiments, \ | ||
scenarios, and model configurations. | ||
""" | ||
|
||
id: str | ||
validation_method: str = Field(default = "list") | ||
name: str | ||
long_name: str | ||
cmip_acronym: str | ||
url: Optional[str] | ||
|
||
|
||
# Model rebuild | ||
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model | ||
Activity.model_rebuild() | ||
url: str|None |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,26 @@ | ||
|
||
from __future__ import annotations | ||
from typing import ( | ||
List, | ||
Optional, | ||
Union | ||
) | ||
from pydantic.version import VERSION as PYDANTIC_VERSION | ||
if int(PYDANTIC_VERSION[0])>=2: | ||
from pydantic import ( | ||
BaseModel, | ||
ConfigDict, | ||
Field | ||
) | ||
else: | ||
from pydantic import ( | ||
BaseModel, | ||
Field | ||
) | ||
|
||
metamodel_version = "None" | ||
version = "None" | ||
|
||
|
||
class ConfiguredBaseModel(BaseModel): | ||
model_config = ConfigDict( | ||
validate_assignment = True, | ||
validate_default = True, | ||
extra = "allow", | ||
arbitrary_types_allowed = True, | ||
use_enum_values = True, | ||
strict = False, | ||
) | ||
pass | ||
from pydantic import Field | ||
from esgvoc.api.data_descriptors.data_descriptor import DrsPlainTermDataDescriptor, ConfiguredBaseModel | ||
|
||
|
||
class Dates(ConfiguredBaseModel): | ||
|
||
phase : str | ||
from_ : int = Field(...,alias="from") # cause from is a keyword | ||
to: Union[int,str] | ||
phase: str | ||
from_: int = Field(...,alias="from") # Cause from is a keyword | ||
to: int|str | ||
|
||
|
||
class Member(ConfiguredBaseModel): | ||
|
||
type : str | ||
institution : str # id | ||
dates : List[Dates] = Field(default_factory=list) | ||
membership_type : str # prior, current | ||
institution: str # id | ||
dates: list[Dates] = Field(default_factory=list) | ||
membership_type: str # prior, current | ||
|
||
class Consortium(ConfiguredBaseModel): | ||
|
||
id: str | ||
class Consortium(DrsPlainTermDataDescriptor): | ||
validation_method: str = Field(default = "list") | ||
type: str | ||
name: Optional[str] = None | ||
cmip_acronym: str = Field(...,alias="cmip-acronym") | ||
status : Optional[str] = None | ||
changes : Optional[str] | ||
members : List[Member] = Field(default_factory=list) | ||
url: Optional[str] | ||
|
||
|
||
# Model rebuild | ||
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model | ||
Consortium.model_rebuild() | ||
name: str|None = None | ||
status: str|None = None | ||
changes: str|None | ||
members: list[Member] = Field(default_factory=list) | ||
url: str|None | ||
# TODO: remove default value when all json will have their description. | ||
description: str = Field(default = "") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,106 @@ | ||
from typing import Protocol, Any | ||
from abc import ABC, abstractmethod | ||
from pydantic import BaseModel, ConfigDict | ||
|
||
class DataDescriptor(BaseModel): | ||
""" | ||
Generic class for the data descriptor classes. | ||
""" | ||
id: str | ||
"""The identifier of the terms""" | ||
type: str | ||
"""The data descriptor to which the term belongs.""" | ||
|
||
class ConfiguredBaseModel(BaseModel): | ||
model_config = ConfigDict( | ||
validate_assignment = True, | ||
validate_default = True, | ||
extra = "allow", | ||
arbitrary_types_allowed = True, | ||
use_enum_values = True, | ||
strict = False, | ||
) | ||
) | ||
|
||
|
||
class DataDescriptorVisitor(Protocol): | ||
""" | ||
The specifications for a term visitor. | ||
""" | ||
def visit_plain_term(term: "PlainTermDataDescriptor") -> Any: | ||
"""Visit a plain term.""" | ||
pass | ||
def visit_drs_plain_term(term: "DrsPlainTermDataDescriptor") -> Any: | ||
"""Visit a DRS plain term.""" | ||
pass | ||
def visit_term_pattern(term: "TermPatternDataDescriptor") -> Any: | ||
"""Visit a term pattern.""" | ||
pass | ||
def visit_term_composite(term: "TermCompositeDataDescriptor") -> Any: | ||
"""Visit a term composite.""" | ||
|
||
|
||
class DataDescriptor(ConfiguredBaseModel, ABC): | ||
""" | ||
Generic class for the data descriptor classes. | ||
""" | ||
id: str | ||
"""The identifier of the terms.""" | ||
type: str | ||
"""The data descriptor to which the term belongs.""" | ||
|
||
@abstractmethod | ||
def accept(visitor: DataDescriptorVisitor) -> any: | ||
""" | ||
Accept an term visitor. | ||
:param visitor: The term visitor. | ||
:type visitor: DataDescriptorVisitor | ||
:return: Depending on the visitor. | ||
:rtype: Any | ||
""" | ||
pass | ||
|
||
|
||
class PlainTermDataDescriptor(DataDescriptor): | ||
""" | ||
A data descriptor that describes hand written terms. | ||
""" | ||
def accept(self, visitor: DataDescriptorVisitor) -> any: | ||
return visitor.visit_plain_term(self) | ||
|
||
|
||
class DrsPlainTermDataDescriptor(PlainTermDataDescriptor): | ||
""" | ||
A data descriptor that describes hand written terms with DRS name. | ||
""" | ||
drs_name: str | ||
"""The DRS name.""" | ||
def accept(self, visitor: DataDescriptorVisitor) -> any: | ||
return visitor.visit_drs_plain_term(self) | ||
|
||
|
||
class TermPatternDataDescriptor(DataDescriptor): | ||
""" | ||
A data descriptor that describes terms defined by a regular expression. | ||
""" | ||
regex: str | ||
"""The regular expression.""" | ||
def accept(self, visitor: DataDescriptorVisitor) -> any: | ||
return visitor.visit_term_pattern(self) | ||
|
||
|
||
class TermCompositePart(ConfiguredBaseModel): | ||
""" | ||
A reference to a term, part of a term composite. | ||
""" | ||
|
||
id: str | ||
"""The id of the referenced term.""" | ||
type: str | ||
"""The type of the referenced term.""" | ||
is_required : bool | ||
"""Denote if the term is optional as part of a term composite""" | ||
|
||
|
||
class TermCompositeDataDescriptor(DataDescriptor): | ||
""" | ||
A data descriptor that describes terms composed of other terms. | ||
""" | ||
separator: str | ||
"""The term separator character.""" | ||
parts: list[TermCompositePart] | ||
"""The composites.""" | ||
def accept(self, visitor: DataDescriptorVisitor) -> any: | ||
return visitor.visit_term_composite(self) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,5 @@ | ||
from esgvoc.api.data_descriptors.data_descriptor import TermPatternDataDescriptor | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
from __future__ import annotations | ||
from pydantic.version import VERSION as PYDANTIC_VERSION | ||
if int(PYDANTIC_VERSION[0])>=2: | ||
from pydantic import ( | ||
BaseModel, | ||
ConfigDict | ||
) | ||
else: | ||
from pydantic import ( | ||
BaseModel | ||
) | ||
|
||
metamodel_version = "None" | ||
version = "None" | ||
|
||
|
||
class ConfiguredBaseModel(BaseModel): | ||
model_config = ConfigDict( | ||
validate_assignment = True, | ||
validate_default = True, | ||
extra = "allow", | ||
arbitrary_types_allowed = True, | ||
use_enum_values = True, | ||
strict = False, | ||
) | ||
pass | ||
|
||
|
||
|
||
|
||
|
||
class Date(ConfiguredBaseModel): | ||
|
||
|
||
|
||
id: str | ||
type : str | ||
regex : str | ||
# Model rebuild | ||
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model | ||
Date.model_rebuild() | ||
class Date(TermPatternDataDescriptor): | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,5 @@ | ||
from esgvoc.api.data_descriptors.data_descriptor import TermPatternDataDescriptor | ||
|
||
|
||
|
||
from __future__ import annotations | ||
from typing import ( | ||
List | ||
) | ||
from pydantic.version import VERSION as PYDANTIC_VERSION | ||
if int(PYDANTIC_VERSION[0])>=2: | ||
from pydantic import ( | ||
BaseModel, | ||
ConfigDict | ||
) | ||
else: | ||
from pydantic import ( | ||
BaseModel | ||
) | ||
|
||
metamodel_version = "None" | ||
version = "None" | ||
|
||
|
||
class ConfiguredBaseModel(BaseModel): | ||
model_config = ConfigDict( | ||
validate_assignment = True, | ||
validate_default = True, | ||
extra = "allow", | ||
arbitrary_types_allowed = True, | ||
use_enum_values = True, | ||
strict = False, | ||
) | ||
pass | ||
|
||
class Part(ConfiguredBaseModel): | ||
id: str | ||
type : str | ||
is_required : bool | ||
|
||
class DirectoryDate(ConfiguredBaseModel): | ||
|
||
|
||
id: str | ||
type: str | ||
regex : str | ||
|
||
# Model rebuild | ||
# see https://pydantic-docs.helpmanual.io/usage/models/#rebuilding-a-model | ||
DirectoryDate.model_rebuild() | ||
class DirectoryDate(TermPatternDataDescriptor): | ||
pass |
Oops, something went wrong.