Skip to content

Commit

Permalink
Formatter / EU-DCAT-AP / Add 2.1.1 base shacl validation level.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Dec 15, 2023
1 parent d8b4c7a commit e3d2780
Show file tree
Hide file tree
Showing 8 changed files with 7,817 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@
<xsl:attribute name="rdf:resource" select="*/mri:metadataReference/@xlink:href"/>
</xsl:when>
<xsl:when test="*/mri:metadataReference/@uuidref">
<!-- TODO: Here we need a URI? -->
<!-- TODO: Here we need a not relative URI? -->
<xsl:attribute name="rdf:resource" select="*/mri:metadataReference/@uuidref"/>
</xsl:when>
<xsl:otherwise>
<!-- TODO: Here we need a URI? -->
<!-- TODO: Here we need a not relative URI? -->
<xsl:attribute name="rdf:resource" select="*/mri:aggregateDataSetIdentifier/*/mri:code/*/text()"/>
</xsl:otherwise>
</xsl:choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<!-- Create resource -->
<xsl:template mode="iso19115-3-to-dcat"
match="mdb:MD_Metadata">
<rdf:Description>
<rdf:Description rdf:about="{$recordUri}">
<xsl:apply-templates mode="iso19115-3-to-dcat"
select="mdb:metadataScope/*/mdb:resourceScope/*/@codeListValue"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,38 +156,36 @@ public void checkFormatter() throws Exception {
}

if("eu-dcat-ap".equalsIgnoreCase(formatter)){
//Test against SHACL rules
//Load SHACL Shapes (rules) for DCAT-AP 3.0
String SHAPES = FormatterApiTest.class.getResource("dcat-ap-3-SHACL.ttl").getFile();
if(SHAPES.startsWith("/")){ SHAPES.replaceFirst("/","");}
String[] shaclValidation = {"dcat-ap-2.1.1-base-SHACL.ttl", "dcat-ap-3-SHACL.ttl"};
for(String shaclShapes : shaclValidation) {
String SHAPES = FormatterApiTest.class.getResource(shaclShapes).getFile();
if(SHAPES.startsWith("/")){ SHAPES.replaceFirst("/","");}

//Load document to validate.
String DATA = FormatterApiTest.class.getResource(
String.format("%s-%s-%s",
schema, formatter, checkfile)
).getFile();
if(DATA.startsWith("/")){
DATA.replaceFirst("/","");
}

Graph shapesGraph = RDFDataMgr.loadGraph(SHAPES);
Graph dataGraph = RDFDataMgr.loadGraph(DATA);

Shapes shapes = Shapes.parse(shapesGraph);

ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);

if(report.conforms() == false){
ShLib.printReport(report);
System.out.println();
RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
fail(String.format("%s. Checked with %s. Invalid DCAT-AP document. See report in the test console output.",
url, checkfile));
}

//Load document to validate.
String DATA = FormatterApiTest.class.getResource(
String.format("%s-%s-%s",
schema, formatter, checkfile)
).getFile();
if(DATA.startsWith("/")){ DATA.replaceFirst("/","");}

//Load RDF Graph from files.
Graph shapesGraph = RDFDataMgr.loadGraph(SHAPES);
Graph dataGraph = RDFDataMgr.loadGraph(DATA);

//Parse shapes from SHACL document.
Shapes shapes = Shapes.parse(shapesGraph);

//Validate document against SHACL rules.
ValidationReport report = ShaclValidator.get().validate(shapes, dataGraph);

//If document is not valid.
if(report.conforms() == false){
//Print validation report and fail.
ShLib.printReport(report);
System.out.println();
RDFDataMgr.write(System.out, report.getModel(), Lang.TTL);
fail(String.format("%s. Checked with %s. Invalid DCAT-AP document. See report in the test console output.",
url, checkfile));
}

}

} else {
Expand Down
Loading

0 comments on commit e3d2780

Please sign in to comment.