forked from CommonCoreOntology/CommonCoreOntologies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
171 lines (139 loc) · 5.54 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
# Common Core Ontology Pipeline
# Adapted from previous works; see header comments for full attribution.
# Contact - John Beverley <johnbeve@buffalo.edu>
### Explanation ###
# The workflow involves two major steps: first, individual ontology files are checked and tested.
# After passing, they are merged into a single file, which is then checked and tested again.
# ----------------------------------------
# Project essentials
config.ONTOLOGY_PREFIX := CCO
config.BASE_IRI := https://www.commoncoreontologies.org/
config.DEV_IRI := $(config.BASE_IRI)/dev
config.MODULES_IRI := $(config.DEV_IRI)/modules
# Local project directories
config.SOURCE_DIR := src/
config.TEMP_DIR := build/artifacts
config.RELEASE_DIR := /
config.REPORTS_DIR := $(config.TEMP_DIR)
config.QUERIES_DIR := .github/deployment/sparql
config.LIBRARY_DIR := build/lib
# Settings
config.FAIL_ON_TEST_FAILURES := false
config.REPORT_FAIL_ON := none
# Branch-specific configurations
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
# File names for dev branch
DEV_FILES = \
src/cco-modules/AgentOntology.ttl \
src/cco-modules/ArtifactOntology.ttl \
src/cco-modules/CurrencyUnitOntology.ttl \
src/cco-modules/EventOntology.ttl \
src/cco-modules/ExtendedRelationOntology.ttl \
src/cco-modules/FacilityOntology.ttl \
src/cco-modules/GeospatialOntology.ttl \
src/cco-modules/QualityOntology.ttl \
src/cco-modules/UnitsOfMeasureOntology.ttl \
src/cco-modules/TimeOntology.ttl \
src/cco-modules/InformationEntityOntology.ttl
# File for combined ontology
combined-file := $(config.SOURCE_DIR)/MergedAllCoreOntology.ttl
# Other constants
TODAY := $(shell date +%Y-%m-%d)
TIMESTAMP := $(shell date +'%Y-%m-%d %H:%M')
# Default name for release
config.RELEASE_NAME := $(config.ONTOLOGY_PREFIX) $(TIMESTAMP)
# Generic files
EDITOR_BUILD_FILE = $(combined-file) # "editors ontology module"
EDITOR_REPORT_FILE = $(config.REPORTS_DIR)/$(config.ONTOLOGY_PREFIX)-edit-report.tsv
# Generic directories to create if needed
REQUIRED_DIRS = $(config.LIBRARY_DIR) $(config.SOURCE_DIR) $(config.QUERIES_DIR) $(config.REPORTS_DIR)
# ----------------------------------------
#### Targets / main "goals" of this Makefile
.PHONY: all
all: setup reason-individual test-individual build-combined reason-combined test-combined
# Setup target for creating necessary directories
.PHONY: setup
setup:
mkdir -p $(REQUIRED_DIRS) src/ .github/deployment/sparql build/artifacts
# Targets for dev branch - QC individual files and the combined file
# Download ROBOT JAR
ROBOT_FILE := $(config.LIBRARY_DIR)/robot.jar
$(ROBOT_FILE): setup
curl -L -o $@ https://github.com/ontodev/robot/releases/download/v1.8.4/robot.jar
chmod +x $@
# Reason individual files
.PHONY: reason-individual
reason-individual: $(ROBOT_FILE)
for file in $(DEV_FILES); do \
echo "Reasoning on $$file..."; \
java -jar $(ROBOT_FILE) reason --input $$file --catalog src/cco-modules/catalog-v001.xml --reasoner HermiT; \
done
# Test individual files
.PHONY: test-individual
test-individual: $(ROBOT_FILE)
for file in $(DEV_FILES); do \
echo "Testing $$file..."; \
java -jar $(ROBOT_FILE) verify --input $$file --output-dir $(config.REPORTS_DIR) --queries $(QUERIES) --fail-on-violation false || true; \
done
# Build combined file after individual files pass checks
$(combined-file): $(DEV_FILES)
cat $(DEV_FILES) > $@
# Build and QC combined file
.PHONY: build-combined
build-combined: $(combined-file)
.PHONY: reason-combined test-combined
reason-combined: $(combined-file) | $(ROBOT_FILE)
java -jar $(ROBOT_FILE) reason --input $(combined-file) --catalog src/cco-modules/catalog-v001.xml --reasoner HermiT
test-combined: $(combined-file) | $(ROBOT_FILE)
java -jar $(ROBOT_FILE) verify --input $(combined-file) --output-dir $(config.REPORTS_DIR) --queries $(QUERIES) --fail-on-violation false || true
.PHONY: report-edit
report-edit: TEST_INPUT = $(EDITOR_BUILD_FILE)
report-edit: REPORT_FILE_INPUT = $(EDITOR_REPORT_FILE)
report-edit: report
.PHONY: output-release-filepath
output-release-filepath:
@echo $(combined-file)
.PHONY: output-release-name
output-release-name:
@echo $(config.RELEASE_NAME)
# ----------------------------------------
#### Test / test ontology with reasoners and queries
QUERIES = $(wildcard $(config.QUERIES_DIR)/*.sparql)
# Check for inconsistency
.PHONY: reason
reason: $(TEST_INPUT) | $(ROBOT_FILE)
java -jar $(ROBOT_FILE) reason --input $(TEST_INPUT) --reasoner HermiT
# Test using specific queries
.PHONY: verify
verify: $(TEST_INPUT) $(QUERIES) | $(config.QUERIES_DIR) $(config.REPORTS_DIR) $(ROBOT_FILE)
ifeq ($(QUERIES),)
$(warning No query files found in $(config.QUERIES_DIR))
else
java -jar $(ROBOT_FILE) verify --input $(TEST_INPUT) --output-dir $(config.REPORTS_DIR) --queries $(QUERIES) --fail-on-violation false || true
endif
# Report using built-in ROBOT queries
.PHONY: report
report: $(TEST_INPUT) | $(config.REPORTS_DIR) $(ROBOT_FILE)
java -jar $(ROBOT_FILE) report --input $(TEST_INPUT) \
--labels true \
--fail-on $(config.REPORT_FAIL_ON) \
--print 10 \
--output $(REPORT_FILE_INPUT)
# ----------------------------------------
#### Setup / configure Make to use with our project
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
.SECONDARY:
# Create any of these directories if they don't exist
$(REQUIRED_DIRS):
mkdir -p $@
# Cleanup - Remove build and release files
.PHONY: clean
clean:
@[ "${config.REPORTS_DIR}" ] || ( echo ">> config.REPORTS_DIR is not set"; exit 1 )
rm -rf $(config.REPORTS_DIR)
rm -rf $(combined-file)