diff --git a/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/_version.py b/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/_version.py index f28d1ae..7edc9ee 100644 --- a/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/_version.py +++ b/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/_version.py @@ -4,4 +4,4 @@ __version__ = version(__name__) except PackageNotFoundError: # package not installed - __version__ = "0.0.0" \ No newline at end of file + __version__ = "0.0.0" diff --git a/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/datamodel/{{cookiecutter.__project_slug}}.py b/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/datamodel/{{cookiecutter.__project_slug}}.py index f212dd3..c7bcaa8 100644 --- a/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/datamodel/{{cookiecutter.__project_slug}}.py +++ b/{{cookiecutter.project_name}}/src/{{cookiecutter.__project_slug}}/datamodel/{{cookiecutter.__project_slug}}.py @@ -65,13 +65,30 @@ class Registry(YAMLRoot): class_name: ClassVar[str] = "Registry" class_model_uri: ClassVar[URIRef] = MY_DATAMODEL.Registry - persons: Optional[Union[Dict[Union[str, PersonId], Union[dict, "Person"]], List[Union[dict, "Person"]]]] = empty_dict() - organizations: Optional[Union[Dict[Union[str, OrganizationId], Union[dict, "Organization"]], List[Union[dict, "Organization"]]]] = empty_dict() + persons: Optional[Union[ + Dict[Union[str, PersonId], Union[dict, "Person"]], + List[Union[dict, "Person"]] + ]] = empty_dict() - def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): - self._normalize_inlined_as_list(slot_name="persons", slot_type=Person, key_name="id", keyed=True) + organizations: Optional[Union[ + Dict[Union[str, OrganizationId], Union[dict, "Organization"]], + List[Union[dict, "Organization"]] + ]] = empty_dict() - self._normalize_inlined_as_list(slot_name="organizations", slot_type=Organization, key_name="id", keyed=True) + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): + self._normalize_inlined_as_list( + slot_name="persons", + slot_type=Person, + key_name="id", + keyed=True + ) + + self._normalize_inlined_as_list( + slot_name="organizations", + slot_type=Organization, + key_name="id", + keyed=True + ) super().__post_init__(**kwargs) @@ -102,7 +119,8 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self.name is not None and not isinstance(self.name, str): self.name = str(self.name) - if self.description is not None and not isinstance(self.description, str): + if self.description is not None \ + and not isinstance(self.description, str): self.description = str(self.description) if self.image is not None and not isinstance(self.image, str): @@ -128,7 +146,10 @@ class Person(NamedThing): birth_date: Optional[str] = None age_in_years: Optional[int] = None current_address: Optional[Union[dict, "Address"]] = None - has_familial_relationships: Optional[Union[Union[dict, "FamilialRelationship"], List[Union[dict, "FamilialRelationship"]]]] = empty_list() + has_familial_relationships: Optional[Union[ + Union[dict, "FamilialRelationship"], + List[Union[dict, "FamilialRelationship"]] + ]] = empty_list() aliases: Optional[Union[str, List[str]]] = empty_list() def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): @@ -137,25 +158,35 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if not isinstance(self.id, PersonId): self.id = PersonId(self.id) - if self.primary_email is not None and not isinstance(self.primary_email, str): + if self.primary_email is not None \ + and not isinstance(self.primary_email, str): self.primary_email = str(self.primary_email) - if self.birth_date is not None and not isinstance(self.birth_date, str): + if self.birth_date is not None \ + and not isinstance(self.birth_date, str): self.birth_date = str(self.birth_date) - if self.age_in_years is not None and not isinstance(self.age_in_years, int): + if self.age_in_years is not None \ + and not isinstance(self.age_in_years, int): self.age_in_years = int(self.age_in_years) - if self.current_address is not None and not isinstance(self.current_address, Address): + if self.current_address is not None \ + and not isinstance(self.current_address, Address): self.current_address = Address(**as_dict(self.current_address)) if not isinstance(self.has_familial_relationships, list): - self.has_familial_relationships = [self.has_familial_relationships] if self.has_familial_relationships is not None else [] - self.has_familial_relationships = [v if isinstance(v, FamilialRelationship) else FamilialRelationship(**as_dict(v)) for v in self.has_familial_relationships] + self.has_familial_relationships = [self.has_familial_relationships] \ + if self.has_familial_relationships is not None \ + else [] + self.has_familial_relationships = [ + v if isinstance(v, FamilialRelationship) \ + else FamilialRelationship(**as_dict(v)) \ + for v in self.has_familial_relationships] if not isinstance(self.aliases, list): self.aliases = [self.aliases] if self.aliases is not None else [] - self.aliases = [v if isinstance(v, str) else str(v) for v in self.aliases] + self.aliases = [v if isinstance(v, str) else str(v) \ + for v in self.aliases] super().__post_init__(**kwargs) @@ -177,7 +208,8 @@ class HasAliases(YAMLRoot): def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if not isinstance(self.aliases, list): self.aliases = [self.aliases] if self.aliases is not None else [] - self.aliases = [v if isinstance(v, str) else str(v) for v in self.aliases] + self.aliases = [v if isinstance(v, str) else str(v) \ + for v in self.aliases] super().__post_init__(**kwargs) @@ -205,15 +237,18 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if not isinstance(self.id, OrganizationId): self.id = OrganizationId(self.id) - if self.mission_statement is not None and not isinstance(self.mission_statement, str): + if self.mission_statement is not None \ + and not isinstance(self.mission_statement, str): self.mission_statement = str(self.mission_statement) - if self.founding_date is not None and not isinstance(self.founding_date, str): + if self.founding_date is not None \ + and not isinstance(self.founding_date, str): self.founding_date = str(self.founding_date) if not isinstance(self.aliases, list): self.aliases = [self.aliases] if self.aliases is not None else [] - self.aliases = [v if isinstance(v, str) else str(v) for v in self.aliases] + self.aliases = [v if isinstance(v, str) else str(v) \ + for v in self.aliases] super().__post_init__(**kwargs) @@ -238,7 +273,8 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self.city is not None and not isinstance(self.city, str): self.city = str(self.city) - if self.postal_code is not None and not isinstance(self.postal_code, str): + if self.postal_code is not None \ + and not isinstance(self.postal_code, str): self.postal_code = str(self.postal_code) super().__post_init__(**kwargs) @@ -259,13 +295,16 @@ class Relationship(YAMLRoot): type: Optional[str] = None def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): - if self.started_at_time is not None and not isinstance(self.started_at_time, XSDDate): + if self.started_at_time is not None \ + and not isinstance(self.started_at_time, XSDDate): self.started_at_time = XSDDate(self.started_at_time) - if self.ended_at_time is not None and not isinstance(self.ended_at_time, XSDDate): + if self.ended_at_time is not None \ + and not isinstance(self.ended_at_time, XSDDate): self.ended_at_time = XSDDate(self.ended_at_time) - if self.related_to is not None and not isinstance(self.related_to, str): + if self.related_to is not None \ + and not isinstance(self.related_to, str): self.related_to = str(self.related_to) if self.type is not None and not isinstance(self.type, str): @@ -304,13 +343,13 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): class PersonStatus(EnumDefinitionImpl): ALIVE = PermissibleValue(text="ALIVE", - description="the person is living", - meaning=PATO["0001421"]) + description="the person is living", + meaning=PATO["0001421"]) DEAD = PermissibleValue(text="DEAD", - description="the person is deceased", - meaning=PATO["0001422"]) + description="the person is deceased", + meaning=PATO["0001422"]) UNKNOWN = PermissibleValue(text="UNKNOWN", - description="the vital status is not known") + description="the vital status is not known") _defn = EnumDefinition( name="PersonStatus", @@ -319,11 +358,11 @@ class PersonStatus(EnumDefinitionImpl): class FamilialRelationshipType(EnumDefinitionImpl): SIBLING_OF = PermissibleValue(text="SIBLING_OF", - meaning=FAMREL["01"]) + meaning=FAMREL["01"]) PARENT_OF = PermissibleValue(text="PARENT_OF", - meaning=FAMREL["02"]) + meaning=FAMREL["02"]) CHILD_OF = PermissibleValue(text="CHILD_OF", - meaning=FAMREL["01"]) + meaning=FAMREL["01"]) _defn = EnumDefinition( name="FamilialRelationshipType", @@ -333,84 +372,250 @@ class FamilialRelationshipType(EnumDefinitionImpl): class slots: pass -slots.id = Slot(uri=SCHEMA.identifier, name="id", curie=SCHEMA.curie('identifier'), - model_uri=MY_DATAMODEL.id, domain=None, range=URIRef) - -slots.name = Slot(uri=SCHEMA.name, name="name", curie=SCHEMA.curie('name'), - model_uri=MY_DATAMODEL.name, domain=None, range=Optional[str]) - -slots.description = Slot(uri=SCHEMA.description, name="description", curie=SCHEMA.curie('description'), - model_uri=MY_DATAMODEL.description, domain=None, range=Optional[str]) - -slots.image = Slot(uri=SCHEMA.image, name="image", curie=SCHEMA.curie('image'), - model_uri=MY_DATAMODEL.image, domain=None, range=Optional[str]) - -slots.primary_email = Slot(uri=SCHEMA.email, name="primary_email", curie=SCHEMA.curie('email'), - model_uri=MY_DATAMODEL.primary_email, domain=None, range=Optional[str]) - -slots.birth_date = Slot(uri=SCHEMA.birthDate, name="birth_date", curie=SCHEMA.curie('birthDate'), - model_uri=MY_DATAMODEL.birth_date, domain=None, range=Optional[str]) - -slots.employed_at = Slot(uri=MY_DATAMODEL.employed_at, name="employed_at", curie=MY_DATAMODEL.curie('employed_at'), - model_uri=MY_DATAMODEL.employed_at, domain=None, range=Optional[Union[str, OrganizationId]]) - -slots.is_current = Slot(uri=MY_DATAMODEL.is_current, name="is_current", curie=MY_DATAMODEL.curie('is_current'), - model_uri=MY_DATAMODEL.is_current, domain=None, range=Optional[Union[bool, Bool]]) - -slots.has_familial_relationships = Slot(uri=MY_DATAMODEL.has_familial_relationships, name="has_familial_relationships", curie=MY_DATAMODEL.curie('has_familial_relationships'), - model_uri=MY_DATAMODEL.has_familial_relationships, domain=None, range=Optional[Union[Union[dict, FamilialRelationship], List[Union[dict, FamilialRelationship]]]]) - -slots.current_address = Slot(uri=MY_DATAMODEL.current_address, name="current_address", curie=MY_DATAMODEL.curie('current_address'), - model_uri=MY_DATAMODEL.current_address, domain=None, range=Optional[Union[dict, Address]]) - -slots.age_in_years = Slot(uri=MY_DATAMODEL.age_in_years, name="age_in_years", curie=MY_DATAMODEL.curie('age_in_years'), - model_uri=MY_DATAMODEL.age_in_years, domain=None, range=Optional[int]) - -slots.related_to = Slot(uri=MY_DATAMODEL.related_to, name="related_to", curie=MY_DATAMODEL.curie('related_to'), - model_uri=MY_DATAMODEL.related_to, domain=None, range=Optional[str]) - -slots.type = Slot(uri=MY_DATAMODEL.type, name="type", curie=MY_DATAMODEL.curie('type'), - model_uri=MY_DATAMODEL.type, domain=None, range=Optional[str]) - -slots.street = Slot(uri=MY_DATAMODEL.street, name="street", curie=MY_DATAMODEL.curie('street'), - model_uri=MY_DATAMODEL.street, domain=None, range=Optional[str]) - -slots.city = Slot(uri=MY_DATAMODEL.city, name="city", curie=MY_DATAMODEL.curie('city'), - model_uri=MY_DATAMODEL.city, domain=None, range=Optional[str]) - -slots.mission_statement = Slot(uri=MY_DATAMODEL.mission_statement, name="mission_statement", curie=MY_DATAMODEL.curie('mission_statement'), - model_uri=MY_DATAMODEL.mission_statement, domain=None, range=Optional[str]) - -slots.founding_date = Slot(uri=MY_DATAMODEL.founding_date, name="founding_date", curie=MY_DATAMODEL.curie('founding_date'), - model_uri=MY_DATAMODEL.founding_date, domain=None, range=Optional[str]) - -slots.postal_code = Slot(uri=MY_DATAMODEL.postal_code, name="postal_code", curie=MY_DATAMODEL.curie('postal_code'), - model_uri=MY_DATAMODEL.postal_code, domain=None, range=Optional[str]) - -slots.started_at_time = Slot(uri=PROV.startedAtTime, name="started_at_time", curie=PROV.curie('startedAtTime'), - model_uri=MY_DATAMODEL.started_at_time, domain=None, range=Optional[Union[str, XSDDate]]) - -slots.ended_at_time = Slot(uri=PROV.endedAtTime, name="ended_at_time", curie=PROV.curie('endedAtTime'), - model_uri=MY_DATAMODEL.ended_at_time, domain=None, range=Optional[Union[str, XSDDate]]) - -slots.registry__persons = Slot(uri=MY_DATAMODEL.persons, name="registry__persons", curie=MY_DATAMODEL.curie('persons'), - model_uri=MY_DATAMODEL.registry__persons, domain=None, range=Optional[Union[Dict[Union[str, PersonId], Union[dict, Person]], List[Union[dict, Person]]]]) - -slots.registry__organizations = Slot(uri=MY_DATAMODEL.organizations, name="registry__organizations", curie=MY_DATAMODEL.curie('organizations'), - model_uri=MY_DATAMODEL.registry__organizations, domain=None, range=Optional[Union[Dict[Union[str, OrganizationId], Union[dict, Organization]], List[Union[dict, Organization]]]]) - -slots.hasAliases__aliases = Slot(uri=MY_DATAMODEL.aliases, name="hasAliases__aliases", curie=MY_DATAMODEL.curie('aliases'), - model_uri=MY_DATAMODEL.hasAliases__aliases, domain=None, range=Optional[Union[str, List[str]]]) - -slots.related_to = Slot(uri=MY_DATAMODEL.related_to, name="related to", curie=MY_DATAMODEL.curie('related_to'), - model_uri=MY_DATAMODEL.related_to, domain=None, range=Union[str, PersonId]) - -slots.Person_primary_email = Slot(uri=SCHEMA.email, name="Person_primary_email", curie=SCHEMA.curie('email'), - model_uri=MY_DATAMODEL.Person_primary_email, domain=Person, range=Optional[str], - pattern=re.compile(r'^\S+@[\S+\.]+\S+')) - -slots.FamilialRelationship_type = Slot(uri=MY_DATAMODEL.type, name="FamilialRelationship_type", curie=MY_DATAMODEL.curie('type'), - model_uri=MY_DATAMODEL.FamilialRelationship_type, domain=FamilialRelationship, range=Union[str, "FamilialRelationshipType"]) - -slots.FamilialRelationship_related_to = Slot(uri=MY_DATAMODEL.related_to, name="FamilialRelationship_related to", curie=MY_DATAMODEL.curie('related_to'), - model_uri=MY_DATAMODEL.FamilialRelationship_related_to, domain=FamilialRelationship, range=Union[str, PersonId]) +slots.id = Slot( + uri=SCHEMA.identifier, + name="id", + curie=SCHEMA.curie('identifier'), + model_uri=MY_DATAMODEL.id, + domain=None, + range=URIRef +) + +slots.name = Slot( + uri=SCHEMA.name, + name="name", + curie=SCHEMA.curie('name'), + model_uri=MY_DATAMODEL.name, + domain=None, + range=Optional[str] +) + +slots.description = Slot( + uri=SCHEMA.description, + name="description", + curie=SCHEMA.curie('description'), + model_uri=MY_DATAMODEL.description, + domain=None, + range=Optional[str] +) + +slots.image = Slot( + uri=SCHEMA.image, + name="image", + curie=SCHEMA.curie('image'), + model_uri=MY_DATAMODEL.image, + domain=None, + range=Optional[str] +) + +slots.primary_email = Slot( + uri=SCHEMA.email, + name="primary_email", + curie=SCHEMA.curie('email'), + model_uri=MY_DATAMODEL.primary_email, + domain=None, + range=Optional[str] +) + +slots.birth_date = Slot( + uri=SCHEMA.birthDate, + name="birth_date", + curie=SCHEMA.curie('birthDate'), + model_uri=MY_DATAMODEL.birth_date, + domain=None, + range=Optional[str] +) + +slots.employed_at = Slot( + uri=MY_DATAMODEL.employed_at, + name="employed_at", + curie=MY_DATAMODEL.curie('employed_at'), + model_uri=MY_DATAMODEL.employed_at, + domain=None, + range=Optional[Union[str, OrganizationId]] +) + +slots.is_current = Slot( + uri=MY_DATAMODEL.is_current, + name="is_current", + curie=MY_DATAMODEL.curie('is_current'), + model_uri=MY_DATAMODEL.is_current, + domain=None, + range=Optional[Union[bool, Bool]] +) + +slots.has_familial_relationships = Slot( + uri=MY_DATAMODEL.has_familial_relationships, + name="has_familial_relationships", + curie=MY_DATAMODEL.curie('has_familial_relationships'), + model_uri=MY_DATAMODEL.has_familial_relationships, + domain=None, + range=Optional[Union[ + Union[dict, FamilialRelationship], + List[Union[dict, FamilialRelationship]] + ]] +) + +slots.current_address = Slot( + uri=MY_DATAMODEL.current_address, name="current_address", + curie=MY_DATAMODEL.curie('current_address'), + model_uri=MY_DATAMODEL.current_address, domain=None, + range=Optional[Union[dict, Address]] +) + +slots.age_in_years = Slot( + uri=MY_DATAMODEL.age_in_years, name="age_in_years", + curie=MY_DATAMODEL.curie('age_in_years'), + model_uri=MY_DATAMODEL.age_in_years, domain=None, range=Optional[int] +) + +slots.related_to = Slot( + uri=MY_DATAMODEL.related_to, + name="related_to", + curie=MY_DATAMODEL.curie('related_to'), + model_uri=MY_DATAMODEL.related_to, + domain=None, + range=Optional[str] +) + +slots.type = Slot( + uri=MY_DATAMODEL.type, + name="type", + curie=MY_DATAMODEL.curie('type'), + model_uri=MY_DATAMODEL.type, + domain=None, + range=Optional[str] +) + +slots.street = Slot( + uri=MY_DATAMODEL.street, + name="street", + curie=MY_DATAMODEL.curie('street'), + model_uri=MY_DATAMODEL.street, + domain=None, + range=Optional[str] +) + +slots.city = Slot( + uri=MY_DATAMODEL.city, + name="city", + curie=MY_DATAMODEL.curie('city'), + model_uri=MY_DATAMODEL.city, + domain=None, + range=Optional[str] +) + +slots.mission_statement = Slot( + uri=MY_DATAMODEL.mission_statement, + name="mission_statement", + curie=MY_DATAMODEL.curie('mission_statement'), + model_uri=MY_DATAMODEL.mission_statement, + domain=None, + range=Optional[str] +) + +slots.founding_date = Slot( + uri=MY_DATAMODEL.founding_date, + name="founding_date", + curie=MY_DATAMODEL.curie('founding_date'), + model_uri=MY_DATAMODEL.founding_date, + domain=None, + range=Optional[str] +) + +slots.postal_code = Slot( + uri=MY_DATAMODEL.postal_code, + name="postal_code", + curie=MY_DATAMODEL.curie('postal_code'), + model_uri=MY_DATAMODEL.postal_code, + domain=None, + range=Optional[str] +) + +slots.started_at_time = Slot( + uri=PROV.startedAtTime, + name="started_at_time", + curie=PROV.curie('startedAtTime'), + model_uri=MY_DATAMODEL.started_at_time, + domain=None, + range=Optional[Union[str, XSDDate]] +) + +slots.ended_at_time = Slot( + uri=PROV.endedAtTime, + name="ended_at_time", + curie=PROV.curie('endedAtTime'), + model_uri=MY_DATAMODEL.ended_at_time, + domain=None, + range=Optional[Union[str, XSDDate]] +) + +slots.registry__persons = Slot( + uri=MY_DATAMODEL.persons, + name="registry__persons", + curie=MY_DATAMODEL.curie('persons'), + model_uri=MY_DATAMODEL.registry__persons, + domain=None, + range=Optional[Union[ + Dict[Union[str, PersonId], Union[dict, Person]], + List[Union[dict, Person]] + ]] +) + +slots.registry__organizations = Slot( + uri=MY_DATAMODEL.organizations, + name="registry__organizations", + curie=MY_DATAMODEL.curie('organizations'), + model_uri=MY_DATAMODEL.registry__organizations, + domain=None, + range=Optional[Union[ + Dict[Union[str, OrganizationId], Union[dict, Organization]], + List[Union[dict, Organization]] + ]] +) + +slots.hasAliases__aliases = Slot( + uri=MY_DATAMODEL.aliases, + name="hasAliases__aliases", + curie=MY_DATAMODEL.curie('aliases'), + model_uri=MY_DATAMODEL.hasAliases__aliases, + domain=None, + range=Optional[Union[str, List[str]]] +) + +slots.related_to = Slot( + uri=MY_DATAMODEL.related_to, + name="related to", + curie=MY_DATAMODEL.curie('related_to'), + model_uri=MY_DATAMODEL.related_to, + domain=None, + range=Union[str, PersonId] +) + +slots.Person_primary_email = Slot( + uri=SCHEMA.email, + name="Person_primary_email", + curie=SCHEMA.curie('email'), + model_uri=MY_DATAMODEL.Person_primary_email, + domain=Person, + range=Optional[str], + pattern=re.compile(r'^\S+@[\S+\.]+\S+') +) + +slots.FamilialRelationship_type = Slot( + uri=MY_DATAMODEL.type, + name="FamilialRelationship_type", + curie=MY_DATAMODEL.curie('type'), + model_uri=MY_DATAMODEL.FamilialRelationship_type, + domain=FamilialRelationship, + range=Union[str, "FamilialRelationshipType"] +) + +slots.FamilialRelationship_related_to = Slot( + uri=MY_DATAMODEL.related_to, + name="FamilialRelationship_related to", + curie=MY_DATAMODEL.curie('related_to'), + model_uri=MY_DATAMODEL.FamilialRelationship_related_to, + domain=FamilialRelationship, + range=Union[str, PersonId] +) diff --git a/{{cookiecutter.project_name}}/tests/test_data.py b/{{cookiecutter.project_name}}/tests/test_data.py index 32b348d..3cf037e 100644 --- a/{{cookiecutter.project_name}}/tests/test_data.py +++ b/{{cookiecutter.project_name}}/tests/test_data.py @@ -11,6 +11,7 @@ EXAMPLE_FILES = glob.glob(os.path.join(DATA_DIR, '*.yaml')) + class TestData(unittest.TestCase): """Test data and datamodel."""