| 83 | |
| 84 | |
| 85 | class Label: |
| 86 | __slots__ = [ |
| 87 | "_name", |
| 88 | "_props", |
| 89 | "_version_id", |
| 90 | "_label_id", |
| 91 | "_valid_props", |
| 92 | "_prop_index", |
| 93 | "_comment", |
| 94 | ] |
| 95 | |
| 96 | def __init__(self, name, label_id=0): |
| 97 | self._name: str = name |
| 98 | self._props: List[Property] = [] |
| 99 | self._version_id: int = 0 |
| 100 | self._label_id: int = label_id |
| 101 | |
| 102 | self._valid_props: List[int] = [] |
| 103 | self._prop_index: dict[str, int] = {} |
| 104 | self._comment: str = "" |
| 105 | |
| 106 | def add_property(self, name, data_type, is_primary_key=False, comment=""): |
| 107 | self._prop_index[name] = len(self._props) |
| 108 | if isinstance(data_type, str): |
| 109 | data_type = unify_type(data_type) |
| 110 | self._props.append( |
| 111 | Property(name, data_type, is_primary_key, len(self._props), comment) |
| 112 | ) |
| 113 | self._valid_props.append(1) |
| 114 | return self |
| 115 | |
| 116 | def set_comment(self, comment): |
| 117 | self._comment = comment |
| 118 | return self |
| 119 | |
| 120 | @property |
| 121 | def id(self) -> int: |
| 122 | return self._label_id |
| 123 | |
| 124 | @property |
| 125 | def label(self) -> str: |
| 126 | return self._name |
| 127 | |
| 128 | @property |
| 129 | def properties(self) -> List: |
| 130 | return list(itertools.compress(self._props, self._valid_props)) |
| 131 | |
| 132 | @property |
| 133 | def comment(self): |
| 134 | return self._comment |
| 135 | |
| 136 | def get_property_id(self, name): |
| 137 | idx = self._prop_index[name] |
| 138 | if not self._valid_props[idx]: |
| 139 | raise ValueError(f"{name} not exist in properties") |
| 140 | return idx |
| 141 | |
| 142 | def property_exists(self, name): |
no outgoing calls
no test coverage detected