ontocast.tool.triple_manager.fuseki
¶
Fuseki triple store management for OntoCast.
This module provides a concrete implementation of triple store management using Apache Fuseki as the backend. It supports named graphs for ontologies and facts, with proper authentication and dataset management.
FusekiTripleStoreManager
¶
Bases: TripleStoreManagerWithAuth
Fuseki-based triple store manager.
This class provides a concrete implementation of triple store management using Apache Fuseki. It stores ontologies as named graphs using their URIs as graph names, and supports dataset creation and cleanup.
The manager uses Fuseki's REST API for all operations, including: - Dataset creation and management - Named graph operations for ontologies - SPARQL queries for ontology discovery - Graph-level data operations
Attributes:
Name | Type | Description |
---|---|---|
dataset |
Optional[str]
|
The Fuseki dataset name to use for storage. |
clean |
Whether to clean the dataset on initialization. |
Source code in ontocast/tool/triple_manager/fuseki.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 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
__init__(uri=None, auth=None, dataset=None, clean=False, **kwargs)
¶
Initialize the Fuseki triple store manager.
This method sets up the connection to Fuseki, creates the dataset if it doesn't exist, and optionally cleans all data from the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
Fuseki server URI (e.g., "http://localhost:3030"). |
None
|
|
auth
|
Authentication tuple (username, password) or string in "user/password" format. |
None
|
|
dataset
|
Dataset name to use for storage. |
None
|
|
clean
|
If True, delete all data from the dataset on initialization. |
False
|
|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If dataset is not specified in URI or as argument. |
Example
manager = FusekiTripleStoreManager( ... uri="http://localhost:3030", ... dataset="test", ... clean=True ... )
Source code in ontocast/tool/triple_manager/fuseki.py
fetch_ontologies()
¶
Fetch all ontologies from their corresponding named graphs.
This method discovers all ontologies in the Fuseki dataset and fetches each one from its corresponding named graph. It uses a two-step process:
- Discovery: Query for all ontology URIs using SPARQL
- Fetching: Retrieve each ontology from its named graph
The method handles both named graphs and the default graph, and verifies that each ontology is properly typed as owl:Ontology.
Returns:
Type | Description |
---|---|
list[Ontology]
|
list[Ontology]: List of all ontologies found in the dataset. |
Example
ontologies = manager.fetch_ontologies() for onto in ontologies: ... print(f"Found ontology: {onto.iri}")
Source code in ontocast/tool/triple_manager/fuseki.py
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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
init_dataset(dataset_name)
¶
Initialize a Fuseki dataset.
This method creates a new dataset in Fuseki if it doesn't already exist. It uses Fuseki's admin API to create the dataset with TDB2 storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_name
|
Name of the dataset to create. |
required |
Note
This method will not fail if the dataset already exists.
Source code in ontocast/tool/triple_manager/fuseki.py
serialize_facts(g, **kwargs)
¶
Store facts (RDF graph) as a named graph in Fuseki.
This method stores the given RDF graph containing facts as a named graph in Fuseki. The graph name is taken from the chunk_uri parameter or defaults to "urn:chunk:default".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The RDF graph containing facts to store. |
required |
**kwargs
|
Additional keyword arguments. chunk_uri: URI to use as the named graph name (optional). |
{}
|
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the facts were successfully stored, False otherwise. |
Example
facts = RDFGraph() success = manager.serialize_facts(facts, chunk_uri="http://example.org/chunk1")
Source code in ontocast/tool/triple_manager/fuseki.py
serialize_ontology(o, **kwargs)
¶
Store an ontology as a named graph in Fuseki.
This method stores the given ontology as a named graph in Fuseki, using the ontology's IRI as the graph name. This ensures that each ontology is stored separately and can be retrieved individually.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
o
|
Ontology
|
The ontology to store. |
required |
**kwargs
|
Additional keyword arguments (not used). |
{}
|
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the ontology was successfully stored, False otherwise. |
Example
ontology = Ontology(iri="http://example.org/onto", graph=graph) success = manager.serialize_ontology(ontology)