Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Aug 18, 2021
1 parent 8324be8 commit e802a0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions dic2owl/dic2owl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
__author__ = "Jesper Friis"
__author_email__ = "[email protected]"

__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'
26 changes: 16 additions & 10 deletions dic2owl/dic2owl/generate_cif.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,19 +16,18 @@

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):
"""Returns `s` converted to a localised string in english."""
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.
Expand All @@ -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
Expand Down

0 comments on commit e802a0f

Please sign in to comment.