def __post_init__(self, **kwargs: Dict[str, Any]): if self.name is None: raise ValueError(f"name must be supplied") if not isinstance(self.name, ClassDefinitionName): self.name = ClassDefinitionName(self.name) self.slots = [v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in ([self.slots] if isinstance(self.slots, str) else self.slots)] for k, v in self.slot_usage.items(): if not isinstance(v, SlotDefinition): self.slot_usage[k] = SlotDefinition(name=k, **({} if v is None else v)) for k, v in self.attributes.items(): if not isinstance(v, SlotDefinition): self.attributes[k] = SlotDefinition(name=k, **({} if v is None else v)) if self.class_uri is not None and not isinstance(self.class_uri, URIorCURIE): self.class_uri = URIorCURIE(self.class_uri) if self.subclass_of is not None and not isinstance(self.subclass_of, URIorCURIE): self.subclass_of = URIorCURIE(self.subclass_of) self.union_of = [v if isinstance(v, ClassDefinitionName) else ClassDefinitionName(v) for v in ([self.union_of] if isinstance(self.union_of, str) else self.union_of)] self.defining_slots = [v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in ([self.defining_slots] if isinstance(self.defining_slots, str) else self.defining_slots)] if self.is_a is not None and not isinstance(self.is_a, ClassDefinitionName): self.is_a = ClassDefinitionName(self.is_a) self.mixins = [v if isinstance(v, ClassDefinitionName) else ClassDefinitionName(v) for v in ([self.mixins] if isinstance(self.mixins, str) else self.mixins)] self.apply_to = [v if isinstance(v, ClassDefinitionName) else ClassDefinitionName(v) for v in ([self.apply_to] if isinstance(self.apply_to, str) else self.apply_to)] super().__post_init__(**kwargs)
def __post_init__(self, **kwargs: Dict[str, Any]): if self.name is None: raise ValueError(f"name must be supplied") if not isinstance(self.name, SlotDefinitionName): self.name = SlotDefinitionName(self.name) if self.domain is not None and not isinstance(self.domain, ClassDefinitionName): self.domain = ClassDefinitionName(self.domain) if self.range is not None and not isinstance(self.range, ElementName): self.range = ElementName(self.range) if self.slot_uri is not None and not isinstance(self.slot_uri, URIorCURIE): self.slot_uri = URIorCURIE(self.slot_uri) if self.owner is not None and not isinstance(self.owner, DefinitionName): self.owner = DefinitionName(self.owner) self.domain_of = [v if isinstance(v, ClassDefinitionName) else ClassDefinitionName(v) for v in ([self.domain_of] if isinstance(self.domain_of, str) else self.domain_of)] if self.subproperty_of is not None and not isinstance(self.subproperty_of, URIorCURIE): self.subproperty_of = URIorCURIE(self.subproperty_of) if self.inverse is not None and not isinstance(self.inverse, SlotDefinitionName): self.inverse = SlotDefinitionName(self.inverse) if self.is_a is not None and not isinstance(self.is_a, SlotDefinitionName): self.is_a = SlotDefinitionName(self.is_a) self.mixins = [v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in ([self.mixins] if isinstance(self.mixins, str) else self.mixins)] self.apply_to = [v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in ([self.apply_to] if isinstance(self.apply_to, str) else self.apply_to)] super().__post_init__(**kwargs)
def _fix_elements(self): super()._fix_elements() self.id_prefixes = [ v if isinstance(v, NCName) else NCName(v) for v in self.id_prefixes ] if not isinstance(self.name, ElementName): self.name = ElementName(self.name) for k, v in self.local_names.items(): if not isinstance(v, LocalName): self.local_names[k] = LocalName(k, v) self.mappings = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.mappings ] for k, v in self.alt_descriptions.items(): if not isinstance(v, AltDescription): self.alt_descriptions[k] = AltDescription(k, v) self.examples = [ v if isinstance(v, Example) else Example(**v) for v in self.examples ] self.in_subset = [ v if isinstance(v, SubsetDefinitionName) else SubsetDefinitionName(v) for v in self.in_subset ] if self.from_schema is not None and not isinstance( self.from_schema, URI): self.from_schema = URI(self.from_schema) self.see_also = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.see_also ]
def _fix_elements(self): super()._fix_elements() if self.name is not None and not isinstance(self.name, ClassDefinitionName): self.name = ClassDefinitionName(self.name) if self.is_a is not None and not isinstance(self.is_a, ClassDefinitionName): self.is_a = ClassDefinitionName(self.is_a) self.mixins = [ v if isinstance(v, ClassDefinitionName) else ClassDefinitionName(v) for v in self.mixins ] self.apply_to = [ v if isinstance(v, ClassDefinitionName) else ClassDefinitionName(v) for v in self.apply_to ] self.slots = [ v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in self.slots ] for k, v in self.slot_usage.items(): if not isinstance(v, SlotDefinition): self.slot_usage[k] = SlotDefinition(name=k, **({} if v is None else v)) if self.class_uri is not None and not isinstance( self.class_uri, URIorCURIE): self.class_uri = URIorCURIE(self.class_uri) if self.subclass_of is not None and not isinstance( self.subclass_of, URIorCURIE): self.subclass_of = URIorCURIE(self.subclass_of) self.defining_slots = [ v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in self.defining_slots ]
def __post_init__(self, **kwargs: Dict[str, Any]): self.id_prefixes = [ v if isinstance(v, NCName) else NCName(v) for v in self.id_prefixes ] if self.name is None: raise ValueError(f"name must be supplied") if not isinstance(self.name, ElementName): self.name = ElementName(self.name) if self.definition_uri is not None and not isinstance( self.definition_uri, URIorCURIE): self.definition_uri = URIorCURIE(self.definition_uri) for k, v in self.local_names.items(): if not isinstance(v, LocalName): self.local_names[k] = LocalName(k, v) self.mappings = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.mappings ] for k, v in self.alt_descriptions.items(): if not isinstance(v, AltDescription): self.alt_descriptions[k] = AltDescription(k, v) self.examples = [ v if isinstance(v, Example) else Example(**v) for v in self.examples ] self.in_subset = [ v if isinstance(v, SubsetDefinitionName) else SubsetDefinitionName(v) for v in self.in_subset ] if self.from_schema is not None and not isinstance( self.from_schema, URI): self.from_schema = URI(self.from_schema) self.see_also = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.see_also ] self.exact_mappings = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.exact_mappings ] self.close_mappings = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.close_mappings ] self.related_mappings = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.related_mappings ] if self.deprecated_element_has_exact_replacement is not None and not isinstance( self.deprecated_element_has_exact_replacement, URIorCURIE): self.deprecated_element_has_exact_replacement = URIorCURIE( self.deprecated_element_has_exact_replacement) if self.deprecated_element_has_possible_replacement is not None and not isinstance( self.deprecated_element_has_possible_replacement, URIorCURIE): self.deprecated_element_has_possible_replacement = URIorCURIE( self.deprecated_element_has_possible_replacement) super().__post_init__(**kwargs)
def _fix_elements(self): super()._fix_elements() if self.name is not None and not isinstance(self.name, SlotDefinitionName): self.name = SlotDefinitionName(self.name) if self.is_a is not None and not isinstance(self.is_a, SlotDefinitionName): self.is_a = SlotDefinitionName(self.is_a) self.mixins = [ v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in self.mixins ] self.apply_to = [ v if isinstance(v, SlotDefinitionName) else SlotDefinitionName(v) for v in self.apply_to ] if self.domain is not None and not isinstance(self.domain, ClassDefinitionName): self.domain = ClassDefinitionName(self.domain) if self.range is not None and not isinstance(self.range, ElementName): self.range = ElementName(self.range) if self.slot_uri is not None and not isinstance(self.slot_uri, URI): self.slot_uri = URI(self.slot_uri) if self.subproperty_of is not None and not isinstance( self.subproperty_of, URIorCURIE): self.subproperty_of = URIorCURIE(self.subproperty_of)
def __post_init__(self, **kwargs: Dict[str, Any]): if self.name is None: raise ValueError(f"name must be supplied") if not isinstance(self.name, TypeDefinitionName): self.name = TypeDefinitionName(self.name) if self.typeof is not None and not isinstance(self.typeof, TypeDefinitionName): self.typeof = TypeDefinitionName(self.typeof) if self.uri is not None and not isinstance(self.uri, URIorCURIE): self.uri = URIorCURIE(self.uri) super().__post_init__(**kwargs)
def _fix_elements(self): super()._fix_elements() if self.name is not None and not isinstance(self.name, TypeDefinitionName): self.name = TypeDefinitionName(self.name) if self.typeof is not None and not isinstance(self.typeof, TypeDefinitionName): self.typeof = TypeDefinitionName(self.typeof) if self.uri is not None and not isinstance(self.uri, URIorCURIE): self.uri = URIorCURIE(self.uri)
def __post_init__(self, **kwargs: Dict[str, Any]): if self.is_a is not None and not isinstance(self.is_a, DefinitionName): self.is_a = DefinitionName(self.is_a) self.mixins = [v if isinstance(v, DefinitionName) else DefinitionName(v) for v in ([self.mixins] if isinstance(self.mixins, str) else self.mixins)] self.apply_to = [v if isinstance(v, DefinitionName) else DefinitionName(v) for v in ([self.apply_to] if isinstance(self.apply_to, str) else self.apply_to)] self.values_from = [v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in ([self.values_from] if isinstance(self.values_from, str) else self.values_from)] if self.created_by is not None and not isinstance(self.created_by, URIorCURIE): self.created_by = URIorCURIE(self.created_by) if self.created_on is not None and not isinstance(self.created_on, XSDDateTime): self.created_on = XSDDateTime(self.created_on) if self.last_updated_on is not None and not isinstance(self.last_updated_on, XSDDateTime): self.last_updated_on = XSDDateTime(self.last_updated_on) if self.modified_by is not None and not isinstance(self.modified_by, URIorCURIE): self.modified_by = URIorCURIE(self.modified_by) if self.status is not None and not isinstance(self.status, URIorCURIE): self.status = URIorCURIE(self.status) super().__post_init__(**kwargs)
def __post_init__(self): if self.id is not None and not isinstance(self.id, EntityToEntityCorrelationId): self.id = EntityToEntityCorrelationId(self.id) if self.relation is not None and not isinstance( self.relation, URIorCURIE): self.relation = URIorCURIE(self.relation) if self.population is not None and not isinstance( self.population, URI): self.population = URI(self.population) if self.cohort is not None and not isinstance(self.cohort, URI): self.cohort = URI(self.cohort) super().__post_init__()
def __post_init__(self, **kwargs: Dict[str, Any]): if self.default_prefix is None: self.default_prefix = sfx(str(self.id)) if self.name is None: raise ValueError(f"name must be supplied") if not isinstance(self.name, SchemaDefinitionName): self.name = SchemaDefinitionName(self.name) if self.id is None: raise ValueError(f"id must be supplied") if not isinstance(self.id, URI): self.id = URI(self.id) self.imports = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.imports ] for k, v in self.prefixes.items(): if not isinstance(v, Prefix): self.prefixes[k] = Prefix(k, v) self.emit_prefixes = [ v if isinstance(v, NCName) else NCName(v) for v in self.emit_prefixes ] if self.default_range is not None and not isinstance( self.default_range, TypeDefinitionName): self.default_range = TypeDefinitionName(self.default_range) for k, v in self.subsets.items(): if not isinstance(v, SubsetDefinition): self.subsets[k] = SubsetDefinition(name=k, **({} if v is None else v)) for k, v in self.types.items(): if not isinstance(v, TypeDefinition): self.types[k] = TypeDefinition(name=k, **({} if v is None else v)) for k, v in self.slots.items(): if not isinstance(v, SlotDefinition): self.slots[k] = SlotDefinition(name=k, **({} if v is None else v)) for k, v in self.classes.items(): if not isinstance(v, ClassDefinition): self.classes[k] = ClassDefinition(name=k, **({} if v is None else v)) if self.source_file_date is not None and not isinstance( self.source_file_date, XSDDateTime): self.source_file_date = XSDDateTime(self.source_file_date) if self.generation_date is not None and not isinstance( self.generation_date, XSDDateTime): self.generation_date = XSDDateTime(self.generation_date) super().__post_init__(**kwargs)
def __post_init__(self, **kwargs: Dict[str, Any]): if self.is_a is not None and not isinstance(self.is_a, DefinitionName): self.is_a = DefinitionName(self.is_a) self.mixins = [ v if isinstance(v, DefinitionName) else DefinitionName(v) for v in self.mixins ] self.apply_to = [ v if isinstance(v, DefinitionName) else DefinitionName(v) for v in self.apply_to ] self.values_from = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.values_from ] super().__post_init__(**kwargs)
def _fix_elements(self): super()._fix_elements() if self.is_a is not None and not isinstance(self.is_a, DefinitionName): self.is_a = DefinitionName(self.is_a) self.mixins = [ v if isinstance(v, DefinitionName) else DefinitionName(v) for v in self.mixins ] self.apply_to = [ v if isinstance(v, DefinitionName) else DefinitionName(v) for v in self.apply_to ] self.values_from = [ v if isinstance(v, URIorCURIE) else URIorCURIE(v) for v in self.values_from ]
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): if self.tag is None: raise ValueError("tag must be supplied") if not isinstance(self.tag, URIorCURIE): self.tag = URIorCURIE(self.tag) if self.value is None: raise ValueError("value must be supplied") if not isinstance(self.value, str): self.value = str(self.value) if self.extensions is None: self.extensions = [] if not isinstance(self.extensions, list): self.extensions = [self.extensions] self._normalize_inlined_slot(slot_name="extensions", slot_type=Extension, key_name="tag", inlined_as_list=True, keyed=False) super().__post_init__(**kwargs)
def test_uris(self): """ Test the URI and URIorCURIE types """ str1 = "https://google.com/test#file?abc=1&def=4" self.assertEqual(str1, URIorCURIE(str1)) self.assertEqual(str1, URI(str1)) str2 = "abc:123" self.assertEqual(str2, URIorCURIE(str2)) str3 = ":123" self.assertEqual(str3, URIorCURIE(str3)) with self.assertRaises(ValueError): URI(str2) with self.assertRaises(ValueError): URIorCURIE("1abc:def") with self.assertRaises(ValueError): URIorCURIE("1:def") lax() URI(str2) URIorCURIE("1abc:def") URIorCURIE("1:def")