ontocast.tool.triple_manager.filesystem_manager
¶
Filesystem triple store management for OntoCast.
This module provides a concrete implementation of triple store management using the local filesystem for storage. It supports reading and writing ontologies and facts as Turtle files.
FilesystemTripleStoreManager
¶
Bases: TripleStoreManager
Filesystem-based implementation of triple store management.
This class provides a concrete implementation of triple store management using the local filesystem for storage. It reads and writes ontologies and facts as Turtle (.ttl) files in specified directories.
The manager supports: - Loading ontologies from a dedicated ontology directory - Storing ontologies with versioned filenames - Storing facts with customizable filenames based on specifications - Error handling for file operations
Attributes:
Name | Type | Description |
---|---|---|
working_directory |
Optional[Path]
|
Path to the working directory for storing data. |
ontology_path |
Optional[Path]
|
Optional path to the ontology directory for loading ontologies. |
Source code in ontocast/tool/triple_manager/filesystem_manager.py
20 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 filesystem triple store manager.
This method sets up the filesystem manager with the specified working and ontology directories.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Additional keyword arguments passed to the parent class. working_directory: Path to the working directory for storing data. ontology_path: Path to the ontology directory for loading ontologies. |
{}
|
Example
manager = FilesystemTripleStoreManager( ... working_directory="/path/to/work", ... ontology_path="/path/to/ontologies" ... )
Source code in ontocast/tool/triple_manager/filesystem_manager.py
fetch_ontologies()
¶
Fetch all available ontologies from the filesystem.
This method scans the ontology directory for Turtle (.ttl) files and loads each one as an Ontology object. Files are processed in sorted order for consistent results.
Returns:
Type | Description |
---|---|
list[Ontology]
|
list[Ontology]: List of all ontologies found in the ontology directory. |
Example
ontologies = manager.fetch_ontologies() for onto in ontologies: ... print(f"Loaded ontology: {onto.ontology_id}")
Source code in ontocast/tool/triple_manager/filesystem_manager.py
serialize_facts(g, **kwargs)
¶
Store a graph with facts in the filesystem.
This method stores the given RDF graph containing facts as a Turtle file in the working directory. The filename can be customized using the spec parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The RDF graph containing facts to store. |
required |
**kwargs
|
Additional keyword arguments for serialization. spec: Optional specification for the filename. If provided as a string, it will be processed to create a meaningful filename. |
{}
|
Raises:
Type | Description |
---|---|
TypeError
|
If spec is provided but not a string. |
Example
facts = RDFGraph() manager.serialize_facts(facts, spec="domain/subdomain")
Creates: working_directory/facts_domain_subdomain.ttl¶
Source code in ontocast/tool/triple_manager/filesystem_manager.py
serialize_ontology(o, **kwargs)
¶
Store an ontology in the filesystem.
This method stores the given ontology as a Turtle file in the working directory. The filename is generated using the ontology ID and version to ensure uniqueness.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
o
|
Ontology
|
The ontology to store. |
required |
**kwargs
|
Additional keyword arguments for serialization (not used). |
{}
|
Example
ontology = Ontology(ontology_id="test", version="1.0", graph=graph) manager.serialize_ontology(ontology)