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

Campagne eap emb2023 #59

Merged
merged 2 commits into from
Jan 2, 2024
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
157 changes: 157 additions & 0 deletions pages/common/eap2023/display-item.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>EAP - consultation</title>
<link href="../commun.css" rel="stylesheet" type="text/css"/>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
/*
var niveau="produits"*/
var endpointURL = "https://rdf.insee.fr/sparql";
var racine = "http://id.insee.fr/codes/";
var nomenclature="eap2023";
var regex = new RegExp(racine +nomenclature +"/[A-Z0-9]+/", "g");
var replacement = 'display-item.htm?code=';
var itemTypes = ['Produit', 'produit'];//Nom "propre" des différents niveaux
var parentLength = [0,4];//Taille des codes parents (0 si n'existe pas)

$(document).ready(function() {
var code = getURLParameter('code');
$('#fil-ariane').html('<ul>' + breadcrumbs(code, false) + '</ul>');
getLabel(code);
});

function getLabel(code) {
var query = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> ";
query += "SELECT ?uri ?label WHERE {";
query += "GRAPH <http://rdf.insee.fr/graphes/codes/"+nomenclature+"> {";
query += "?uri skos:prefLabel ?label ; skos:notation '"+ code;
query += "'. FILTER langMatches (lang(?label), 'fr')}";
query += " . }";
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);

$.getJSON(queryURL).success(function(data) {
var itemURI = data.results.bindings[0].uri.value;
$('#label').html(code + " - " + data.results.bindings[0].label.value);
if (code.length>6){
getDescription(itemURI);
}
var childTypeIndex = (code.length == 6 ? 1 : 0);
getChildren(itemURI, itemTypes[childTypeIndex]);

})
}

function getDescription(itemURI) {
var query = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> DESCRIBE <" + itemURI + ">";
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);
"OK"
$.getJSON(queryURL).success(function(data) {
for (var index = 0; index < data.results.bindings.length; index++) {
var bindingObject = data.results.bindings[index];
if (bindingObject.predicate.value === "http://www.w3.org/2004/02/skos/core#definition") getNote(bindingObject.object.value, "note-generale"); // Note générale

if (bindingObject.predicate.value === "http://www.w3.org/2004/02/skos/core#scopeNote") getNote(bindingObject.object.value, "note-generale"); // Note générale
else if (bindingObject.predicate.value === "http://rdf-vocabulary.ddialliance.org/xkos#coreContentNote") getNote(bindingObject.object.value, "contenu-central"); // Contenu central
else if (bindingObject.predicate.value === "http://rdf-vocabulary.ddialliance.org/xkos#additionalContentNote") getNote(bindingObject.object.value, "contenu-limite"); // Contenu central
else if (bindingObject.predicate.value === "http://rdf-vocabulary.ddialliance.org/xkos#exclusionNote") getNote(bindingObject.object.value, "exclusions"); // Exclusions
else if (bindingObject.predicate.value === "http://www.w3.org/2004/02/skos/core#note") getNote(bindingObject.object.value, "remarques"); // Remarque
}
})
}

function getChildren(itemURI, childType) {

var query = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> SELECT ?code ?label WHERE { <" + itemURI + "> skos:narrower ?child . ";
query += "?child skos:notation ?code ; skos:prefLabel ?label . FILTER langMatches (lang(?label), 'fr') } ORDER BY ?code"
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);

$.getJSON(queryURL).success(function(data) {
if (data.results.bindings.length > 0) {
var innerHTML = '<p class="nom-enfants">Liste des produits détaillés</p><ul class="enfants">';
for (var index = 0; index < data.results.bindings.length; index++) {
var childCode = data.results.bindings[index].code.value;
innerHTML += '<li><p><a href="'+replacement + childCode + '">' + childCode + ' - ' + data.results.bindings[index].label.value + '</a></p></li>';
}
innerHTML += '</ul>';
$('#sous-items').html(innerHTML);
$('#sous-items').addClass("sous-items");
}
})
}

function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}

function getNote(uri, tag) {

var query = 'SELECT ?text WHERE { <' + uri + '> <http://eurovoc.europa.eu/schema#noteLiteral> ?text }'
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);

$.getJSON(queryURL).success(function(data) {
var noteText = data.results.bindings[0].text.value.replace(regex, replacement);
$('#' + tag).append(noteText.replace(/\\\$/g, "<br />"));
$('#' + tag).addClass(tag);
})
}

function breadcrumbs(code, finalLink) {
if (code && code.length > 6) {
niveau='Produit détaillé ';
}else niveau = 'Produit agrégé ';
var name = niveau+code;
//itemTypes[code.length] + ' ' + code;
var html;
var fin = (finalLink ?
('<li><a href="'+ replacement + code +'" title="' + name + '">' + name + '</a></li>')
: ('<li>' + name + '</li>')
);

if (code && code.length <= 6) {
html = '<li><a href="eap.htm" title="Accueil">'+nomenclature.toUpperCase()+'</a></li>&nbsp;' + fin;

}
else if (code){
html =
breadcrumbs(getParentCode(code), true) + '&nbsp;' +
fin;
}
return html;
}

/**
à partir du code enfant return le code parent
**/
function getParentCode(code) {
//TODO à réécrire pour chaque nomenclature
var codeParent;
if (code && code.length > 6) {
codeParent = code.substr(0, parentLength[1]);
if (code.slice(-1).match(/[A-Z]/)){//le dernier élément du code est une lettre
codeParent+=code.slice(-1).toLowerCase();
}
return codeParent;
}
return null;
}



</script>
</head>
<body>
<div id="fil-ariane"></div>
<h1 id="label" class="item"></h1>
<br/>
<div id="notes">
<div id="note-generale"></div>
<div id="contenu-central"></div>
<div id="contenu-limite"></div>
<div id="exclusions"></div>
<div id="remarques"></div>
</div>
<div id="sous-items"></div>
</body>
</html>
61 changes: 61 additions & 0 deletions pages/common/eap2023/eap.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Consultation - EAP 2023</title>
<link href="../commun.css" rel="stylesheet" type="text/css"/>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
var endpointURL = "https://rdf.insee.fr/sparql";
var racine = "http://id.insee.fr/codes/";
var nomenclature="eap2023";
var niveau="produits";
var niveau2="produitsAgreges";
$(document).ready(function() {

var query = 'PREFIX skos:<http://www.w3.org/2004/02/skos/core#> ';
query += 'SELECT ?code ?label WHERE {GRAPH <http://rdf.insee.fr/graphes/codes/'+nomenclature+'> { ?uri skos:prefLabel ?label ; skos:notation ?code . '
query += '<'+racine+nomenclature+'/'+niveau+'> skos:member ?uri . FILTER langMatches (lang(?label), "fr")} . } ORDER BY ?code';
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);

$.getJSON(queryURL).success(function(data) {

var innerHTML = '<p class="nom-enfants"> Liste des produits détaillés </p><ul class="enfants">';
for (var index = 0; index < data.results.bindings.length; index++) {
var childCode = data.results.bindings[index].code.value;
innerHTML += '<li><p><a href="display-item.htm?code=' + childCode + '">' + childCode + ' - ' + data.results.bindings[index].label.value + '</a></p></li>';
}
innerHTML += '</ul>';
$('#sous-items2').html(innerHTML);


});


var query2 = 'PREFIX skos:<http://www.w3.org/2004/02/skos/core#> ';
query2 += 'SELECT ?code ?label WHERE {GRAPH <http://rdf.insee.fr/graphes/codes/'+nomenclature+'> { ?uri skos:prefLabel ?label ; skos:notation ?code . '
query2 += '<'+racine+nomenclature+'/'+niveau2+'> skos:member ?uri . FILTER langMatches (lang(?label), "fr")} . } ORDER BY ?code';
var queryURL2 = endpointURL + "?query=" + encodeURIComponent(query2);

$.getJSON(queryURL2).success(function(data) {
var innerHTML = '<p class="nom-enfants"> Liste des produits agrégés </p><ul class="enfants">';
for (var index = 0; index < data.results.bindings.length; index++) {
var childCode = data.results.bindings[index].code.value;
innerHTML += '<li><p><a href="display-item.htm?code=' + childCode + '">' + childCode + ' - ' + data.results.bindings[index].label.value + '</a></p></li>';
}
innerHTML += '</ul>';

$('#sous-items1').html(innerHTML);
});
});

</script>
</head>
<body>
<h1 class="titre-class">Nomenclatures de l'Enquête Annuelle de Production (EAP) 2023</h1>
<div class="note-generale">
<p>Liste des produits de l'Enquête Annuelle de Production 2023</p>
</div>
<div id="sous-items1" class="sous-items" style="width: 45%; float: left;"></div>
<div id="sous-items2" class="sous-items" style="width: 45%; float: left;"></div>
</body>
</html>
164 changes: 164 additions & 0 deletions pages/common/emb2024/display-item.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>EMB - consultation</title>
<link href="../commun.css" rel="stylesheet" type="text/css"/>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
/*
var niveau="produits"*/
var endpointURL = "https://rdf.insee.fr/sparql";
var racine = "http://id.insee.fr/codes/";
var nomenclature="emb2024";
var regex = new RegExp(racine +nomenclature +"/[A-Z0-9]+/", "g");
var replacement = 'display-item.htm?code=';
var itemTypes = ['Activité de la NAF', 'Produit'];//Nom "propre" des différents niveaux
var parentLength = [0,5];//Taille des codes parents (0 si n'existe pas)

$(document).ready(function() {
var codeAAffiche = getURLParameter('code');
var code;
if (codeAAffiche.length<6){
code = codeAAffiche.substring(0, 2) + "." + codeAAffiche.substring(2);
}else{ code = codeAAffiche;}
$('#fil-ariane').html('<ul>' + breadcrumbs(code, false) + '</ul>');
getLabel(code);
});

function getLabel(code) {
var query = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> ";
query += "SELECT ?uri ?label WHERE {";
//query += "GRAPH <http://rdf.insee.fr/graphes/codes/"+nomenclature+"> {";
query += "?uri skos:prefLabel ?label ; skos:notation '"+ code;
query += "'. FILTER langMatches (lang(?label), 'fr')}";
//query += " . }";
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);
var codeAAffiche = code.replace(".","") ;
$.getJSON(queryURL).success(function(data) {
var itemURI = data.results.bindings[0].uri.value;
$('#label').html(codeAAffiche + " - " + data.results.bindings[0].label.value);
if (code.length>6){
getDescription(itemURI);
}else{
var childTypeIndex = (code.length == 6 ? 1 : 0);
getChildren(itemURI, itemTypes[childTypeIndex]);
}

})
}

function getDescription(itemURI) {
var query = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> DESCRIBE <" + itemURI + ">";
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);
"OK"
$.getJSON(queryURL).success(function(data) {
for (var index = 0; index < data.results.bindings.length; index++) {
var bindingObject = data.results.bindings[index];
if (bindingObject.predicate.value === "http://www.w3.org/2004/02/skos/core#definition") getNote(bindingObject.object.value, "note-generale"); // Note générale

if (bindingObject.predicate.value === "http://www.w3.org/2004/02/skos/core#scopeNote") getNote(bindingObject.object.value, "note-generale"); // Note générale
else if (bindingObject.predicate.value === "http://rdf-vocabulary.ddialliance.org/xkos#coreContentNote") getNote(bindingObject.object.value, "contenu-central"); // Contenu central
else if (bindingObject.predicate.value === "http://rdf-vocabulary.ddialliance.org/xkos#additionalContentNote") getNote(bindingObject.object.value, "contenu-limite"); // Contenu central
else if (bindingObject.predicate.value === "http://rdf-vocabulary.ddialliance.org/xkos#exclusionNote") getNote(bindingObject.object.value, "exclusions"); // Exclusions
else if (bindingObject.predicate.value === "http://www.w3.org/2004/02/skos/core#note") getNote(bindingObject.object.value, "remarques"); // Remarque
}
})
}

function getChildren(itemURI, childType) {

var query = "PREFIX skos:<http://www.w3.org/2004/02/skos/core#> SELECT ?code ?label WHERE { <" + itemURI + "> skos:relatedMatch ?child . ";
query += "?child skos:notation ?code ; skos:prefLabel ?label . FILTER langMatches (lang(?label), 'fr') } ORDER BY ?code"
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);

$.getJSON(queryURL).success(function(data) {
if (data.results.bindings.length > 0) {
var innerHTML = '<p class="nom-enfants">' + childType + (data.results.bindings.length > 1 ? 's' : '') + '</p><ul class="enfants">';
for (var index = 0; index < data.results.bindings.length; index++) {
var childCode = data.results.bindings[index].code.value;
innerHTML += '<li><p><a href="'+replacement + childCode + '">' + childCode + ' - ' + data.results.bindings[index].label.value + '</a></p></li>';
}
innerHTML += '</ul>';
$('#sous-items').html(innerHTML);
$('#sous-items').addClass("sous-items");
}
})
}

function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}

function getNote(uri, tag) {

var query = 'SELECT ?text WHERE { <' + uri + '> <http://eurovoc.europa.eu/schema#noteLiteral> ?text }'
var queryURL = endpointURL + "?query=" + encodeURIComponent(query);

$.getJSON(queryURL).success(function(data) {
var noteText = data.results.bindings[0].text.value.replace(regex, replacement);
$('#' + tag).append(noteText.replace(/\\\$/g, "<br />"));
$('#' + tag).addClass(tag);
})
}

function breadcrumbs(code, finalLink) {
var codeAAffiche ;
if (code && code.length > 6) {
niveau='Produit ';
codeAAffiche = code;
}else {
niveau = 'Activité ';
codeAAffiche = code.replace(".","") ;
}
var name = niveau+codeAAffiche;
//itemTypes[code.length] + ' ' + code;
var html;
var fin = (finalLink ?
('<li><a href="'+ replacement + codeAAffiche +'" title="' + name + '">' + name + '</a></li>')
: ('<li>' + name + '</li>')
);

if (code && code.length == 6) {
html = '<li><a href="emb.htm" title="Accueil">'+nomenclature.toUpperCase()+'</a></li>&nbsp;' + fin;
}
else if (code){
html =
breadcrumbs(getParentCode(code), true) + '&nbsp;' +
fin;
}
return html;
}

/**
à partir du code enfant return le code parent
**/
function getParentCode(code) {
//TODO à réécrire pour chaque nomenclature
var codeParent;
if (code && code.length > 6) {
var codeParentSansPoint = code.substr(0, parentLength[1]);
codeParent = codeParentSansPoint.substring(0, 2) + "." + codeParentSansPoint.substring(2);
return codeParent;
}
return null;
}



</script>
</head>
<body>
<div id="fil-ariane"></div>
<h1 id="label" class="item"></h1>
<br/>
<div id="notes">
<div id="note-generale"></div>
<div id="contenu-central"></div>
<div id="contenu-limite"></div>
<div id="exclusions"></div>
<div id="remarques"></div>
</div>
<div id="sous-items"></div>
</body>
</html>
Loading
Loading