Skip to content

Commit 87d6619

Browse files
authored
Minor refactors before implementing SKOS reader (#515)
1 parent 00f9063 commit 87d6619

4 files changed

Lines changed: 66 additions & 4 deletions

File tree

src/pyobo/constants.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ class IterHelperHelperDict(SlimGetOntologyKwargs):
218218

219219

220220
#: The ontology format
221-
OntologyFormat: TypeAlias = Literal["obo", "owl", "json", "rdf"]
221+
OntologyFormat: TypeAlias = Literal[
222+
"obo",
223+
"owl",
224+
"json",
225+
"rdf",
226+
]
222227

223228
#: from table 2 of the Functional OWL syntax definition
224229
#: at https://www.w3.org/TR/owl2-syntax/#IRIs

src/pyobo/struct/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def _parse_reference_or_uri_literal(
284284
case BlocklistError():
285285
return None
286286
case UnparsableIRIError():
287-
# this means that it's defininitely a URI,
287+
# this means that it's definitely a URI,
288288
# but it couldn't be parsed with Bioregistry
289289
return OBOLiteral.uri(str_or_curie_or_uri)
290290
case NotCURIEError() as exc:

src/pyobo/struct/struct.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,60 @@ def append_exact_match(
376376
self.annotate_object(v.exact_match, reference, annotations=axioms)
377377
return self
378378

379+
def append_broad_match(
380+
self,
381+
reference: ReferenceHint,
382+
*,
383+
mapping_justification: Reference | None = None,
384+
confidence: float | None = None,
385+
contributor: Reference | None = None,
386+
) -> Self:
387+
"""Append a broad match, also adding an xref."""
388+
reference = _ensure_ref(reference)
389+
axioms = self._prepare_mapping_annotations(
390+
mapping_justification=mapping_justification,
391+
confidence=confidence,
392+
contributor=contributor,
393+
)
394+
self.annotate_object(v.broad_match, reference, annotations=axioms)
395+
return self
396+
397+
def append_narrow_match(
398+
self,
399+
reference: ReferenceHint,
400+
*,
401+
mapping_justification: Reference | None = None,
402+
confidence: float | None = None,
403+
contributor: Reference | None = None,
404+
) -> Self:
405+
"""Append a narrow match, also adding an xref."""
406+
reference = _ensure_ref(reference)
407+
axioms = self._prepare_mapping_annotations(
408+
mapping_justification=mapping_justification,
409+
confidence=confidence,
410+
contributor=contributor,
411+
)
412+
self.annotate_object(v.narrow_match, reference, annotations=axioms)
413+
return self
414+
415+
def append_related_match(
416+
self,
417+
reference: ReferenceHint,
418+
*,
419+
mapping_justification: Reference | None = None,
420+
confidence: float | None = None,
421+
contributor: Reference | None = None,
422+
) -> Self:
423+
"""Append a related match, also adding an xref."""
424+
reference = _ensure_ref(reference)
425+
axioms = self._prepare_mapping_annotations(
426+
mapping_justification=mapping_justification,
427+
confidence=confidence,
428+
contributor=contributor,
429+
)
430+
self.annotate_object(v.related_match, reference, annotations=axioms)
431+
return self
432+
379433
def set_species(self, identifier: str, name: str | None = None) -> Self:
380434
"""Append the from_species relation."""
381435
if name is None:

src/pyobo/utils/misc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import logging
66
from collections.abc import Callable, Iterable
77
from datetime import datetime
8+
from typing import TypeAlias
89

910
import bioversions.utils
1011

11-
from pyobo.constants import ONTOLOGY_GETTERS, OntologyFormat
12+
from ..constants import ONTOLOGY_GETTERS, OntologyFormat
1213

1314
__all__ = [
1415
"VERSION_GETTERS",
@@ -137,8 +138,10 @@ def _get_obograph_json_version(prefix: str, url: str) -> str | None:
137138
return cleanup_version(rv, prefix)
138139

139140

141+
VersionGetter: TypeAlias = Callable[[str, str], str | None]
142+
140143
#: A mapping from data type to gersion getter function
141-
VERSION_GETTERS: dict[OntologyFormat, Callable[[str, str], str | None]] = {
144+
VERSION_GETTERS: dict[OntologyFormat, VersionGetter] = {
142145
"obo": _get_obo_version,
143146
"owl": _get_owl_version,
144147
"json": _get_obograph_json_version,

0 commit comments

Comments
 (0)