Skip to content

Instantly share code, notes, and snippets.

@EmmanuelDemey
Last active May 25, 2020 08:12
Show Gist options
  • Save EmmanuelDemey/5a9241cacc1258ceab22d5016db1c1e5 to your computer and use it in GitHub Desktop.
Save EmmanuelDemey/5a9241cacc1258ceab22d5016db1c1e5 to your computer and use it in GitHub Desktop.
PREFIX insee: <http://rdf.insee.fr/def/base#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX qb: <http://purl.org/linked-data/cube#>
INSERT DATA {
GRAPH <http://test.id.insee.fr/graphes/components> {
<http://test.id.insee.fr/attributs/a9999> rdf:label "Test Manu FR"@fr ;
rdf:label "Test Manu EN"@en .
}
}
PREFIX insee: <http://rdf.insee.fr/def/base#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT DISTINCT ?id ?identifiant ?labelLg1 ?labelLg2 ?type ?concept ?codeList ?range ?descriptionLg1 ?descriptionLg2
WHERE {
GRAPH <http://test.id.insee.fr/graphes/components> {
# ?component dcterms:identifier "a1005" .
?component dcterms:identifier ?id .
?component <http://test.id.insee.fr/identifiantMetier> ?identifiant .
?component rdf:type ?type .
?component rdfs:label ?labelLg1 .
OPTIONAL {
?component qb:concept ?conceptObject
} .
OPTIONAL {
?component qb:codeList ?codeList
} .
OPTIONAL {
?component rdfs:range ?range
} .
FILTER (lang(?labelLg1) = 'fr')
OPTIONAL {?component rdfs:label ?labelLg2 .
FILTER (lang(?labelLg2) = 'en') } .
OPTIONAL {?component rdfs:descriptionLg1 ?descriptionLg1 .
FILTER (lang(?descriptionLg1) = 'fr') } .
OPTIONAL {?component rdfs:descriptionLg2 ?descriptionLg2 .
FILTER (lang(?descriptionLg2) = 'en') } .
BIND(STRAFTER(STR(?conceptObject),'http://id.insee.fr/concepts/definition/') AS ?concept) .
}
}
ORDER BY ?labelLg1
PREFIX insee: <http://rdf.insee.fr/def/base#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX qb: <http://purl.org/linked-data/cube#>
SELECT DISTINCT ?id ?label
WHERE {
GRAPH <http://test.id.insee.fr/graphes/structures/dsd1001> {
?structure qb:component ?component .
?component dcterms:identifier "cs1003" .
?structure dcterms:identifier ?id .
?structure rdfs:label ?label .
FILTER (lang(?label) = 'fr')
}
}
ORDER BY ?label
@alicela
Copy link

alicela commented May 25, 2020

When the subject is the same, you can remove it and replace '.' by ';'
For example :

  ?component dcterms:identifier ?id .
		?component <http://test.id.insee.fr/identifiantMetier> ?identifiant .
        
        ?component rdf:type ?type .
        ?component rdfs:label ?labelLg1 .

will become :

  ?component dcterms:identifier ?id ;
		 <http://test.id.insee.fr/identifiantMetier> ?identifiant ;
                  rdf:type ?type ;
                  rdfs:label ?labelLg1 .

@alicela
Copy link

alicela commented May 25, 2020

Two solutions for multiple graph

  1. Don't mention the graph
SELECT DISTINCT ?id ?label
WHERE { 
        ?structure qb:component ?component .
        ?component dcterms:identifier "cs1003" .
		?structure dcterms:identifier ?id . 
        ?structure rdfs:label ?label .
        FILTER (lang(?label) = 'fr')
} 
ORDER BY ?label 
  1. Mention all graphs used
SELECT ?idMas ?masLabelLg1 ?masLabelLg2 ?idParent ?isPresentational 
 FROM <http://rdf.insee.fr/graphes/def/simsv2fr> 
 FROM <http://rdf.insee.fr/graphes/concepts/qualite>
 WHERE { 
	 	?reportStructure sdmx-mm:metadataAttributeSpecification ?mas . 
   		OPTIONAL {?mas sdmx-mm:parent ?parent } 
		BIND(REPLACE( STR(?parent) , '(.*/)(\\w.+$)', '$2' ) AS ?idParent) . 
		
   		OPTIONAL {?mas sdmx-mm:isPresentational ?isPresentational } 
		
		FILTER(STRENDS(STR(?reportStructure),'/qualite/simsv2fr/reportStructure')) . 
		BIND(REPLACE( STR(?mas) , '(.*/)(\\w.+$)', '$2' ) AS ?idMas) . 
		
		?mas sdmx-mm:metadataAttributeProperty ?map . 
	  	?map sdmx-mm:concept ?concept .
	  	?concept skos:prefLabel ?masLabelLg1 ; 
	  		    skos:prefLabel ?masLabelLg2 ; 
	  	FILTER(lang(?masLabelLg1) = '${LG1}') 
	  	FILTER(lang(?masLabelLg2) = '${LG2}') 
  } 
 ORDER BY ?mas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment