@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix shacl: <http://www.w3.org/ns/shacl#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix r5r: <http://data.europa.eu/r5r/> .

@prefix : <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd#>.


<https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> a shacl:ShapesGraph ;
  rdfs:label "DCAT-AP HVD SHACL shapes for Controlled Vocabularies"@en ;
  owl:imports <http://publications.europa.eu/resource/distribution/high-value-dataset-category/rdf/skos_core/high-value-dataset-category.rdf> .

:HVDCategoryRestriction a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
    rdfs:comment "HVD Category restriction. The category must be the most granular one, from the correct controlled vocabulary."@en ;
    rdfs:label "HVD Category restriction"@en ;
    shacl:property [
        shacl:hasValue <http://data.europa.eu/bna/asd487ae75> ;
        shacl:minCount 1 ;
        shacl:nodeKind shacl:IRI ;
        shacl:path skos:inScheme
    ] ;
    shacl:property [
        shacl:path [ shacl:inversePath skos:broader ] ;
        shacl:maxCount 0 ;
        shacl:message "The HVD category must be one of the most granular ones, i.e. no other category may have it as skos:broader."@en
    ] .

:DatasetLicenceShape a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
    rdfs:comment "HVD reporting licence restriction"@en ;
    rdfs:label "HVD reporting licence restriction"@en ;
    shacl:or (
        [
            shacl:path [shacl:inversePath dcat:servesDataset] ;
            shacl:node :ServiceLicenceShape ;
            shacl:minCount 1 ;
        ]
        [
            shacl:path dcat:distribution;
            shacl:node :DistributionLicenceShape ;
            shacl:minCount 1 ;
        ]
        [
            shacl:path (dcat:distribution dcat:accessService);
            shacl:node :ServiceLicenceShape ;
            shacl:minCount 1 ;
        ]
    );
    shacl:targetClass dcat:Dataset .

# EU Licence HVD restrictions - CC0, CC BY 4.0, or mapped to them via owl:sameAs,skos:exactMatch or skos:narrowMatch.
:ServiceLicenceShape a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
  shacl:or (
    [
        shacl:path dct:license;
        shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC_BY_4_0>;
        shacl:minCount 1 ;
    ]
    [
        shacl:path dct:license;
        shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC0> ;
        shacl:minCount 1 ;
    ]
    [
        shacl:path dct:license;
        shacl:node :EULicenceMappingRestriction; 
        shacl:minCount 1 ;
    ]
    [
        shacl:path [shacl:inversePath dcat:accessService];
        shacl:node :DistributionLicenceShape;
        shacl:minCount 1 ;
    ]
  ).

# EU Licence HVD restrictions - CC0, CC BY 4.0, or mapped to them via owl:sameAs,skos:exactMatch or skos:narrowMatch.
:DistributionLicenceShape a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
  shacl:or (
    [
        shacl:path dct:license;
        shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC_BY_4_0>;
        shacl:minCount 1 ;
    ]
    [
        shacl:path dct:license;
        shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC0> ;
        shacl:minCount 1 ;
    ]
    [
        shacl:path dct:license;
        shacl:node :EULicenceMappingRestriction; 
        shacl:minCount 1 ;
    ]
  ).

:EULicenceMappingRestriction rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
  a sh:NodeShape ;
    sh:or (
		[
  			shacl:path skos:exactMatch;
            shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC_BY_4_0>;
			shacl:minCount 1 ;
		]
		[
  			shacl:path owl:sameAs;
            shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC_BY_4_0>;
			shacl:minCount 1 ;
		]
		[
  			shacl:path skos:narrowMatch;
            shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC_BY_4_0>;
			shacl:minCount 1 ;
		]
		[
  			shacl:path skos:exactMatch;
            shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC0>;
			shacl:minCount 1 ;
		]
		[
  			shacl:path owl:sameAs;
            shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC0>;
			shacl:minCount 1 ;
		]
		[
  			shacl:path skos:narrowMatch;
            shacl:hasValue <http://publications.europa.eu/resource/authority/licence/CC0>;
			shacl:minCount 1 ;
		]
	).

:DatasetShapeCV a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
    shacl:property [
        shacl:node :HVDCategoryRestriction ;
        shacl:nodeKind shacl:IRI ;
        shacl:path r5r:hvdCategory
    ] ;
    shacl:targetClass dcat:Dataset.


:DataServiceShapeCV a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
    shacl:property [
        shacl:node :HVDCategoryRestriction ;
        shacl:nodeKind shacl:IRI ;
        shacl:path r5r:hvdCategory
    ] ; 
    shacl:targetClass dcat:DataService.


:DatasetSeriesShapeCV a shacl:NodeShape ;
  rdfs:isDefinedBy <https://semiceu.github.io/DCAT-AP/releases/3.0.1-hvd/html/hvd-SHACL-cv.ttl> ;
    shacl:property [
        shacl:node :HVDCategoryRestriction ;
        shacl:nodeKind shacl:IRI ;
        shacl:path r5r:hvdCategory
    ] ; 
    shacl:targetClass dcat:DatasetSeries.