Skip to content

Commit

Permalink
Formatter / EU-DCAT-AP / Validation / Shacl 2.1.1 / Success.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxprunayre committed Dec 15, 2023
1 parent e3d2780 commit 9aae81d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
-->
<xsl:for-each select="ancestor::mrd:MD_DigitalTransferOptions/mrd:transferSize/*/text()[. castable as xs:double]">
<!-- Not valid for eu-dcat-ap <dcat:byteSize><xsl:value-of select="concat(., ' MB')"/></dcat:byteSize>-->
<dcat:byteSize><xsl:value-of select="format-number(. * 1048576, '#')"/></dcat:byteSize>
<dcat:byteSize rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal"><xsl:value-of select="format-number(. * 1048576, '#')"/></dcat:byteSize>
</xsl:for-each>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,10 @@
<xsl:template mode="iso19115-3-to-dcat"
match="mdb:identificationInfo/*/mri:resourceMaintenance/*/mmi:maintenanceAndUpdateFrequency[position() > 1]"/>

<!--
Path=<http://www.w3.org/ns/dcat#spatialResolutionInMeters>
Message: maxCount[1]: Invalid cardinality: expected max 1: Got count = 3
-->
<xsl:template mode="iso19115-3-to-dcat"
match="mdb:identificationInfo/*/mri:spatialResolution[count(preceding-sibling::mri:spatialResolution[*/mri:distance]) > 0]/*/mri:distance" priority="2"/>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,9 @@ public void checkFormatter() throws Exception {
if("eu-dcat-ap".equalsIgnoreCase(formatter)){
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));
}

applyShaclValidation(formatter, schema, checkfile, url, shaclShapes);
}
}

} else {
assertEquals(
url,
Expand All @@ -201,6 +174,35 @@ public void checkFormatter() throws Exception {
}
}

private static void applyShaclValidation(String formatter, String schema, String checkfile, String url, String shaclShapes) {
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 [%s]. Invalid DCAT-AP document. See report in the test console output.",
url, checkfile, shaclShapes));
}
}

private void createTestData() throws Exception {
loginAsAdmin(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
<dcat:Distribution>
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2023-12-08T00:00:00</dct:issued>
<dcat:accessURL rdf:resource="https://data.monde.org/secteur.shp"/>
<dcat:byteSize>10485760</dcat:byteSize>
<dcat:byteSize rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">10485760</dcat:byteSize>
<dct:format>
<dct:MediaType>
<rdfs:label>ESRI Shapefile (.shp)</rdfs:label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,6 @@
</dcat:theme>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.01
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">30
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.3048
</dcat:spatialResolutionInMeters>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">P0Y2M0DT0H0M0S
</dcat:temporalResolution>
<dct:accrualPeriodicity>
Expand All @@ -412,7 +408,7 @@
<dcat:Distribution>
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2023-12-08T00:00:00</dct:issued>
<dcat:accessURL rdf:resource="https://data.monde.org/secteur.shp"/>
<dcat:byteSize>10485760</dcat:byteSize>
<dcat:byteSize rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">10485760</dcat:byteSize>
<dct:format>
<dct:MediaType>
<rdfs:label>ESRI Shapefile (.shp)</rdfs:label>
Expand All @@ -431,10 +427,6 @@
</dct:accessRights>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.01
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">30
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.3048
</dcat:spatialResolutionInMeters>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">P0Y2M0DT0H0M0S
</dcat:temporalResolution>
<dct:conformsTo>
Expand Down Expand Up @@ -478,10 +470,6 @@
</dct:accessRights>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.01
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">30
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.3048
</dcat:spatialResolutionInMeters>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">P0Y2M0DT0H0M0S
</dcat:temporalResolution>
<dct:conformsTo>
Expand Down Expand Up @@ -527,10 +515,6 @@
</dct:accessRights>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.01
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">30
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.3048
</dcat:spatialResolutionInMeters>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">P0Y2M0DT0H0M0S
</dcat:temporalResolution>
<dct:conformsTo>
Expand Down Expand Up @@ -577,10 +561,6 @@
</dct:accessRights>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.01
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">30
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.3048
</dcat:spatialResolutionInMeters>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">P0Y2M0DT0H0M0S
</dcat:temporalResolution>
<dct:conformsTo>
Expand Down Expand Up @@ -629,10 +609,6 @@
</dct:accessRights>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.01
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">30
</dcat:spatialResolutionInMeters>
<dcat:spatialResolutionInMeters rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">0.3048
</dcat:spatialResolutionInMeters>
<dcat:temporalResolution rdf:datatype="http://www.w3.org/2001/XMLSchema#duration">P0Y2M0DT0H0M0S
</dcat:temporalResolution>
<dct:conformsTo>
Expand Down

0 comments on commit 9aae81d

Please sign in to comment.