forked from BFO-Mappings/PROV-to-BFO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
204 lines (163 loc) · 8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#### Basic Ontology Pipeline
# https://github.com/tmprd/ontology-pipeline/
# Heavily adapted from https://github.com/obi-ontology/obi/blob/master/Makefile by James A. Overton <[email protected]>
# Tim Prudhomme <[email protected]>
# WARN: This file contains significant whitespace, i.e. tabs!
# Ensure that your text editor shows you those characters.
# ----------------------------------------
#### Configuration / details about our project
# Project essentials
config.ONTOLOGY_FILE := prov-mappings-edit.ttl
config.ONTOLOGY_PREFIX := prov-bfo-directmappings
config.ONTOLOGY-IRI := http://www.w3.org/ns/prov-bfo-directmappings
config.BASE_IRI := $(config.ONTOLOGY-IRI)_
config.DEV_IRI := $(config.ONTOLOGY-IRI)/dev
config.MODULES_IRI := $(config.DEV_IRI)/modules
# Local project directories
config.SOURCE_DIR := /
config.TEMP_DIR := build/artifacts
config.RELEASE_DIR := /
config.REPORTS_DIR := $(config.TEMP_DIR)
config.QUERIES_DIR := sparql
config.IMPORTS_DIR := $(config.SOURCE_DIR)/OntoFox_outputs
config.LIBRARY_DIR := ../build/lib
# Settings
# These will cause targets run by a Github Action to fail, if desired
config.FAIL_ON_TEST_FAILURES := false
config.REPORT_FAIL_ON := none
# Other constants
TODAY := $(shell date +%Y-%m-%d)
TIMESTAMP := $(shell date +'%Y-%m-%d %H:%M')
# Default name for release. Ideally this should incude some kind of semantic versioning
config.RELEASE_NAME := $(config.ONTOLOGY_PREFIX) $(TIMESTAMP)
# Generic files
EDITOR_BUILD_FILE = $(config.ONTOLOGY_FILE) # "editors ontology module" http://purl.obolibrary.org/obo/IAO_8000002
RELEASE_BUILD_FILE = $(config.ONTOLOGY_PREFIX).ttl # "main release ontology module" http://purl.obolibrary.org/obo/IAO_8000003
EDITOR_REPORT_FILE = $(config.REPORTS_DIR)/$(config.ONTOLOGY_PREFIX)-edit-report.tsv
RELEASE_REPORT_FILE = $(config.REPORTS_DIR)/$(config.ONTOLOGY_PREFIX)-release-report.tsv
# Generic directories to create if needed
REQUIRED_DIRS = $(config.TEMP_DIR) $(config.LIBRARY_DIR) $(config.SOURCE_DIR) $(config.QUERIES_DIR) $(config.REPORTS_DIR)
#--- Custom targets
# NOTE: diff is not needed anymore for the extension approach (we aren't editing PROV-O but extending it)
# SOURCE_ONTOLOGY_FILE := prov-bfo-merged/prov-o-original.ttl
# DIFF_REPORT_FILE := prov-bfo-merged/diff.md
# diff: $(RELEASE_BUILD_FILE)
# $(ROBOT) diff --left $(RELEASE_BUILD_FILE) --right $(SOURCE_ONTOLOGY_FILE) -output $(DIFF_REPORT_FILE)
MAPPINGS_FILE := prov-bfo-mappings.sssom.csv # csv for importing into google sheets
mappings:
$(ROBOT) query --input $(EDITOR_BUILD_FILE) -q $(config.QUERIES_DIR)/get-mappings.rq $(MAPPINGS_FILE) --use-graphs true
candidates:
$(ROBOT) query --input $(EDITOR_BUILD_FILE) -q $(config.QUERIES_DIR)/candidate-superproperties.rq $(config.TEMP_DIR)/candidate-superproperties.tsv --use-graphs true
# Materialize inferred mappings (after removing individuals) then check for unmapped terms
unmapped:
$(ROBOT) remove --input $(EDITOR_BUILD_FILE) --select individuals \
reason --reasoner HermiT --axiom-generators "SubClass SubObjectProperty InverseObjectProperties" --include-indirect true \
query --output-dir $(config.TEMP_DIR) --queries $(config.QUERIES_DIR)/unmapped-terms.rq --use-graph true
# Remove CCO individuals to speed up reasoner
config.CCO_FILENAME = ../MergedAllCoreOntology-v1.4-2023-04-07
config.CCO_FILE = $(config.CCO_FILENAME).ttl
config.CCO_EDITED_FILE = $(config.CCO_FILENAME)-no-individuals.ttl
prep-cco:
$(ROBOT) remove --input $(config.CCO_FILE) --select individuals --output $(config.CCO_EDITED_FILE)
# ----------------------------------------
#### Targets / main "goals" of this Makefile
.PHONY: all
#all: reason-edit test-edit build-release reason-release test-release mappings
# NOTE: We aren't building automatically building a release version, but instead editing & testing the release version directly
all: reason-edit test-edit mappings
build-release: $(RELEASE_BUILD_FILE)
# These are parameterized targets, which assign "target-specific variables" to be used in a resuable target
.PHONY: reason-edit reason-release test-edit test-release report-edit report-release
reason-edit test-edit report-edit explain-edit: TEST_INPUT = $(EDITOR_BUILD_FILE)
reason-release test-release report-release explain-release: TEST_INPUT = $(RELEASE_BUILD_FILE)
report-edit: REPORT_FILE_INPUT = $(EDITOR_REPORT_FILE)
report-release: REPORT_FILE_INPUT = $(RELEASE_REPORT_FILE)
# Map to reusable targets (this is a disjunction mapped to a conjunction: either target maps to all of these targets)
reason-edit reason-release: reason
explain-edit: explain
test-edit test-release: verify
report-edit report-release: report
# Output variables that are useful to a Github Action
.PHONY: output-release-filepath
output-release-filepath:
@echo $(RELEASE_BUILD_FILE)
.PHONY: output-release-version
output-release-name:
@echo $(config.RELEASE_NAME)
# ----------------------------------------
#### Setup / configure Make to use with our project
# Make configuration --- Ignore this section unless curious
# <http://clarkgrubb.com/makefile-style-guide#toc2>
MAKEFLAGS += --warn-undefined-variables
SHELL := bash # need bash to use `pipefail`
# `-e` causes exit if a command fails. `-u` causes exit for undefined variables. `-c` passes Make script to bash
# `pipefail` causes a chain of piped commands to fail if any of its commands fail
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all # default target running Make without arguments
.DELETE_ON_ERROR: # delete target if recipe fails
.SUFFIXES: # ignore default suffix rules
.SECONDARY: # keep all files created by pattern rules
# Create any of these directories if they don't exist
$(REQUIRED_DIRS):
mkdir -p $@
# ROBOT
ROBOT_FILE := $(config.LIBRARY_DIR)/robot.jar
$(ROBOT_FILE): | $(config.LIBRARY_DIR)
curl -L -o $@ https://github.com/ontodev/robot/releases/download/v1.9.5/robot.jar
ROBOT := java -jar $(ROBOT_FILE)
# Cleanup
.PHONY: clean
clean:
@[ "${config.TEMP_DIR}" ] || ( echo ">> config.TEMP_DIR is not set"; exit 1 )
rm -rf $(config.TEMP_DIR)
rm -rf $(RELEASE_BUILD_FILE)
# ----------------------------------------
#### Build / different versions of the ontology
# Release build has import declarations removed
$(RELEASE_BUILD_FILE): $(EDITOR_BUILD_FILE)
$(ROBOT) remove --input $< --select "imports individuals" \
reason --reasoner ELK \
annotate ${call annotation-inputs,$@,$@}
# Function (aka "canned recipe") using parameters to build arguments for `annnotate`
define annotation-inputs
--ontology-iri "$(config.ONTOLOGY-IRI)/$1" \
--version-iri "$(config.ONTOLOGY-IRI)/$(TODAY)/$1" \
--annotation owl:versionInfo "$(TODAY)" \
--output $2
endef
# ----------------------------------------
#### Test / test ontology with reasoners and queries
QUERIES = $(wildcard $(config.QUERIES_DIR)/*.rq)
# Check for inconsistency
# Note: $(TEST_INPUT) is a "target-specific variable" that isn't a evaluated as a prerequisite here
.PHONY: reason
reason: $(TEST_INPUT) | $(ROBOT_FILE)
$(ROBOT) reason --input $(TEST_INPUT) --reasoner HermiT
explain: $(TEST_INPUT) | $(ROBOT_FILE)
$(ROBOT) explain --input $(TEST_INPUT) --reasoner HermiT -M inconsistency --explanation inconsistency-explanation.md
# Test using specific queries
.PHONY: verify
verify: $(TEST_INPUT) $(QUERIES) | $(config.QUERIES_DIR) $(config.TEMP_DIR) $(ROBOT_FILE)
ifeq ($(QUERIES),)
$(warning No query files found in $(config.QUERIES_DIR))
else
$(ROBOT) verify --input $(TEST_INPUT) --output-dir $(config.TEMP_DIR) --queries $(QUERIES) --fail-on-violation $(config.FAIL_ON_TEST_FAILURES)
endif
# Report using built-in ROBOT queries
.PHONY: report
report: $(TEST_INPUT) | $(config.REPORTS_DIR) $(ROBOT_FILE)
$(ROBOT) report --input $(TEST_INPUT) \
--labels true \
--fail-on $(config.REPORT_FAIL_ON) \
--print 10 \
--output $(REPORT_FILE_INPUT)
# ----------------------------------------
#### Make syntax cheatsheet
# targets
# .PHONY means a target that isn't a file to be created or checked
# automatic variables
# $@ means target
# $< means first prerequisite
# $^ means all prerequisites
# := means simply expand
# = means recursively/lazily expand