Coverage for src/oc_graphenricher/_identifiers.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-07-06 11:55 +0000

1# SPDX-FileCopyrightText: 2026 Arcangelo Massari <arcangelo.massari@unibo.it> 

2# 

3# SPDX-License-Identifier: ISC 

4 

5from __future__ import annotations 

6 

7from typing import TYPE_CHECKING 

8 

9from oc_ocdm.graph.graph_entity import GraphEntity 

10 

11if TYPE_CHECKING: 

12 from collections.abc import Iterator 

13 

14 from oc_ocdm.graph.entities.bibliographic_entity import BibliographicEntity 

15 

16 

17BR_API_SCHEMAS = { 

18 GraphEntity.iri_doi: "doi", 

19 GraphEntity.iri_issn: "issn", 

20 GraphEntity.iri_pmid: "pmid", 

21 GraphEntity.iri_pmcid: "pmcid", 

22} 

23 

24 

25def valid_identifiers(entity: BibliographicEntity) -> Iterator[tuple[str, str]]: 

26 for identifier in entity.get_identifiers(): 

27 scheme = identifier.get_scheme() 

28 literal = identifier.get_literal_value() 

29 if scheme is not None and literal is not None: 

30 yield scheme, literal 

31 

32 

33def supported_br_identifiers(entity: BibliographicEntity) -> Iterator[tuple[str, str]]: 

34 for scheme, literal in valid_identifiers(entity): 

35 schema = BR_API_SCHEMAS.get(scheme) 

36 if schema is not None: 

37 yield schema, literal