Coverage for heritrace / uri_generator / default_uri_generator.py: 93%
14 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-07-02 10:16 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-07-02 10:16 +0000
1# SPDX-FileCopyrightText: 2024-2025 Arcangelo Massari <arcangelo.massari@unibo.it>
2#
3# SPDX-License-Identifier: ISC
5from __future__ import annotations
7import os
8import uuid
9from typing import TYPE_CHECKING
11from rdflib import URIRef
13from heritrace.uri_generator.uri_generator import URIGenerator
15if TYPE_CHECKING:
16 from heritrace.sparql import SPARQLWrapperWithRetry
19class DefaultURIGenerator(URIGenerator):
20 def __init__(self, base_iri: str | None = None) -> None:
21 self.base_iri = base_iri if base_iri is not None else os.environ["BASE_IRI"]
23 def generate_uri(
24 self, _entity_type: str | None = None, _context_data: dict | None = None
25 ) -> str:
26 return URIRef(f"{self.base_iri}/{uuid.uuid4().hex}")
28 def initialize_counters(self, sparql: SPARQLWrapperWithRetry) -> None:
29 """
30 Initialize counters for entity types supported by this URI generator.
31 Since DefaultURIGenerator uses UUIDs, no counter initialization is needed.
33 :param sparql: SPARQLWrapper instance to execute queries on the dataset
34 :return: None
35 """