Schema
DataSchema
Source code in blue/data/schema.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
__init__()
Initialize empty containers for entities and relations.
Source code in blue/data/schema.py
5 6 7 8 | |
add_entity(key)
Add a new entity to the schema.
If the entity already exists, a unique suffix is appended (e.g., "__1").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The name of the entity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
The original entity key. |
Source code in blue/data/schema.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
add_entity_property(key, attribute, type)
Add a property (attribute) to an existing entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The entity key. |
required |
attribute
|
str
|
The name of the attribute. |
required |
type
|
str
|
The type or description of the attribute. |
required |
Source code in blue/data/schema.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
add_relation(source, relation, target)
Add a relation between two entities in the schema.
If the same relation already exists, a numeric suffix is appended.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source entity name. |
required |
relation
|
str
|
Relation name. |
required |
target
|
str
|
Target entity name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
Unique key of the created relation. |
Source code in blue/data/schema.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
add_relation_property(key, property, type)
Add a property to an existing relation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Relation key. |
required |
property
|
str
|
Property name. |
required |
type
|
str
|
Property type or description. |
required |
Source code in blue/data/schema.py
144 145 146 147 148 149 150 151 152 153 154 155 156 | |
get_entities()
Get all entities defined in the schema.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Mapping of entity keys to entity definitions. |
Source code in blue/data/schema.py
158 159 160 161 162 163 164 165 | |
get_relations()
Get all relations defined in the schema.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Mapping of relation keys to relation definitions. |
Source code in blue/data/schema.py
167 168 169 170 171 172 173 174 | |
has_entity(key)
Check if an entity exists in the schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The entity name or identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the entity exists, False otherwise. |
Source code in blue/data/schema.py
10 11 12 13 14 15 16 17 18 19 20 | |
has_relation(source, relation, target)
Check if a relation exists in the schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source entity name. |
required |
relation
|
str
|
Relation name. |
required |
target
|
str
|
Target entity name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
True if the relation exists, False otherwise. |
Source code in blue/data/schema.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
to_json()
Convert the schema to a JSON-serializable dictionary.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dictionary with 'entities' and 'relations' keys. |
Source code in blue/data/schema.py
176 177 178 179 180 181 182 183 184 185 186 | |