|
| 1 | +# Auto generated from linkml_issue_576.yaml by pythongen.py version: 0.9.0 |
| 2 | +# Generation date: 2022-11-15T16:23:46 |
| 3 | +# Schema: personinfo |
| 4 | +# |
| 5 | +# id: https://w3id.org/linkml/examples/personinfo |
| 6 | +# description: |
| 7 | +# license: https://creativecommons.org/publicdomain/zero/1.0/ |
| 8 | + |
| 9 | +import dataclasses |
| 10 | +import sys |
| 11 | +import re |
| 12 | +from jsonasobj2 import JsonObj, as_dict |
| 13 | +from typing import Optional, List, Union, Dict, ClassVar, Any |
| 14 | +from dataclasses import dataclass |
| 15 | +from linkml_runtime.linkml_model.meta import EnumDefinition, PermissibleValue, PvFormulaOptions |
| 16 | + |
| 17 | +from linkml_runtime.utils.slot import Slot |
| 18 | +from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode |
| 19 | +from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int |
| 20 | +from linkml_runtime.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs |
| 21 | +from linkml_runtime.utils.formatutils import camelcase, underscore, sfx |
| 22 | +from linkml_runtime.utils.enumerations import EnumDefinitionImpl |
| 23 | +from rdflib import Namespace, URIRef |
| 24 | +from linkml_runtime.utils.curienamespace import CurieNamespace |
| 25 | +from linkml_runtime.linkml_model.types import String, Uriorcurie |
| 26 | +from linkml_runtime.utils.metamodelcore import URIorCURIE |
| 27 | + |
| 28 | +metamodel_version = "1.7.0" |
| 29 | +version = None |
| 30 | + |
| 31 | +# Overwrite dataclasses _init_fn to add **kwargs in __init__ |
| 32 | +dataclasses._init_fn = dataclasses_init_fn_with_kwargs |
| 33 | + |
| 34 | +# Namespaces |
| 35 | +EX = CurieNamespace('ex', 'https://example.org/') |
| 36 | +LINKML = CurieNamespace('linkml', 'https://w3id.org/linkml/') |
| 37 | +PERSONINFO = CurieNamespace('personinfo', 'https://w3id.org/linkml/personinfo/') |
| 38 | +SCHEMA = CurieNamespace('schema', 'http://schema.org/') |
| 39 | +XSD = CurieNamespace('xsd', 'http://www.w3.org/2001/XMLSchema#') |
| 40 | +DEFAULT_ = PERSONINFO |
| 41 | + |
| 42 | + |
| 43 | +# Types |
| 44 | +class Code(String): |
| 45 | + """ An identifier that is encoded in a string. This is used to represent identifiers that are not URIs, but are encoded as strings. For example, a person's social security number is an encoded identifier. """ |
| 46 | + type_class_uri = XSD.string |
| 47 | + type_class_curie = "xsd:string" |
| 48 | + type_name = "Code" |
| 49 | + type_model_uri = PERSONINFO.Code |
| 50 | + |
| 51 | + |
| 52 | +# Class references |
| 53 | +class PersonId(URIorCURIE): |
| 54 | + pass |
| 55 | + |
| 56 | + |
| 57 | +class PetId(extended_str): |
| 58 | + pass |
| 59 | + |
| 60 | + |
| 61 | +class OrganizationId(Code): |
| 62 | + pass |
| 63 | + |
| 64 | + |
| 65 | +@dataclass |
| 66 | +class Person(YAMLRoot): |
| 67 | + _inherited_slots: ClassVar[List[str]] = [] |
| 68 | + |
| 69 | + class_class_uri: ClassVar[URIRef] = SCHEMA.Person |
| 70 | + class_class_curie: ClassVar[str] = "schema:Person" |
| 71 | + class_name: ClassVar[str] = "Person" |
| 72 | + class_model_uri: ClassVar[URIRef] = PERSONINFO.Person |
| 73 | + |
| 74 | + id: Union[str, PersonId] = None |
| 75 | + name: Optional[str] = None |
| 76 | + friends: Optional[Union[Union[str, PersonId], List[Union[str, PersonId]]]] = empty_list() |
| 77 | + |
| 78 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 79 | + if self._is_empty(self.id): |
| 80 | + self.MissingRequiredField("id") |
| 81 | + if not isinstance(self.id, PersonId): |
| 82 | + self.id = PersonId(self.id) |
| 83 | + |
| 84 | + if self.name is not None and not isinstance(self.name, str): |
| 85 | + self.name = str(self.name) |
| 86 | + |
| 87 | + if not isinstance(self.friends, list): |
| 88 | + self.friends = [self.friends] if self.friends is not None else [] |
| 89 | + self.friends = [v if isinstance(v, PersonId) else PersonId(v) for v in self.friends] |
| 90 | + |
| 91 | + super().__post_init__(**kwargs) |
| 92 | + |
| 93 | + |
| 94 | +@dataclass |
| 95 | +class Pet(YAMLRoot): |
| 96 | + _inherited_slots: ClassVar[List[str]] = [] |
| 97 | + |
| 98 | + class_class_uri: ClassVar[URIRef] = PERSONINFO.Pet |
| 99 | + class_class_curie: ClassVar[str] = "personinfo:Pet" |
| 100 | + class_name: ClassVar[str] = "Pet" |
| 101 | + class_model_uri: ClassVar[URIRef] = PERSONINFO.Pet |
| 102 | + |
| 103 | + id: Union[str, PetId] = None |
| 104 | + name: Optional[str] = None |
| 105 | + owner: Optional[Union[str, PersonId]] = None |
| 106 | + |
| 107 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 108 | + if self._is_empty(self.id): |
| 109 | + self.MissingRequiredField("id") |
| 110 | + if not isinstance(self.id, PetId): |
| 111 | + self.id = PetId(self.id) |
| 112 | + |
| 113 | + if self.name is not None and not isinstance(self.name, str): |
| 114 | + self.name = str(self.name) |
| 115 | + |
| 116 | + if self.owner is not None and not isinstance(self.owner, PersonId): |
| 117 | + self.owner = PersonId(self.owner) |
| 118 | + |
| 119 | + super().__post_init__(**kwargs) |
| 120 | + |
| 121 | + |
| 122 | +@dataclass |
| 123 | +class Organization(YAMLRoot): |
| 124 | + _inherited_slots: ClassVar[List[str]] = [] |
| 125 | + |
| 126 | + class_class_uri: ClassVar[URIRef] = SCHEMA.Organization |
| 127 | + class_class_curie: ClassVar[str] = "schema:Organization" |
| 128 | + class_name: ClassVar[str] = "Organization" |
| 129 | + class_model_uri: ClassVar[URIRef] = PERSONINFO.Organization |
| 130 | + |
| 131 | + id: Union[str, OrganizationId] = None |
| 132 | + name: Optional[str] = None |
| 133 | + part_of: Optional[Union[Union[str, OrganizationId], List[Union[str, OrganizationId]]]] = empty_list() |
| 134 | + |
| 135 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 136 | + if self._is_empty(self.id): |
| 137 | + self.MissingRequiredField("id") |
| 138 | + if not isinstance(self.id, OrganizationId): |
| 139 | + self.id = OrganizationId(self.id) |
| 140 | + |
| 141 | + if self.name is not None and not isinstance(self.name, str): |
| 142 | + self.name = str(self.name) |
| 143 | + |
| 144 | + if not isinstance(self.part_of, list): |
| 145 | + self.part_of = [self.part_of] if self.part_of is not None else [] |
| 146 | + self.part_of = [v if isinstance(v, OrganizationId) else OrganizationId(v) for v in self.part_of] |
| 147 | + |
| 148 | + super().__post_init__(**kwargs) |
| 149 | + |
| 150 | + |
| 151 | +@dataclass |
| 152 | +class Dataset(YAMLRoot): |
| 153 | + _inherited_slots: ClassVar[List[str]] = [] |
| 154 | + |
| 155 | + class_class_uri: ClassVar[URIRef] = PERSONINFO.Dataset |
| 156 | + class_class_curie: ClassVar[str] = "personinfo:Dataset" |
| 157 | + class_name: ClassVar[str] = "Dataset" |
| 158 | + class_model_uri: ClassVar[URIRef] = PERSONINFO.Dataset |
| 159 | + |
| 160 | + persons: Optional[Union[Dict[Union[str, PersonId], Union[dict, Person]], List[Union[dict, Person]]]] = empty_dict() |
| 161 | + organizations: Optional[Union[Dict[Union[str, OrganizationId], Union[dict, Organization]], List[Union[dict, Organization]]]] = empty_dict() |
| 162 | + pets: Optional[Union[Dict[Union[str, PetId], Union[dict, Pet]], List[Union[dict, Pet]]]] = empty_dict() |
| 163 | + |
| 164 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 165 | + self._normalize_inlined_as_dict(slot_name="persons", slot_type=Person, key_name="id", keyed=True) |
| 166 | + |
| 167 | + self._normalize_inlined_as_dict(slot_name="organizations", slot_type=Organization, key_name="id", keyed=True) |
| 168 | + |
| 169 | + self._normalize_inlined_as_dict(slot_name="pets", slot_type=Pet, key_name="id", keyed=True) |
| 170 | + |
| 171 | + super().__post_init__(**kwargs) |
| 172 | + |
| 173 | + |
| 174 | +# Enumerations |
| 175 | + |
| 176 | + |
| 177 | +# Slots |
| 178 | +class slots: |
| 179 | + pass |
| 180 | + |
| 181 | +slots.person__id = Slot(uri=PERSONINFO.id, name="person__id", curie=PERSONINFO.curie('id'), |
| 182 | + model_uri=PERSONINFO.person__id, domain=None, range=URIRef) |
| 183 | + |
| 184 | +slots.person__name = Slot(uri=SCHEMA.name, name="person__name", curie=SCHEMA.curie('name'), |
| 185 | + model_uri=PERSONINFO.person__name, domain=None, range=Optional[str]) |
| 186 | + |
| 187 | +slots.person__friends = Slot(uri=PERSONINFO.friends, name="person__friends", curie=PERSONINFO.curie('friends'), |
| 188 | + model_uri=PERSONINFO.person__friends, domain=None, range=Optional[Union[Union[str, PersonId], List[Union[str, PersonId]]]]) |
| 189 | + |
| 190 | +slots.pet__id = Slot(uri=PERSONINFO.id, name="pet__id", curie=PERSONINFO.curie('id'), |
| 191 | + model_uri=PERSONINFO.pet__id, domain=None, range=URIRef) |
| 192 | + |
| 193 | +slots.pet__name = Slot(uri=SCHEMA.name, name="pet__name", curie=SCHEMA.curie('name'), |
| 194 | + model_uri=PERSONINFO.pet__name, domain=None, range=Optional[str]) |
| 195 | + |
| 196 | +slots.pet__owner = Slot(uri=SCHEMA.owner, name="pet__owner", curie=SCHEMA.curie('owner'), |
| 197 | + model_uri=PERSONINFO.pet__owner, domain=None, range=Optional[Union[str, PersonId]]) |
| 198 | + |
| 199 | +slots.organization__id = Slot(uri=PERSONINFO.id, name="organization__id", curie=PERSONINFO.curie('id'), |
| 200 | + model_uri=PERSONINFO.organization__id, domain=None, range=URIRef) |
| 201 | + |
| 202 | +slots.organization__name = Slot(uri=SCHEMA.name, name="organization__name", curie=SCHEMA.curie('name'), |
| 203 | + model_uri=PERSONINFO.organization__name, domain=None, range=Optional[str]) |
| 204 | + |
| 205 | +slots.organization__part_of = Slot(uri=PERSONINFO.part_of, name="organization__part_of", curie=PERSONINFO.curie('part_of'), |
| 206 | + model_uri=PERSONINFO.organization__part_of, domain=None, range=Optional[Union[Union[str, OrganizationId], List[Union[str, OrganizationId]]]]) |
| 207 | + |
| 208 | +slots.dataset__persons = Slot(uri=PERSONINFO.persons, name="dataset__persons", curie=PERSONINFO.curie('persons'), |
| 209 | + model_uri=PERSONINFO.dataset__persons, domain=None, range=Optional[Union[Dict[Union[str, PersonId], Union[dict, Person]], List[Union[dict, Person]]]]) |
| 210 | + |
| 211 | +slots.dataset__organizations = Slot(uri=PERSONINFO.organizations, name="dataset__organizations", curie=PERSONINFO.curie('organizations'), |
| 212 | + model_uri=PERSONINFO.dataset__organizations, domain=None, range=Optional[Union[Dict[Union[str, OrganizationId], Union[dict, Organization]], List[Union[dict, Organization]]]]) |
| 213 | + |
| 214 | +slots.dataset__pets = Slot(uri=PERSONINFO.pets, name="dataset__pets", curie=PERSONINFO.curie('pets'), |
| 215 | + model_uri=PERSONINFO.dataset__pets, domain=None, range=Optional[Union[Dict[Union[str, PetId], Union[dict, Pet]], List[Union[dict, Pet]]]]) |
0 commit comments