Skip to content

Commit

Permalink
Merge pull request #181 from emmo-repo/cwa/add-Word
Browse files Browse the repository at this point in the history
Add new `Word` content type.
Adds Word in a similar fashion as Code and similar.

---

When storing the Turtle file (cif-ddl.ttl) from Protégé it
changed the formatting. In order to understand the
actual change(s), I have split it up into several commits.

To see the purely formatting changes, see a34fd90.
To see the addition of Word, see d47bf00.

---

Updates to minimum v4.4.6 of PyCIFRW.

---

This PR goes a small step further and updates the cif-core.ttl
file under ontologies/ to the latest generated version of the
CIF-ontology according to the updated cif_core.dic in
COMCIFS and the newly added Word content type.
  • Loading branch information
CasperWA authored Nov 9, 2023
2 parents 56c5901 + 2368db1 commit 17281e9
Show file tree
Hide file tree
Showing 6 changed files with 28,450 additions and 1,602 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ __pycache__
*.dic
*.cif

dist/
site/

*.properties

!test-cif/**/*.cif
!tests/**/*.dic

Expand Down
14 changes: 13 additions & 1 deletion dic2owl/dic2owl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ def main(argv: "Optional[List[str]]" = None) -> None:
"to the CIF_DIC file."
),
)
parser.add_argument(
"--local-ontologies",
action="store_true",
help=(
"Use local ontologies instead of the latest commit on GitHub. "
"This is mainly for debugging purposes."
),
)
parser.add_argument(
"dicfile",
metavar="CIF_DIC",
Expand All @@ -84,4 +92,8 @@ def main(argv: "Optional[List[str]]" = None) -> None:
# downloaded.
args.dicfile = str(args.dicfile)

dic2owl_run(dicfile=args.dicfile, ttlfile=args.ttlfile)
dic2owl_run(
dicfile=args.dicfile,
ttlfile=args.ttlfile,
local_ontologies=args.local_ontologies,
)
33 changes: 23 additions & 10 deletions dic2owl/dic2owl/dic2owl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from contextlib import redirect_stderr
from os import devnull as DEVNULL
from pathlib import Path

# import textwrap
import types
from typing import TYPE_CHECKING
import urllib.request
Expand Down Expand Up @@ -61,28 +59,35 @@ class MissingAnnotationError(Exception):
"""Raised when using a cif-dictionary annotation not defined in ddl"""


# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods,too-many-instance-attributes
class Generator:
"""Class for generating CIF ontology from a CIF dictionary.
Parameters:
dicfile: File name of CIF dictionary to generate an ontology for.
base_iri: Base IRI of the generated ontology.
comments: Sequence of comments to add to the ontology itself.
local_ddl: If `True`, the CIF DDL ontology will be loaded from the
local repository.
"""

CIF_DDL = (
"https://raw.githubusercontent.com/emmo-repo/CIF-ontology/main/"
"ontology/cif-ddl.ttl"
)
cif_ddl: str

def __init__(
self,
dicfile: "StrPath",
base_iri: str,
comments: "Sequence[str]" = (),
local_ddl: bool = False,
) -> None:
self.cif_ddl = (
(ONTOLOGY_DIR / "cif-ddl.ttl").as_uri()
if local_ddl
else "https://raw.githubusercontent.com/emmo-repo/CIF-ontology/main/"
"ontology/cif-ddl.ttl"
)

self.dicfile = dicfile
self.dic = CifDic(str(self.dicfile), do_dREL=False)
self.comments = comments
Expand All @@ -92,7 +97,7 @@ def __init__(
self.onto = self.world.get_ontology(base_iri)

# Load cif-ddl ontology and append it to imported ontologies
self.ddl = self.world.get_ontology(self.CIF_DDL).load()
self.ddl = self.world.get_ontology(self.cif_ddl).load()
self.ddl.sync_python_names()
self.onto.imported_ontologies.append(self.ddl)

Expand Down Expand Up @@ -223,7 +228,9 @@ def _add_metadata(self) -> None:


def main(
dicfile: "Union[str, Path]", ttlfile: "Union[str, Path]"
dicfile: "Union[str, Path]",
ttlfile: "Union[str, Path]",
local_ontologies: bool = False,
) -> Generator:
"""Main function for ontology generation.
Expand All @@ -238,6 +245,10 @@ def main(
!!! important
The file will be overwritten if it already exists.
local_ontologies: If `True`, the ontologies used to generate the
ontology will be loaded from the local repository.
If `False`, the ontologies will be loaded from the latest commit in
the `main` branch on GitHub.
Returns:
The setup ontology generator class. This is mainly returned for
Expand All @@ -257,7 +268,9 @@ def main(
# `file://` or similar.
urllib.request.urlretrieve(baseurl + dic, dic) # nosec

gen = Generator(dicfile=dicfile, base_iri=base_iri)
gen = Generator(
dicfile=dicfile, base_iri=base_iri, local_ddl=local_ontologies
)
onto = gen.generate()
onto.save(
ttlfile if isinstance(ttlfile, str) else str(ttlfile.resolve()),
Expand Down
2 changes: 1 addition & 1 deletion dic2owl/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
EMMOntoPy>=0.6.0,<1
PyCifRW>=4.4.5,<5
PyCifRW>=4.4.6,<5
Loading

0 comments on commit 17281e9

Please sign in to comment.