Spaces:
Running
Running
File size: 4,811 Bytes
5621ad9 606f214 5621ad9 e4f2993 5621ad9 606f214 5621ad9 8b0d0d3 5621ad9 606f214 5621ad9 8b0d0d3 5621ad9 606f214 5621ad9 606f214 5621ad9 606f214 6103a62 606f214 5621ad9 606f214 5621ad9 606f214 5621ad9 21d97a8 606f214 6103a62 5621ad9 6103a62 606f214 5621ad9 606f214 5621ad9 606f214 5621ad9 606f214 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
import { useMemo, useRef } from "react";
const LANGUAGE_FAMILIES = {
"Indo-European": {
Germanic: ["english", "german", "dutch", "danish", "swedish", "icelandic"],
Romance: [
"french",
"spanish",
"italian",
"portuguese",
"romanian",
"catalan",
"galician",
],
Slavic: [
"russian",
"polish",
"czech",
"slovak",
"ukrainian",
"bulgarian",
"slovenian",
"serbian",
"croatian",
],
Baltic: ["lithuanian", "latvian"],
"Indo-Iranian": [
"persian",
"hindi",
"bengali",
"gujarati",
"nepali",
"marathi",
"indic",
],
Greek: ["greek"],
Armenian: ["armenian"],
},
"Sino-Tibetan": ["chinese", "mandarin", "taiwanese"],
Afroasiatic: [
"arabic",
"hebrew",
"darija", // Variante de l'arabe
],
Austronesian: [
"indonesian",
"malay",
"filipino",
"singlish", // Créole basé sur l'anglais mais avec influence malaise
],
"Niger-Congo": ["swahili", "yoruba"],
Dravidian: ["tamil", "telugu", "kannada", "malayalam"],
Austroasiatic: ["vietnamese"],
"Kra-Dai": ["thai"],
Japonic: [
"japanese",
"日本語", // Japonais en caractères japonais
],
Koreanic: ["korean"],
Uralic: ["hungarian", "finnish", "estonian"],
Turkic: ["turkish", "azerbaijani", "uzbek", "kazakh"],
"Language Isolate": [
"basque", // Langue isolée, pas de famille connue
],
"Other Languages": [], // Will catch any language not in other families
};
const FAMILY_ORDER = [
"Indo-European", // Plus grande famille en Europe et Asie du Sud
"Sino-Tibetan", // Deuxième plus grande famille en Asie
"Afroasiatic", // Principale famille en Afrique du Nord et Moyen-Orient
"Austronesian", // Principale famille en Asie du Sud-Est insulaire
"Niger-Congo", // Plus grande famille en Afrique subsaharienne
"Dravidian", // Principale famille en Inde du Sud
"Austroasiatic", // Importante en Asie du Sud-Est continentale
"Kra-Dai", // Famille du thaï
"Japonic", // Japonais
"Koreanic", // Coréen
"Uralic", // Famille finno-ougrienne
"Turkic", // Famille des langues turciques
"Language Isolate", // Langues isolées
"Other Languages", // Autres langues non classifiées
];
const findLanguageFamily = (language) => {
for (const [family, content] of Object.entries(LANGUAGE_FAMILIES)) {
if (family === "Indo-European") {
// Cas spécial pour l'Indo-Européen qui a des sous-familles
for (const [subFamily, languages] of Object.entries(content)) {
if (languages.includes(language.toLowerCase())) {
return { family, subFamily };
}
}
} else if (content.includes(language.toLowerCase())) {
return { family, subFamily: language };
}
}
return { family: "Other Languages", subFamily: language };
};
export const useLanguageStats = (leaderboards, filteredLeaderboards) => {
const statsRef = useRef(null);
const languagesRef = useRef(null);
// Reset stats when leaderboards or filteredLeaderboards change
if (leaderboards && filteredLeaderboards) {
// Calculate unique languages from all leaderboards
const langMap = new Map();
const langFamilyMap = new Map();
leaderboards.forEach((board) => {
board.tags?.forEach((tag) => {
if (tag.toLowerCase().startsWith("language:")) {
const lang = tag.split(":")[1].toLowerCase();
langMap.set(lang, (langMap.get(lang) || 0) + 1);
const { family } = findLanguageFamily(lang);
langFamilyMap.set(family, (langFamilyMap.get(family) || 0) + 1);
}
});
});
const langArray = Array.from(langMap.entries()).map(([lang, count]) => {
const { family } = findLanguageFamily(lang);
return [lang, count, family];
});
languagesRef.current = langArray
.sort((a, b) => {
const familyA = a[2];
const familyB = b[2];
const orderA = FAMILY_ORDER.indexOf(familyA);
const orderB = FAMILY_ORDER.indexOf(familyB);
if (orderA !== orderB) {
return orderA - orderB;
}
// Sort alphabetically by language name instead of by count
return a[0].localeCompare(b[0]);
})
.map(([lang]) => lang);
// Calculate stats based on filtered leaderboards
statsRef.current = new Map();
languagesRef.current.forEach((lang) => {
const count = filteredLeaderboards.filter((board) =>
board.tags?.some(
(tag) => tag.toLowerCase() === `language:${lang.toLowerCase()}`
)
).length;
statsRef.current.set(lang, count);
});
}
return {
languages: languagesRef.current,
languageStats: statsRef.current,
LANGUAGE_FAMILIES,
findLanguageFamily,
};
};
|