Ejemplo n.º 1
0
 def test_uri(self):
     """ Test the URI data type """
     self.assertEqual("http://foo.org/bargles",
                      URI("http://foo.org/bargles"))
     with self.assertRaises(ValueError):
         URI("rdf:type")
     lax()
     x = URI("rdf:type")
     self.assertFalse(URI.is_valid(x))
Ejemplo n.º 2
0
 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__()
Ejemplo n.º 3
0
    def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
        if self.uri is None:
            raise ValueError("uri must be supplied")
        if not isinstance(self.uri, ConceptReferenceUri):
            self.uri = ConceptReferenceUri(self.uri)

        if self.code is None:
            raise ValueError("code must be supplied")
        if not isinstance(self.code, str):
            self.code = str(self.code)

        if self.defined_in is None:
            raise ValueError("defined_in must be supplied")
        if not isinstance(self.defined_in, ConceptSystemNamespace):
            self.defined_in = ConceptSystemNamespace(self.defined_in)

        if self.designation is not None and not isinstance(self.designation, str):
            self.designation = str(self.designation)

        if self.definition is not None and not isinstance(self.definition, str):
            self.definition = str(self.definition)

        if self.reference is None:
            self.reference = []
        if not isinstance(self.reference, list):
            self.reference = [self.reference]
        self.reference = [v if isinstance(v, URI) else URI(v) for v in self.reference]

        if self.narrower_than is None:
            self.narrower_than = []
        if not isinstance(self.narrower_than, list):
            self.narrower_than = [self.narrower_than]
        self.narrower_than = [v if isinstance(v, ConceptReferenceUri) else ConceptReferenceUri(v) for v in self.narrower_than]

        super().__post_init__(**kwargs)
Ejemplo n.º 4
0
 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
     ]
Ejemplo n.º 5
0
    def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
        if self.namespace is None:
            raise ValueError("namespace must be supplied")
        if not isinstance(self.namespace, ConceptSystemNamespace):
            self.namespace = ConceptSystemNamespace(self.namespace)

        if self.prefix is None:
            raise ValueError("prefix must be supplied")
        if not isinstance(self.prefix, str):
            self.prefix = str(self.prefix)

        if self.description is not None and not isinstance(self.description, str):
            self.description = str(self.description)

        if self.reference is None:
            self.reference = []
        if not isinstance(self.reference, list):
            self.reference = [self.reference]
        self.reference = [v if isinstance(v, URI) else URI(v) for v in self.reference]

        if self.root_concept is None:
            self.root_concept = []
        if not isinstance(self.root_concept, list):
            self.root_concept = [self.root_concept]
        self.root_concept = [v if isinstance(v, ConceptReferenceUri) else ConceptReferenceUri(v) for v in self.root_concept]

        if self.contents is None:
            self.contents = []
        if not isinstance(self.contents, (list)):
            self.contents = [self.contents]
        self._normalize_inlined_slot(slot_name="contents", slot_type=ConceptReference, key_name="uri", inlined_as_list=True, keyed=True)

        super().__post_init__(**kwargs)
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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")
Ejemplo n.º 9
0
 def __post_init__(self, **kwargs: Dict[str, Any]):
     if self.prefix_prefix is None:
         raise ValueError(f"prefix_prefix must be supplied")
     if not isinstance(self.prefix_prefix, PrefixPrefixPrefix):
         self.prefix_prefix = PrefixPrefixPrefix(self.prefix_prefix)
     if self.prefix_reference is None:
         raise ValueError(f"prefix_reference must be supplied")
     if not isinstance(self.prefix_reference, URI):
         self.prefix_reference = URI(self.prefix_reference)
     super().__post_init__(**kwargs)
Ejemplo n.º 10
0
 def _fix_elements(self):
     super()._fix_elements()
     if self.name is not None and not isinstance(self.name,
                                                 SchemaDefinitionName):
         self.name = SchemaDefinitionName(self.name)
     if self.id is not None and not isinstance(self.id, URI):
         self.id = URI(self.id)
     self.imports = [
         v if isinstance(v, URI) else URI(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, DefinitionName):
         self.default_range = DefinitionName(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, XSDDate):
         self.source_file_date = XSDDate(self.source_file_date)
     if self.generation_date is not None and not isinstance(
             self.generation_date, XSDDate):
         self.generation_date = XSDDate(self.generation_date)
Ejemplo n.º 11
0
 def __post_init__(self, **kwargs: Dict[str, Any]):
     if self.id is None:
         raise ValueError(f"id must be supplied")
     if not isinstance(self.id, C1Id):
         self.id = C1Id(self.id)
     if self.hasCurie is not None and not isinstance(self.hasCurie, Curie):
         self.hasCurie = Curie(self.hasCurie)
     if self.hasURI is not None and not isinstance(self.hasURI, URI):
         self.hasURI = URI(self.hasURI)
     if self.hasNcName is not None and not isinstance(
             self.hasNcName, NCName):
         self.hasNcName = NCName(self.hasNcName)
     if self.id2 is not None and not isinstance(self.id2, NodeIdentifier):
         self.id2 = NodeIdentifier(self.id2)
     super().__post_init__(**kwargs)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 def _fix_elements(self):
     super()._fix_elements()
     if not isinstance(self.prefix_prefix, PrefixPrefixPrefix):
         self.prefix_prefix = PrefixPrefixPrefix(self.prefix_prefix)
     if not isinstance(self.prefix_reference, URI):
         self.prefix_reference = URI(self.prefix_reference)