-
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.
- Loading branch information
1 parent
c785f4c
commit 452c5c6
Showing
28 changed files
with
627 additions
and
516 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
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from pydantic import ConfigDict | ||
|
||
from mex.common.models.base import BaseModel | ||
from mex.common.types import Identifier | ||
|
||
|
||
class BaseEntity(BaseModel): | ||
"""Abstract base model for extracted data, merged item and rule set classes. | ||
This class gives type hints for an `identifier` field and the frozen class variable | ||
`entityType`. Subclasses should implement both fields and set the correct identifier | ||
type as well as the correct literal value for the entity type. | ||
""" | ||
|
||
model_config = ConfigDict(extra="forbid") | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
# The `entityType` class variable is added to all `BaseEntity` subclasses to | ||
# help with assigning the correct class when reading raw JSON entities. | ||
# E.g.: https://docs.pydantic.dev/latest/concepts/fields/#discriminator | ||
# Simple duck-typing would not work, because some entity-types have overlapping | ||
# attributes, like `Person.email` and `ContactPoint.email`. | ||
entityType: str | ||
|
||
# A globally unique identifier is added to all `BaseEntity` subclasses and | ||
# should be typed to the correct identifier type. Regardless of the entity-type | ||
# or whether this item was extracted, merged, etc., identifiers will be assigned | ||
# just once and should be declared as `frozen` on subclasses. | ||
identifier: Identifier | ||
|
||
def __str__(self) -> str: | ||
"""Format this instance as a string for logging.""" | ||
return f"{self.entityType}: {self.identifier}" |
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
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,5 +1,5 @@ | ||
from mex.common.models.base import MExModel | ||
from mex.common.models.entity import BaseEntity | ||
|
||
|
||
class MergedItem(MExModel): | ||
class MergedItem(BaseEntity): | ||
"""Base model for all merged item classes.""" |
Oops, something went wrong.