|
| 1 | +# Auto generated from table.yaml by pythongen.py version: 0.9.0 |
| 2 | +# Generation date: 2022-10-10T16:55:54 |
| 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 | + |
| 43 | +# Class references |
| 44 | +class RowColumnA(URIorCURIE): |
| 45 | + pass |
| 46 | + |
| 47 | + |
| 48 | +@dataclass |
| 49 | +class Object(YAMLRoot): |
| 50 | + """ |
| 51 | + An object (bnode) which needs embedding in a single row |
| 52 | + """ |
| 53 | + |
| 54 | + _inherited_slots: ClassVar[List[str]] = [] |
| 55 | + |
| 56 | + class_class_uri: ClassVar[URIRef] = TABLE.Object |
| 57 | + class_class_curie: ClassVar[str] = "table:Object" |
| 58 | + class_name: ClassVar[str] = "Object" |
| 59 | + class_model_uri: ClassVar[URIRef] = TABLE.Object |
| 60 | + |
| 61 | + name: Optional[str] = None |
| 62 | + value: Optional[str] = None |
| 63 | + |
| 64 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 65 | + if self.name is not None and not isinstance(self.name, str): |
| 66 | + self.name = str(self.name) |
| 67 | + |
| 68 | + if self.value is not None and not isinstance(self.value, str): |
| 69 | + self.value = str(self.value) |
| 70 | + |
| 71 | + super().__post_init__(**kwargs) |
| 72 | + |
| 73 | + |
| 74 | +@dataclass |
| 75 | +class Row(YAMLRoot): |
| 76 | + """ |
| 77 | + A single data point made up of columns. |
| 78 | + """ |
| 79 | + |
| 80 | + _inherited_slots: ClassVar[List[str]] = [] |
| 81 | + |
| 82 | + class_class_uri: ClassVar[URIRef] = TABLE.Row |
| 83 | + class_class_curie: ClassVar[str] = "table:Row" |
| 84 | + class_name: ClassVar[str] = "Row" |
| 85 | + class_model_uri: ClassVar[URIRef] = TABLE.Row |
| 86 | + |
| 87 | + columnA: Union[str, RowColumnA] = None |
| 88 | + objectB: Optional[Union[dict, Object]] = None |
| 89 | + columnC: Optional[str] = None |
| 90 | + |
| 91 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 92 | + if self._is_empty(self.columnA): |
| 93 | + self.MissingRequiredField("columnA") |
| 94 | + if not isinstance(self.columnA, RowColumnA): |
| 95 | + self.columnA = RowColumnA(self.columnA) |
| 96 | + |
| 97 | + if self.objectB is not None and not isinstance(self.objectB, Object): |
| 98 | + self.objectB = Object(**as_dict(self.objectB)) |
| 99 | + |
| 100 | + if self.columnC is not None and not isinstance(self.columnC, str): |
| 101 | + self.columnC = str(self.columnC) |
| 102 | + |
| 103 | + super().__post_init__(**kwargs) |
| 104 | + |
| 105 | + |
| 106 | +@dataclass |
| 107 | +class Table(YAMLRoot): |
| 108 | + """ |
| 109 | + Container of rows. |
| 110 | + """ |
| 111 | + |
| 112 | + _inherited_slots: ClassVar[List[str]] = [] |
| 113 | + |
| 114 | + class_class_uri: ClassVar[URIRef] = TABLE.Table |
| 115 | + class_class_curie: ClassVar[str] = "table:Table" |
| 116 | + class_name: ClassVar[str] = "Table" |
| 117 | + class_model_uri: ClassVar[URIRef] = TABLE.Table |
| 118 | + |
| 119 | + rows: Optional[Union[Dict[Union[str, RowColumnA], Union[dict, Row]], List[Union[dict, Row]]]] = empty_dict() |
| 120 | + |
| 121 | + def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]): |
| 122 | + self._normalize_inlined_as_list(slot_name="rows", slot_type=Row, key_name="columnA", keyed=True) |
| 123 | + |
| 124 | + super().__post_init__(**kwargs) |
| 125 | + |
| 126 | + |
| 127 | +# Enumerations |
| 128 | + |
| 129 | + |
| 130 | +# Slots |
| 131 | +class slots: |
| 132 | + pass |
| 133 | + |
| 134 | + |
| 135 | +slots.rows = Slot( |
| 136 | + uri=TABLE.rows, |
| 137 | + name="rows", |
| 138 | + curie=TABLE.curie("rows"), |
| 139 | + model_uri=TABLE.rows, |
| 140 | + domain=None, |
| 141 | + range=Optional[Union[Dict[Union[str, RowColumnA], Union[dict, Row]], List[Union[dict, Row]]]], |
| 142 | +) |
| 143 | + |
| 144 | +slots.columnA = Slot( |
| 145 | + uri=TABLE.columnA, name="columnA", curie=TABLE.curie("columnA"), model_uri=TABLE.columnA, domain=None, range=URIRef |
| 146 | +) |
| 147 | + |
| 148 | +slots.objectB = Slot( |
| 149 | + uri=TABLE.objectB, |
| 150 | + name="objectB", |
| 151 | + curie=TABLE.curie("objectB"), |
| 152 | + model_uri=TABLE.objectB, |
| 153 | + domain=None, |
| 154 | + range=Optional[Union[dict, Object]], |
| 155 | +) |
| 156 | + |
| 157 | +slots.columnC = Slot( |
| 158 | + uri=TABLE.columnC, |
| 159 | + name="columnC", |
| 160 | + curie=TABLE.curie("columnC"), |
| 161 | + model_uri=TABLE.columnC, |
| 162 | + domain=None, |
| 163 | + range=Optional[str], |
| 164 | +) |
| 165 | + |
| 166 | +slots.name = Slot( |
| 167 | + uri=TABLE.name, name="name", curie=TABLE.curie("name"), model_uri=TABLE.name, domain=None, range=Optional[str] |
| 168 | +) |
| 169 | + |
| 170 | +slots.value = Slot( |
| 171 | + uri=TABLE.value, name="value", curie=TABLE.curie("value"), model_uri=TABLE.value, domain=None, range=Optional[str] |
| 172 | +) |
0 commit comments