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
Base class for managing RDF triple stores.
This class defines the interface for triple store management operations, including fetching and storing ontologies and their graphs. All concrete triple store implementations should inherit from this class.
This is an abstract base class that must be implemented by specific triple store backends (e.g., Neo4j, Fuseki, Filesystem).
Source code in ontocast/tool/triple_manager/core.py
__init__(**kwargs)
¶
Initialize the triple store manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. |
{}
|
clean(dataset=None)
abstractmethod
async
¶
Clean/flush data from the triple store.
This method removes data from the triple store. For Fuseki, the optional dataset parameter allows cleaning a specific dataset, or all datasets if None. For Neo4j and Filesystem, the dataset parameter is ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
str | None
|
Optional dataset name to clean (Fuseki only). If None, cleans all data. For other stores, this parameter is ignored. |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the triple store doesn't support cleaning. |
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
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" ... )