Skip to content

Commit

Permalink
Add or modify Makefile recipes to enable regeneration of *.rdf files …
Browse files Browse the repository at this point in the history
…and retain expected *.ttl files content

`rdfpipe` utility is now used to regenerate *.rdf files what results in the
duplicated imports being discarded. Changes were made in Makefile file and
affects generation of *.rdf artefacts (owl-core, owl-restrictions and shacl
Makefile recipes) as well as conversion of these to TTL format
(convert-rdf-to-turtle). The latter were needed to keep the same TTL output
when using the new *.rdf files.

Scope of the changes:
* New generic convert-between-serialization-formats Makefile recipe
* The existing owl-core, owl-restrictions and shacl Makefile recipes now include an RDF regeneration step
* The existing convert-rdf-to-turtle Makefile recipe now uses the same namespaces that are used for XSLT transformation (test/ePO-default-config/namespaces.xml) to provide rdfpipe with prefixes so the output makes use of compact URIs.
* As the reported issue occurs for EPO v4.2.0 which introduces some new prefixes, these prefixes have also been added to test/ePO-default-config/namespaces.xml so it would be possible to reproduce the fix.
  • Loading branch information
gkostkowski committed Sep 18, 2024
1 parent ca63046 commit abde78b
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
65 changes: 61 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ TURTLE_FILELIST=$(shell ls ${ONTOLOGY_FOLDER_PATH}/*.ttl)
# Widoco variables
WIDOCO_RDF_INPUT_FILE_PATH?=test/reasoning-investigation/model-2020-12-16/ePO_restrictions.rdf
WIDOCO_OUTPUT_FOLDER_PATH?=output/widoco
NAMESPACES_AS_RDFPIPE_ARGS=$(shell ${MODEL2OWL_FOLDER}/scripts/get_namespaces.sh)
RDF_XML_MIME_TYPE:='application/rdf+xml'
TURTLE_MIME_TYPE:='turtle'

# download saxon library
get-saxon:
Expand Down Expand Up @@ -110,17 +113,37 @@ generate-convention-SVRL-report:
#Example how to run transformation commands :
# make owl-core XMI_INPUT_FILE_PATH=/home/mypc/work/model2owl/eNotice_CM.xml OUTPUT_FOLDER_PATH=./my-folder
owl-core:
@java -jar ${SAXON} -s:${XMI_INPUT_FILE_PATH} -xsl:${MODEL2OWL_FOLDER}/src/owl-core.xsl -o:${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}.rdf
@java -jar ${SAXON} -s:${XMI_INPUT_FILE_PATH} -xsl:${MODEL2OWL_FOLDER}/src/owl-core.xsl \
-o:${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}.tmp.rdf
@make convert-between-serialization-formats INPUT_FORMAT=${RDF_XML_MIME_TYPE} \
OUTPUT_FORMAT=${RDF_XML_MIME_TYPE} \
FILE_PATH=${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}.tmp.rdf \
OUTPUT_FILE_PATH=${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}.rdf
@echo Output owl core file:
@ls -lh ${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}.rdf
@rm -f ${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}.tmp.rdf

owl-restrictions:
@java -jar ${SAXON} -s:${XMI_INPUT_FILE_PATH} -xsl:${MODEL2OWL_FOLDER}/src/owl-restrictions.xsl -o:${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_restrictions.rdf
@java -jar ${SAXON} -s:${XMI_INPUT_FILE_PATH} -xsl:${MODEL2OWL_FOLDER}/src/owl-restrictions.xsl \
-o:${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_restrictions.tmp.rdf
@make convert-between-serialization-formats INPUT_FORMAT=${RDF_XML_MIME_TYPE} \
OUTPUT_FORMAT=${RDF_XML_MIME_TYPE} \
FILE_PATH=${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_restrictions.tmp.rdf \
OUTPUT_FILE_PATH=${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_restrictions.rdf
@echo Output owl restrictions file:
@ls -lh ${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_restrictions.rdf
@rm -f ${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_restrictions.tmp.rdf

shacl:
@java -jar ${SAXON} -s:${XMI_INPUT_FILE_PATH} -xsl:${MODEL2OWL_FOLDER}/src/shacl-shapes.xsl -o:${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_shapes.rdf
@java -jar ${SAXON} -s:${XMI_INPUT_FILE_PATH} -xsl:${MODEL2OWL_FOLDER}/src/shacl-shapes.xsl \
-o:${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_shapes.tmp.rdf
@make convert-between-serialization-formats INPUT_FORMAT=${RDF_XML_MIME_TYPE} \
OUTPUT_FORMAT=${RDF_XML_MIME_TYPE} \
FILE_PATH=${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_shapes.tmp.rdf \
OUTPUT_FILE_PATH=${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_shapes.rdf
@echo Output shacl file location:
@ls -lh ${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_shapes.rdf
@rm -f ${OUTPUT_FOLDER_PATH}/${XMI_INPUT_FILENAME_WITHOUT_EXTENSION}_shapes.tmp.rdf


# Combine xmi UML files
Expand All @@ -144,7 +167,12 @@ convert-rdf-to-turtle:
@for FILE_PATH in ${RDF_FILELIST}; do \
echo Converting $${FILE_PATH} into Turtle; \
source model2owl-venv/bin/activate; \
rdfpipe -i application/rdf+xml -o turtle $${FILE_PATH} > $${FILE_PATH%.*}.ttl; \
make convert-between-serialization-formats \
INPUT_FORMAT=${RDF_XML_MIME_TYPE} \
OUTPUT_FORMAT=${TURTLE_MIME_TYPE} \
FILE_PATH=$${FILE_PATH} \
OUTPUT_FILE_PATH=$${FILE_PATH%.*}.ttl \
USE_NAMESPACES=1; \
echo Input in RDF/XML format; \
echo $${FILE_PATH}; \
echo " ==> Output in Turtle format"; \
Expand Down Expand Up @@ -182,6 +210,35 @@ convert-rdf-to-rdf:
echo " ==> Output in RDF/XML format"; \
ls -lh $${FILE_PATH%.*}.rdf; \
done

# A generic recipe for converting RDF data from one serialization format to
# another. It can also be used to regenerate a file using the same format.
#
# Arguments:
# FILE_PATH: Input RDF file in any allowed serialization format
# OUTPUT_FILE_PATH: Path for the output file
# INPUT_FORMAT: a MIME type of the given input RDF file
# OUTPUT_FORMAT: a MIME type of any of the valid RDF serializations
# USE_NAMESPACES: optional; if non-empty then namespaces (from the namespaces.xml file).
# This can be used if the input (FILE_PATH) doesn't include
# namespaces we want to be applied (e.g. to have compact
# instead of full URIs in the output file).
#
# Supported MIME types: https://rdflib.readthedocs.io/en/7.0.0/plugin_serializers.html
#
# Example:
# make convert-between-serialization-formats
# INPUT_FORMAT='application/rdf+xml'
# OUTPUT_FORMAT='application/rdf+xml'
# FILE_PATH=output/ePO_core.tmp.rdf
# OUTPUT_FILE_PATH=output/ePO_core.rdf
# USE_NAMESPACES=1
convert-between-serialization-formats:
@source model2owl-venv/bin/activate; \
rdfpipe -i ${INPUT_FORMAT} -o ${OUTPUT_FORMAT} \
$(if $(USE_NAMESPACES),${NAMESPACES_AS_RDFPIPE_ARGS}) \
${FILE_PATH} > ${OUTPUT_FILE_PATH}

# make validate-rdf-file FILE_TO_VALIDATE_PATH=./output/eFulfilment.rdf
validate-rdf-file:
@$(JENA_RIOT_TOOL) --validate $(FILE_TO_VALIDATE_PATH)
Expand Down
20 changes: 20 additions & 0 deletions scripts/get_namespaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
#
# Gets namespaces from namespaces.xml file and prepares argument
# list from them to be used with `rdfpipe` tool.
# Uses Saxon installed in the project main directory.

PROJECT_DIR=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})))
NAMESPACES_DIR=${PROJECT_DIR}/test/ePO-default-config

cd ${NAMESPACES_DIR}
namespaces=$(
java -cp ../../saxon/saxon.jar net.sf.saxon.Query -s:namespaces.xml \
-qs:'for $x in /*:prefixes/*:prefix return concat(string($x/@name), "=", string($x/@value))' \
\!method=text
)
ns_args=$( \
echo "$namespaces" | tr ' ' '\n' | awk '{printf("--ns='\''%s'\'' ", $0)}'
)

echo "$ns_args"
11 changes: 8 additions & 3 deletions test/ePO-default-config/namespaces.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@
<prefix name="dct" value="http://purl.org/dc/terms/" importURI="http://purl.org/dc/terms/"/>
<prefix name="org" value="http://www.w3.org/ns/org#"/>
<prefix name="skos" value="http://www.w3.org/2004/02/skos/core#" importURI="http://www.w3.org/2004/02/skos/core#"/>
<prefix name="eli" value="http://data.europa.eu/eli/ontology#"/>

<prefix name="epo" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-acc" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-cat" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-con" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-ord" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-not" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-ful" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-inv" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-not" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-ord" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="epo-sub" value="http://data.europa.eu/a4g/ontology#"/>
<prefix name="core-shape" value="http://data.europa.eu/a4g/data-shape#"/>

<prefix name="nuts" value="http://data.europa.eu/nuts/"/>
<prefix name="reg2015" value="http://data.europa.eu/a4g/extension/ontology#"/>
<prefix name="espd" value="https://github.com/ESPD/ESPD-EDM/"/>
<prefix name="at-voc" value="http://publications.europa.eu/resource/authority/"/>
<prefix name="time" value="http://www.w3.org/2006/time#"/>
<prefix name="locn" value="http://www.w3.org/ns/locn#"/>
<prefix name="cccev" value="http://data.europa.eu/m8g/" importURI="https://data.europa.eu/m8g"/>
<prefix name="cv" value="http://data.europa.eu/m8g/" importURI="https://data.europa.eu/m8g"/>
<prefix name="core" value="http://data.europa.eu/m8g/"/>
<prefix name="cpv" value="http://data.europa.eu/m8g/"/>
<prefix name="cpsv" value="http://data.europa.eu/m8g/"/>
<prefix name="cpov" value="http://data.europa.eu/m8g/"/>
<prefix name="cccev" value="http://data.europa.eu/m8g/" importURI="https://data.europa.eu/m8g"/>
<prefix name="geosparql" value="http://www.opengis.net/ont/geosparql#"/>
<prefix name="dul" value="http://www.loa-cnr.it/ontologies/DUL.owl#"/>
<prefix name="person" value="http://www.w3.org/ns/person#"/>
Expand Down

0 comments on commit abde78b

Please sign in to comment.