RDF store¶
app.rdf
¶
RDF store wrapper: Oxigraph for SPARQL, rdflib for SHACL introspection.
RDFStore(data_path, shapes_path, vocab_path)
¶
In-process ontology store used by every query route.
Oxigraph answers SPARQL; a lazily built rdflib Graph serves SHACL
introspection. A single process-wide instance is held on _instance.
Load Turtle files into a fresh Oxigraph store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str
|
Path to |
required |
shapes_path
|
str
|
Path to |
required |
vocab_path
|
str
|
Path to |
required |
Source code in src/backend/app/rdf.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
read_graph
property
¶
Merged rdflib graph of shapes, data, and vocab (parsed once).
Returns:
| Type | Description |
|---|---|
Graph
|
Shared |
load_data()
¶
Parse the three Turtle files into the Oxigraph store.
Source code in src/backend/app/rdf.py
43 44 45 46 47 48 49 50 | |
query(sparql)
¶
Run a SPARQL SELECT; one dict per row, unbound variables omitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sparql
|
str
|
Full SELECT query string. |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of row dicts keyed by variable name. |
Raises:
| Type | Description |
|---|---|
QueryError
|
When Oxigraph rejects or fails the query. The failing query text is attached for logging. |
Source code in src/backend/app/rdf.py
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 | |
get_entities()
¶
Return cached EntityShape descriptors projected from SHACL.
Returns:
| Type | Description |
|---|---|
list[EntityShape]
|
Property descriptors used to build SPARQL and decode GeoJSON. |
Source code in src/backend/app/rdf.py
101 102 103 104 105 106 107 108 109 | |
validate()
¶
Reject a store that parsed but cannot answer a query.
Turtle can parse and still be useless — a truncated file, or shapes that no longer describe the data — and a reload that swapped such a store in would take the map down. Deriving entity shapes exercises the SHACL introspection the whole query layer is built on, and counting entities proves the data reached the store.
Raises:
| Type | Description |
|---|---|
ReloadError
|
When shapes yield nothing or no entity has coordinates. |
Source code in src/backend/app/rdf.py
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 | |
from_settings()
classmethod
¶
Build a store from the configured ontology and use-case directories.
Returns:
| Type | Description |
|---|---|
RDFStore
|
New |
RDFStore
|
|
RDFStore
|
|
Source code in src/backend/app/rdf.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
instance()
classmethod
¶
Return the single live store, creating it from settings if needed.
Returns:
| Type | Description |
|---|---|
RDFStore
|
Process-wide |
Source code in src/backend/app/rdf.py
156 157 158 159 160 161 162 163 164 165 | |
reload_instance()
classmethod
¶
Swap in the files currently on disk, keeping the live store on failure.
The candidate is built and validated in full before _instance moves,
so a bad edit leaves the last good version serving rather than taking the
API down with it.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Status dict with |
dict[str, Any]
|
|
Raises:
| Type | Description |
|---|---|
ReloadError
|
When the on-disk ontology is not usable. |
Source code in src/backend/app/rdf.py
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 | |