Girilen metindeki olumlu ve olumsuz kelimelere göre basit bir duygu analizi yapan uygulama.
HTML:
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Duygu Analizi</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
.container {
text-align: center;
}
textarea {
width: 300px;
height: 100px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>Duygu Analizi</h1>
<textarea id="textInput" placeholder="Metin girin..."></textarea><br>
<button onclick="analyzeSentiment()">Analiz Et</button>
<p id="result"></p>
</div>
<script>
function analyzeSentiment() {
var positiveWords = ['iyi', 'harika', 'mükemmel', 'güzel', 'mutlu'];
var negativeWords = ['kötü', 'berbat', 'feci', 'korkunç', 'üzgün'];
var text = document.getElementById('textInput').value.toLowerCase();
var positiveCount = 0;
var negativeCount = 0;
positiveWords.forEach(function(word) {
if (text.includes(word)) {
positiveCount++;
}
});
negativeWords.forEach(function(word) {
if (text.includes(word)) {
negativeCount++;
}
});
var result = 'Nötr';
if (positiveCount > negativeCount) {
result = 'Olumlu';
} else if (negativeCount > positiveCount) {
result = 'Olumsuz';
}
document.getElementById('result').textContent = `Duygu Analizi Sonucu: ${result}`;
}
</script>
</body>
</html>