Skip to content

Commit 55a9540

Browse files
committed
Update
1 parent 7829bbf commit 55a9540

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

src/pyobo/getters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,15 @@ def _ensure_ontology_path(
255255
case None:
256256
continue
257257
case AnnotatedURL() as a:
258-
name = _name_from_url(a.url, ontology_format, rdf_format=a.rdf_format)
258+
url = a.url
259259
rdf_format = a.rdf_format
260260
case str() as url:
261-
name = _name_from_url(url, ontology_format)
262261
rdf_format = None
263262
case _:
264263
raise TypeError
265264

265+
name = _name_from_url(url, ontology_format, rdf_format=rdf_format)
266+
266267
try:
267268
path = ensure_path(prefix, url=url, force=force, version=version, name=name)
268269
except (urllib.error.HTTPError, pystow.utils.DownloadError):

src/pyobo/struct/jskos_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,36 @@
55
import curies
66

77
from .struct import Obo, build_ontology
8+
import jskos
9+
from jskos import ProcessedConcept, ProcessedKOS
810

911
__all__ = [
1012
"read_jskos",
13+
"from_pkos",
1114
]
1215

1316

1417
def read_jskos(path: str | Path, *, prefix: str, converter: curies.Converter | None = None) -> Obo:
1518
"""Read JSKOS into an ontology."""
19+
if converter is None:
20+
from ..identifier_utils import get_converter
21+
converter = get_converter()
22+
kos = jskos.read(path)
23+
pkos = jskos.process(kos, converter)
24+
return from_pkos(prefix=prefix, pkos=pkos)
25+
26+
27+
def from_pkos(prefix: str, pkos: ProcessedKOS) -> Obo:
28+
raise NotImplementedError
1629
return build_ontology(prefix=prefix)
30+
31+
32+
def _iterate_concepts(pkos: ProcessedKOS) -> list[ProcessedConcept]:
33+
for c in pkos.concepts:
34+
yield from _iterate_concepts_inner(c)
35+
36+
37+
def _iterate_concepts_inner(concept: ProcessedConcept):
38+
yield concept
39+
for narrower in concept.narrower:
40+
yield from _iterate_concepts_inner(concept)

src/pyobo/struct/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def _parse_reference_or_uri_literal(
277277
case BlocklistError():
278278
return None
279279
case UnparsableIRIError():
280-
# this means that it's defininitely a URI,
280+
# this means that it's definitely a URI,
281281
# but it couldn't be parsed with Bioregistry
282282
return OBOLiteral.uri(str_or_curie_or_uri)
283283
case NotCURIEError() as exc:

src/pyobo/utils/misc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
from typing import TYPE_CHECKING, TypeAlias
99

1010
import bioversions.utils
11-
1211
from pyobo.constants import ONTOLOGY_GETTERS, OntologyFormat
13-
14-
if TYPE_CHECKING:
15-
from bioregistry.schema.struct import AnnotatedURL
12+
from bioregistry.schema.struct import AnnotatedURL
1613

1714
__all__ = [
1815
"VERSION_GETTERS",
@@ -52,6 +49,8 @@
5249
"https://w3id.org/lehrplan/ontology/", # like in https://w3id.org/lehrplan/ontology/1.0.0-4
5350
"http://www.ebi.ac.uk/swo/version/", # http://www.ebi.ac.uk/swo/version/6.0
5451
"https://w3id.org/emi/version/",
52+
"https://nfdi4culture.de/ontology/", # https://nfdi4culture.de/ontology/3.0.0
53+
"http://purls.helmholtz-metadaten.de/mwo/mwo.owl/", # http://purls.helmholtz-metadaten.de/mwo/mwo.owl/3.0.0
5554
]
5655
VERSION_PREFIX_SPLITS = [
5756
"http://www.ebi.ac.uk/efo/releases/v",
@@ -60,6 +59,7 @@
6059
"http://ontology.neuinfo.org/NIF/ttl/nif/version/",
6160
"http://nmrml.org/cv/v", # as in http://nmrml.org/cv/v1.1.0/nmrCV
6261
"http://enanomapper.github.io/ontologies/releases/", # as in http://enanomapper.github.io/ontologies/releases/10.0/enanomapper
62+
"https://w3id.org/sulo/sulo-", # as in https://w3id.org/sulo/sulo-0.2.4.ttl
6363
]
6464
BAD = {
6565
"http://purl.obolibrary.org/obo",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for ingestion of JSKOS."""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Test JSKOS."""
2+
3+
import unittest
4+
from pyobo.struct.jskos_utils import read_jskos
5+
6+
import curies
7+
8+
URL = "https://skohub.io/KDSF-FFK/kdsf-ffk/heads/main/w3id.org/kdsf-ffk/index.json"
9+
10+
11+
class TestJSKOS(unittest.TestCase):
12+
"""Test JSKOS."""
13+
14+
def test_jskos(self) -> None:
15+
"""Test JSKOS."""
16+
converter = curies.Converter.from_prefix_map({
17+
"ksdf.fkk": "https://w3id.org/kdsf-ffk/",
18+
})
19+
ontology = read_jskos(prefix="ksdf.fkk", path=URL, converter=converter)
20+
names = ontology.get_id_name_mapping()
21+
self.assertIn("ArbeitUndWirtschaft", names)
22+
self.assertIn("Work and Economy", names["ArbeitUndWirtschaft"])

0 commit comments

Comments
 (0)