Ontology Service
The OntologyService handles ontology-related operations.
The OntologyService handles ontology-related operations and is accessed via the ontology property of an active PerseusClient instance.
Upload Ontology
Uploads an ontology file to the Perseus API. This is a higher-level function that encapsulates create_ontology and the upload to a presigned URL. If an ontology with the same content already exists, it will be returned without uploading.
async def upload_ontology(ontology_path: str) -> Ontologydef upload_ontology(ontology_path: str) -> OntologyParameters:
ontology_path(str): The local path to the ontology file to upload.
Output:
A Ontology object representing the uploaded or existing ontology, including its ID, name, status, and creation timestamp.
Create Ontology
Creates an ontology record on the server and returns a presigned URL for uploading the ontology content.
async def create_ontology(name: str, source_hash: str) -> Dictdef create_ontology(name: str, source_hash: str) -> DictParameters:
name(str): The name of the ontology.source_hash(str): The SHA256 hash of the ontology file's content.
Output:
A dictionary containing:
ontology: AnOntologyobject representing the newly created ontology.upload_url: Astr(presigned URL) to which the ontology content should be uploaded.
Find Ontologies
Finds and retrieves a list of ontologies based on their IDs or source hashes.
async def find_ontologies(ids: Optional[List[str]] = None, source_hashes: Optional[List[str]] = None) -> List[Ontology]def find_ontologies(ids: Optional[List[str]] = None, source_hashes: Optional[List[str]] = None) -> List[Ontology]Parameters:
ids(Optional[List[str]]): A list of ontology IDs to search for.source_hashes(Optional[List[str]]): A list of SHA256 source hashes to search for. |
Output:
A list of Ontology objects matching the criteria. Returns an empty list if no ontologies are found.
Find Ontology
Finds and retrieves a single ontology by its ID.
async def find_ontology(id: str) -> Optional[Ontology]def find_ontology(id: str) -> Optional[Ontology]Parameters:
id(str): The ID of the ontology to find.
Output:
An Ontology object if an ontology with the given ID is found, otherwise None.
Delete Ontology
Deletes an ontology by its ID.
async def delete_ontology(ontology_id: str) -> Nonedef delete_ontology(ontology_id: str) -> NoneParameters:
ontology_id(str): The ID of the ontology to delete.
Output:
None
Wait for Ontology Upload
Waits for an ontology's status to become UPLOADED or FAILED. This is useful after getting a presigned URL and uploading the ontology.
async def wait_for_ontology_upload(ontology_id: str, polling_interval: float = 0.5, timeout: int = 3600) -> Ontologydef wait_for_ontology_upload(ontology_id: str, polling_interval: float = 0.5, timeout: int = 3600) -> OntologyParameters:
ontology_id(str): The ID of the ontology to wait for.polling_interval(float): The interval in seconds to poll for the ontology status. Defaults to0.5.timeout(int): The maximum time in seconds to wait. Defaults to3600.
Output:
The final Ontology object once the upload is complete.