SHACL to filters¶
app.shacl_to_filters
¶
Project SHACL property shapes into filter-panel widgets.
FilterOption
¶
Bases: BaseModel
One selectable value inside a multiselect filter widget.
FilterWidget
¶
Bases: BaseModel
One filter-panel widget derived from SHACL (UI only; not SPARQL).
get_filters_from_shacl(g, lang='en')
¶
Build filter-panel dimensions from the SHACL property shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Merged ontology graph. |
required |
lang
|
str
|
UI language for labels and literal options. |
'en'
|
Returns:
| Type | Description |
|---|---|
list[FilterWidget]
|
Widgets sorted by label, including the synthetic entity-type dimension. |
Source code in src/backend/app/shacl_to_filters.py
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 | |
_infer_widget(datatype)
¶
Map an XSD datatype to a filter widget kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datatype
|
Node | None
|
|
required |
Returns:
| Type | Description |
|---|---|
FilterWidgetType
|
Widget type; defaults to |
Source code in src/backend/app/shacl_to_filters.py
119 120 121 122 123 124 125 126 127 128 | |
_multiselect_options(g, prop_shape, path, target_class, lang)
¶
Collect multiselect choices from class instances, sh:in, or observed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
prop_shape
|
Node
|
Property-shape subject. |
required |
path
|
Node
|
Property path URIRef. |
required |
target_class
|
Node | None
|
|
required |
lang
|
str
|
Preferred label language. |
required |
Returns:
| Type | Description |
|---|---|
list[FilterOption]
|
Options sorted by label. |
Source code in src/backend/app/shacl_to_filters.py
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 | |
_iri_option(g, term, lang)
¶
Build the option selecting concept term.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
term
|
URIRef
|
Concept IRI the option selects. |
required |
lang
|
str
|
Preferred language for label and definition. |
required |
Returns:
| Type | Description |
|---|---|
FilterOption
|
The option, with |
Source code in src/backend/app/shacl_to_filters.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
_scheme_description(g, target_class, lang)
¶
Return the definition of the concept scheme a dimension's options sit in.
The scheme is found through skos:inScheme of the class instances, not by
naming convention. Its definition is used over the shape's sh:description
because the vocabulary carries it in every language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
target_class
|
Node | None
|
|
required |
lang
|
str
|
Preferred definition language. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The definition, or |
str | None
|
defines one (e.g. relations to entity classes). |
Source code in src/backend/app/shacl_to_filters.py
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 | |
_numeric_values(g, path)
¶
Collect numeric objects of path that parse as floats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
path
|
Node
|
Property path. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
Successfully parsed numeric values (may be empty). |
Source code in src/backend/app/shacl_to_filters.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
_slider_bounds(g, prop_shape, path, datatype)
¶
Compute min/max for a slider from SHACL bounds or observed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
prop_shape
|
Node
|
Property-shape subject. |
required |
path
|
Node
|
Property path. |
required |
datatype
|
Node | None
|
XSD datatype (affects gYear defaults). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float | int, float | int]
|
|
Source code in src/backend/app/shacl_to_filters.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
_datepicker_bounds(g, path)
¶
Compute min/max ISO date strings from observed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph. |
required |
path
|
Node
|
Property path. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
|
Source code in src/backend/app/shacl_to_filters.py
259 260 261 262 263 264 265 266 267 268 269 270 | |
_entity_type_dimension(g, lang)
¶
Build the entity-type multiselect over the filterable pin classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Graph
|
Ontology graph (for class labels). |
required |
lang
|
str
|
UI language. |
required |
Returns:
| Type | Description |
|---|---|
FilterWidget
|
Synthetic |
Source code in src/backend/app/shacl_to_filters.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |