File size: 17,844 Bytes
34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 41b19b0 b1f7536 41b19b0 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 b1f7536 34dee13 | 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nuage de Mots - Analyseur de Texte</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.word-cloud {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 10px;
padding: 20px;
min-height: 300px;
background-color: #f8fafc;
border-radius: 0.5rem;
box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}
.word-item {
display: inline-block;
transition: all 0.3s ease;
cursor: default;
}
.word-item:hover {
transform: scale(1.1);
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-5px); }
100% { transform: translateY(0px); }
}
.floating {
animation: float 3s ease-in-out infinite;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8">
<header class="text-center mb-8">
<h1 class="text-3xl md:text-4xl font-bold text-indigo-700 mb-2">Nuage de Mots</h1>
<p class="text-gray-600">Analysez la fréquence des mots dans votre texte</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Entrez votre texte</h2>
<textarea id="text-input" class="w-full h-64 p-4 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500" placeholder="Collez ou écrivez votre texte ici..."></textarea>
<div class="flex flex-wrap gap-3 mt-4">
<button id="generate-btn" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors">
Générer le nuage
</button>
<button id="clear-btn" class="px-6 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition-colors">
Effacer
</button>
<div class="flex items-center ml-auto">
<label for="max-words" class="mr-2 text-sm text-gray-600">Mots max:</label>
<input type="number" id="max-words" min="10" max="100" value="50" class="w-16 p-1 border border-gray-300 rounded">
</div>
</div>
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-2">Options</h3>
<div class="flex flex-wrap gap-4">
<label class="inline-flex items-center">
<input type="checkbox" id="ignore-case" checked class="rounded text-indigo-600">
<span class="ml-2 text-gray-700">Ignorer la casse</span>
</label>
<label class="inline-flex items-center">
<input type="checkbox" id="ignore-common" checked class="rounded text-indigo-600">
<span class="ml-2 text-gray-700">Ignorer mots courants</span>
</label>
<label class="inline-flex items-center">
<input type="checkbox" id="animate" checked class="rounded text-indigo-600">
<span class="ml-2 text-gray-700">Animation</span>
</label>
</div>
</div>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Résultats</h2>
<div id="word-cloud-container" class="word-cloud">
<p class="text-gray-400">Le nuage de mots apparaîtra ici</p>
</div>
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-2">Statistiques</h3>
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="bg-indigo-50 p-3 rounded-lg">
<p class="text-sm text-indigo-600">Mots uniques</p>
<p id="unique-words" class="text-2xl font-bold text-indigo-800">0</p>
</div>
<div class="bg-blue-50 p-3 rounded-lg">
<p class="text-sm text-blue-600">Mots totaux</p>
<p id="total-words" class="text-2xl font-bold text-blue-800">0</p>
</div>
<div class="bg-purple-50 p-3 rounded-lg">
<p class="text-sm text-purple-600">Mots analysés</p>
<p id="analyzed-words" class="text-2xl font-bold text-purple-800">0</p>
</div>
<div class="bg-pink-50 p-3 rounded-lg">
<p class="text-sm text-pink-600">Densité</p>
<p id="density" class="text-2xl font-bold text-pink-800">0%</p>
</div>
</div>
</div>
<div class="mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-2">Top 10 des mots</h3>
<div class="h-64">
<canvas id="chart"></canvas>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const textInput = document.getElementById('text-input');
const generateBtn = document.getElementById('generate-btn');
const clearBtn = document.getElementById('clear-btn');
const wordCloudContainer = document.getElementById('word-cloud-container');
const maxWordsInput = document.getElementById('max-words');
const ignoreCaseCheckbox = document.getElementById('ignore-case');
const ignoreCommonCheckbox = document.getElementById('ignore-common');
const animateCheckbox = document.getElementById('animate');
// Elements for statistics
const uniqueWordsEl = document.getElementById('unique-words');
const totalWordsEl = document.getElementById('total-words');
const analyzedWordsEl = document.getElementById('analyzed-words');
const densityEl = document.getElementById('density');
let chart = null;
// Common words to ignore (French)
const commonWords = new Set([
'le', 'la', 'les', 'de', 'des', 'un', 'une', 'et', 'est', 'que',
'qui', 'dans', 'en', 'au', 'aux', 'pour', 'par', 'sur', 'avec',
'il', 'elle', 'on', 'nous', 'vous', 'ils', 'elles', 'ce', 'cet',
'cette', 'ces', 'son', 'sa', 'ses', 'leur', 'leurs', 'du', 'pas',
'mais', 'ou', 'où', 'si', 'ne', 'se', 'sans', 'sous', 'vers', 'à'
]);
// Color palette for words
const colors = [
'text-indigo-600', 'text-blue-600', 'text-green-600',
'text-yellow-600', 'text-red-600', 'text-purple-600',
'text-pink-600', 'text-gray-600', 'text-teal-600',
'text-orange-600'
];
generateBtn.addEventListener('click', generateWordCloud);
clearBtn.addEventListener('click', clearAll);
function clearAll() {
textInput.value = '';
wordCloudContainer.innerHTML = '<p class="text-gray-400">Le nuage de mots apparaîtra ici</p>';
updateStatistics(0, 0, 0);
if (chart) {
chart.destroy();
chart = null;
}
}
function generateWordCloud() {
const text = textInput.value.trim();
if (!text) {
alert('Veuillez entrer du texte à analyser');
return;
}
// Process text and count words
const words = processText(text);
const wordCounts = countWords(words);
const sortedWords = sortWords(wordCounts);
// Limit to max words
const maxWords = parseInt(maxWordsInput.value) || 50;
const limitedWords = sortedWords.slice(0, maxWords);
// Update statistics
updateStatistics(
Object.keys(wordCounts).length,
words.length,
limitedWords.length
);
// Generate word cloud
generateWordCloudVisual(limitedWords);
// Generate chart
generateChart(limitedWords.slice(0, 10));
}
function processText(text) {
// Remove punctuation and split into words
const cleanedText = text.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()«»'"…]/g, '');
// Split into words
let words = cleanedText.split(/\s+/);
// Filter empty strings
words = words.filter(word => word.length > 0);
// Ignore case if needed
if (ignoreCaseCheckbox.checked) {
words = words.map(word => word.toLowerCase());
}
// Ignore common words if needed
if (ignoreCommonCheckbox.checked) {
words = words.filter(word => !commonWords.has(word.toLowerCase()));
}
return words;
}
function countWords(words) {
const counts = {};
for (const word of words) {
if (counts[word]) {
counts[word]++;
} else {
counts[word] = 1;
}
}
return counts;
}
function sortWords(wordCounts) {
return Object.entries(wordCounts)
.map(([word, count]) => ({ word, count }))
.sort((a, b) => b.count - a.count);
}
function generateWordCloudVisual(wordsData) {
if (wordsData.length === 0) {
wordCloudContainer.innerHTML = '<p class="text-gray-400">Aucun mot à afficher après filtrage</p>';
return;
}
// Find min and max counts for scaling
const counts = wordsData.map(item => item.count);
const maxCount = Math.max(...counts);
const minCount = Math.min(...counts);
wordCloudContainer.innerHTML = '';
wordsData.forEach(item => {
// Calculate font size based on frequency (logarithmic scale)
const scale = Math.log(item.count) / Math.log(maxCount);
const fontSize = 12 + (scale * 36); // Between 12px and 48px
// Random rotation between -30 and 30 degrees
const rotation = Math.floor(Math.random() * 60) - 30;
// Random color from palette
const color = colors[Math.floor(Math.random() * colors.length)];
// Create word element
const wordEl = document.createElement('div');
wordEl.className = `word-item ${color} ${animateCheckbox.checked ? 'floating' : ''}`;
wordEl.style.fontSize = `${fontSize}px`;
wordEl.style.transform = `rotate(${rotation}deg)`;
wordEl.style.opacity = 0.8 + (scale * 0.2); // More opaque for larger words
wordEl.textContent = item.word;
// Add tooltip with count
wordEl.title = `Apparaît ${item.count} fois`;
wordCloudContainer.appendChild(wordEl);
});
}
function updateStatistics(uniqueWords, totalWords, analyzedWords) {
uniqueWordsEl.textContent = uniqueWords;
totalWordsEl.textContent = totalWords;
analyzedWordsEl.textContent = analyzedWords;
// Calculate density (percentage of unique words)
const density = totalWords > 0 ? (uniqueWords / totalWords * 100).toFixed(1) : 0;
densityEl.textContent = `${density}%`;
}
function generateChart(topWords) {
const ctx = document.getElementById('chart').getContext('2d');
// Destroy previous chart if exists
if (chart) {
chart.destroy();
}
if (topWords.length === 0) {
return;
}
const labels = topWords.map(item => item.word);
const data = topWords.map(item => item.count);
chart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Fréquence',
data: data,
backgroundColor: [
'rgba(79, 70, 229, 0.7)',
'rgba(59, 130, 246, 0.7)',
'rgba(16, 185, 129, 0.7)',
'rgba(234, 179, 8, 0.7)',
'rgba(239, 68, 68, 0.7)',
'rgba(139, 92, 246, 0.7)',
'rgba(236, 72, 153, 0.7)',
'rgba(75, 85, 99, 0.7)',
'rgba(20, 184, 166, 0.7)',
'rgba(249, 115, 22, 0.7)'
],
borderColor: [
'rgba(79, 70, 229, 1)',
'rgba(59, 130, 246, 1)',
'rgba(16, 185, 129, 1)',
'rgba(234, 179, 8, 1)',
'rgba(239, 68, 68, 1)',
'rgba(139, 92, 246, 1)',
'rgba(236, 72, 153, 1)',
'rgba(75, 85, 99, 1)',
'rgba(20, 184, 166, 1)',
'rgba(249, 115, 22, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Nombre d\'occurrences'
}
},
x: {
title: {
display: true,
text: 'Mots'
}
}
},
plugins: {
legend: {
display: false
},
tooltip: {
callbacks: {
label: function(context) {
return `Fréquence: ${context.raw}`;
}
}
}
}
}
});
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=masterseb/nuage" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |