Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thesaurus / OWL format / Mobility theme hierarchy #8393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ public void testImportOntologyToSkos() throws Exception {
"Mobility Theme", scheme.getChildText("title", NAMESPACE_DCT));

List concepts = thesaurus.getChildren("Concept", SKOS_NAMESPACE);
assertEquals(123, concepts.size());
assertEquals(121, concepts.size());
}
}
61 changes: 53 additions & 8 deletions web/src/main/webapp/xslt/services/thesaurus/owl-to-skos.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:terms="http://purl.org/dc/terms/"
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="2.0">

Expand All @@ -40,23 +40,68 @@

<xsl:template mode="owl-to-skos"
match="owl:Ontology">
<rdf:RDF xmlns:skos="http://www.w3.org/2004/02/skos/core#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/">
<rdf:RDF>
<xsl:namespace name="skos" select="'http://www.w3.org/2004/02/skos/core#'"/>
<xsl:namespace name="rdf" select="'http://www.w3.org/1999/02/22-rdf-syntax-ns#'"/>
<xsl:namespace name="dc" select="'http://purl.org/dc/elements/1.1/'"/>
<xsl:namespace name="terms" select="'http://purl.org/dc/terms/'"/>
<skos:ConceptScheme rdf:about="{@rdf:about}">
<xsl:copy-of select="dcterms:*|skos:*"/>
<xsl:copy-of select="terms:*|skos:*[local-name() != 'hasTopConcept']" copy-namespaces="no"/>

<!--
Custom case for Mobility DCAT theme vocabulary top concepts.
https://mobilitydcat-ap.github.io/controlled-vocabularies/mobility-theme/latest/index.html#/

The vocabulary contains 2 top concepts:
<skos:hasTopConcept rdf:resource="https://w3id.org/mobilitydcat-ap/mobility-theme/data-content-category"/>
<skos:hasTopConcept rdf:resource="https://w3id.org/mobilitydcat-ap/mobility-theme/data-content-sub-category"/>
which are not really needed for browsing the main categories and sub categories.

Use the narrower terms of the "content category" top concept as the top concepts of the scheme
to facilitate keyword selection in editor and generate proper facet hierarchy in search.
-->
<xsl:variable name="mobilityThemeTopConcept"
select="../owl:NamedIndividual[@rdf:about = 'https://w3id.org/mobilitydcat-ap/mobility-theme/data-content-category']"/>
<xsl:choose>
<xsl:when test="$mobilityThemeTopConcept">
<xsl:for-each select="$mobilityThemeTopConcept/skos:narrower">
<skos:hasTopConcept rdf:resource="{@rdf:resource}"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="skos:hasTopConcept" copy-namespaces="no"/>
</xsl:otherwise>
</xsl:choose>
</skos:ConceptScheme>

<xsl:apply-templates mode="owl-to-skos"
select="../owl:NamedIndividual[skos:prefLabel]"/>
</rdf:RDF>
</xsl:template>

<xsl:variable name="excludedConcepts"
select="(
'https://w3id.org/mobilitydcat-ap/mobility-theme/data-content-category',
'https://w3id.org/mobilitydcat-ap/mobility-theme/data-content-sub-category'
)"
as="xs:string*"/>

<xsl:template mode="owl-to-skos"
match="owl:NamedIndividual[@rdf:about = $excludedConcepts]
|skos:broader[@rdf:resource = $excludedConcepts]"/>

<xsl:template mode="owl-to-skos"
match="owl:NamedIndividual">
<skos:Concept rdf:about="{@rdf:about}">
<xsl:copy-of select="skos:*"/>
<xsl:apply-templates mode="owl-to-skos" select="skos:*"/>
</skos:Concept>
</xsl:template>

<xsl:template mode="owl-to-skos"
match="@*|node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*|node()" mode="owl-to-skos"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>