Main Page: Difference between revisions
From wikibase
No edit summary Tags: Reverted Visual edit: Switched |
Tag: Reverted |
||
| Line 1: | Line 1: | ||
<strong>Bienvenue sur le référentiel des <i>Bibliothèques Virtuelles Humanistes</i>.</strong> | <strong>Bienvenue sur le référentiel des <i>Bibliothèques Virtuelles Humanistes</i>.</strong> | ||
=== Statistiques des entités === | |||
=== Statistiques des entités === | === Statistiques des entités === | ||
<div id="entity-counts-container" style="background: #f0f8ff; padding: 15px; border: 1px solid #add8e6; border-radius: 5px; margin: 10px 0;"> | <div id="entity-counts-container" style="background: #f0f8ff; padding: 15px; border: 1px solid #add8e6; border-radius: 5px; margin: 10px 0;"> | ||
Chargement des statistiques | Chargement des statistiques... | ||
</div> | </div> | ||
<script> | |||
// Liste des types d'entités à compter | |||
const entityTypes = ["Q2", "Q5", "Q6", "Q7", "Q8"]; | |||
const results = {}; | |||
const apiUrl = window.location.origin + "/w/api.php"; | |||
// Fonction pour compter les entités via wbgetentities | |||
async function countEntities() { | |||
const container = document.getElementById('entity-counts-container'); | |||
if (!container) { | |||
console.error("Conteneur introuvable !"); | |||
return; | |||
} | |||
// Étape 1: Récupérer toutes les entités dans le namespace Item (ID: 120) | |||
const allPagesUrl = `${apiUrl}?action=query&list=allpages&apnamespace=120&aplimit=500&format=json`; | |||
const allPagesResponse = await fetch(allPagesUrl); | |||
const allPagesData = await allPagesResponse.json(); | |||
const entityIds = []; | |||
if (allPagesData.query?.allpages) { | |||
allPagesData.query.allpages.forEach(page => { | |||
const match = page.title.match(/^Item:(Q\d+)$/); | |||
if (match) entityIds.push(match[1]); | |||
}); | |||
} | |||
if (entityIds.length === 0) { | |||
container.innerHTML = "<p style='color: orange;'>Aucune entité trouvée dans le namespace Item (ID: 120).</p>"; | |||
return; | |||
} | |||
container.innerHTML = `<p>Trouvé ${entityIds.length} entités. Comptage en cours...</p>`; | |||
// Étape 2: Compter les entités par type (P1) | |||
const counts = {}; | |||
entityTypes.forEach(type => counts[type] = 0); | |||
// Traiter par lots de 50 (limite de wbgetentities) | |||
for (let i = 0; i < entityIds.length; i += 50) { | |||
const batch = entityIds.slice(i, i + 50); | |||
const batchUrl = `${apiUrl}?action=wbgetentities&ids=${batch.join('|')}&format=json&props=claims`; | |||
const batchResponse = await fetch(batchUrl); | |||
const batchData = await batchResponse.json(); | |||
if (batchData.entities) { | |||
for (const [id, entity] of Object.entries(batchData.entities)) { | |||
if (entity.claims?.P1) { | |||
entity.claims.P1.forEach(claim => { | |||
const targetId = claim.mainsnak?.datavalue?.value?.id; | |||
if (targetId && entityTypes.includes(targetId)) { | |||
counts[targetId]++; | |||
} | |||
}); | |||
} | |||
} | |||
} | |||
} | |||
// Afficher les résultats | |||
let html = '<ul style="list-style: none; padding: 0; margin: 0;">'; | |||
for (const [type, count] of Object.entries(counts)) { | |||
html += `<li style="margin: 5px 0;"><b>Type ${type}:</b> ${count} éléments</li>`; | |||
} | |||
const total = Object.values(counts).reduce((a, b) => a + b, 0); | |||
html += `<li style="margin: 5px 0; font-weight: bold;"><b>Total:</b> ${total} éléments</li></ul>`; | |||
container.innerHTML = html; | |||
} | |||
// Lancer le comptage quand la page est chargée | |||
document.addEventListener('DOMContentLoaded', countEntities); | |||
</script> | |||
== Consulter le référentiel == | == Consulter le référentiel == | ||
Revision as of 14:43, 19 May 2026
Bienvenue sur le référentiel des Bibliothèques Virtuelles Humanistes.
Statistiques des entités
Statistiques des entités
Chargement des statistiques...
<script> // Liste des types d'entités à compter const entityTypes = ["Q2", "Q5", "Q6", "Q7", "Q8"]; const results = {}; const apiUrl = window.location.origin + "/w/api.php";
// Fonction pour compter les entités via wbgetentities async function countEntities() {
const container = document.getElementById('entity-counts-container');
if (!container) {
console.error("Conteneur introuvable !");
return;
}
// Étape 1: Récupérer toutes les entités dans le namespace Item (ID: 120)
const allPagesUrl = `${apiUrl}?action=query&list=allpages&apnamespace=120&aplimit=500&format=json`;
const allPagesResponse = await fetch(allPagesUrl);
const allPagesData = await allPagesResponse.json();
const entityIds = [];
if (allPagesData.query?.allpages) {
allPagesData.query.allpages.forEach(page => {
const match = page.title.match(/^Item:(Q\d+)$/);
if (match) entityIds.push(match[1]);
});
}
if (entityIds.length === 0) {
container.innerHTML = "
Aucune entité trouvée dans le namespace Item (ID: 120).
";
return; }
container.innerHTML = `
Trouvé ${entityIds.length} entités. Comptage en cours...
`;
// Étape 2: Compter les entités par type (P1)
const counts = {};
entityTypes.forEach(type => counts[type] = 0);
// Traiter par lots de 50 (limite de wbgetentities)
for (let i = 0; i < entityIds.length; i += 50) {
const batch = entityIds.slice(i, i + 50);
const batchUrl = `${apiUrl}?action=wbgetentities&ids=${batch.join('|')}&format=json&props=claims`;
const batchResponse = await fetch(batchUrl);
const batchData = await batchResponse.json();
if (batchData.entities) {
for (const [id, entity] of Object.entries(batchData.entities)) {
if (entity.claims?.P1) {
entity.claims.P1.forEach(claim => {
const targetId = claim.mainsnak?.datavalue?.value?.id;
if (targetId && entityTypes.includes(targetId)) {
counts[targetId]++;
}
});
}
}
}
}
// Afficher les résultats
let html = '
- ';
for (const [type, count] of Object.entries(counts)) {
html += `
- Type ${type}: ${count} éléments `; } const total = Object.values(counts).reduce((a, b) => a + b, 0); html += `
- Total: ${total} éléments
`;
container.innerHTML = html;
}
// Lancer le comptage quand la page est chargée document.addEventListener('DOMContentLoaded', countEntities); </script>
Consulter le référentiel
Contribuer au référentiel
Démarrer avec Wikibase
- Configuration settings list
- MediaWiki FAQ
- MediaWiki release mailing list
- Localise MediaWiki for your language
- Learn how to combat spam on your wiki
Consult the User's Guide for information on using the wiki software.
