From ca8eaf801d49b75aba13a06ac9d54b6f53901e45 Mon Sep 17 00:00:00 2001 From: hkir-dev Date: Tue, 27 Jul 2021 14:28:53 +0100 Subject: [PATCH] #145 addind owl:versionInfo yyyy-mm-dd to imported and defined entities through extracting date from related ontology versionIRIs --- src/ontology/bdscratch.Makefile | 17 +++++++++++++++++ src/sparql/inject-version-info.ru | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/sparql/inject-version-info.ru diff --git a/src/ontology/bdscratch.Makefile b/src/ontology/bdscratch.Makefile index 99dbab33..e2414eee 100644 --- a/src/ontology/bdscratch.Makefile +++ b/src/ontology/bdscratch.Makefile @@ -29,6 +29,23 @@ dosdp_patterns_default: $(SRC) all_imports .FORCE $(PATTERNDIR)/data/default/%.txt: $(PATTERNDIR)/dosdp-patterns/%.yaml $(PATTERNDIR)/data/default/%.tsv .FORCE if [ $(PAT) = true ]; then $(DOSDPT) terms --prefixes=template_prefixes.yaml --infile=$(word 2, $^) --template=$< --obo-prefixes=true --outfile=$@; fi +# adding an extra query step to inject version info to imported entities +imports/%_import.owl: mirror/%.owl imports/%_terms_combined.txt + if [ $(IMP) = true ]; then $(ROBOT) query -i $< --update ../sparql/inject-version-info.ru --update ../sparql/preprocess-module.ru \ + extract -T imports/$*_terms_combined.txt --force true --copy-ontology-annotations true --individuals exclude --method BOT \ + query --update ../sparql/inject-subset-declaration.ru --update ../sparql/postprocess-module.ru \ + annotate --ontology-iri $(ONTBASE)/$@ $(ANNOTATE_ONTOLOGY_VERSION) --output $@.tmp.owl && mv $@.tmp.owl $@; fi + +# Full: The full artefacts with imports merged, reasoned. Added extra step to inject version info to entities +$(ONT)-full.owl: $(SRC) $(OTHER_SRC) + $(ROBOT) merge --input $< \ + reason --reasoner ELK --equivalent-classes-allowed all --exclude-tautologies structural \ + relax \ + reduce -r ELK \ + annotate --ontology-iri $(ONTBASE)/$@ $(ANNOTATE_ONTOLOGY_VERSION) \ + query --update ../sparql/inject-version-info.ru \ + --output $@.tmp.owl && mv $@.tmp.owl $@ + # hard wiring for now. Work on patsubst later mirror/ensmusg.owl: ../templates/ensmusg.tsv if [ $(MIR) = true ] && [ $(IMP) = true ]; then $(ROBOT) template --input bdscratch-edit.owl --template $< \ diff --git a/src/sparql/inject-version-info.ru b/src/sparql/inject-version-info.ru new file mode 100644 index 00000000..a2c8b0a2 --- /dev/null +++ b/src/sparql/inject-version-info.ru @@ -0,0 +1,26 @@ +PREFIX : +PREFIX owl: +PREFIX rdf: +PREFIX rdfs: +PREFIX dc: + +INSERT { + ?individual owl:versionInfo ?versionStr . + ?class owl:versionInfo ?versionStr . +} +WHERE { + ?ontology rdf:type owl:Ontology ; + owl:versionIRI ?versionIRI . + # regex matches date and the previous text in the iri. When replaced string after the date remains + BIND (REPLACE(str(?versionIRI), "^.*\\d{4}[\\-]\\d{2}[\\-]\\d{2}", "") AS ?dateTrailingStr) + # regex matches date and the trailing text in the iri. When replaced string before the date remains + BIND (REPLACE(str(?versionIRI), "\\d{4}[\\-]\\d{2}[\\-]\\d{2}.*$", "") AS ?dateHeadingStr) + # replace heading and trailing text in the versionIRI to remain only the date + BIND (REPLACE(str(?versionIRI), ?dateTrailingStr, "") AS ?versionSubStr) + BIND (REPLACE(str(?versionSubStr), ?dateHeadingStr, "") AS ?versionStr) + + ?class rdf:type owl:Class . + OPTIONAL { ?individual rdf:type owl:NamedIndividual . FILTER NOT EXISTS {?individual owl:versionInfo ?o1} } + FILTER (!isBlank(?class)) + FILTER NOT EXISTS {?class owl:versionInfo ?o2} +} \ No newline at end of file