Skip to content

Commit

Permalink
Thesaurus / OWL format / Mobility theme hierarchy
Browse files Browse the repository at this point in the history
Follow up of #7674


Mobility DCAT theme vocabulary top concepts is available at
https://mobilitydcat-ap.github.io/controlled-vocabularies/mobility-theme/latest/index.html#/

The vocabulary contains 2 top concepts:

```xml
<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.
  • Loading branch information
fxprunayre committed Sep 30, 2024
1 parent cfcd829 commit 63e4a1d
Showing 1 changed file with 53 additions and 8 deletions.
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>

0 comments on commit 63e4a1d

Please sign in to comment.