diff --git a/dic2owl/dic2owl/__init__.py b/dic2owl/dic2owl/__init__.py index fef08f7..7dd380a 100644 --- a/dic2owl/dic2owl/__init__.py +++ b/dic2owl/dic2owl/__init__.py @@ -2,5 +2,7 @@ __author__ = "Jesper Friis" __author_email__ = "jesper.friis@sintef.no" +__ontology_version__ = "0.0.1" + # Where versioned releases can be downloaded from release_site = 'https://raw.githubusercontent.com/emmo-repo/CIF-ontology/gh-pages/versions' diff --git a/dic2owl/dic2owl/generate_cif.py b/dic2owl/dic2owl/generate_cif.py index 7dae3b7..4dce907 100644 --- a/dic2owl/dic2owl/generate_cif.py +++ b/dic2owl/dic2owl/generate_cif.py @@ -1,5 +1,8 @@ #!/usr/bin/env python -"""Python script for generating an ontology corresponding to a CIF dictionary. +""" +# Generate ontology + +Python script for generating an ontology corresponding to a CIF dictionary. """ from pathlib import Path import textwrap @@ -13,7 +16,11 @@ from CifFile import CifDic -from __init__ import __version__, release_site +from dic2owl import __ontology_version__, release_site + + +"""Return the absolute, normalized path to the `ontology` directory in this repository""" +ONTOLOGY_DIR = Path(__file__).parent.parent.parent.joinpath("ontology").resolve() def en(s): @@ -21,11 +28,6 @@ def en(s): return locstr(s, lang="en") -def ontology_dir() -> Path: - """Return the absolute, normalized path to the `ontology` directory in this repository""" - return Path(__file__).parent.parent.parent.joinpath("ontology").resolve() - - class Generator: """Class for generating CIF ontology from a CIF dictionary. @@ -41,11 +43,15 @@ class Generator: def __init__(self, dicfile, base_iri, cif_top=None): self.cd = CifDic(dicfile, do_dREL=False) if not cif_top: - self.cif_top = f'{release_site}/{__version__}/cif_top.ttl' - elif cif_top.startswith('http'): + self.cif_top = f'{release_site}/{__ontology_version__}/cif_top.ttl' + elif isinstance(cif_top, str) and cif_top.startswith('http'): self.cif_top = cif_top + elif isinstance(cif_top, (Path, str)): + self.cif_top = ONTOLOGY_DIR / cif_top else: - self.cif_top = ontology_dir() / cif_top + raise TypeError( + f"`cif_top` must be either a string or a PathType. Got type {type(cif_top)!r}" + ) self.categories = set() # Load cif_top ontology