SHACL to entities¶
app.shacl_to_entities
¶
Project SHACL property shapes into EntityShape descriptors.
The descriptors drive both SPARQL generation and GeoJSON decoding.
shacl_to_filters walks the same shapes to build the filter panel.
BUILTIN_PATHS = {GEO.lat, GEO.long, COMPASS.name}
module-attribute
¶
Paths the pin query binds itself, so they are never projected.
DISPLAY_ONLY = {SCHEMA.url, SCHEMA.image, COMPASS.description, COMPASS.location, SKOS.altLabel, COMPASS.relatedOrganization, COMPASS.wpEntityTagId}
module-attribute
¶
Paths shown on a pin but never offered as a filter.
EntityShape
¶
Bases: BaseModel
One property descriptor projected from SHACL (not an instance).
targets_map_entity(g, node_shape)
¶
Report whether node_shape targets a compass:MapEntity subclass.
Shapes targeting anything else (the SKOS tag vocabularies, for instance) only validate the generated Turtle and stay out of the map projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Merged ontology graph (shapes + data + vocab). |
required |
node_shape
|
Node
|
Shape to classify. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/backend/app/shacl_to_entities.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
map_property_shapes(g)
¶
Yield every sh:property IRI of every NodeShape targeting a map entity class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Merged ontology graph (shapes + data + vocab). |
required |
Yields:
| Type | Description |
|---|---|
URIRef
|
|
Source code in src/backend/app/shacl_to_entities.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_definition(g, subject, lang)
¶
Return a non-blank skos:definition in lang, falling back to English.
Unlike :func:get_label, there is no fallback to any other language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
subject
|
URIRef
|
Concept whose definition is sought. |
required |
lang
|
str
|
BCP 47 language tag. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The definition, or |
Source code in src/backend/app/shacl_to_entities.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
get_label(g, subject, predicate, lang)
¶
Return a label in lang, falling back to English, then any available label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
subject
|
URIRef
|
Resource whose label is sought. |
required |
predicate
|
URIRef
|
Preferred label predicate (e.g. |
required |
lang
|
str
|
BCP 47 language tag. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Best-matching label string, or the subject's local name as last resort. |
Source code in src/backend/app/shacl_to_entities.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
get_entity_shapes_from_shacl(g)
¶
Project SHACL property shapes into EntityShape descriptors for query and decode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Merged ontology graph. |
required |
Returns:
| Type | Description |
|---|---|
list[EntityShape]
|
One |
Source code in src/backend/app/shacl_to_entities.py
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 | |
_infer_category(datatype, is_iri)
¶
Map SHACL datatype / IRI-ness to a SPARQL binding category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
Node | None
|
|
required |
is_iri
|
bool
|
True when the property values are IRIs (class, nodeKind, or sh:in). |
required |
Returns:
| Type | Description |
|---|---|
PropertyCategory
|
Category string consumed by the SPARQL builder and GeoJSON translator. |
Source code in src/backend/app/shacl_to_entities.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
_infer_filter_type(path, category, datatype)
¶
Choose the filter widget for a property, or none if display-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Node
|
Property path URIRef. |
required |
category
|
PropertyCategory
|
Inferred |
required |
datatype
|
Node | None
|
|
required |
Returns:
| Type | Description |
|---|---|
FilterType
|
Filter widget type used by the panel, or |
Source code in src/backend/app/shacl_to_entities.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |