Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import from web instead of local files #27

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dic2owl/dic2owl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
__version__ = "0.1.0"
__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"
)
29 changes: 21 additions & 8 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,17 +16,18 @@

from CifFile import CifDic

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 @@ -36,9 +40,18 @@ class Generator:
URI or file name of the cif_top ontology that will be imported.
"""

def __init__(self, dicfile, base_iri, cif_top="cif_top.ttl"):
def __init__(self, dicfile, base_iri, cif_top=None):
self.cd = CifDic(dicfile, do_dREL=False)
self.cif_top = ontology_dir() / cif_top
if not cif_top:
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:
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
raise TypeError(
f"`cif_top` must be either a string or a PathType. Got type {type(cif_top)!r}"
)
self.categories = set()
CasperWA marked this conversation as resolved.
Show resolved Hide resolved

# Load cif_top ontology
Expand Down