Skip to content

Commit

Permalink
Merge pull request #11 from sentier-dev/ci
Browse files Browse the repository at this point in the history
Add script to generate output files
  • Loading branch information
tngTUDOR authored Oct 9, 2024
2 parents 811ed2b + b7ac116 commit 2a772ed
Show file tree
Hide file tree
Showing 6 changed files with 794 additions and 4 deletions.
77 changes: 77 additions & 0 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# This script generates all output data from the input files in this repository.
#
# If executed without arguments, it downloads the required external files and
# executes all generators:
#
# $ scripts/generate.sh
#
# The `fetch` and `generate` sub-commands can be used to execute individual
# stages:
#
# $ scripts/generate.sh fetch
# $ scripts/generate.sh generate nace
set -euo pipefail

GENERATORS=(
qudt
combined_nomenclature
envo
model_terms
open_energy_ontology
custom_products
)

declare -A GENERATOR_ARGS
GENERATOR_ARGS=(
[combined_nomenclature]=sentier_vocab/CN_2024.rdf
)

main() {
[[ "$#" -eq 0 ]] && set -- all
local cmd=$1; shift
case "$cmd" in
all) fetch; generate;;
fetch) fetch "$@";;
generate) generate "$@";;
*) usage;;
esac
}

usage() {
echo >&2 <<EOF
Usage: $0 [CMD [ARG...]]
Commands:
[all]
fetch
generate [MODULE...]
EOF
return 1
}

fetch() {
[[ "$#" -eq 0 ]] || usage
echo == CN_2024.rdf.zip ==
curl \
--silent --show-error \
--cookie-jar cookies.txt --output /dev/null \
--data 'email=public%40showvoc.eu&password=showvoc' \
'https://showvoc.op.europa.eu/semanticturkey/it.uniroma2.art.semanticturkey/st-core-services/Auth/login'
curl \
--cookie cookies.txt --output CN_2024.rdf.zip \
'https://showvoc.op.europa.eu/semanticturkey/it.uniroma2.art.semanticturkey/st-core-services/Download/getFile?fileName=CN_2024.rdf.zip&ctx_project=ESTAT_Combined_Nomenclature%2C_2024_(CN_2024)'
unzip -u CN_2024.rdf.zip
}

generate() {
[[ "$#" -eq 0 ]] && set -- "${GENERATORS[@]}"
local x
for x; do
echo "== $x =="
python -m "sentier_vocab.$x" ${GENERATOR_ARGS[$x]-}
done
}

main "$@"
4 changes: 2 additions & 2 deletions sentier_vocab/combined_nomenclature.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ def CN2024(filepath: Path):
skosify.infer.skos_hierarchical(graph, narrower=True)
skosify.infer.skos_transitive(graph, narrower=True)

output_path = filepath.with_suffix(".ttl")
output_path = Path(__file__).parent / "output" / Path(str(filepath.stem) + ".ttl")
logger.info("Writing output TTL file {}", output_path)
graph.serialize(destination=output_path)
return filepath.with_suffix(".ttl")
return output_path


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion sentier_vocab/envo.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ def write_graph(


if __name__ == "__main__":
ENVO().write_graph()
ENVO().write_graph(dirpath = Path(__file__).parent / "output")
Loading

0 comments on commit 2a772ed

Please sign in to comment.