|
| 1 | +# Auto generated from table.yaml by pythongen.py version: 0.9.0 |
| 2 | +# Generation date: 2022-09-29T09:11:32 |
| 3 | +# Schema: table |
| 4 | +# |
| 5 | +# id: https://w3id.org/linkml/examples/table |
| 6 | +# description: Represent a table in linkml |
| 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 | +LINKML = CurieNamespace('linkml', 'https://w3id.org/linkml/') |
| 36 | +TABLE = CurieNamespace('table', 'https://w3id.org/linkml/examples/table/') |
| 37 | +DEFAULT_ = TABLE |
| 38 | + |
| 39 | + |
| 40 | +# Types |
| 41 | + |
| 42 | +# Class references |
| 43 | +class RowColumnA(URIorCURIE): |
| 44 | + pass |
| 45 | + |
| 46 | + |
| 47 | +@dataclass |
| 48 | +class Object(YAMLRoot): |
| 49 | + """ |
| 50 | + An object (bnode) which needs embedding in a single row |
| 51 | + """ |
| 52 | + _inherited_slots: ClassVar[List[str]] = [] |
| 53 | + |
| 54 | + class_class_uri: ClassVar[URIRef] = TABLE.Object |
| 55 | + class_class_curie: ClassVar[str] = "table:Object" |
| 56 | + class_name: ClassVar[str] = "Object" |
| 57 | + class_model_uri: ClassVar[URIRef] = TABLE.Object |
| 58 | + |
| 59 | + name: Optional[str] = None |
| 60 | + value: Optional[str] = None |
| 61 | + |
| 62 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 63 | + if self.name is not None and not isinstance(self.name, str): |
| 64 | + self.name = str(self.name) |
| 65 | + |
| 66 | + if self.value is not None and not isinstance(self.value, str): |
| 67 | + self.value = str(self.value) |
| 68 | + |
| 69 | + super().__post_init__(**kwargs) |
| 70 | + |
| 71 | + |
| 72 | +@dataclass |
| 73 | +class Row(YAMLRoot): |
| 74 | + """ |
| 75 | + A single data point made up of columns. |
| 76 | + """ |
| 77 | + _inherited_slots: ClassVar[List[str]] = [] |
| 78 | + |
| 79 | + class_class_uri: ClassVar[URIRef] = TABLE.Row |
| 80 | + class_class_curie: ClassVar[str] = "table:Row" |
| 81 | + class_name: ClassVar[str] = "Row" |
| 82 | + class_model_uri: ClassVar[URIRef] = TABLE.Row |
| 83 | + |
| 84 | + columnA: Union[str, RowColumnA] = None |
| 85 | + objectB: Optional[Union[dict, Object]] = None |
| 86 | + columnC: Optional[str] = None |
| 87 | + |
| 88 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 89 | + if self._is_empty(self.columnA): |
| 90 | + self.MissingRequiredField("columnA") |
| 91 | + if not isinstance(self.columnA, RowColumnA): |
| 92 | + self.columnA = RowColumnA(self.columnA) |
| 93 | + |
| 94 | + if self.objectB is not None and not isinstance(self.objectB, Object): |
| 95 | + self.objectB = Object(**as_dict(self.objectB)) |
| 96 | + |
| 97 | + if self.columnC is not None and not isinstance(self.columnC, str): |
| 98 | + self.columnC = str(self.columnC) |
| 99 | + |
| 100 | + super().__post_init__(**kwargs) |
| 101 | + |
| 102 | + |
| 103 | +@dataclass |
| 104 | +class Table(YAMLRoot): |
| 105 | + """ |
| 106 | + Container of rows. |
| 107 | + """ |
| 108 | + _inherited_slots: ClassVar[List[str]] = [] |
| 109 | + |
| 110 | + class_class_uri: ClassVar[URIRef] = TABLE.Table |
| 111 | + class_class_curie: ClassVar[str] = "table:Table" |
| 112 | + class_name: ClassVar[str] = "Table" |
| 113 | + class_model_uri: ClassVar[URIRef] = TABLE.Table |
| 114 | + |
| 115 | + rows: Optional[Union[Dict[Union[str, RowColumnA], Union[dict, Row]], List[Union[dict, Row]]]] = empty_dict() |
| 116 | + |
| 117 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 118 | + self._normalize_inlined_as_list(slot_name="rows", slot_type=Row, key_name="columnA", keyed=True) |
| 119 | + |
| 120 | + super().__post_init__(**kwargs) |
| 121 | + |
| 122 | + |
| 123 | +# Enumerations |
| 124 | + |
| 125 | + |
| 126 | +# Slots |
| 127 | +class slots: |
| 128 | + pass |
| 129 | + |
| 130 | +slots.object__name = Slot(uri=TABLE.name, name="object__name", curie=TABLE.curie('name'), |
| 131 | + model_uri=TABLE.object__name, domain=None, range=Optional[str]) |
| 132 | + |
| 133 | +slots.object__value = Slot(uri=TABLE.value, name="object__value", curie=TABLE.curie('value'), |
| 134 | + model_uri=TABLE.object__value, domain=None, range=Optional[str]) |
| 135 | + |
| 136 | +slots.row__columnA = Slot(uri=TABLE.columnA, name="row__columnA", curie=TABLE.curie('columnA'), |
| 137 | + model_uri=TABLE.row__columnA, domain=None, range=URIRef) |
| 138 | + |
| 139 | +slots.row__objectB = Slot(uri=TABLE.objectB, name="row__objectB", curie=TABLE.curie('objectB'), |
| 140 | + model_uri=TABLE.row__objectB, domain=None, range=Optional[Union[dict, Object]]) |
| 141 | + |
| 142 | +slots.row__columnC = Slot(uri=TABLE.columnC, name="row__columnC", curie=TABLE.curie('columnC'), |
| 143 | + model_uri=TABLE.row__columnC, domain=None, range=Optional[str]) |
| 144 | + |
| 145 | +slots.table__rows = Slot(uri=TABLE.rows, name="table__rows", curie=TABLE.curie('rows'), |
| 146 | + model_uri=TABLE.table__rows, domain=None, range=Optional[Union[Dict[Union[str, RowColumnA], Union[dict, Row]], List[Union[dict, Row]]]]) |
0 commit comments