ontocast.tool.triple_manager.core¶
Triple store management tools for OntoCast.
This module provides functionality for managing RDF triple stores, including abstract interfaces and concrete implementations for different triple store backends.
TripleStoreManager
¶
Bases: Tool
Source code in ontocast/tool/triple_manager/core.py
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 | |
__init__(**kwargs)
¶
Initialize the triple store manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
afetch_ontologies()
async
¶
aserialize(o, **kwargs)
async
¶
Async serialize helper for backends without native async I/O.
clean()
abstractmethod
async
¶
Clean/flush data managed by this store (backend-specific scope).
Warning: This operation is irreversible and will delete data.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the triple store doesn't support cleaning. |
Source code in ontocast/tool/triple_manager/core.py
clean_tenancy(tenant, project)
async
¶
Remove all triples for datasets derived from tenant / project.
Backends without per-tenant partitions raise :class:NotImplementedError.
Source code in ontocast/tool/triple_manager/core.py
fetch_ontologies()
abstractmethod
¶
Fetch all available ontologies from the triple store.
This method should retrieve all ontologies stored in the triple store and return them as Ontology objects with their associated RDF graphs.
Returns:
| Type | Description |
|---|---|
list[Ontology]
|
list[Ontology]: List of available ontologies with their graphs. |
Source code in ontocast/tool/triple_manager/core.py
serialize(o, **kwargs)
abstractmethod
¶
Store an RDF graph in the triple store.
This method should store the given RDF graph in the triple store. The implementation may choose how to organize the storage (e.g., as named graphs, in specific collections, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
o
|
Ontology | RDFGraph
|
RDF graph or Ontology object to store. |
required |
**kwargs
|
Implementation-specific arguments (e.g., graph_uri for Fuseki). |
{}
|
Returns:
| Type | Description |
|---|---|
bool | None
|
bool | None: Implementation-specific return value (bool for Fuseki, summary for Neo4j, None for Filesystem). |
Source code in ontocast/tool/triple_manager/core.py
serialize_graph(graph, **kwargs)
abstractmethod
¶
Store an RDF graph in the triple store.
This method should store the given RDF graph in the triple store. The implementation may choose how to organize the storage (e.g., as named graphs, in specific collections, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
The RDF graph to store. |
required |
**kwargs
|
Implementation-specific arguments (e.g., fname for filesystem, graph_uri for Fuseki). |
{}
|
Returns:
| Type | Description |
|---|---|
bool | None
|
bool | None: Implementation-specific return value (bool for Fuseki, summary for Neo4j, None for Filesystem). |
Source code in ontocast/tool/triple_manager/core.py
strip_provenance(graph)
classmethod
¶
Return a graph without reification/provenance scaffolding triples.
Source code in ontocast/tool/triple_manager/core.py
supports_tenancy_partition()
¶
TripleStoreManagerWithAuth
¶
Bases: TripleStoreManager
Base class for triple store managers that require authentication.
This class provides common functionality for triple store managers that need URI and authentication credentials. It handles environment variable loading and credential parsing.
Attributes:
| Name | Type | Description |
|---|---|---|
uri |
str | None
|
The connection URI for the triple store. |
auth |
tuple | None
|
Authentication tuple (username, password) for the triple store. |
Source code in ontocast/tool/triple_manager/core.py
__init__(uri=None, auth=None, env_uri=None, env_auth=None, **kwargs)
¶
Initialize the triple store manager with authentication.
This method handles loading URI and authentication credentials from either direct parameters or environment variables. It also parses authentication strings in the format "user/password".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
Direct URI for the triple store connection. |
None
|
|
auth
|
Direct authentication tuple or string in "user/password" format. |
None
|
|
env_uri
|
Environment variable name for the URI (e.g., "NEO4J_URI"). |
None
|
|
env_auth
|
Environment variable name for authentication (e.g., "NEO4J_AUTH"). |
None
|
|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If authentication string is not in "user/password" format. |
Example
manager = TripleStoreManagerWithAuth( ... env_uri="NEO4J_URI", ... env_auth="NEO4J_AUTH" ... )