Skip to content

Commit f508280

Browse files
committed
Add recipes and instructions to build ontology
References: * [AC-210] Add validation command to CASE-Utilities-Python * [ONT-445] (CP-38) rdf-toolkit base-iri flag degenerates versionIRI when slash IRI form is used Signed-off-by: Alex Nelson <[email protected]>
1 parent 73800db commit f508280

File tree

7 files changed

+162
-6
lines changed

7 files changed

+162
-6
lines changed

CONTRIBUTE.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Contributing to CASE-Utilities-Python
2+
3+
4+
## Deploying a new ontology version
5+
6+
1. After cloning this repository, ensure the CASE submodule is checked out. This can be done with either `git submodule init && git submodule update`, `make .git_submodule_init.done.log`, or `make check`.
7+
2. Update the CASE submodule pointer to the new tagged release.
8+
3. The version of CASE is also hard-coded in [`case_utils/ontology/version_info.py`](case_utils/ontology/version_info.py). Edit the variable `CURRENT_CASE_VERSION`.
9+
4. From the top source directory, run `make clean`. This guarantees a clean state of this repository as well as the ontology submodules.
10+
5. Still from the top source directory, run `make`.
11+
6. Any new `.ttl` files will be created under [`case_utils/ontology/`](case_utils/ontology/). Use `git add` to add each of them. (The patch-weight of these files could overshadow manual revisions, so it is fine to commit the built files after the manual changes are committed.)
12+
13+
Here is a sample sequence of shell commands to run the build:
14+
15+
```bash
16+
# (Starting from fresh `git clone`.)
17+
make check
18+
pushd dependencies/CASE
19+
git checkout master
20+
git pull
21+
popd
22+
git add dependencies/CASE
23+
# (Here, edits should be made to case_utils/ontology/version_info.py)
24+
make
25+
pushd case_utils/ontology
26+
git add case-0.6.0.ttl # Assuming CASE 0.6.0 was just released.
27+
# and/or
28+
git add uco-0.8.0.ttl # Assuming UCO 0.8.0 was adopted in CASE 0.6.0.
29+
popd
30+
make check
31+
# Assuming `make check` passes:
32+
git commit -m "Update CASE ontology pointer to version 0.6.0" dependencies/CASE case_utils/ontology/version_info.py
33+
git commit -m "Build CASE 0.6.0.ttl" case_utils/ontology/case-0.6.0.ttl
34+
```

Makefile

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ SHELL := /bin/bash
1515

1616
PYTHON3 ?= $(shell which python3.9 2>/dev/null || which python3.8 2>/dev/null || which python3.7 2>/dev/null || which python3.6 2>/dev/null || which python3)
1717

18-
all:
18+
case_version := $(shell $(PYTHON3) case_utils/ontology/version_info.py)
19+
ifeq ($(case_version),)
20+
$(error Unable to determine CASE version)
21+
endif
22+
23+
all: \
24+
.ontology.done.log
1925

2026
.PHONY: \
2127
download
@@ -38,10 +44,25 @@ all:
3844
test -r dependencies/CASE/ontology/master/case.ttl \
3945
|| (git submodule init dependencies/CASE && git submodule update dependencies/CASE)
4046
test -r dependencies/CASE/ontology/master/case.ttl
47+
$(MAKE) \
48+
--directory dependencies/CASE \
49+
.git_submodule_init.done.log \
50+
.lib.done.log
51+
touch $@
52+
53+
.ontology.done.log: \
54+
dependencies/CASE/ontology/master/case.ttl
55+
# Do not rebuild the current ontology file if it is already present. It is expected not to change once built.
56+
# touch -c: Do not create the file if it does not exist. This will convince the recursive make nothing needs to be done if the file is present.
57+
touch -c case_utils/ontology/case-$(case_version).ttl
58+
$(MAKE) \
59+
--directory case_utils/ontology
60+
# Confirm the current monolithic file is in place.
61+
test -r case_utils/ontology/case-$(case_version).ttl
4162
touch $@
4263

4364
check: \
44-
.git_submodule_init.done.log
65+
.ontology.done.log
4566
$(MAKE) \
4667
PYTHON3=$(PYTHON3) \
4768
--directory tests \
@@ -52,7 +73,8 @@ clean:
5273
--directory tests \
5374
clean
5475
@rm -f \
55-
.git_submodule_init.done.log
76+
.*.done.log
77+
@# 'clean' in the ontology directory should only happen when testing and building new ontology versions. Hence, it is not called from the top-level Makefile.
5678
@test ! -r dependencies/CASE/README.md \
5779
|| @$(MAKE) \
5880
--directory dependencies/CASE \
@@ -71,6 +93,12 @@ clean:
7193
dependencies/CASE-Examples-QC/.git_submodule_init.done.log \
7294
dependencies/CASE-Examples-QC/.lib.done.log
7395

96+
# This recipe guarantees timestamp update order, and is otherwise intended to be a no-op.
97+
dependencies/CASE/ontology/master/case.ttl: \
98+
.git_submodule_init.done.log
99+
test -r $@
100+
touch $@
101+
74102
distclean: \
75103
clean
76104
@rm -rf \

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ This project follows [SEMVER 2.0.0](https://semver.org/) where versions are decl
8686

8787
## Ontology versions supported
8888

89-
This repository supports the CASE ontology version that is linked as a submodule [here](dependencies/CASE). Currently, the ontology versions are:
89+
This repository supports the CASE ontology version that is linked as a submodule [here](dependencies/CASE). The CASE version is encoded as a variable (and checked in unit tests) in [`case_utils/ontology/version_info.py`](case_utils/ontology/version_info.py), and used throughout this code base, as `CURRENT_CASE_VERSION`.
9090

91-
* CASE - 0.5.0
92-
* UCO - 0.7.0
91+
For instructions on how to update the CASE version for an ontology release, see [`CONTRIBUTE.md`](CONTRIBUTE.md).
9392

9493

9594
## Repository locations

case_utils/ontology/Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/make -f
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
SHELL := /bin/bash
15+
16+
top_srcdir := $(shell cd ../.. ; pwd)
17+
18+
case_srcdir := $(top_srcdir)/dependencies/CASE
19+
20+
uco_srcdir := $(case_srcdir)/dependencies/UCO
21+
22+
RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar
23+
24+
case_version := $(shell python3 version_info.py)
25+
26+
all: \
27+
case-$(case_version).ttl
28+
29+
case-$(case_version).ttl: \
30+
$(top_srcdir)/.git_submodule_init.done.log \
31+
$(RDF_TOOLKIT_JAR)
32+
$(MAKE) \
33+
--directory $(case_srcdir)/tests \
34+
case_monolithic.ttl
35+
#TODO This cleanup step should be removed after the 0.3.0 release of CASE-Utility-SHACL-Inheritance-Reviewer.
36+
test ! -d $(uco_srcdir)/dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/build \
37+
|| rm -rf \
38+
$(uco_srcdir)/dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/build
39+
#TODO This normalization step will not be needed after resolution of ONT-445.
40+
java -jar $(RDF_TOOLKIT_JAR) \
41+
--inline-blank-nodes \
42+
--source $(case_srcdir)/tests/case_monolithic.ttl \
43+
--source-format turtle \
44+
--target _$@ \
45+
--target-format turtle
46+
mv _$@ $@
47+
48+
clean:
49+
@rm -f case-$(case_version).ttl

case_utils/ontology/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This software was developed at the National Institute of Standards
2+
# and Technology by employees of the Federal Government in the course
3+
# of their official duties. Pursuant to title 17 Section 105 of the
4+
# United States Code this software is not subject to copyright
5+
# protection and is in the public domain. NIST assumes no
6+
# responsibility whatsoever for its use by other parties, and makes
7+
# no guarantees, expressed or implied, about its quality,
8+
# reliability, or any other characteristic.
9+
#
10+
# We would appreciate acknowledgement if the software is used.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
"""
15+
This program serves two roles:
16+
1. As a module, it houses the hard-coded values for the current CASE version packaged with case_utils.
17+
2. As a script, it prints that version when called.
18+
19+
When preparing to build a new monolithic ontology, please edit this variable to match the new respective version.
20+
"""
21+
22+
__version__ = "0.1.0"
23+
24+
__all__ = [
25+
"CURRENT_CASE_VERSION"
26+
]
27+
28+
# Tested with CI to match versionInfo of <https://ontology.caseontology.org/case/case>.
29+
CURRENT_CASE_VERSION : str = "0.5.0"
30+
31+
def main() -> None:
32+
print(CURRENT_CASE_VERSION)
33+
34+
if __name__ == "__main__":
35+
main()

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ console_scripts =
3232

3333
[options.package_data]
3434
case_utils = py.typed
35+
case_utils.ontology = *.ttl

0 commit comments

Comments
 (0)