Skip to content

Commit

Permalink
Standard / ISO / DCAT formatters / Refactor for easier object referen…
Browse files Browse the repository at this point in the history
…ce configuration. References are added to org, individual, keywords now.
  • Loading branch information
fxprunayre committed Apr 10, 2024
1 parent 8b3e348 commit 7e4ecc9
Show file tree
Hide file tree
Showing 12 changed files with 1,081 additions and 891 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@
else 'dct:relation'"/>

<xsl:element name="{$elementType}">
<xsl:apply-templates mode="rdf-metadata-ref" select="*/mri:metadataReference|*/mri:aggregateDataSetIdentifier"/>
<xsl:apply-templates mode="rdf-object-ref-attribute"
select="*/mri:metadataReference|*/mri:aggregateDataSetIdentifier">
<xsl:with-param name="isAbout" select="false()"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:prov="http://www.w3.org/ns/prov#"
xmlns:dcat="http://www.w3.org/ns/dcat#"
Expand All @@ -16,6 +17,7 @@
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:vcard="http://www.w3.org/2006/vcard/ns#"
xmlns:org="http://www.w3.org/ns/org#"
xmlns:gn-fn-dcat="http://geonetwork-opensource.org/xsl/functions/dcat"
exclude-result-prefixes="#all">

<!--
Expand Down Expand Up @@ -84,31 +86,51 @@


<xsl:template name="rdf-contact-vcard">
<xsl:variable name="reference"
as="xs:string?"
select="(cit:partyIdentifier/*/mcc:code/*/text()|cit:name/gcx:Anchor/@xlink:href)[1]"/>

<rdf:Description>
<xsl:if test="$reference != ''">
<xsl:attribute name="rdf:about" select="$reference"/>
</xsl:if>
<xsl:call-template name="rdf-object-ref-attribute"/>

<rdf:type rdf:resource="http://www.w3.org/2006/vcard/ns#Organization"/>
<xsl:for-each select="cit:name">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'vcard:fn'"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="cit:contactInfo/*/cit:address/*/cit:electronicMailAddress">
<vcard:hasEmail rdf:resource="mailto:{*/text()}"/>
<xsl:for-each select="cit:contactInfo/*/cit:address">
<xsl:for-each select="*/cit:electronicMailAddress">
<vcard:hasEmail rdf:resource="mailto:{*/text()}"/>
</xsl:for-each>
<xsl:if test="normalize-space(*/cit:city) != ''">
<vcard:hasAddress>
<vcard:Address>
<xsl:for-each select="*/cit:country">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'vcard:country-name'"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="*/cit:city">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'vcard:locality'"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="*/cit:postalCode">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'vcard:postal-code'"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="*/cit:administrativeArea">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'vcard:region'"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="*/cit:deliveryPoint">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'vcard:street-address'"/>
</xsl:call-template>
</xsl:for-each>
</vcard:Address>
</vcard:hasAddress>
</xsl:if>
</xsl:for-each>
<!-- TODO: map other properties
vcard:hasAddress [ a vcard:Address ;
vcard:country-name "Denmark" ;
vcard:locality "Copenhagen" ;
vcard:postal-code "1050" ;
vcard:region "K" ;
vcard:street-address "Kongens Nytorv 6" ] ;
-->
</rdf:Description>
</xsl:template>

Expand All @@ -125,17 +147,17 @@
select="cit:name"/>
<xsl:variable name="orgReference"
as="xs:string?"
select="(cit:partyIdentifier/*/mcc:code/*/text()|cit:name/gcx:Anchor/@xlink:href)[1]"/>
select="gn-fn-dcat:rdf-object-ref(.)"/>
<xsl:variable name="reference"
as="xs:string?"
select="if ($isindividual)
then (cit:individual/*/(cit:partyIdentifier/*/mcc:code/*/text()|cit:name/gcx:Anchor/@xlink:href))[1]
then gn-fn-dcat:rdf-object-ref(cit:individual/*)
else $orgReference"/>

<rdf:Description>
<xsl:if test="$reference != ''">
<xsl:attribute name="rdf:about" select="$reference"/>
</xsl:if>
<xsl:call-template name="rdf-object-ref-attribute">
<xsl:with-param name="reference" select="$reference"/>
</xsl:call-template>
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/{if ($isindividual) then 'Person' else 'Organization'}"/>
<rdf:type rdf:resource="http://www.w3.org/ns/prov#Agent"/>

Expand All @@ -145,9 +167,9 @@
<org:memberOf>
<xsl:for-each select="$organisation">
<foaf:Organization>
<xsl:if test="$orgReference != ''">
<xsl:attribute name="rdf:about" select="$orgReference"/>
</xsl:if>
<xsl:call-template name="rdf-object-ref-attribute">
<xsl:with-param name="reference" select="$reference"/>
</xsl:call-template>
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName" select="'foaf:name'"/>
</xsl:call-template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dcat="http://www.w3.org/ns/dcat#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
exclude-result-prefixes="#all">

<!--
Expand All @@ -23,4 +29,26 @@
</xsl:for-each>
</xsl:template>

<xsl:template mode="iso19115-3-to-dcat"
match="mdb:identificationInfo/*/mri:descriptiveKeywords/*/mri:keyword[gcx:Anchor/@xlink:href != '']"
priority="2">
<dcat:keyword>
<skos:Concept>
<xsl:call-template name="rdf-object-ref-attribute"/>
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName"
select="'skos:prefLabel'"/>
</xsl:call-template>
</skos:Concept>
</dcat:keyword>
</xsl:template>

<xsl:template mode="iso19115-3-to-dcat"
match="mdb:identificationInfo/*/mri:descriptiveKeywords/*/mri:keyword[gco:CharacterString/text() != '']"
priority="2">
<xsl:call-template name="rdf-localised">
<xsl:with-param name="nodeName"
select="'dcat:keyword'"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:dqm="http://standards.iso.org/iso/19157/-2/dqm/1.0"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:cat="http://standards.iso.org/iso/19115/-3/cat/1.0"
xmlns:lan="http://standards.iso.org/iso/19115/-3/lan/1.0"
xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
Expand All @@ -21,7 +22,6 @@
xmlns:mrd="http://standards.iso.org/iso/19115/-3/mrd/1.0"
xmlns:mdq="http://standards.iso.org/iso/19157/-2/mdq/1.0"
xmlns:srv="http://standards.iso.org/iso/19115/-3/srv/2.1"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:gex="http://standards.iso.org/iso/19115/-3/gex/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
Expand Down Expand Up @@ -78,7 +78,7 @@
<xsl:param name="metadata" as="node()"/>

<xsl:variable name="metadataLinkage"
select="$metadata/mdb:metadataLinkage/*/cit:linkage/*/text()"
select="$metadata/mdb:metadataLinkage/*/cit:linkage/(gco:CharacterString|gcx:Anchor)/text()"
as="xs:string?"/>

<xsl:value-of select="if($metadataLinkage) then $metadataLinkage
Expand Down Expand Up @@ -126,7 +126,6 @@
match="mdb:identificationInfo/*/mri:citation/*/cit:title
|mdb:identificationInfo/*/mri:citation/*/cit:edition
|mdb:identificationInfo/*/mri:abstract
|mdb:identificationInfo/*/mri:descriptiveKeywords/*/mri:keyword
|mdb:metadataStandard/*/cit:title
|mdb:metadataStandard/*/cit:edition
|mdb:resourceLineage/*/mrl:statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:adms="http://www.w3.org/ns/adms#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:gn-fn-dcat="http://geonetwork-opensource.org/xsl/functions/dcat"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="#all">

Expand Down Expand Up @@ -84,20 +85,54 @@
</xsl:element>
</xsl:template>

<xsl:template mode="rdf-metadata-ref" match="*">
<xsl:choose>
<xsl:when test="@xlink:href">
<xsl:attribute name="rdf:resource" select="@xlink:href"/>
</xsl:when>
<xsl:when test="@uuidref">
<!-- TODO: Here we need a not relative URI? -->
<xsl:attribute name="rdf:resource" select="@uuidref"/>
</xsl:when>
<xsl:otherwise>
<!-- TODO: Here we need a not relative URI? -->
<xsl:attribute name="rdf:resource" select="*/mri:code/*/text()"/>
</xsl:otherwise>
</xsl:choose>

<!--
Get an object reference from an node.
In ISO, object reference are usually stored using gcx:Anchor elements (eg. keywords).
But in other cases, the reference can be stored in a more specific element.
Define here the rules to extract the reference from the object.
-->
<xsl:function name="gn-fn-dcat:rdf-object-ref" as="xs:string?">
<xsl:param name="node" as="node()"/>

<xsl:value-of select="if (name($node) = 'cit:CI_Organisation')
then $node/(cit:partyIdentifier/*/mcc:code/*/text(),
cit:contactInfo/*/cit:onlineResource/*/cit:linkage/gco:CharacterString/text(),
cit:name/gcx:Anchor/@xlink:href,
@uuid
)[1]
else if (name($node) = 'cit:CI_Individual')
then $node/(cit:partyIdentifier/*/mcc:code/*/text(),
cit:name/gcx:Anchor/@xlink:href,
@uuid
)[1]
else if ($node/gcx:Anchor/@xlink:href) then $node/gcx:Anchor/@xlink:href
else if ($node/@xlink:href) then $node/@xlink:href
else if ($node/@uuidref) then $node/@uuidref
else if ($node/*/mri:code/*/text() != '') then $node/*/mri:code/*/text()
else ''"/>
</xsl:function>

<!--
Template for creating a reference to an object as an XML attribute.
-->
<xsl:template name="rdf-object-ref-attribute"
mode="rdf-object-ref-attribute"
match="*">
<xsl:param name="isAbout"
as="xs:boolean"
select="true()"/>
<xsl:param name="reference"
as="xs:string?"
select="gn-fn-dcat:rdf-object-ref(.)"/>

<xsl:variable name="attributeName"
select="if($isAbout) then 'rdf:about' else 'rdf:resource'"/>

<xsl:if test="$reference != ''">
<xsl:attribute name="{$attributeName}" select="$reference"/>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@
<xsl:template mode="iso19115-3-to-eu-dcat-ap"
match="mrl:source">
<dct:source>
<xsl:apply-templates mode="rdf-metadata-ref" select="."/>
<xsl:call-template name="rdf-object-ref-attribute">
<xsl:with-param name="isAbout" select="false()"/>
</xsl:call-template>
</dct:source>
</xsl:template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ public void checkFormatter() throws Exception {
boolean isXml = checkfile.endsWith(".xml");

if (isXml || isRdf) {
if (isRdf) {
try {
Model model = ModelFactory.createMemModelMaker().createDefaultModel();
RDFDataMgr.read(model,
IOUtils.toInputStream(actual, StandardCharsets.UTF_8),
Lang.RDFXML);
} catch (Exception rdfException) {
fail(String.format("%s. Checked with %s. RDF model error. %s. Checked with: %s",
url, checkfile, rdfException.getMessage(), actual));
}
}

Diff diff = DiffBuilder
.compare(Input.fromString(actual))
.withTest(Input.fromString(expected))
Expand All @@ -148,15 +160,6 @@ public void checkFormatter() throws Exception {
diff.hasDifferences());

if (isRdf) {
try {
Model model = ModelFactory.createMemModelMaker().createDefaultModel();
RDFDataMgr.read(model,
IOUtils.toInputStream(actual, StandardCharsets.UTF_8),
Lang.RDFXML);
} catch (Exception rdfException) {
fail(String.format("%s. Checked with %s. RDF model error. %s. Checked with: %s",
url, checkfile, rdfException.getMessage(), actual));
}
String[] shaclValidation = {};
// if("eu-dcat-ap".equalsIgnoreCase(formatter)){
//// shaclValidation = new String[]{"dcat-ap-2.1.1-base-SHACL.ttl"};
Expand Down
Loading

0 comments on commit 7e4ecc9

Please sign in to comment.