-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from investigativedata/develop
v0.5.1
- Loading branch information
Showing
14 changed files
with
2,845 additions
and
2,554 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
all: clean install test | ||
|
||
install: | ||
poetry install --with dev | ||
|
||
|
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 +1 @@ | ||
0.5.0 | ||
0.5.1 |
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,4 +1,4 @@ | ||
from ftmq.query import Query | ||
|
||
__version__ = "0.5.0" | ||
__version__ = "0.5.1" | ||
__all__ = ["Query"] |
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,4 +1,5 @@ | ||
from .coverage import Coverage | ||
from .dataset import Catalog, Dataset, Maintainer, Publisher, Resource | ||
from ftmq.model.coverage import Coverage | ||
from ftmq.model.dataset import Catalog, Dataset, Maintainer, Publisher, Resource | ||
from ftmq.model.proxy import Entity | ||
|
||
__all__ = [Catalog, Coverage, Dataset, Maintainer, Publisher, Resource] | ||
__all__ = [Catalog, Coverage, Dataset, Entity, Maintainer, Publisher, Resource] |
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,50 @@ | ||
from typing import Any, Iterable, TypeAlias, Union | ||
|
||
from followthemoney.model import registry | ||
from pydantic import BaseModel, ConfigDict, Field, model_validator | ||
|
||
from ftmq.types import CE | ||
from ftmq.util import make_proxy | ||
|
||
Properties: TypeAlias = dict[str, list[Union[str, "Entity"]]] | ||
|
||
|
||
class Entity(BaseModel): | ||
model_config = ConfigDict(populate_by_name=True) | ||
|
||
id: str = Field(..., example="NK-A7z....") | ||
caption: str = Field(..., example="John Doe") | ||
schema_: str = Field(..., example="LegalEntity", alias="schema") | ||
properties: Properties = Field(..., example={"name": ["John Doe"]}) | ||
datasets: list[str] = Field([], example=["us_ofac_sdn"]) | ||
referents: list[str] = Field([], example=["ofac-1234"]) | ||
|
||
@classmethod | ||
def from_proxy(cls, entity: CE, adjacents: Iterable[CE] | None = None) -> "Entity": | ||
properties = dict(entity.properties) | ||
if adjacents: | ||
adjacents = {e.id: Entity.from_proxy(e) for e in adjacents} | ||
for prop in entity.iterprops(): | ||
if prop.type == registry.entity: | ||
properties[prop.name] = [ | ||
adjacents.get(i, i) for i in entity.get(prop) | ||
] | ||
return cls( | ||
id=entity.id, | ||
caption=entity.caption, | ||
schema=entity.schema.name, | ||
properties=properties, | ||
datasets=list(entity.datasets), | ||
referents=list(entity.referents), | ||
) | ||
|
||
def to_proxy(self) -> CE: | ||
return make_proxy(self.model_dump(by_alias=True)) | ||
|
||
@model_validator(mode="before") | ||
@classmethod | ||
def get_caption(cls, data: Any) -> Any: | ||
if data.get("caption") is None: | ||
proxy = make_proxy(data) | ||
data["caption"] = proxy.caption | ||
return data |
Oops, something went wrong.